
(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%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- z))))
(if (<= z -2.05e+211)
(* y z)
(if (<= z -8.5e+137)
t_0
(if (<= z -1.05e-108)
(* y z)
(if (<= z 2.8e-37) x (if (<= z 2.6e+144) (* y z) t_0)))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -2.05e+211) {
tmp = y * z;
} else if (z <= -8.5e+137) {
tmp = t_0;
} else if (z <= -1.05e-108) {
tmp = y * z;
} else if (z <= 2.8e-37) {
tmp = x;
} else if (z <= 2.6e+144) {
tmp = y * z;
} 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.05d+211)) then
tmp = y * z
else if (z <= (-8.5d+137)) then
tmp = t_0
else if (z <= (-1.05d-108)) then
tmp = y * z
else if (z <= 2.8d-37) then
tmp = x
else if (z <= 2.6d+144) then
tmp = y * z
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.05e+211) {
tmp = y * z;
} else if (z <= -8.5e+137) {
tmp = t_0;
} else if (z <= -1.05e-108) {
tmp = y * z;
} else if (z <= 2.8e-37) {
tmp = x;
} else if (z <= 2.6e+144) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -2.05e+211: tmp = y * z elif z <= -8.5e+137: tmp = t_0 elif z <= -1.05e-108: tmp = y * z elif z <= 2.8e-37: tmp = x elif z <= 2.6e+144: tmp = y * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-z)) tmp = 0.0 if (z <= -2.05e+211) tmp = Float64(y * z); elseif (z <= -8.5e+137) tmp = t_0; elseif (z <= -1.05e-108) tmp = Float64(y * z); elseif (z <= 2.8e-37) tmp = x; elseif (z <= 2.6e+144) tmp = Float64(y * z); 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.05e+211) tmp = y * z; elseif (z <= -8.5e+137) tmp = t_0; elseif (z <= -1.05e-108) tmp = y * z; elseif (z <= 2.8e-37) tmp = x; elseif (z <= 2.6e+144) tmp = y * z; 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.05e+211], N[(y * z), $MachinePrecision], If[LessEqual[z, -8.5e+137], t$95$0, If[LessEqual[z, -1.05e-108], N[(y * z), $MachinePrecision], If[LessEqual[z, 2.8e-37], x, If[LessEqual[z, 2.6e+144], N[(y * z), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -2.05 \cdot 10^{+211}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -8.5 \cdot 10^{+137}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -1.05 \cdot 10^{-108}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 2.8 \cdot 10^{-37}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.6 \cdot 10^{+144}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -2.0499999999999999e211 or -8.50000000000000028e137 < z < -1.05e-108 or 2.8000000000000001e-37 < z < 2.5999999999999999e144Initial program 100.0%
Taylor expanded in z around inf 99.9%
Taylor expanded in y around inf 64.0%
*-commutative64.0%
Simplified64.0%
if -2.0499999999999999e211 < z < -8.50000000000000028e137 or 2.5999999999999999e144 < z Initial program 100.0%
Taylor expanded in x around inf 69.7%
mul-1-neg69.7%
unsub-neg69.7%
Simplified69.7%
Taylor expanded in z around inf 69.7%
mul-1-neg69.7%
distribute-lft-neg-out69.7%
*-commutative69.7%
Simplified69.7%
if -1.05e-108 < z < 2.8000000000000001e-37Initial program 100.0%
Taylor expanded in z around 0 78.1%
Final simplification70.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.7e-11) (not (<= x 2e-103))) (* x (- 1.0 z)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.7e-11) || !(x <= 2e-103)) {
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 <= (-1.7d-11)) .or. (.not. (x <= 2d-103))) 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 <= -1.7e-11) || !(x <= 2e-103)) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.7e-11) or not (x <= 2e-103): tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.7e-11) || !(x <= 2e-103)) 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 <= -1.7e-11) || ~((x <= 2e-103))) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.7e-11], N[Not[LessEqual[x, 2e-103]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.7 \cdot 10^{-11} \lor \neg \left(x \leq 2 \cdot 10^{-103}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -1.6999999999999999e-11 or 1.99999999999999992e-103 < x Initial program 100.0%
Taylor expanded in x around inf 82.3%
mul-1-neg82.3%
unsub-neg82.3%
Simplified82.3%
if -1.6999999999999999e-11 < x < 1.99999999999999992e-103Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in y around inf 77.6%
*-commutative77.6%
Simplified77.6%
Final simplification80.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.65e-108) (not (<= z 5.2e-37))) (* (- y x) z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.65e-108) || !(z <= 5.2e-37)) {
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 <= (-1.65d-108)) .or. (.not. (z <= 5.2d-37))) 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 <= -1.65e-108) || !(z <= 5.2e-37)) {
tmp = (y - x) * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.65e-108) or not (z <= 5.2e-37): tmp = (y - x) * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.65e-108) || !(z <= 5.2e-37)) 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 <= -1.65e-108) || ~((z <= 5.2e-37))) tmp = (y - x) * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.65e-108], N[Not[LessEqual[z, 5.2e-37]], $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 -1.65 \cdot 10^{-108} \lor \neg \left(z \leq 5.2 \cdot 10^{-37}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if z < -1.6500000000000001e-108 or 5.19999999999999959e-37 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in z around inf 92.1%
if -1.6500000000000001e-108 < z < 5.19999999999999959e-37Initial program 100.0%
Taylor expanded in x around inf 78.1%
mul-1-neg78.1%
unsub-neg78.1%
Simplified78.1%
Final simplification86.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 1.8e-16))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.8e-16)) {
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 <= (-1.0d0)) .or. (.not. (z <= 1.8d-16))) 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 <= -1.0) || !(z <= 1.8e-16)) {
tmp = (y - x) * z;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 1.8e-16): tmp = (y - x) * z else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 1.8e-16)) 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 <= -1.0) || ~((z <= 1.8e-16))) tmp = (y - x) * z; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 1.8e-16]], $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 -1 \lor \neg \left(z \leq 1.8 \cdot 10^{-16}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if z < -1 or 1.79999999999999991e-16 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in z around inf 97.5%
if -1 < z < 1.79999999999999991e-16Initial program 100.0%
Taylor expanded in y around inf 99.1%
*-commutative99.1%
Simplified99.1%
Final simplification98.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -9e-109) (not (<= z 5.8e-37))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -9e-109) || !(z <= 5.8e-37)) {
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 <= (-9d-109)) .or. (.not. (z <= 5.8d-37))) 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 <= -9e-109) || !(z <= 5.8e-37)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -9e-109) or not (z <= 5.8e-37): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -9e-109) || !(z <= 5.8e-37)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -9e-109) || ~((z <= 5.8e-37))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -9e-109], N[Not[LessEqual[z, 5.8e-37]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9 \cdot 10^{-109} \lor \neg \left(z \leq 5.8 \cdot 10^{-37}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -9.0000000000000002e-109 or 5.80000000000000009e-37 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in y around inf 57.3%
*-commutative57.3%
Simplified57.3%
if -9.0000000000000002e-109 < z < 5.80000000000000009e-37Initial program 100.0%
Taylor expanded in z around 0 78.1%
Final simplification65.7%
(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 36.0%
Final simplification36.0%
herbie shell --seed 2024078
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))