
(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 (* x (- z))))
(if (<= z -2.35e+191)
t_0
(if (<= z -4.8e+153)
(* y z)
(if (<= z -4e+89)
t_0
(if (<= z -8e-90)
(* y z)
(if (<= z 1.0) x (if (<= z 1.7e+240) t_0 (* y z)))))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -2.35e+191) {
tmp = t_0;
} else if (z <= -4.8e+153) {
tmp = y * z;
} else if (z <= -4e+89) {
tmp = t_0;
} else if (z <= -8e-90) {
tmp = y * z;
} else if (z <= 1.0) {
tmp = x;
} else if (z <= 1.7e+240) {
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 = x * -z
if (z <= (-2.35d+191)) then
tmp = t_0
else if (z <= (-4.8d+153)) then
tmp = y * z
else if (z <= (-4d+89)) then
tmp = t_0
else if (z <= (-8d-90)) then
tmp = y * z
else if (z <= 1.0d0) then
tmp = x
else if (z <= 1.7d+240) 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 = x * -z;
double tmp;
if (z <= -2.35e+191) {
tmp = t_0;
} else if (z <= -4.8e+153) {
tmp = y * z;
} else if (z <= -4e+89) {
tmp = t_0;
} else if (z <= -8e-90) {
tmp = y * z;
} else if (z <= 1.0) {
tmp = x;
} else if (z <= 1.7e+240) {
tmp = t_0;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -2.35e+191: tmp = t_0 elif z <= -4.8e+153: tmp = y * z elif z <= -4e+89: tmp = t_0 elif z <= -8e-90: tmp = y * z elif z <= 1.0: tmp = x elif z <= 1.7e+240: tmp = t_0 else: tmp = y * z return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-z)) tmp = 0.0 if (z <= -2.35e+191) tmp = t_0; elseif (z <= -4.8e+153) tmp = Float64(y * z); elseif (z <= -4e+89) tmp = t_0; elseif (z <= -8e-90) tmp = Float64(y * z); elseif (z <= 1.0) tmp = x; elseif (z <= 1.7e+240) tmp = t_0; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -z; tmp = 0.0; if (z <= -2.35e+191) tmp = t_0; elseif (z <= -4.8e+153) tmp = y * z; elseif (z <= -4e+89) tmp = t_0; elseif (z <= -8e-90) tmp = y * z; elseif (z <= 1.0) tmp = x; elseif (z <= 1.7e+240) tmp = t_0; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-z)), $MachinePrecision]}, If[LessEqual[z, -2.35e+191], t$95$0, If[LessEqual[z, -4.8e+153], N[(y * z), $MachinePrecision], If[LessEqual[z, -4e+89], t$95$0, If[LessEqual[z, -8e-90], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.0], x, If[LessEqual[z, 1.7e+240], t$95$0, N[(y * z), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -2.35 \cdot 10^{+191}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -4.8 \cdot 10^{+153}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -4 \cdot 10^{+89}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -8 \cdot 10^{-90}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.7 \cdot 10^{+240}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -2.35000000000000005e191 or -4.79999999999999985e153 < z < -3.99999999999999998e89 or 1 < z < 1.70000000000000004e240Initial program 100.0%
Taylor expanded in x around inf 62.6%
mul-1-neg62.6%
unsub-neg62.6%
Simplified62.6%
sub-neg62.6%
distribute-rgt-in62.5%
*-un-lft-identity62.5%
distribute-lft-neg-in62.5%
unsub-neg62.5%
Applied egg-rr62.5%
Taylor expanded in z around inf 61.6%
mul-1-neg61.6%
distribute-rgt-neg-out61.6%
Simplified61.6%
if -2.35000000000000005e191 < z < -4.79999999999999985e153 or -3.99999999999999998e89 < z < -7.99999999999999996e-90 or 1.70000000000000004e240 < z Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-lft-in98.6%
Applied egg-rr98.6%
associate-+r+98.6%
distribute-rgt-neg-out98.6%
unsub-neg98.6%
+-commutative98.6%
Applied egg-rr98.6%
Taylor expanded in y around inf 69.9%
*-commutative69.9%
Simplified69.9%
if -7.99999999999999996e-90 < z < 1Initial program 100.0%
Taylor expanded in z around 0 82.9%
Final simplification72.8%
(FPCore (x y z)
:precision binary64
(if (or (<= z -10.5)
(and (not (<= z -4.8e-41))
(or (<= z -8e-90) (not (<= z 2600000000000.0)))))
(* (- y x) z)
(* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -10.5) || (!(z <= -4.8e-41) && ((z <= -8e-90) || !(z <= 2600000000000.0)))) {
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 <= (-10.5d0)) .or. (.not. (z <= (-4.8d-41))) .and. (z <= (-8d-90)) .or. (.not. (z <= 2600000000000.0d0))) 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 <= -10.5) || (!(z <= -4.8e-41) && ((z <= -8e-90) || !(z <= 2600000000000.0)))) {
tmp = (y - x) * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -10.5) or (not (z <= -4.8e-41) and ((z <= -8e-90) or not (z <= 2600000000000.0))): tmp = (y - x) * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -10.5) || (!(z <= -4.8e-41) && ((z <= -8e-90) || !(z <= 2600000000000.0)))) 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 <= -10.5) || (~((z <= -4.8e-41)) && ((z <= -8e-90) || ~((z <= 2600000000000.0))))) tmp = (y - x) * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -10.5], And[N[Not[LessEqual[z, -4.8e-41]], $MachinePrecision], Or[LessEqual[z, -8e-90], N[Not[LessEqual[z, 2600000000000.0]], $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 -10.5 \lor \neg \left(z \leq -4.8 \cdot 10^{-41}\right) \land \left(z \leq -8 \cdot 10^{-90} \lor \neg \left(z \leq 2600000000000\right)\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if z < -10.5 or -4.80000000000000044e-41 < z < -7.99999999999999996e-90 or 2.6e12 < 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 96.5%
if -10.5 < z < -4.80000000000000044e-41 or -7.99999999999999996e-90 < z < 2.6e12Initial program 100.0%
Taylor expanded in x around inf 84.0%
mul-1-neg84.0%
unsub-neg84.0%
Simplified84.0%
Final simplification90.8%
(FPCore (x y z)
:precision binary64
(if (or (<= y -5400000000000.0)
(not
(or (<= y 7.8e+147) (and (not (<= y 3.9e+232)) (<= y 1.15e+268)))))
(* y z)
(* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5400000000000.0) || !((y <= 7.8e+147) || (!(y <= 3.9e+232) && (y <= 1.15e+268)))) {
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 <= (-5400000000000.0d0)) .or. (.not. (y <= 7.8d+147) .or. (.not. (y <= 3.9d+232)) .and. (y <= 1.15d+268))) 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 <= -5400000000000.0) || !((y <= 7.8e+147) || (!(y <= 3.9e+232) && (y <= 1.15e+268)))) {
tmp = y * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5400000000000.0) or not ((y <= 7.8e+147) or (not (y <= 3.9e+232) and (y <= 1.15e+268))): tmp = y * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5400000000000.0) || !((y <= 7.8e+147) || (!(y <= 3.9e+232) && (y <= 1.15e+268)))) 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 <= -5400000000000.0) || ~(((y <= 7.8e+147) || (~((y <= 3.9e+232)) && (y <= 1.15e+268))))) tmp = y * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5400000000000.0], N[Not[Or[LessEqual[y, 7.8e+147], And[N[Not[LessEqual[y, 3.9e+232]], $MachinePrecision], LessEqual[y, 1.15e+268]]]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5400000000000 \lor \neg \left(y \leq 7.8 \cdot 10^{+147} \lor \neg \left(y \leq 3.9 \cdot 10^{+232}\right) \land y \leq 1.15 \cdot 10^{+268}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < -5.4e12 or 7.80000000000000033e147 < y < 3.8999999999999999e232 or 1.15000000000000006e268 < y Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-lft-in94.7%
Applied egg-rr94.7%
associate-+r+94.7%
distribute-rgt-neg-out94.7%
unsub-neg94.7%
+-commutative94.7%
Applied egg-rr94.7%
Taylor expanded in y around inf 76.6%
*-commutative76.6%
Simplified76.6%
if -5.4e12 < y < 7.80000000000000033e147 or 3.8999999999999999e232 < y < 1.15000000000000006e268Initial program 100.0%
Taylor expanded in x around inf 83.4%
mul-1-neg83.4%
unsub-neg83.4%
Simplified83.4%
Final simplification80.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 1.0))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.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 <= (-1.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 <= -1.0) || !(z <= 1.0)) {
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.0): 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.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 <= -1.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, -1.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 -1 \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 < -1 or 1 < z Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-lft-in93.8%
Applied egg-rr93.8%
associate-+r+93.8%
distribute-rgt-neg-out93.8%
unsub-neg93.8%
+-commutative93.8%
Applied egg-rr93.8%
Taylor expanded in z around inf 97.9%
if -1 < z < 1Initial program 100.0%
Taylor expanded in y around inf 99.0%
*-commutative99.0%
Simplified99.0%
Final simplification98.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -8e-90) (not (<= z 2.2e-6))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -8e-90) || !(z <= 2.2e-6)) {
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 <= (-8d-90)) .or. (.not. (z <= 2.2d-6))) 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 <= -8e-90) || !(z <= 2.2e-6)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -8e-90) or not (z <= 2.2e-6): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -8e-90) || !(z <= 2.2e-6)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -8e-90) || ~((z <= 2.2e-6))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -8e-90], N[Not[LessEqual[z, 2.2e-6]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8 \cdot 10^{-90} \lor \neg \left(z \leq 2.2 \cdot 10^{-6}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -7.99999999999999996e-90 or 2.2000000000000001e-6 < z Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-lft-in94.6%
Applied egg-rr94.6%
associate-+r+94.6%
distribute-rgt-neg-out94.6%
unsub-neg94.6%
+-commutative94.6%
Applied egg-rr94.6%
Taylor expanded in y around inf 55.1%
*-commutative55.1%
Simplified55.1%
if -7.99999999999999996e-90 < z < 2.2000000000000001e-6Initial program 100.0%
Taylor expanded in z around 0 82.9%
Final simplification66.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%
(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 39.6%
herbie shell --seed 2024098
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))