
(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 (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%
lift--.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- y x) z))) (if (<= z -1.32e+19) t_0 (if (<= z 0.16) (fma z y x) t_0))))
double code(double x, double y, double z) {
double t_0 = (y - x) * z;
double tmp;
if (z <= -1.32e+19) {
tmp = t_0;
} else if (z <= 0.16) {
tmp = fma(z, y, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(y - x) * z) tmp = 0.0 if (z <= -1.32e+19) tmp = t_0; elseif (z <= 0.16) tmp = fma(z, y, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[z, -1.32e+19], t$95$0, If[LessEqual[z, 0.16], N[(z * y + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y - x\right) \cdot z\\
\mathbf{if}\;z \leq -1.32 \cdot 10^{+19}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 0.16:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.32e19 or 0.160000000000000003 < z Initial program 100.0%
Taylor expanded in z around inf
lower-*.f64N/A
lower--.f6499.6
Applied rewrites99.6%
if -1.32e19 < z < 0.160000000000000003Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6499.3
Applied rewrites99.3%
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.3
Applied rewrites99.3%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- (* x z)))) (if (<= z -3.8e+169) t_0 (if (<= z 2.3e+14) (fma z y x) t_0))))
double code(double x, double y, double z) {
double t_0 = -(x * z);
double tmp;
if (z <= -3.8e+169) {
tmp = t_0;
} else if (z <= 2.3e+14) {
tmp = fma(z, y, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(-Float64(x * z)) tmp = 0.0 if (z <= -3.8e+169) tmp = t_0; elseif (z <= 2.3e+14) tmp = fma(z, y, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = (-N[(x * z), $MachinePrecision])}, If[LessEqual[z, -3.8e+169], t$95$0, If[LessEqual[z, 2.3e+14], N[(z * y + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -x \cdot z\\
\mathbf{if}\;z \leq -3.8 \cdot 10^{+169}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 2.3 \cdot 10^{+14}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -3.79999999999999992e169 or 2.3e14 < z Initial program 100.0%
Taylor expanded in z around inf
lower-*.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6462.8
Applied rewrites62.8%
if -3.79999999999999992e169 < z < 2.3e14Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6489.1
Applied rewrites89.1%
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6489.1
Applied rewrites89.1%
Final simplification79.4%
(FPCore (x y z) :precision binary64 (fma z y x))
double code(double x, double y, double z) {
return fma(z, y, x);
}
function code(x, y, z) return fma(z, y, x) end
code[x_, y_, z_] := N[(z * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, y, x\right)
\end{array}
Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6473.2
Applied rewrites73.2%
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6473.2
Applied rewrites73.2%
(FPCore (x y z) :precision binary64 (* y z))
double code(double x, double y, double z) {
return y * z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y * z
end function
public static double code(double x, double y, double z) {
return y * z;
}
def code(x, y, z): return y * z
function code(x, y, z) return Float64(y * z) end
function tmp = code(x, y, z) tmp = y * z; end
code[x_, y_, z_] := N[(y * z), $MachinePrecision]
\begin{array}{l}
\\
y \cdot z
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6438.9
Applied rewrites38.9%
herbie shell --seed 2024219
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))