
(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 7 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 (if (<= z -3.1e+217) (* (- x) z) (if (<= z -6.6e-19) (* z y) (if (<= z 4.1e-91) (* 1.0 x) (* z y)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.1e+217) {
tmp = -x * z;
} else if (z <= -6.6e-19) {
tmp = z * y;
} else if (z <= 4.1e-91) {
tmp = 1.0 * x;
} else {
tmp = z * y;
}
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 <= (-3.1d+217)) then
tmp = -x * z
else if (z <= (-6.6d-19)) then
tmp = z * y
else if (z <= 4.1d-91) then
tmp = 1.0d0 * x
else
tmp = z * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -3.1e+217) {
tmp = -x * z;
} else if (z <= -6.6e-19) {
tmp = z * y;
} else if (z <= 4.1e-91) {
tmp = 1.0 * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3.1e+217: tmp = -x * z elif z <= -6.6e-19: tmp = z * y elif z <= 4.1e-91: tmp = 1.0 * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3.1e+217) tmp = Float64(Float64(-x) * z); elseif (z <= -6.6e-19) tmp = Float64(z * y); elseif (z <= 4.1e-91) tmp = Float64(1.0 * x); else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -3.1e+217) tmp = -x * z; elseif (z <= -6.6e-19) tmp = z * y; elseif (z <= 4.1e-91) tmp = 1.0 * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3.1e+217], N[((-x) * z), $MachinePrecision], If[LessEqual[z, -6.6e-19], N[(z * y), $MachinePrecision], If[LessEqual[z, 4.1e-91], N[(1.0 * x), $MachinePrecision], N[(z * y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.1 \cdot 10^{+217}:\\
\;\;\;\;\left(-x\right) \cdot z\\
\mathbf{elif}\;z \leq -6.6 \cdot 10^{-19}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq 4.1 \cdot 10^{-91}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if z < -3.1000000000000002e217Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites74.0%
if -3.1000000000000002e217 < z < -6.5999999999999995e-19 or 4.10000000000000024e-91 < z Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6460.4
Applied rewrites60.4%
if -6.5999999999999995e-19 < z < 4.10000000000000024e-91Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6476.5
Applied rewrites76.5%
Taylor expanded in z around 0
Applied rewrites76.5%
Final simplification68.4%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* z (- y x)))) (if (<= z -1.0) t_0 (if (<= z 1.0) (+ (* 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 <= 1.0) {
tmp = (z * y) + x;
} 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 * (y - x)
if (z <= (-1.0d0)) then
tmp = t_0
else if (z <= 1.0d0) then
tmp = (z * y) + x
else
tmp = t_0
end if
code = tmp
end function
public static 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 <= 1.0) {
tmp = (z * y) + x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * (y - x) tmp = 0 if z <= -1.0: tmp = t_0 elif z <= 1.0: tmp = (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 <= 1.0) tmp = Float64(Float64(z * y) + x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * (y - x); tmp = 0.0; if (z <= -1.0) tmp = t_0; elseif (z <= 1.0) tmp = (z * y) + x; else tmp = t_0; end tmp_2 = 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, 1.0], N[(N[(z * y), $MachinePrecision] + 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 1:\\
\;\;\;\;z \cdot y + x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1 or 1 < z Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6498.0
Applied rewrites98.0%
if -1 < z < 1Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6499.5
Applied rewrites99.5%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* z (- y x)))) (if (<= z -1.08e-27) t_0 (if (<= z 3.2e-73) (* 1.0 x) t_0))))
double code(double x, double y, double z) {
double t_0 = z * (y - x);
double tmp;
if (z <= -1.08e-27) {
tmp = t_0;
} else if (z <= 3.2e-73) {
tmp = 1.0 * x;
} 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 * (y - x)
if (z <= (-1.08d-27)) then
tmp = t_0
else if (z <= 3.2d-73) then
tmp = 1.0d0 * x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * (y - x);
double tmp;
if (z <= -1.08e-27) {
tmp = t_0;
} else if (z <= 3.2e-73) {
tmp = 1.0 * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * (y - x) tmp = 0 if z <= -1.08e-27: tmp = t_0 elif z <= 3.2e-73: tmp = 1.0 * 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.08e-27) tmp = t_0; elseif (z <= 3.2e-73) tmp = Float64(1.0 * x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * (y - x); tmp = 0.0; if (z <= -1.08e-27) tmp = t_0; elseif (z <= 3.2e-73) tmp = 1.0 * x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.08e-27], t$95$0, If[LessEqual[z, 3.2e-73], N[(1.0 * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(y - x\right)\\
\mathbf{if}\;z \leq -1.08 \cdot 10^{-27}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 3.2 \cdot 10^{-73}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.08e-27 or 3.19999999999999986e-73 < z Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6494.4
Applied rewrites94.4%
if -1.08e-27 < z < 3.19999999999999986e-73Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6476.9
Applied rewrites76.9%
Taylor expanded in z around 0
Applied rewrites76.9%
Final simplification87.2%
(FPCore (x y z) :precision binary64 (if (<= y -4.5e+97) (* z y) (if (<= y 5.2e+143) (* (- 1.0 z) x) (* z y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.5e+97) {
tmp = z * y;
} else if (y <= 5.2e+143) {
tmp = (1.0 - z) * x;
} else {
tmp = z * y;
}
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 <= (-4.5d+97)) then
tmp = z * y
else if (y <= 5.2d+143) then
tmp = (1.0d0 - z) * x
else
tmp = z * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -4.5e+97) {
tmp = z * y;
} else if (y <= 5.2e+143) {
tmp = (1.0 - z) * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4.5e+97: tmp = z * y elif y <= 5.2e+143: tmp = (1.0 - z) * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4.5e+97) tmp = Float64(z * y); elseif (y <= 5.2e+143) tmp = Float64(Float64(1.0 - z) * x); else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4.5e+97) tmp = z * y; elseif (y <= 5.2e+143) tmp = (1.0 - z) * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4.5e+97], N[(z * y), $MachinePrecision], If[LessEqual[y, 5.2e+143], N[(N[(1.0 - z), $MachinePrecision] * x), $MachinePrecision], N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.5 \cdot 10^{+97}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{+143}:\\
\;\;\;\;\left(1 - z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if y < -4.49999999999999976e97 or 5.1999999999999998e143 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6480.1
Applied rewrites80.1%
if -4.49999999999999976e97 < y < 5.1999999999999998e143Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6476.4
Applied rewrites76.4%
Final simplification77.6%
(FPCore (x y z) :precision binary64 (if (<= z -6.6e-19) (* z y) (if (<= z 4.1e-91) (* 1.0 x) (* z y))))
double code(double x, double y, double z) {
double tmp;
if (z <= -6.6e-19) {
tmp = z * y;
} else if (z <= 4.1e-91) {
tmp = 1.0 * x;
} else {
tmp = z * y;
}
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 <= (-6.6d-19)) then
tmp = z * y
else if (z <= 4.1d-91) then
tmp = 1.0d0 * x
else
tmp = z * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -6.6e-19) {
tmp = z * y;
} else if (z <= 4.1e-91) {
tmp = 1.0 * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -6.6e-19: tmp = z * y elif z <= 4.1e-91: tmp = 1.0 * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (z <= -6.6e-19) tmp = Float64(z * y); elseif (z <= 4.1e-91) tmp = Float64(1.0 * x); else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -6.6e-19) tmp = z * y; elseif (z <= 4.1e-91) tmp = 1.0 * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -6.6e-19], N[(z * y), $MachinePrecision], If[LessEqual[z, 4.1e-91], N[(1.0 * x), $MachinePrecision], N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.6 \cdot 10^{-19}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq 4.1 \cdot 10^{-91}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if z < -6.5999999999999995e-19 or 4.10000000000000024e-91 < z Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6459.1
Applied rewrites59.1%
if -6.5999999999999995e-19 < z < 4.10000000000000024e-91Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6476.5
Applied rewrites76.5%
Taylor expanded in z around 0
Applied rewrites76.5%
Final simplification66.4%
(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 y around inf
lower-*.f6444.3
Applied rewrites44.3%
Final simplification44.3%
herbie shell --seed 2024267
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))