
(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 (* (- y x) z))) (if (<= z -1.0) t_0 (if (<= z 6.8e-23) (+ 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 <= 6.8e-23) {
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 <= 6.8d-23) 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 <= 6.8e-23) {
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 <= 6.8e-23: 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 <= 6.8e-23) 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 <= 6.8e-23) 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, 6.8e-23], 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 6.8 \cdot 10^{-23}:\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1 or 6.8000000000000001e-23 < z Initial program 100.0%
Taylor expanded in z around inf
lower-*.f64N/A
lower--.f6498.6
Applied rewrites98.6%
if -1 < z < 6.8000000000000001e-23Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6499.4
Applied rewrites99.4%
Final simplification98.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- y x) z))) (if (<= z -1.5e-60) t_0 (if (<= z 5.5e-41) (- x (* x z)) t_0))))
double code(double x, double y, double z) {
double t_0 = (y - x) * z;
double tmp;
if (z <= -1.5e-60) {
tmp = t_0;
} else if (z <= 5.5e-41) {
tmp = x - (x * 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.5d-60)) then
tmp = t_0
else if (z <= 5.5d-41) then
tmp = x - (x * 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.5e-60) {
tmp = t_0;
} else if (z <= 5.5e-41) {
tmp = x - (x * z);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (y - x) * z tmp = 0 if z <= -1.5e-60: tmp = t_0 elif z <= 5.5e-41: tmp = x - (x * 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.5e-60) tmp = t_0; elseif (z <= 5.5e-41) tmp = Float64(x - Float64(x * 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.5e-60) tmp = t_0; elseif (z <= 5.5e-41) tmp = x - (x * 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.5e-60], t$95$0, If[LessEqual[z, 5.5e-41], N[(x - N[(x * 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.5 \cdot 10^{-60}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 5.5 \cdot 10^{-41}:\\
\;\;\;\;x - x \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.50000000000000009e-60 or 5.50000000000000022e-41 < z Initial program 100.0%
Taylor expanded in z around inf
lower-*.f64N/A
lower--.f6495.4
Applied rewrites95.4%
if -1.50000000000000009e-60 < z < 5.50000000000000022e-41Initial program 100.0%
Taylor expanded in x around inf
mul-1-negN/A
unsub-negN/A
distribute-lft-out--N/A
*-rgt-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6481.9
Applied rewrites81.9%
Final simplification89.8%
(FPCore (x y z) :precision binary64 (if (<= y -6.2e-84) (* y z) (if (<= y 3.2e-40) (* z (- x)) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -6.2e-84) {
tmp = y * z;
} else if (y <= 3.2e-40) {
tmp = z * -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 (y <= (-6.2d-84)) then
tmp = y * z
else if (y <= 3.2d-40) then
tmp = z * -x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -6.2e-84) {
tmp = y * z;
} else if (y <= 3.2e-40) {
tmp = z * -x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -6.2e-84: tmp = y * z elif y <= 3.2e-40: tmp = z * -x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -6.2e-84) tmp = Float64(y * z); elseif (y <= 3.2e-40) tmp = Float64(z * Float64(-x)); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -6.2e-84) tmp = y * z; elseif (y <= 3.2e-40) tmp = z * -x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -6.2e-84], N[(y * z), $MachinePrecision], If[LessEqual[y, 3.2e-40], N[(z * (-x)), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.2 \cdot 10^{-84}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 3.2 \cdot 10^{-40}:\\
\;\;\;\;z \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -6.20000000000000003e-84 or 3.20000000000000002e-40 < y Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6459.0
Applied rewrites59.0%
if -6.20000000000000003e-84 < y < 3.20000000000000002e-40Initial program 100.0%
Taylor expanded in z around inf
lower-*.f64N/A
lower--.f6455.9
Applied rewrites55.9%
Taylor expanded in y around 0
Applied rewrites46.2%
(FPCore (x y z) :precision binary64 (* (- y x) z))
double code(double x, double y, double z) {
return (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 = (y - x) * z
end function
public static double code(double x, double y, double z) {
return (y - x) * z;
}
def code(x, y, z): return (y - x) * z
function code(x, y, z) return Float64(Float64(y - x) * z) end
function tmp = code(x, y, z) tmp = (y - x) * z; end
code[x_, y_, z_] := N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]
\begin{array}{l}
\\
\left(y - x\right) \cdot z
\end{array}
Initial program 100.0%
Taylor expanded in z around inf
lower-*.f64N/A
lower--.f6463.8
Applied rewrites63.8%
Final simplification63.8%
(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-*.f6439.9
Applied rewrites39.9%
herbie shell --seed 2024221
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))