
(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 z (- y x) x))
double code(double x, double y, double z) {
return fma(z, (y - x), x);
}
function code(x, y, z) return fma(z, Float64(y - x), x) end
code[x_, y_, z_] := N[(z * N[(y - x), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, y - x, x\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
+-commutativeN/A
distribute-lft-inN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
*-rgt-identityN/A
associate-+l+N/A
mul-1-negN/A
unsub-negN/A
distribute-rgt-out--N/A
lower-fma.f64N/A
lower--.f64100.0
Simplified100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- z))))
(if (<= z -1.45e+215)
(fma z y x)
(if (<= z -1.4e+31) t_0 (if (<= z 5e+211) (fma z y x) t_0)))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -1.45e+215) {
tmp = fma(z, y, x);
} else if (z <= -1.4e+31) {
tmp = t_0;
} else if (z <= 5e+211) {
tmp = fma(z, y, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * Float64(-z)) tmp = 0.0 if (z <= -1.45e+215) tmp = fma(z, y, x); elseif (z <= -1.4e+31) tmp = t_0; elseif (z <= 5e+211) 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, -1.45e+215], N[(z * y + x), $MachinePrecision], If[LessEqual[z, -1.4e+31], t$95$0, If[LessEqual[z, 5e+211], N[(z * y + x), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -1.45 \cdot 10^{+215}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{elif}\;z \leq -1.4 \cdot 10^{+31}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 5 \cdot 10^{+211}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.45e215 or -1.40000000000000008e31 < z < 4.9999999999999995e211Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6485.9
Simplified85.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6485.9
Simplified85.9%
if -1.45e215 < z < -1.40000000000000008e31 or 4.9999999999999995e211 < z Initial program 100.0%
Taylor expanded in z around inf
lower-*.f64N/A
lower--.f64100.0
Simplified100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6475.8
Simplified75.8%
Final simplification83.7%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* z (- y x)))) (if (<= z -1.0) t_0 (if (<= z 5e-8) (fma z y x) t_0))))
double code(double x, double y, double z) {
double t_0 = z * (y - x);
double tmp;
if (z <= -1.0) {
tmp = t_0;
} else if (z <= 5e-8) {
tmp = fma(z, y, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * Float64(y - x)) tmp = 0.0 if (z <= -1.0) tmp = t_0; elseif (z <= 5e-8) tmp = fma(z, y, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.0], t$95$0, If[LessEqual[z, 5e-8], N[(z * y + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(y - x\right)\\
\mathbf{if}\;z \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 5 \cdot 10^{-8}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1 or 4.9999999999999998e-8 < z Initial program 100.0%
Taylor expanded in z around inf
lower-*.f64N/A
lower--.f6498.9
Simplified98.9%
if -1 < z < 4.9999999999999998e-8Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6499.4
Simplified99.4%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6499.5
Simplified99.5%
(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-*.f6474.1
Simplified74.1%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6474.1
Simplified74.1%
(FPCore (x y z) :precision binary64 (* z y))
double code(double x, double y, double z) {
return z * y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z * y
end function
public static double code(double x, double y, double z) {
return z * y;
}
def code(x, y, z): return z * y
function code(x, y, z) return Float64(z * y) end
function tmp = code(x, y, z) tmp = z * y; end
code[x_, y_, z_] := N[(z * y), $MachinePrecision]
\begin{array}{l}
\\
z \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6439.5
Simplified39.5%
Final simplification39.5%
herbie shell --seed 2024215
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))