
(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-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (- x))))
(if (<= z -1.0)
t_0
(if (<= z 2.3e-56)
x
(if (or (<= z 3.5e+143) (and (not (<= z 1.6e+249)) (<= z 3.3e+300)))
(* y z)
t_0)))))
double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (z <= -1.0) {
tmp = t_0;
} else if (z <= 2.3e-56) {
tmp = x;
} else if ((z <= 3.5e+143) || (!(z <= 1.6e+249) && (z <= 3.3e+300))) {
tmp = y * z;
} else {
tmp = t_0;
}
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 = z * -x
if (z <= (-1.0d0)) then
tmp = t_0
else if (z <= 2.3d-56) then
tmp = x
else if ((z <= 3.5d+143) .or. (.not. (z <= 1.6d+249)) .and. (z <= 3.3d+300)) then
tmp = y * z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (z <= -1.0) {
tmp = t_0;
} else if (z <= 2.3e-56) {
tmp = x;
} else if ((z <= 3.5e+143) || (!(z <= 1.6e+249) && (z <= 3.3e+300))) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * -x tmp = 0 if z <= -1.0: tmp = t_0 elif z <= 2.3e-56: tmp = x elif (z <= 3.5e+143) or (not (z <= 1.6e+249) and (z <= 3.3e+300)): tmp = y * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * Float64(-x)) tmp = 0.0 if (z <= -1.0) tmp = t_0; elseif (z <= 2.3e-56) tmp = x; elseif ((z <= 3.5e+143) || (!(z <= 1.6e+249) && (z <= 3.3e+300))) tmp = Float64(y * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * -x; tmp = 0.0; if (z <= -1.0) tmp = t_0; elseif (z <= 2.3e-56) tmp = x; elseif ((z <= 3.5e+143) || (~((z <= 1.6e+249)) && (z <= 3.3e+300))) tmp = y * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-x)), $MachinePrecision]}, If[LessEqual[z, -1.0], t$95$0, If[LessEqual[z, 2.3e-56], x, If[Or[LessEqual[z, 3.5e+143], And[N[Not[LessEqual[z, 1.6e+249]], $MachinePrecision], LessEqual[z, 3.3e+300]]], N[(y * z), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-x\right)\\
\mathbf{if}\;z \leq -1:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 2.3 \cdot 10^{-56}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 3.5 \cdot 10^{+143} \lor \neg \left(z \leq 1.6 \cdot 10^{+249}\right) \land z \leq 3.3 \cdot 10^{+300}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -1 or 3.50000000000000008e143 < z < 1.60000000000000007e249 or 3.29999999999999988e300 < z Initial program 100.0%
Taylor expanded in z around inf 99.9%
Taylor expanded in y around 0 60.2%
mul-1-neg60.2%
distribute-rgt-neg-out60.2%
Simplified60.2%
if -1 < z < 2.30000000000000002e-56Initial program 100.0%
Taylor expanded in z around 0 76.0%
if 2.30000000000000002e-56 < z < 3.50000000000000008e143 or 1.60000000000000007e249 < z < 3.29999999999999988e300Initial program 99.9%
Taylor expanded in z around inf 85.6%
Taylor expanded in y around inf 57.4%
*-commutative57.4%
Simplified57.4%
Final simplification66.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.4e-28) (not (<= x 1.55e-113))) (* x (- 1.0 z)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.4e-28) || !(x <= 1.55e-113)) {
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 <= (-2.4d-28)) .or. (.not. (x <= 1.55d-113))) 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 <= -2.4e-28) || !(x <= 1.55e-113)) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.4e-28) or not (x <= 1.55e-113): tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.4e-28) || !(x <= 1.55e-113)) 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 <= -2.4e-28) || ~((x <= 1.55e-113))) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.4e-28], N[Not[LessEqual[x, 1.55e-113]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.4 \cdot 10^{-28} \lor \neg \left(x \leq 1.55 \cdot 10^{-113}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -2.4000000000000002e-28 or 1.55000000000000006e-113 < x Initial program 100.0%
Taylor expanded in x around inf 83.3%
distribute-rgt1-in83.3%
mul-1-neg83.3%
cancel-sign-sub-inv83.3%
Simplified83.3%
Taylor expanded in x around 0 83.3%
if -2.4000000000000002e-28 < x < 1.55000000000000006e-113Initial program 100.0%
Taylor expanded in z around inf 82.0%
Taylor expanded in y around inf 70.8%
*-commutative70.8%
Simplified70.8%
Final simplification78.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -5500.0) (not (<= z 7e-64))) (* (- y x) z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5500.0) || !(z <= 7e-64)) {
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 <= (-5500.0d0)) .or. (.not. (z <= 7d-64))) 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 <= -5500.0) || !(z <= 7e-64)) {
tmp = (y - x) * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -5500.0) or not (z <= 7e-64): tmp = (y - x) * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -5500.0) || !(z <= 7e-64)) 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 <= -5500.0) || ~((z <= 7e-64))) tmp = (y - x) * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -5500.0], N[Not[LessEqual[z, 7e-64]], $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 -5500 \lor \neg \left(z \leq 7 \cdot 10^{-64}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if z < -5500 or 7.0000000000000006e-64 < z Initial program 100.0%
Taylor expanded in z around inf 94.3%
if -5500 < z < 7.0000000000000006e-64Initial program 100.0%
Taylor expanded in x around inf 77.5%
distribute-rgt1-in77.5%
mul-1-neg77.5%
cancel-sign-sub-inv77.5%
Simplified77.5%
Taylor expanded in x around 0 77.5%
Final simplification87.0%
(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%
Taylor expanded in z around inf 99.3%
if -1 < z < 1Initial program 100.0%
Taylor expanded in y around inf 98.2%
*-commutative28.6%
Simplified98.2%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (if (<= z -4.2e-13) (* y z) (if (<= z 7e-64) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.2e-13) {
tmp = y * z;
} else if (z <= 7e-64) {
tmp = x;
} 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 (z <= (-4.2d-13)) then
tmp = y * z
else if (z <= 7d-64) then
tmp = x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -4.2e-13) {
tmp = y * z;
} else if (z <= 7e-64) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4.2e-13: tmp = y * z elif z <= 7e-64: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4.2e-13) tmp = Float64(y * z); elseif (z <= 7e-64) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -4.2e-13) tmp = y * z; elseif (z <= 7e-64) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4.2e-13], N[(y * z), $MachinePrecision], If[LessEqual[z, 7e-64], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.2 \cdot 10^{-13}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 7 \cdot 10^{-64}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -4.19999999999999977e-13 or 7.0000000000000006e-64 < z Initial program 100.0%
Taylor expanded in z around inf 93.0%
Taylor expanded in y around inf 46.8%
*-commutative46.8%
Simplified46.8%
if -4.19999999999999977e-13 < z < 7.0000000000000006e-64Initial program 100.0%
Taylor expanded in z around 0 78.1%
Final simplification60.0%
(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.2%
Final simplification37.2%
herbie shell --seed 2023268
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))