
(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 -6.7e+232)
t_0
(if (<= z -1.02e+215)
(* y z)
(if (<= z -2.6e+166)
t_0
(if (<= z -3.4e-14)
(* y z)
(if (<= z 1.5e-36)
x
(if (or (<= z 4.8e+62) (not (<= z 4.6e+125))) (* y z) t_0))))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -6.7e+232) {
tmp = t_0;
} else if (z <= -1.02e+215) {
tmp = y * z;
} else if (z <= -2.6e+166) {
tmp = t_0;
} else if (z <= -3.4e-14) {
tmp = y * z;
} else if (z <= 1.5e-36) {
tmp = x;
} else if ((z <= 4.8e+62) || !(z <= 4.6e+125)) {
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 <= (-6.7d+232)) then
tmp = t_0
else if (z <= (-1.02d+215)) then
tmp = y * z
else if (z <= (-2.6d+166)) then
tmp = t_0
else if (z <= (-3.4d-14)) then
tmp = y * z
else if (z <= 1.5d-36) then
tmp = x
else if ((z <= 4.8d+62) .or. (.not. (z <= 4.6d+125))) 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 <= -6.7e+232) {
tmp = t_0;
} else if (z <= -1.02e+215) {
tmp = y * z;
} else if (z <= -2.6e+166) {
tmp = t_0;
} else if (z <= -3.4e-14) {
tmp = y * z;
} else if (z <= 1.5e-36) {
tmp = x;
} else if ((z <= 4.8e+62) || !(z <= 4.6e+125)) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -6.7e+232: tmp = t_0 elif z <= -1.02e+215: tmp = y * z elif z <= -2.6e+166: tmp = t_0 elif z <= -3.4e-14: tmp = y * z elif z <= 1.5e-36: tmp = x elif (z <= 4.8e+62) or not (z <= 4.6e+125): 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 <= -6.7e+232) tmp = t_0; elseif (z <= -1.02e+215) tmp = Float64(y * z); elseif (z <= -2.6e+166) tmp = t_0; elseif (z <= -3.4e-14) tmp = Float64(y * z); elseif (z <= 1.5e-36) tmp = x; elseif ((z <= 4.8e+62) || !(z <= 4.6e+125)) 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 <= -6.7e+232) tmp = t_0; elseif (z <= -1.02e+215) tmp = y * z; elseif (z <= -2.6e+166) tmp = t_0; elseif (z <= -3.4e-14) tmp = y * z; elseif (z <= 1.5e-36) tmp = x; elseif ((z <= 4.8e+62) || ~((z <= 4.6e+125))) 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, -6.7e+232], t$95$0, If[LessEqual[z, -1.02e+215], N[(y * z), $MachinePrecision], If[LessEqual[z, -2.6e+166], t$95$0, If[LessEqual[z, -3.4e-14], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.5e-36], x, If[Or[LessEqual[z, 4.8e+62], N[Not[LessEqual[z, 4.6e+125]], $MachinePrecision]], N[(y * z), $MachinePrecision], t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -6.7 \cdot 10^{+232}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -1.02 \cdot 10^{+215}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -2.6 \cdot 10^{+166}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -3.4 \cdot 10^{-14}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1.5 \cdot 10^{-36}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 4.8 \cdot 10^{+62} \lor \neg \left(z \leq 4.6 \cdot 10^{+125}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -6.69999999999999976e232 or -1.0199999999999999e215 < z < -2.5999999999999999e166 or 4.8e62 < z < 4.60000000000000026e125Initial program 100.0%
Taylor expanded in x around inf 76.2%
mul-1-neg76.2%
unsub-neg76.2%
Simplified76.2%
Taylor expanded in z around inf 76.2%
associate-*r*76.2%
neg-mul-176.2%
*-commutative76.2%
Simplified76.2%
if -6.69999999999999976e232 < z < -1.0199999999999999e215 or -2.5999999999999999e166 < z < -3.40000000000000003e-14 or 1.5000000000000001e-36 < z < 4.8e62 or 4.60000000000000026e125 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in y around inf 68.3%
*-commutative68.3%
Simplified68.3%
if -3.40000000000000003e-14 < z < 1.5000000000000001e-36Initial program 100.0%
Taylor expanded in z around 0 75.0%
Final simplification72.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.25e-74) (not (<= x 2.1e-90))) (* x (- 1.0 z)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.25e-74) || !(x <= 2.1e-90)) {
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.25d-74)) .or. (.not. (x <= 2.1d-90))) 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.25e-74) || !(x <= 2.1e-90)) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.25e-74) or not (x <= 2.1e-90): tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.25e-74) || !(x <= 2.1e-90)) 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.25e-74) || ~((x <= 2.1e-90))) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.25e-74], N[Not[LessEqual[x, 2.1e-90]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.25 \cdot 10^{-74} \lor \neg \left(x \leq 2.1 \cdot 10^{-90}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -1.25e-74 or 2.0999999999999999e-90 < x Initial program 100.0%
Taylor expanded in x around inf 84.2%
mul-1-neg84.2%
unsub-neg84.2%
Simplified84.2%
if -1.25e-74 < x < 2.0999999999999999e-90Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in y around inf 78.5%
*-commutative78.5%
Simplified78.5%
Final simplification81.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -1e-11) (not (<= z 1.3e-36))) (* (- y x) z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1e-11) || !(z <= 1.3e-36)) {
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 <= (-1d-11)) .or. (.not. (z <= 1.3d-36))) 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 <= -1e-11) || !(z <= 1.3e-36)) {
tmp = (y - x) * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1e-11) or not (z <= 1.3e-36): tmp = (y - x) * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1e-11) || !(z <= 1.3e-36)) 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 <= -1e-11) || ~((z <= 1.3e-36))) tmp = (y - x) * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1e-11], N[Not[LessEqual[z, 1.3e-36]], $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 \cdot 10^{-11} \lor \neg \left(z \leq 1.3 \cdot 10^{-36}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if z < -9.99999999999999939e-12 or 1.3e-36 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in z around inf 97.9%
if -9.99999999999999939e-12 < z < 1.3e-36Initial program 100.0%
Taylor expanded in x around inf 75.0%
mul-1-neg75.0%
unsub-neg75.0%
Simplified75.0%
Final simplification87.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -20000000.0) (not (<= z 1.0))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -20000000.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 <= (-20000000.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 <= -20000000.0) || !(z <= 1.0)) {
tmp = (y - x) * z;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -20000000.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 <= -20000000.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 <= -20000000.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, -20000000.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 -20000000 \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 < -2e7 or 1 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in z around inf 99.2%
if -2e7 < z < 1Initial program 100.0%
Taylor expanded in y around inf 100.0%
*-commutative100.0%
Simplified100.0%
Final simplification99.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.8e-17) (not (<= z 1.25e-36))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.8e-17) || !(z <= 1.25e-36)) {
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 <= (-4.8d-17)) .or. (.not. (z <= 1.25d-36))) 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 <= -4.8e-17) || !(z <= 1.25e-36)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.8e-17) or not (z <= 1.25e-36): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.8e-17) || !(z <= 1.25e-36)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -4.8e-17) || ~((z <= 1.25e-36))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.8e-17], N[Not[LessEqual[z, 1.25e-36]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.8 \cdot 10^{-17} \lor \neg \left(z \leq 1.25 \cdot 10^{-36}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.79999999999999973e-17 or 1.25000000000000001e-36 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in y around inf 58.7%
*-commutative58.7%
Simplified58.7%
if -4.79999999999999973e-17 < z < 1.25000000000000001e-36Initial program 100.0%
Taylor expanded in z around 0 75.0%
Final simplification66.0%
(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 35.9%
Final simplification35.9%
herbie shell --seed 2024077
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))