
(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 6 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 (+ 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
(if (<= z -1.7e+273)
(* y z)
(if (<= z -1.52e+19)
(* z (- x))
(if (or (<= z -1.05e-22) (not (<= z 1.12e-16))) (* y z) x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.7e+273) {
tmp = y * z;
} else if (z <= -1.52e+19) {
tmp = z * -x;
} else if ((z <= -1.05e-22) || !(z <= 1.12e-16)) {
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.7d+273)) then
tmp = y * z
else if (z <= (-1.52d+19)) then
tmp = z * -x
else if ((z <= (-1.05d-22)) .or. (.not. (z <= 1.12d-16))) 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.7e+273) {
tmp = y * z;
} else if (z <= -1.52e+19) {
tmp = z * -x;
} else if ((z <= -1.05e-22) || !(z <= 1.12e-16)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.7e+273: tmp = y * z elif z <= -1.52e+19: tmp = z * -x elif (z <= -1.05e-22) or not (z <= 1.12e-16): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.7e+273) tmp = Float64(y * z); elseif (z <= -1.52e+19) tmp = Float64(z * Float64(-x)); elseif ((z <= -1.05e-22) || !(z <= 1.12e-16)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.7e+273) tmp = y * z; elseif (z <= -1.52e+19) tmp = z * -x; elseif ((z <= -1.05e-22) || ~((z <= 1.12e-16))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.7e+273], N[(y * z), $MachinePrecision], If[LessEqual[z, -1.52e+19], N[(z * (-x)), $MachinePrecision], If[Or[LessEqual[z, -1.05e-22], N[Not[LessEqual[z, 1.12e-16]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.7 \cdot 10^{+273}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -1.52 \cdot 10^{+19}:\\
\;\;\;\;z \cdot \left(-x\right)\\
\mathbf{elif}\;z \leq -1.05 \cdot 10^{-22} \lor \neg \left(z \leq 1.12 \cdot 10^{-16}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.69999999999999999e273 or -1.52e19 < z < -1.05000000000000004e-22 or 1.12e-16 < z Initial program 100.0%
Taylor expanded in y around inf 67.1%
*-commutative67.1%
Simplified67.1%
Taylor expanded in x around 0 66.8%
*-commutative66.8%
Simplified66.8%
if -1.69999999999999999e273 < z < -1.52e19Initial program 100.0%
Taylor expanded in x around inf 59.1%
mul-1-neg59.1%
unsub-neg59.1%
Simplified59.1%
Taylor expanded in z around inf 59.1%
neg-mul-159.1%
distribute-lft-neg-in59.1%
Simplified59.1%
if -1.05000000000000004e-22 < z < 1.12e-16Initial program 100.0%
Taylor expanded in z around 0 80.2%
Final simplification71.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.45e-145) (not (<= y 1.3e-18))) (+ x (* y z)) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.45e-145) || !(y <= 1.3e-18)) {
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 <= (-2.45d-145)) .or. (.not. (y <= 1.3d-18))) 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 <= -2.45e-145) || !(y <= 1.3e-18)) {
tmp = x + (y * z);
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.45e-145) or not (y <= 1.3e-18): tmp = x + (y * z) else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.45e-145) || !(y <= 1.3e-18)) 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 <= -2.45e-145) || ~((y <= 1.3e-18))) tmp = x + (y * z); else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.45e-145], N[Not[LessEqual[y, 1.3e-18]], $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 -2.45 \cdot 10^{-145} \lor \neg \left(y \leq 1.3 \cdot 10^{-18}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < -2.44999999999999984e-145 or 1.3e-18 < y Initial program 100.0%
Taylor expanded in y around inf 90.4%
*-commutative90.4%
Simplified90.4%
if -2.44999999999999984e-145 < y < 1.3e-18Initial program 100.0%
Taylor expanded in x around inf 92.5%
mul-1-neg92.5%
unsub-neg92.5%
Simplified92.5%
Final simplification91.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -6e+116) (not (<= y 8e+124))) (* y z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6e+116) || !(y <= 8e+124)) {
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 <= (-6d+116)) .or. (.not. (y <= 8d+124))) 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 <= -6e+116) || !(y <= 8e+124)) {
tmp = y * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6e+116) or not (y <= 8e+124): tmp = y * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6e+116) || !(y <= 8e+124)) 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 <= -6e+116) || ~((y <= 8e+124))) tmp = y * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6e+116], N[Not[LessEqual[y, 8e+124]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6 \cdot 10^{+116} \lor \neg \left(y \leq 8 \cdot 10^{+124}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < -5.9999999999999997e116 or 7.99999999999999959e124 < y Initial program 100.0%
Taylor expanded in y around inf 98.7%
*-commutative98.7%
Simplified98.7%
Taylor expanded in x around 0 83.5%
*-commutative83.5%
Simplified83.5%
if -5.9999999999999997e116 < y < 7.99999999999999959e124Initial program 100.0%
Taylor expanded in x around inf 79.6%
mul-1-neg79.6%
unsub-neg79.6%
Simplified79.6%
Final simplification80.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.5e-25) (not (<= z 2.1e-17))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.5e-25) || !(z <= 2.1e-17)) {
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.5d-25)) .or. (.not. (z <= 2.1d-17))) 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.5e-25) || !(z <= 2.1e-17)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.5e-25) or not (z <= 2.1e-17): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.5e-25) || !(z <= 2.1e-17)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -4.5e-25) || ~((z <= 2.1e-17))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.5e-25], N[Not[LessEqual[z, 2.1e-17]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.5 \cdot 10^{-25} \lor \neg \left(z \leq 2.1 \cdot 10^{-17}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.5000000000000001e-25 or 2.09999999999999992e-17 < z Initial program 100.0%
Taylor expanded in y around inf 57.4%
*-commutative57.4%
Simplified57.4%
Taylor expanded in x around 0 56.7%
*-commutative56.7%
Simplified56.7%
if -4.5000000000000001e-25 < z < 2.09999999999999992e-17Initial program 100.0%
Taylor expanded in z around 0 80.2%
Final simplification67.2%
(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 37.5%
herbie shell --seed 2024123
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))