
(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 -5.9e+91) (* (- z) x) (if (<= z -3.3e-25) (* z y) (if (<= z 1.9e-139) (* 1.0 x) (* z y)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -5.9e+91) {
tmp = -z * x;
} else if (z <= -3.3e-25) {
tmp = z * y;
} else if (z <= 1.9e-139) {
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 <= (-5.9d+91)) then
tmp = -z * x
else if (z <= (-3.3d-25)) then
tmp = z * y
else if (z <= 1.9d-139) 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 <= -5.9e+91) {
tmp = -z * x;
} else if (z <= -3.3e-25) {
tmp = z * y;
} else if (z <= 1.9e-139) {
tmp = 1.0 * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5.9e+91: tmp = -z * x elif z <= -3.3e-25: tmp = z * y elif z <= 1.9e-139: tmp = 1.0 * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5.9e+91) tmp = Float64(Float64(-z) * x); elseif (z <= -3.3e-25) tmp = Float64(z * y); elseif (z <= 1.9e-139) 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 <= -5.9e+91) tmp = -z * x; elseif (z <= -3.3e-25) tmp = z * y; elseif (z <= 1.9e-139) tmp = 1.0 * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5.9e+91], N[((-z) * x), $MachinePrecision], If[LessEqual[z, -3.3e-25], N[(z * y), $MachinePrecision], If[LessEqual[z, 1.9e-139], N[(1.0 * x), $MachinePrecision], N[(z * y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.9 \cdot 10^{+91}:\\
\;\;\;\;\left(-z\right) \cdot x\\
\mathbf{elif}\;z \leq -3.3 \cdot 10^{-25}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq 1.9 \cdot 10^{-139}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if z < -5.9000000000000002e91Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6464.4
Applied rewrites64.4%
Taylor expanded in z around inf
Applied rewrites64.4%
if -5.9000000000000002e91 < z < -3.2999999999999998e-25 or 1.90000000000000004e-139 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6458.7
Applied rewrites58.7%
if -3.2999999999999998e-25 < z < 1.90000000000000004e-139Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6474.2
Applied rewrites74.2%
Taylor expanded in z around 0
Applied rewrites74.2%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* z (- y x)))) (if (<= z -3.3e-25) t_0 (if (<= z 1.9e-139) (* 1.0 x) t_0))))
double code(double x, double y, double z) {
double t_0 = z * (y - x);
double tmp;
if (z <= -3.3e-25) {
tmp = t_0;
} else if (z <= 1.9e-139) {
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 <= (-3.3d-25)) then
tmp = t_0
else if (z <= 1.9d-139) 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 <= -3.3e-25) {
tmp = t_0;
} else if (z <= 1.9e-139) {
tmp = 1.0 * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * (y - x) tmp = 0 if z <= -3.3e-25: tmp = t_0 elif z <= 1.9e-139: 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 <= -3.3e-25) tmp = t_0; elseif (z <= 1.9e-139) 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 <= -3.3e-25) tmp = t_0; elseif (z <= 1.9e-139) 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, -3.3e-25], t$95$0, If[LessEqual[z, 1.9e-139], 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 -3.3 \cdot 10^{-25}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.9 \cdot 10^{-139}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -3.2999999999999998e-25 or 1.90000000000000004e-139 < z Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift--.f64N/A
sub-negN/A
distribute-lft-inN/A
associate-+l+N/A
*-commutativeN/A
lower-fma.f64N/A
lower-fma.f64N/A
lower-neg.f6498.6
Applied rewrites98.6%
Taylor expanded in z around inf
mul-1-negN/A
sub-negN/A
lower-*.f64N/A
lower--.f6489.2
Applied rewrites89.2%
if -3.2999999999999998e-25 < z < 1.90000000000000004e-139Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6474.2
Applied rewrites74.2%
Taylor expanded in z around 0
Applied rewrites74.2%
(FPCore (x y z) :precision binary64 (if (<= y -3.1e+93) (* z y) (if (<= y 4.2e+137) (fma (- z) x x) (* z y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.1e+93) {
tmp = z * y;
} else if (y <= 4.2e+137) {
tmp = fma(-z, x, x);
} else {
tmp = z * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -3.1e+93) tmp = Float64(z * y); elseif (y <= 4.2e+137) tmp = fma(Float64(-z), x, x); else tmp = Float64(z * y); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -3.1e+93], N[(z * y), $MachinePrecision], If[LessEqual[y, 4.2e+137], N[((-z) * x + x), $MachinePrecision], N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.1 \cdot 10^{+93}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;y \leq 4.2 \cdot 10^{+137}:\\
\;\;\;\;\mathsf{fma}\left(-z, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if y < -3.10000000000000019e93 or 4.1999999999999998e137 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6476.3
Applied rewrites76.3%
if -3.10000000000000019e93 < y < 4.1999999999999998e137Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6478.0
Applied rewrites78.0%
Applied rewrites78.0%
(FPCore (x y z) :precision binary64 (if (<= y -3.1e+93) (* z y) (if (<= y 4.2e+137) (* (- 1.0 z) x) (* z y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.1e+93) {
tmp = z * y;
} else if (y <= 4.2e+137) {
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 <= (-3.1d+93)) then
tmp = z * y
else if (y <= 4.2d+137) 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 <= -3.1e+93) {
tmp = z * y;
} else if (y <= 4.2e+137) {
tmp = (1.0 - z) * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.1e+93: tmp = z * y elif y <= 4.2e+137: tmp = (1.0 - z) * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.1e+93) tmp = Float64(z * y); elseif (y <= 4.2e+137) 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 <= -3.1e+93) tmp = z * y; elseif (y <= 4.2e+137) tmp = (1.0 - z) * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.1e+93], N[(z * y), $MachinePrecision], If[LessEqual[y, 4.2e+137], N[(N[(1.0 - z), $MachinePrecision] * x), $MachinePrecision], N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.1 \cdot 10^{+93}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;y \leq 4.2 \cdot 10^{+137}:\\
\;\;\;\;\left(1 - z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if y < -3.10000000000000019e93 or 4.1999999999999998e137 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6476.3
Applied rewrites76.3%
if -3.10000000000000019e93 < y < 4.1999999999999998e137Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6478.0
Applied rewrites78.0%
(FPCore (x y z) :precision binary64 (if (<= z -3.3e-25) (* z y) (if (<= z 1.9e-139) (* 1.0 x) (* z y))))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.3e-25) {
tmp = z * y;
} else if (z <= 1.9e-139) {
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.3d-25)) then
tmp = z * y
else if (z <= 1.9d-139) 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.3e-25) {
tmp = z * y;
} else if (z <= 1.9e-139) {
tmp = 1.0 * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3.3e-25: tmp = z * y elif z <= 1.9e-139: tmp = 1.0 * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3.3e-25) tmp = Float64(z * y); elseif (z <= 1.9e-139) 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.3e-25) tmp = z * y; elseif (z <= 1.9e-139) tmp = 1.0 * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3.3e-25], N[(z * y), $MachinePrecision], If[LessEqual[z, 1.9e-139], N[(1.0 * x), $MachinePrecision], N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.3 \cdot 10^{-25}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq 1.9 \cdot 10^{-139}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if z < -3.2999999999999998e-25 or 1.90000000000000004e-139 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6453.4
Applied rewrites53.4%
if -3.2999999999999998e-25 < z < 1.90000000000000004e-139Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6474.2
Applied rewrites74.2%
Taylor expanded in z around 0
Applied rewrites74.2%
(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
*-commutativeN/A
lower-*.f6442.9
Applied rewrites42.9%
herbie shell --seed 2024331
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))