
(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 7 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
(if (or (<= x -4.2e-7)
(not (or (<= x 4e-81) (and (not (<= x 1.06e-26)) (<= x 2.2e+42)))))
(* x (- 1.0 z))
(* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.2e-7) || !((x <= 4e-81) || (!(x <= 1.06e-26) && (x <= 2.2e+42)))) {
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 <= (-4.2d-7)) .or. (.not. (x <= 4d-81) .or. (.not. (x <= 1.06d-26)) .and. (x <= 2.2d+42))) 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 <= -4.2e-7) || !((x <= 4e-81) || (!(x <= 1.06e-26) && (x <= 2.2e+42)))) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.2e-7) or not ((x <= 4e-81) or (not (x <= 1.06e-26) and (x <= 2.2e+42))): tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.2e-7) || !((x <= 4e-81) || (!(x <= 1.06e-26) && (x <= 2.2e+42)))) 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 <= -4.2e-7) || ~(((x <= 4e-81) || (~((x <= 1.06e-26)) && (x <= 2.2e+42))))) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.2e-7], N[Not[Or[LessEqual[x, 4e-81], And[N[Not[LessEqual[x, 1.06e-26]], $MachinePrecision], LessEqual[x, 2.2e+42]]]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.2 \cdot 10^{-7} \lor \neg \left(x \leq 4 \cdot 10^{-81} \lor \neg \left(x \leq 1.06 \cdot 10^{-26}\right) \land x \leq 2.2 \cdot 10^{+42}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -4.2e-7 or 3.9999999999999998e-81 < x < 1.06000000000000001e-26 or 2.2000000000000001e42 < x Initial program 100.0%
Taylor expanded in x around inf 88.3%
mul-1-neg88.3%
unsub-neg88.3%
Simplified88.3%
if -4.2e-7 < x < 3.9999999999999998e-81 or 1.06000000000000001e-26 < x < 2.2000000000000001e42Initial program 100.0%
Taylor expanded in x around 0 72.6%
Final simplification81.1%
(FPCore (x y z)
:precision binary64
(if (or (<= z -5.4e-64)
(and (not (<= z 1.2e-143))
(or (<= z 2.55e-104) (not (<= z 7.5e-18)))))
(* y z)
x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5.4e-64) || (!(z <= 1.2e-143) && ((z <= 2.55e-104) || !(z <= 7.5e-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 <= (-5.4d-64)) .or. (.not. (z <= 1.2d-143)) .and. (z <= 2.55d-104) .or. (.not. (z <= 7.5d-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 <= -5.4e-64) || (!(z <= 1.2e-143) && ((z <= 2.55e-104) || !(z <= 7.5e-18)))) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -5.4e-64) or (not (z <= 1.2e-143) and ((z <= 2.55e-104) or not (z <= 7.5e-18))): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -5.4e-64) || (!(z <= 1.2e-143) && ((z <= 2.55e-104) || !(z <= 7.5e-18)))) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -5.4e-64) || (~((z <= 1.2e-143)) && ((z <= 2.55e-104) || ~((z <= 7.5e-18))))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -5.4e-64], And[N[Not[LessEqual[z, 1.2e-143]], $MachinePrecision], Or[LessEqual[z, 2.55e-104], N[Not[LessEqual[z, 7.5e-18]], $MachinePrecision]]]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.4 \cdot 10^{-64} \lor \neg \left(z \leq 1.2 \cdot 10^{-143}\right) \land \left(z \leq 2.55 \cdot 10^{-104} \lor \neg \left(z \leq 7.5 \cdot 10^{-18}\right)\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -5.39999999999999971e-64 or 1.1999999999999999e-143 < z < 2.54999999999999996e-104 or 7.50000000000000015e-18 < z Initial program 100.0%
Taylor expanded in x around 0 54.2%
if -5.39999999999999971e-64 < z < 1.1999999999999999e-143 or 2.54999999999999996e-104 < z < 7.50000000000000015e-18Initial program 100.0%
Taylor expanded in z around 0 78.7%
Final simplification64.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -11600.0) (not (<= x 1.8e+59))) (* x (- 1.0 z)) (* (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -11600.0) || !(x <= 1.8e+59)) {
tmp = x * (1.0 - z);
} else {
tmp = (y - 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 ((x <= (-11600.0d0)) .or. (.not. (x <= 1.8d+59))) then
tmp = x * (1.0d0 - z)
else
tmp = (y - x) * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -11600.0) || !(x <= 1.8e+59)) {
tmp = x * (1.0 - z);
} else {
tmp = (y - x) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -11600.0) or not (x <= 1.8e+59): tmp = x * (1.0 - z) else: tmp = (y - x) * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -11600.0) || !(x <= 1.8e+59)) tmp = Float64(x * Float64(1.0 - z)); else tmp = Float64(Float64(y - x) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -11600.0) || ~((x <= 1.8e+59))) tmp = x * (1.0 - z); else tmp = (y - x) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -11600.0], N[Not[LessEqual[x, 1.8e+59]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -11600 \lor \neg \left(x \leq 1.8 \cdot 10^{+59}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;\left(y - x\right) \cdot z\\
\end{array}
\end{array}
if x < -11600 or 1.7999999999999999e59 < x Initial program 100.0%
Taylor expanded in x around inf 90.6%
mul-1-neg90.6%
unsub-neg90.6%
Simplified90.6%
if -11600 < x < 1.7999999999999999e59Initial program 100.0%
Taylor expanded in z around inf 78.2%
Final simplification84.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -7e+19) (not (<= z 1.0))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -7e+19) || !(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 <= (-7d+19)) .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 <= -7e+19) || !(z <= 1.0)) {
tmp = (y - x) * z;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -7e+19) 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 <= -7e+19) || !(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 <= -7e+19) || ~((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, -7e+19], 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 -7 \cdot 10^{+19} \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 < -7e19 or 1 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
if -7e19 < z < 1Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-lft-in100.0%
Applied egg-rr100.0%
Taylor expanded in y around inf 98.1%
*-commutative98.1%
Simplified98.1%
Final simplification98.9%
(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 37.1%
Final simplification37.1%
herbie shell --seed 2024041
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))