
(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 6 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
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (- x))))
(if (<= z -1.7e+214)
t_0
(if (<= z -2.9e-14)
(* y z)
(if (<= z 1.3e-25) (fma x z x) (if (<= z 1.1e+224) (* y z) t_0))))))
double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (z <= -1.7e+214) {
tmp = t_0;
} else if (z <= -2.9e-14) {
tmp = y * z;
} else if (z <= 1.3e-25) {
tmp = fma(x, z, x);
} else if (z <= 1.1e+224) {
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.7e+214) tmp = t_0; elseif (z <= -2.9e-14) tmp = Float64(y * z); elseif (z <= 1.3e-25) tmp = fma(x, z, x); elseif (z <= 1.1e+224) tmp = Float64(y * z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-x)), $MachinePrecision]}, If[LessEqual[z, -1.7e+214], t$95$0, If[LessEqual[z, -2.9e-14], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.3e-25], N[(x * z + x), $MachinePrecision], If[LessEqual[z, 1.1e+224], 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.7 \cdot 10^{+214}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -2.9 \cdot 10^{-14}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1.3 \cdot 10^{-25}:\\
\;\;\;\;\mathsf{fma}\left(x, z, x\right)\\
\mathbf{elif}\;z \leq 1.1 \cdot 10^{+224}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.6999999999999999e214 or 1.1e224 < 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
Applied rewrites69.9%
if -1.6999999999999999e214 < z < -2.9000000000000003e-14 or 1.3e-25 < z < 1.1e224Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6463.9
Applied rewrites63.9%
if -2.9000000000000003e-14 < z < 1.3e-25Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6476.3
Applied rewrites76.3%
Applied rewrites76.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- y x) z))) (if (<= z -1.0) t_0 (if (<= z 0.17) (+ x (* y z)) t_0))))
double code(double x, double y, double z) {
double t_0 = (y - x) * z;
double tmp;
if (z <= -1.0) {
tmp = t_0;
} else if (z <= 0.17) {
tmp = x + (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 = (y - x) * z
if (z <= (-1.0d0)) then
tmp = t_0
else if (z <= 0.17d0) then
tmp = x + (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 = (y - x) * z;
double tmp;
if (z <= -1.0) {
tmp = t_0;
} else if (z <= 0.17) {
tmp = x + (y * z);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (y - x) * z tmp = 0 if z <= -1.0: tmp = t_0 elif z <= 0.17: tmp = x + (y * z) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(y - x) * z) tmp = 0.0 if (z <= -1.0) tmp = t_0; elseif (z <= 0.17) tmp = Float64(x + Float64(y * z)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (y - x) * z; tmp = 0.0; if (z <= -1.0) tmp = t_0; elseif (z <= 0.17) tmp = x + (y * z); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[z, -1.0], t$95$0, If[LessEqual[z, 0.17], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y - x\right) \cdot z\\
\mathbf{if}\;z \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 0.17:\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1 or 0.170000000000000012 < z Initial program 100.0%
Taylor expanded in z around inf
lower-*.f64N/A
lower--.f6498.5
Applied rewrites98.5%
if -1 < z < 0.170000000000000012Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6498.8
Applied rewrites98.8%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- y x) z))) (if (<= z -1.7e-31) t_0 (if (<= z 1.3e-25) (fma x z x) t_0))))
double code(double x, double y, double z) {
double t_0 = (y - x) * z;
double tmp;
if (z <= -1.7e-31) {
tmp = t_0;
} else if (z <= 1.3e-25) {
tmp = fma(x, z, 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.7e-31) tmp = t_0; elseif (z <= 1.3e-25) tmp = fma(x, z, 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.7e-31], t$95$0, If[LessEqual[z, 1.3e-25], N[(x * z + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y - x\right) \cdot z\\
\mathbf{if}\;z \leq -1.7 \cdot 10^{-31}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.3 \cdot 10^{-25}:\\
\;\;\;\;\mathsf{fma}\left(x, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.7000000000000001e-31 or 1.3e-25 < z Initial program 100.0%
Taylor expanded in z around inf
lower-*.f64N/A
lower--.f6496.6
Applied rewrites96.6%
if -1.7000000000000001e-31 < z < 1.3e-25Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6476.8
Applied rewrites76.8%
Applied rewrites76.8%
Final simplification87.5%
(FPCore (x y z) :precision binary64 (if (<= z -2.9e-14) (* y z) (if (<= z 1.3e-25) (fma x z x) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.9e-14) {
tmp = y * z;
} else if (z <= 1.3e-25) {
tmp = fma(x, z, x);
} else {
tmp = y * z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -2.9e-14) tmp = Float64(y * z); elseif (z <= 1.3e-25) tmp = fma(x, z, x); else tmp = Float64(y * z); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -2.9e-14], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.3e-25], N[(x * z + x), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.9 \cdot 10^{-14}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1.3 \cdot 10^{-25}:\\
\;\;\;\;\mathsf{fma}\left(x, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -2.9000000000000003e-14 or 1.3e-25 < z Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6457.4
Applied rewrites57.4%
if -2.9000000000000003e-14 < z < 1.3e-25Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6476.3
Applied rewrites76.3%
Applied rewrites76.3%
(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-*.f6442.8
Applied rewrites42.8%
herbie shell --seed 2024226
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))