
(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
(let* ((t_0 (* (- z) x)))
(if (<= z -8.3e+276)
t_0
(if (<= z -3.2e-46)
(* z y)
(if (<= z 8e-114) (* 1.0 x) (if (<= z 2.95e+77) (* z y) t_0))))))
double code(double x, double y, double z) {
double t_0 = -z * x;
double tmp;
if (z <= -8.3e+276) {
tmp = t_0;
} else if (z <= -3.2e-46) {
tmp = z * y;
} else if (z <= 8e-114) {
tmp = 1.0 * x;
} else if (z <= 2.95e+77) {
tmp = z * y;
} 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 * x
if (z <= (-8.3d+276)) then
tmp = t_0
else if (z <= (-3.2d-46)) then
tmp = z * y
else if (z <= 8d-114) then
tmp = 1.0d0 * x
else if (z <= 2.95d+77) then
tmp = z * y
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = -z * x;
double tmp;
if (z <= -8.3e+276) {
tmp = t_0;
} else if (z <= -3.2e-46) {
tmp = z * y;
} else if (z <= 8e-114) {
tmp = 1.0 * x;
} else if (z <= 2.95e+77) {
tmp = z * y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -z * x tmp = 0 if z <= -8.3e+276: tmp = t_0 elif z <= -3.2e-46: tmp = z * y elif z <= 8e-114: tmp = 1.0 * x elif z <= 2.95e+77: tmp = z * y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(-z) * x) tmp = 0.0 if (z <= -8.3e+276) tmp = t_0; elseif (z <= -3.2e-46) tmp = Float64(z * y); elseif (z <= 8e-114) tmp = Float64(1.0 * x); elseif (z <= 2.95e+77) tmp = Float64(z * y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -z * x; tmp = 0.0; if (z <= -8.3e+276) tmp = t_0; elseif (z <= -3.2e-46) tmp = z * y; elseif (z <= 8e-114) tmp = 1.0 * x; elseif (z <= 2.95e+77) tmp = z * y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-z) * x), $MachinePrecision]}, If[LessEqual[z, -8.3e+276], t$95$0, If[LessEqual[z, -3.2e-46], N[(z * y), $MachinePrecision], If[LessEqual[z, 8e-114], N[(1.0 * x), $MachinePrecision], If[LessEqual[z, 2.95e+77], N[(z * y), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-z\right) \cdot x\\
\mathbf{if}\;z \leq -8.3 \cdot 10^{+276}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -3.2 \cdot 10^{-46}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq 8 \cdot 10^{-114}:\\
\;\;\;\;1 \cdot x\\
\mathbf{elif}\;z \leq 2.95 \cdot 10^{+77}:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -8.3000000000000004e276 or 2.95e77 < z Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6470.2
Applied rewrites70.2%
Taylor expanded in z around inf
Applied rewrites70.2%
if -8.3000000000000004e276 < z < -3.1999999999999999e-46 or 8.0000000000000004e-114 < z < 2.95e77Initial program 99.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6461.6
Applied rewrites61.6%
if -3.1999999999999999e-46 < z < 8.0000000000000004e-114Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6477.0
Applied rewrites77.0%
Taylor expanded in z around 0
Applied rewrites77.0%
Final simplification68.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.25e-58) (not (<= z 5.5e-100))) (* z (- y x)) (* 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.25e-58) || !(z <= 5.5e-100)) {
tmp = z * (y - x);
} else {
tmp = 1.0 * x;
}
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 <= (-1.25d-58)) .or. (.not. (z <= 5.5d-100))) then
tmp = z * (y - x)
else
tmp = 1.0d0 * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.25e-58) || !(z <= 5.5e-100)) {
tmp = z * (y - x);
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.25e-58) or not (z <= 5.5e-100): tmp = z * (y - x) else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.25e-58) || !(z <= 5.5e-100)) tmp = Float64(z * Float64(y - x)); else tmp = Float64(1.0 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.25e-58) || ~((z <= 5.5e-100))) tmp = z * (y - x); else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.25e-58], N[Not[LessEqual[z, 5.5e-100]], $MachinePrecision]], N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.25 \cdot 10^{-58} \lor \neg \left(z \leq 5.5 \cdot 10^{-100}\right):\\
\;\;\;\;z \cdot \left(y - x\right)\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if z < -1.24999999999999994e-58 or 5.50000000000000011e-100 < 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.f6497.5
Applied rewrites97.5%
Taylor expanded in z around inf
mul-1-negN/A
sub-negN/A
lower-*.f64N/A
lower--.f6491.8
Applied rewrites91.8%
if -1.24999999999999994e-58 < z < 5.50000000000000011e-100Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6475.9
Applied rewrites75.9%
Taylor expanded in z around 0
Applied rewrites75.9%
Final simplification85.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.02e+27) (not (<= y 1.3e+49))) (* z y) (fma (- x) z x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.02e+27) || !(y <= 1.3e+49)) {
tmp = z * y;
} else {
tmp = fma(-x, z, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -1.02e+27) || !(y <= 1.3e+49)) tmp = Float64(z * y); else tmp = fma(Float64(-x), z, x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.02e+27], N[Not[LessEqual[y, 1.3e+49]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[((-x) * z + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.02 \cdot 10^{+27} \lor \neg \left(y \leq 1.3 \cdot 10^{+49}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-x, z, x\right)\\
\end{array}
\end{array}
if y < -1.0199999999999999e27 or 1.29999999999999994e49 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6477.0
Applied rewrites77.0%
if -1.0199999999999999e27 < y < 1.29999999999999994e49Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6479.7
Applied rewrites79.7%
Applied rewrites79.7%
Final simplification78.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.02e+27) (not (<= y 1.3e+49))) (* z y) (* (- 1.0 z) x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.02e+27) || !(y <= 1.3e+49)) {
tmp = z * y;
} else {
tmp = (1.0 - z) * x;
}
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 <= (-1.02d+27)) .or. (.not. (y <= 1.3d+49))) then
tmp = z * y
else
tmp = (1.0d0 - z) * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.02e+27) || !(y <= 1.3e+49)) {
tmp = z * y;
} else {
tmp = (1.0 - z) * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.02e+27) or not (y <= 1.3e+49): tmp = z * y else: tmp = (1.0 - z) * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.02e+27) || !(y <= 1.3e+49)) tmp = Float64(z * y); else tmp = Float64(Float64(1.0 - z) * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.02e+27) || ~((y <= 1.3e+49))) tmp = z * y; else tmp = (1.0 - z) * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.02e+27], N[Not[LessEqual[y, 1.3e+49]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(N[(1.0 - z), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.02 \cdot 10^{+27} \lor \neg \left(y \leq 1.3 \cdot 10^{+49}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;\left(1 - z\right) \cdot x\\
\end{array}
\end{array}
if y < -1.0199999999999999e27 or 1.29999999999999994e49 < y Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6477.0
Applied rewrites77.0%
if -1.0199999999999999e27 < y < 1.29999999999999994e49Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6479.7
Applied rewrites79.7%
Final simplification78.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.2e-46) (not (<= z 8e-114))) (* z y) (* 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.2e-46) || !(z <= 8e-114)) {
tmp = z * y;
} else {
tmp = 1.0 * x;
}
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.2d-46)) .or. (.not. (z <= 8d-114))) then
tmp = z * y
else
tmp = 1.0d0 * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3.2e-46) || !(z <= 8e-114)) {
tmp = z * y;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.2e-46) or not (z <= 8e-114): tmp = z * y else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.2e-46) || !(z <= 8e-114)) tmp = Float64(z * y); else tmp = Float64(1.0 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.2e-46) || ~((z <= 8e-114))) tmp = z * y; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.2e-46], N[Not[LessEqual[z, 8e-114]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.2 \cdot 10^{-46} \lor \neg \left(z \leq 8 \cdot 10^{-114}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if z < -3.1999999999999999e-46 or 8.0000000000000004e-114 < z Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6455.5
Applied rewrites55.5%
if -3.1999999999999999e-46 < z < 8.0000000000000004e-114Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6477.0
Applied rewrites77.0%
Taylor expanded in z around 0
Applied rewrites77.0%
Final simplification63.3%
(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-*.f6444.9
Applied rewrites44.9%
Final simplification44.9%
herbie shell --seed 2024324
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))