
(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 8 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-define100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (- x))))
(if (<= z -6.2e+185)
t_0
(if (<= z -2.15e+142)
(* y z)
(if (<= z -1.1e+40)
t_0
(if (<= z -1.55e-81)
(* y z)
(if (<= z 1.0)
x
(if (or (<= z 6.7e+87) (not (<= z 1.05e+157))) t_0 (* y z)))))))))
double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (z <= -6.2e+185) {
tmp = t_0;
} else if (z <= -2.15e+142) {
tmp = y * z;
} else if (z <= -1.1e+40) {
tmp = t_0;
} else if (z <= -1.55e-81) {
tmp = y * z;
} else if (z <= 1.0) {
tmp = x;
} else if ((z <= 6.7e+87) || !(z <= 1.05e+157)) {
tmp = t_0;
} else {
tmp = y * 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) :: t_0
real(8) :: tmp
t_0 = z * -x
if (z <= (-6.2d+185)) then
tmp = t_0
else if (z <= (-2.15d+142)) then
tmp = y * z
else if (z <= (-1.1d+40)) then
tmp = t_0
else if (z <= (-1.55d-81)) then
tmp = y * z
else if (z <= 1.0d0) then
tmp = x
else if ((z <= 6.7d+87) .or. (.not. (z <= 1.05d+157))) then
tmp = t_0
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (z <= -6.2e+185) {
tmp = t_0;
} else if (z <= -2.15e+142) {
tmp = y * z;
} else if (z <= -1.1e+40) {
tmp = t_0;
} else if (z <= -1.55e-81) {
tmp = y * z;
} else if (z <= 1.0) {
tmp = x;
} else if ((z <= 6.7e+87) || !(z <= 1.05e+157)) {
tmp = t_0;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): t_0 = z * -x tmp = 0 if z <= -6.2e+185: tmp = t_0 elif z <= -2.15e+142: tmp = y * z elif z <= -1.1e+40: tmp = t_0 elif z <= -1.55e-81: tmp = y * z elif z <= 1.0: tmp = x elif (z <= 6.7e+87) or not (z <= 1.05e+157): tmp = t_0 else: tmp = y * z return tmp
function code(x, y, z) t_0 = Float64(z * Float64(-x)) tmp = 0.0 if (z <= -6.2e+185) tmp = t_0; elseif (z <= -2.15e+142) tmp = Float64(y * z); elseif (z <= -1.1e+40) tmp = t_0; elseif (z <= -1.55e-81) tmp = Float64(y * z); elseif (z <= 1.0) tmp = x; elseif ((z <= 6.7e+87) || !(z <= 1.05e+157)) tmp = t_0; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * -x; tmp = 0.0; if (z <= -6.2e+185) tmp = t_0; elseif (z <= -2.15e+142) tmp = y * z; elseif (z <= -1.1e+40) tmp = t_0; elseif (z <= -1.55e-81) tmp = y * z; elseif (z <= 1.0) tmp = x; elseif ((z <= 6.7e+87) || ~((z <= 1.05e+157))) tmp = t_0; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-x)), $MachinePrecision]}, If[LessEqual[z, -6.2e+185], t$95$0, If[LessEqual[z, -2.15e+142], N[(y * z), $MachinePrecision], If[LessEqual[z, -1.1e+40], t$95$0, If[LessEqual[z, -1.55e-81], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.0], x, If[Or[LessEqual[z, 6.7e+87], N[Not[LessEqual[z, 1.05e+157]], $MachinePrecision]], t$95$0, N[(y * z), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-x\right)\\
\mathbf{if}\;z \leq -6.2 \cdot 10^{+185}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -2.15 \cdot 10^{+142}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -1.1 \cdot 10^{+40}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -1.55 \cdot 10^{-81}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 6.7 \cdot 10^{+87} \lor \neg \left(z \leq 1.05 \cdot 10^{+157}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -6.19999999999999999e185 or -2.15000000000000006e142 < z < -1.0999999999999999e40 or 1 < z < 6.7000000000000003e87 or 1.05e157 < z Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-lft-in94.3%
Applied egg-rr94.3%
associate-+r+94.3%
distribute-rgt-neg-out94.3%
unsub-neg94.3%
+-commutative94.3%
Applied egg-rr94.3%
Taylor expanded in z around inf 98.7%
Taylor expanded in y around 0 68.3%
mul-1-neg68.3%
distribute-rgt-neg-in68.3%
Simplified68.3%
if -6.19999999999999999e185 < z < -2.15000000000000006e142 or -1.0999999999999999e40 < z < -1.54999999999999994e-81 or 6.7000000000000003e87 < z < 1.05e157Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-lft-in100.0%
Applied egg-rr100.0%
associate-+r+100.0%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
+-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in y around inf 78.0%
*-commutative78.0%
Simplified78.0%
if -1.54999999999999994e-81 < z < 1Initial program 100.0%
Taylor expanded in z around 0 73.4%
Final simplification72.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -60000000000000.0) (not (<= z 1.0))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -60000000000000.0) || !(z <= 1.0)) {
tmp = (y - x) * z;
} else {
tmp = x + (y * 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 ((z <= (-60000000000000.0d0)) .or. (.not. (z <= 1.0d0))) then
tmp = (y - x) * z
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -60000000000000.0) || !(z <= 1.0)) {
tmp = (y - x) * z;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -60000000000000.0) or not (z <= 1.0): tmp = (y - x) * z else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -60000000000000.0) || !(z <= 1.0)) tmp = Float64(Float64(y - x) * z); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -60000000000000.0) || ~((z <= 1.0))) tmp = (y - x) * z; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -60000000000000.0], N[Not[LessEqual[z, 1.0]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -60000000000000 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if z < -6e13 or 1 < z Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-lft-in95.6%
Applied egg-rr95.6%
associate-+r+95.6%
distribute-rgt-neg-out95.6%
unsub-neg95.6%
+-commutative95.6%
Applied egg-rr95.6%
Taylor expanded in z around inf 99.0%
if -6e13 < z < 1Initial program 100.0%
Taylor expanded in y around inf 99.1%
*-commutative99.1%
Simplified99.1%
Final simplification99.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -5.5e-82) (not (<= z 2.4e+14))) (* (- y x) z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5.5e-82) || !(z <= 2.4e+14)) {
tmp = (y - x) * 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 ((z <= (-5.5d-82)) .or. (.not. (z <= 2.4d+14))) then
tmp = (y - x) * 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 ((z <= -5.5e-82) || !(z <= 2.4e+14)) {
tmp = (y - x) * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -5.5e-82) or not (z <= 2.4e+14): tmp = (y - x) * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -5.5e-82) || !(z <= 2.4e+14)) tmp = Float64(Float64(y - x) * z); else tmp = Float64(x * Float64(1.0 - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -5.5e-82) || ~((z <= 2.4e+14))) tmp = (y - x) * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -5.5e-82], N[Not[LessEqual[z, 2.4e+14]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.5 \cdot 10^{-82} \lor \neg \left(z \leq 2.4 \cdot 10^{+14}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if z < -5.4999999999999998e-82 or 2.4e14 < z Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-lft-in95.8%
Applied egg-rr95.8%
associate-+r+95.8%
distribute-rgt-neg-out95.8%
unsub-neg95.8%
+-commutative95.8%
Applied egg-rr95.8%
Taylor expanded in z around inf 97.5%
if -5.4999999999999998e-82 < z < 2.4e14Initial program 100.0%
Taylor expanded in x around inf 74.5%
mul-1-neg74.5%
unsub-neg74.5%
Simplified74.5%
Final simplification87.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.1e-92) (not (<= x 3.6e-88))) (* x (- 1.0 z)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.1e-92) || !(x <= 3.6e-88)) {
tmp = x * (1.0 - z);
} else {
tmp = y * 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 ((x <= (-5.1d-92)) .or. (.not. (x <= 3.6d-88))) then
tmp = x * (1.0d0 - z)
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -5.1e-92) || !(x <= 3.6e-88)) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.1e-92) or not (x <= 3.6e-88): tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.1e-92) || !(x <= 3.6e-88)) tmp = Float64(x * Float64(1.0 - z)); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -5.1e-92) || ~((x <= 3.6e-88))) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.1e-92], N[Not[LessEqual[x, 3.6e-88]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.1 \cdot 10^{-92} \lor \neg \left(x \leq 3.6 \cdot 10^{-88}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -5.09999999999999972e-92 or 3.5999999999999999e-88 < x Initial program 100.0%
Taylor expanded in x around inf 80.6%
mul-1-neg80.6%
unsub-neg80.6%
Simplified80.6%
if -5.09999999999999972e-92 < x < 3.5999999999999999e-88Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-lft-in100.0%
Applied egg-rr100.0%
associate-+r+100.0%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
+-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in y around inf 74.3%
*-commutative74.3%
Simplified74.3%
Final simplification78.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.65e-81) (not (<= z 1.2e-7))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.65e-81) || !(z <= 1.2e-7)) {
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 <= (-1.65d-81)) .or. (.not. (z <= 1.2d-7))) 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 <= -1.65e-81) || !(z <= 1.2e-7)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.65e-81) or not (z <= 1.2e-7): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.65e-81) || !(z <= 1.2e-7)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.65e-81) || ~((z <= 1.2e-7))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.65e-81], N[Not[LessEqual[z, 1.2e-7]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.65 \cdot 10^{-81} \lor \neg \left(z \leq 1.2 \cdot 10^{-7}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.64999999999999994e-81 or 1.19999999999999989e-7 < z Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-lft-in96.0%
Applied egg-rr96.0%
associate-+r+96.0%
distribute-rgt-neg-out96.0%
unsub-neg96.0%
+-commutative96.0%
Applied egg-rr96.0%
Taylor expanded in y around inf 51.0%
*-commutative51.0%
Simplified51.0%
if -1.64999999999999994e-81 < z < 1.19999999999999989e-7Initial program 100.0%
Taylor expanded in z around 0 73.4%
Final simplification60.3%
(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%
(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 33.6%
herbie shell --seed 2024096
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))