
(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 5 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 (or (<= z -5.8e+257)
(not
(or (<= z -3.9e+200)
(and (not (<= z -1.2e+169))
(or (<= z -2.25e+115)
(and (not (<= z 4.1e+18)) (<= z 5e+122)))))))
(+ x (* y z))
(* x (- z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5.8e+257) || !((z <= -3.9e+200) || (!(z <= -1.2e+169) && ((z <= -2.25e+115) || (!(z <= 4.1e+18) && (z <= 5e+122)))))) {
tmp = x + (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 <= (-5.8d+257)) .or. (.not. (z <= (-3.9d+200)) .or. (.not. (z <= (-1.2d+169))) .and. (z <= (-2.25d+115)) .or. (.not. (z <= 4.1d+18)) .and. (z <= 5d+122))) then
tmp = x + (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 <= -5.8e+257) || !((z <= -3.9e+200) || (!(z <= -1.2e+169) && ((z <= -2.25e+115) || (!(z <= 4.1e+18) && (z <= 5e+122)))))) {
tmp = x + (y * z);
} else {
tmp = x * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -5.8e+257) or not ((z <= -3.9e+200) or (not (z <= -1.2e+169) and ((z <= -2.25e+115) or (not (z <= 4.1e+18) and (z <= 5e+122))))): tmp = x + (y * z) else: tmp = x * -z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -5.8e+257) || !((z <= -3.9e+200) || (!(z <= -1.2e+169) && ((z <= -2.25e+115) || (!(z <= 4.1e+18) && (z <= 5e+122)))))) tmp = Float64(x + 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 <= -5.8e+257) || ~(((z <= -3.9e+200) || (~((z <= -1.2e+169)) && ((z <= -2.25e+115) || (~((z <= 4.1e+18)) && (z <= 5e+122))))))) tmp = x + (y * z); else tmp = x * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -5.8e+257], N[Not[Or[LessEqual[z, -3.9e+200], And[N[Not[LessEqual[z, -1.2e+169]], $MachinePrecision], Or[LessEqual[z, -2.25e+115], And[N[Not[LessEqual[z, 4.1e+18]], $MachinePrecision], LessEqual[z, 5e+122]]]]]], $MachinePrecision]], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x * (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.8 \cdot 10^{+257} \lor \neg \left(z \leq -3.9 \cdot 10^{+200} \lor \neg \left(z \leq -1.2 \cdot 10^{+169}\right) \land \left(z \leq -2.25 \cdot 10^{+115} \lor \neg \left(z \leq 4.1 \cdot 10^{+18}\right) \land z \leq 5 \cdot 10^{+122}\right)\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-z\right)\\
\end{array}
\end{array}
if z < -5.7999999999999998e257 or -3.90000000000000019e200 < z < -1.1999999999999999e169 or -2.24999999999999982e115 < z < 4.1e18 or 4.99999999999999989e122 < z Initial program 100.0%
Taylor expanded in y around inf 89.4%
*-commutative89.4%
Simplified89.4%
if -5.7999999999999998e257 < z < -3.90000000000000019e200 or -1.1999999999999999e169 < z < -2.24999999999999982e115 or 4.1e18 < z < 4.99999999999999989e122Initial program 100.0%
Taylor expanded in y around 0 70.8%
mul-1-neg70.8%
distribute-lft-neg-out70.8%
*-commutative70.8%
Simplified70.8%
Taylor expanded in z around inf 70.8%
associate-*r*70.8%
mul-1-neg70.8%
Simplified70.8%
Final simplification85.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.8e+132) (not (<= x 1.1e+182))) (- x (* x z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.8e+132) || !(x <= 1.1e+182)) {
tmp = x - (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 ((x <= (-3.8d+132)) .or. (.not. (x <= 1.1d+182))) then
tmp = x - (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 ((x <= -3.8e+132) || !(x <= 1.1e+182)) {
tmp = x - (x * z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.8e+132) or not (x <= 1.1e+182): tmp = x - (x * z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.8e+132) || !(x <= 1.1e+182)) tmp = Float64(x - Float64(x * z)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.8e+132) || ~((x <= 1.1e+182))) tmp = x - (x * z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.8e+132], N[Not[LessEqual[x, 1.1e+182]], $MachinePrecision]], N[(x - N[(x * z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.8 \cdot 10^{+132} \lor \neg \left(x \leq 1.1 \cdot 10^{+182}\right):\\
\;\;\;\;x - x \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -3.80000000000000006e132 or 1.09999999999999998e182 < x Initial program 100.0%
Taylor expanded in y around 0 93.4%
mul-1-neg93.4%
distribute-lft-neg-out93.4%
*-commutative93.4%
Simplified93.4%
distribute-rgt-neg-out93.4%
unsub-neg93.4%
*-commutative93.4%
Applied egg-rr93.4%
if -3.80000000000000006e132 < x < 1.09999999999999998e182Initial program 100.0%
Taylor expanded in y around inf 85.2%
*-commutative85.2%
Simplified85.2%
Final simplification87.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -5.2) (not (<= z 6800000000000.0))) (* x (- z)) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5.2) || !(z <= 6800000000000.0)) {
tmp = 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 <= (-5.2d0)) .or. (.not. (z <= 6800000000000.0d0))) then
tmp = 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 <= -5.2) || !(z <= 6800000000000.0)) {
tmp = x * -z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -5.2) or not (z <= 6800000000000.0): tmp = x * -z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -5.2) || !(z <= 6800000000000.0)) tmp = Float64(x * Float64(-z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -5.2) || ~((z <= 6800000000000.0))) tmp = x * -z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -5.2], N[Not[LessEqual[z, 6800000000000.0]], $MachinePrecision]], N[(x * (-z)), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.2 \lor \neg \left(z \leq 6800000000000\right):\\
\;\;\;\;x \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -5.20000000000000018 or 6.8e12 < z Initial program 100.0%
Taylor expanded in y around 0 50.1%
mul-1-neg50.1%
distribute-lft-neg-out50.1%
*-commutative50.1%
Simplified50.1%
Taylor expanded in z around inf 50.1%
associate-*r*50.1%
mul-1-neg50.1%
Simplified50.1%
if -5.20000000000000018 < z < 6.8e12Initial program 100.0%
Taylor expanded in y around 0 61.0%
mul-1-neg61.0%
distribute-lft-neg-out61.0%
*-commutative61.0%
Simplified61.0%
Taylor expanded in z around 0 60.7%
Final simplification55.5%
(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 y around 0 55.7%
mul-1-neg55.7%
distribute-lft-neg-out55.7%
*-commutative55.7%
Simplified55.7%
Taylor expanded in z around 0 32.7%
herbie shell --seed 2024108
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))