
(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 (if (<= z -1.25e-39) (* y z) (if (<= z 5.9e-15) x (if (<= z 6.6e+193) (* y z) (* x (- z))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.25e-39) {
tmp = y * z;
} else if (z <= 5.9e-15) {
tmp = x;
} else if (z <= 6.6e+193) {
tmp = y * z;
} else {
tmp = x * -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.25d-39)) then
tmp = y * z
else if (z <= 5.9d-15) then
tmp = x
else if (z <= 6.6d+193) then
tmp = y * z
else
tmp = x * -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.25e-39) {
tmp = y * z;
} else if (z <= 5.9e-15) {
tmp = x;
} else if (z <= 6.6e+193) {
tmp = y * z;
} else {
tmp = x * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.25e-39: tmp = y * z elif z <= 5.9e-15: tmp = x elif z <= 6.6e+193: tmp = y * z else: tmp = x * -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.25e-39) tmp = Float64(y * z); elseif (z <= 5.9e-15) tmp = x; elseif (z <= 6.6e+193) tmp = Float64(y * z); else tmp = Float64(x * Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.25e-39) tmp = y * z; elseif (z <= 5.9e-15) tmp = x; elseif (z <= 6.6e+193) tmp = y * z; else tmp = x * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.25e-39], N[(y * z), $MachinePrecision], If[LessEqual[z, 5.9e-15], x, If[LessEqual[z, 6.6e+193], N[(y * z), $MachinePrecision], N[(x * (-z)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.25 \cdot 10^{-39}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 5.9 \cdot 10^{-15}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 6.6 \cdot 10^{+193}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-z\right)\\
\end{array}
\end{array}
if z < -1.25e-39 or 5.89999999999999963e-15 < z < 6.6e193Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in y around inf 57.3%
*-commutative57.3%
Simplified57.3%
if -1.25e-39 < z < 5.89999999999999963e-15Initial program 100.0%
Taylor expanded in z around 0 78.3%
if 6.6e193 < z Initial program 100.0%
Taylor expanded in x around inf 66.5%
mul-1-neg66.5%
unsub-neg66.5%
Simplified66.5%
Taylor expanded in z around inf 66.5%
neg-mul-166.5%
distribute-rgt-neg-in66.5%
Simplified66.5%
Final simplification67.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -52.0) (not (<= z 2.45e-13))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -52.0) || !(z <= 2.45e-13)) {
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 <= (-52.0d0)) .or. (.not. (z <= 2.45d-13))) 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 <= -52.0) || !(z <= 2.45e-13)) {
tmp = (y - x) * z;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -52.0) or not (z <= 2.45e-13): tmp = (y - x) * z else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -52.0) || !(z <= 2.45e-13)) 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 <= -52.0) || ~((z <= 2.45e-13))) tmp = (y - x) * z; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -52.0], N[Not[LessEqual[z, 2.45e-13]], $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 -52 \lor \neg \left(z \leq 2.45 \cdot 10^{-13}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if z < -52 or 2.45000000000000016e-13 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in y around inf 98.2%
if -52 < z < 2.45000000000000016e-13Initial program 100.0%
Taylor expanded in y around inf 99.5%
*-commutative99.5%
Simplified99.5%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.32e-49) (not (<= z 2.75e-19))) (* (- y x) z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.32e-49) || !(z <= 2.75e-19)) {
tmp = (y - x) * 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.32d-49)) .or. (.not. (z <= 2.75d-19))) then
tmp = (y - x) * 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.32e-49) || !(z <= 2.75e-19)) {
tmp = (y - x) * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.32e-49) or not (z <= 2.75e-19): tmp = (y - x) * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.32e-49) || !(z <= 2.75e-19)) tmp = Float64(Float64(y - x) * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.32e-49) || ~((z <= 2.75e-19))) tmp = (y - x) * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.32e-49], N[Not[LessEqual[z, 2.75e-19]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.32 \cdot 10^{-49} \lor \neg \left(z \leq 2.75 \cdot 10^{-19}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.3199999999999999e-49 or 2.7499999999999998e-19 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in y around inf 97.0%
if -1.3199999999999999e-49 < z < 2.7499999999999998e-19Initial program 100.0%
Taylor expanded in z around 0 78.3%
Final simplification88.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.8e+165) (not (<= y 2.8e+15))) (* y z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.8e+165) || !(y <= 2.8e+15)) {
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 <= (-3.8d+165)) .or. (.not. (y <= 2.8d+15))) 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 <= -3.8e+165) || !(y <= 2.8e+15)) {
tmp = y * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.8e+165) or not (y <= 2.8e+15): tmp = y * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.8e+165) || !(y <= 2.8e+15)) 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 <= -3.8e+165) || ~((y <= 2.8e+15))) tmp = y * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.8e+165], N[Not[LessEqual[y, 2.8e+15]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.8 \cdot 10^{+165} \lor \neg \left(y \leq 2.8 \cdot 10^{+15}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < -3.7999999999999999e165 or 2.8e15 < y Initial program 100.0%
Taylor expanded in z around inf 88.0%
Taylor expanded in y around inf 77.5%
*-commutative77.5%
Simplified77.5%
if -3.7999999999999999e165 < y < 2.8e15Initial program 100.0%
Taylor expanded in x around inf 83.3%
mul-1-neg83.3%
unsub-neg83.3%
Simplified83.3%
Final simplification81.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.4e-43) (not (<= z 1e-18))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.4e-43) || !(z <= 1e-18)) {
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 <= (-3.4d-43)) .or. (.not. (z <= 1d-18))) 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 <= -3.4e-43) || !(z <= 1e-18)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.4e-43) or not (z <= 1e-18): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.4e-43) || !(z <= 1e-18)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.4e-43) || ~((z <= 1e-18))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.4e-43], N[Not[LessEqual[z, 1e-18]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.4 \cdot 10^{-43} \lor \neg \left(z \leq 10^{-18}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.4000000000000001e-43 or 1.0000000000000001e-18 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in y around inf 54.6%
*-commutative54.6%
Simplified54.6%
if -3.4000000000000001e-43 < z < 1.0000000000000001e-18Initial program 100.0%
Taylor expanded in z around 0 78.3%
Final simplification65.6%
(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 38.5%
herbie shell --seed 2024143
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))