
(FPCore (x y z) :precision binary64 (+ x (* (- y x) z)))
double code(double x, double y, double z) {
return x + ((y - x) * z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + ((y - x) * z)
end function
public static double code(double x, double y, double z) {
return x + ((y - x) * z);
}
def code(x, y, z): return x + ((y - x) * z)
function code(x, y, z) return Float64(x + Float64(Float64(y - x) * z)) end
function tmp = code(x, y, z) tmp = x + ((y - x) * z); end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - x\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (* (- y x) z)))
double code(double x, double y, double z) {
return x + ((y - x) * z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + ((y - x) * z)
end function
public static double code(double x, double y, double z) {
return x + ((y - x) * z);
}
def code(x, y, z): return x + ((y - x) * z)
function code(x, y, z) return Float64(x + Float64(Float64(y - x) * z)) end
function tmp = code(x, y, z) tmp = x + ((y - x) * z); end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - x\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (fma (- y x) z x))
double code(double x, double y, double z) {
return fma((y - x), z, x);
}
function code(x, y, z) return fma(Float64(y - x), z, x) end
code[x_, y_, z_] := N[(N[(y - x), $MachinePrecision] * z + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y - x, z, x\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- z))))
(if (<= z -2.7e+232)
t_0
(if (<= z -2.2e+136)
(* y z)
(if (<= z -4e+110)
t_0
(if (<= z -4.6e+65)
(* y z)
(if (<= z -5e+49)
t_0
(if (<= z -7e-41) (* y z) (if (<= z 1.0) x t_0)))))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -2.7e+232) {
tmp = t_0;
} else if (z <= -2.2e+136) {
tmp = y * z;
} else if (z <= -4e+110) {
tmp = t_0;
} else if (z <= -4.6e+65) {
tmp = y * z;
} else if (z <= -5e+49) {
tmp = t_0;
} else if (z <= -7e-41) {
tmp = y * z;
} else if (z <= 1.0) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = x * -z
if (z <= (-2.7d+232)) then
tmp = t_0
else if (z <= (-2.2d+136)) then
tmp = y * z
else if (z <= (-4d+110)) then
tmp = t_0
else if (z <= (-4.6d+65)) then
tmp = y * z
else if (z <= (-5d+49)) then
tmp = t_0
else if (z <= (-7d-41)) then
tmp = y * z
else if (z <= 1.0d0) then
tmp = x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -2.7e+232) {
tmp = t_0;
} else if (z <= -2.2e+136) {
tmp = y * z;
} else if (z <= -4e+110) {
tmp = t_0;
} else if (z <= -4.6e+65) {
tmp = y * z;
} else if (z <= -5e+49) {
tmp = t_0;
} else if (z <= -7e-41) {
tmp = y * z;
} else if (z <= 1.0) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -2.7e+232: tmp = t_0 elif z <= -2.2e+136: tmp = y * z elif z <= -4e+110: tmp = t_0 elif z <= -4.6e+65: tmp = y * z elif z <= -5e+49: tmp = t_0 elif z <= -7e-41: tmp = y * z elif z <= 1.0: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-z)) tmp = 0.0 if (z <= -2.7e+232) tmp = t_0; elseif (z <= -2.2e+136) tmp = Float64(y * z); elseif (z <= -4e+110) tmp = t_0; elseif (z <= -4.6e+65) tmp = Float64(y * z); elseif (z <= -5e+49) tmp = t_0; elseif (z <= -7e-41) tmp = Float64(y * z); elseif (z <= 1.0) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -z; tmp = 0.0; if (z <= -2.7e+232) tmp = t_0; elseif (z <= -2.2e+136) tmp = y * z; elseif (z <= -4e+110) tmp = t_0; elseif (z <= -4.6e+65) tmp = y * z; elseif (z <= -5e+49) tmp = t_0; elseif (z <= -7e-41) tmp = y * z; elseif (z <= 1.0) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-z)), $MachinePrecision]}, If[LessEqual[z, -2.7e+232], t$95$0, If[LessEqual[z, -2.2e+136], N[(y * z), $MachinePrecision], If[LessEqual[z, -4e+110], t$95$0, If[LessEqual[z, -4.6e+65], N[(y * z), $MachinePrecision], If[LessEqual[z, -5e+49], t$95$0, If[LessEqual[z, -7e-41], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.0], x, t$95$0]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -2.7 \cdot 10^{+232}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -2.2 \cdot 10^{+136}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -4 \cdot 10^{+110}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -4.6 \cdot 10^{+65}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -5 \cdot 10^{+49}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -7 \cdot 10^{-41}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -2.7000000000000001e232 or -2.1999999999999999e136 < z < -4.0000000000000001e110 or -4.6e65 < z < -5.0000000000000004e49 or 1 < z Initial program 100.0%
Taylor expanded in x around inf 72.6%
mul-1-neg72.6%
unsub-neg72.6%
Simplified72.6%
Taylor expanded in z around inf 72.5%
associate-*r*72.5%
mul-1-neg72.5%
Simplified72.5%
if -2.7000000000000001e232 < z < -2.1999999999999999e136 or -4.0000000000000001e110 < z < -4.6e65 or -5.0000000000000004e49 < z < -6.9999999999999999e-41Initial program 100.0%
Taylor expanded in y around inf 77.7%
*-commutative77.7%
Simplified77.7%
Taylor expanded in x around 0 75.0%
*-commutative75.0%
Simplified75.0%
if -6.9999999999999999e-41 < z < 1Initial program 100.0%
Taylor expanded in z around 0 80.1%
Final simplification76.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.8e+18) (not (<= y 4.2e+69))) (* y z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.8e+18) || !(y <= 4.2e+69)) {
tmp = y * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((y <= (-5.8d+18)) .or. (.not. (y <= 4.2d+69))) then
tmp = y * z
else
tmp = x * (1.0d0 - z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -5.8e+18) || !(y <= 4.2e+69)) {
tmp = y * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.8e+18) or not (y <= 4.2e+69): tmp = y * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.8e+18) || !(y <= 4.2e+69)) tmp = Float64(y * z); else tmp = Float64(x * Float64(1.0 - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -5.8e+18) || ~((y <= 4.2e+69))) tmp = y * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.8e+18], N[Not[LessEqual[y, 4.2e+69]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.8 \cdot 10^{+18} \lor \neg \left(y \leq 4.2 \cdot 10^{+69}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < -5.8e18 or 4.2000000000000003e69 < y Initial program 100.0%
Taylor expanded in y around inf 96.7%
*-commutative96.7%
Simplified96.7%
Taylor expanded in x around 0 76.1%
*-commutative76.1%
Simplified76.1%
if -5.8e18 < y < 4.2000000000000003e69Initial program 100.0%
Taylor expanded in x around inf 89.2%
mul-1-neg89.2%
unsub-neg89.2%
Simplified89.2%
Final simplification84.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.2e-58) (not (<= y 3.7e-28))) (+ x (* y z)) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.2e-58) || !(y <= 3.7e-28)) {
tmp = x + (y * z);
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((y <= (-5.2d-58)) .or. (.not. (y <= 3.7d-28))) then
tmp = x + (y * z)
else
tmp = x * (1.0d0 - z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -5.2e-58) || !(y <= 3.7e-28)) {
tmp = x + (y * z);
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.2e-58) or not (y <= 3.7e-28): tmp = x + (y * z) else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.2e-58) || !(y <= 3.7e-28)) tmp = Float64(x + Float64(y * z)); else tmp = Float64(x * Float64(1.0 - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -5.2e-58) || ~((y <= 3.7e-28))) tmp = x + (y * z); else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.2e-58], N[Not[LessEqual[y, 3.7e-28]], $MachinePrecision]], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.2 \cdot 10^{-58} \lor \neg \left(y \leq 3.7 \cdot 10^{-28}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < -5.20000000000000013e-58 or 3.7000000000000002e-28 < y Initial program 100.0%
Taylor expanded in y around inf 94.5%
*-commutative94.5%
Simplified94.5%
if -5.20000000000000013e-58 < y < 3.7000000000000002e-28Initial program 100.0%
Taylor expanded in x around inf 94.5%
mul-1-neg94.5%
unsub-neg94.5%
Simplified94.5%
Final simplification94.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -8e-41) (not (<= z 3.5e-5))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -8e-41) || !(z <= 3.5e-5)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((z <= (-8d-41)) .or. (.not. (z <= 3.5d-5))) then
tmp = y * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -8e-41) || !(z <= 3.5e-5)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -8e-41) or not (z <= 3.5e-5): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -8e-41) || !(z <= 3.5e-5)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -8e-41) || ~((z <= 3.5e-5))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -8e-41], N[Not[LessEqual[z, 3.5e-5]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8 \cdot 10^{-41} \lor \neg \left(z \leq 3.5 \cdot 10^{-5}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -8.00000000000000005e-41 or 3.4999999999999997e-5 < z Initial program 100.0%
Taylor expanded in y around inf 53.6%
*-commutative53.6%
Simplified53.6%
Taylor expanded in x around 0 52.4%
*-commutative52.4%
Simplified52.4%
if -8.00000000000000005e-41 < z < 3.4999999999999997e-5Initial program 100.0%
Taylor expanded in z around 0 80.1%
Final simplification65.4%
(FPCore (x y z) :precision binary64 (+ x (* (- y x) z)))
double code(double x, double y, double z) {
return x + ((y - x) * z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + ((y - x) * z)
end function
public static double code(double x, double y, double z) {
return x + ((y - x) * z);
}
def code(x, y, z): return x + ((y - x) * z)
function code(x, y, z) return Float64(x + Float64(Float64(y - x) * z)) end
function tmp = code(x, y, z) tmp = x + ((y - x) * z); end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - x\right) \cdot z
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in z around 0 39.0%
Final simplification39.0%
herbie shell --seed 2024011
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))