
(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 (* (- x) z)))
(if (<= z -33000000000000.0)
t_0
(if (<= z -6.5e-27)
(* z y)
(if (<= z 2.55e-101) (* 1.0 x) (if (<= z 1.4e+279) (* z y) t_0))))))
double code(double x, double y, double z) {
double t_0 = -x * z;
double tmp;
if (z <= -33000000000000.0) {
tmp = t_0;
} else if (z <= -6.5e-27) {
tmp = z * y;
} else if (z <= 2.55e-101) {
tmp = 1.0 * x;
} else if (z <= 1.4e+279) {
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 = -x * z
if (z <= (-33000000000000.0d0)) then
tmp = t_0
else if (z <= (-6.5d-27)) then
tmp = z * y
else if (z <= 2.55d-101) then
tmp = 1.0d0 * x
else if (z <= 1.4d+279) 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 = -x * z;
double tmp;
if (z <= -33000000000000.0) {
tmp = t_0;
} else if (z <= -6.5e-27) {
tmp = z * y;
} else if (z <= 2.55e-101) {
tmp = 1.0 * x;
} else if (z <= 1.4e+279) {
tmp = z * y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -x * z tmp = 0 if z <= -33000000000000.0: tmp = t_0 elif z <= -6.5e-27: tmp = z * y elif z <= 2.55e-101: tmp = 1.0 * x elif z <= 1.4e+279: tmp = z * y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(-x) * z) tmp = 0.0 if (z <= -33000000000000.0) tmp = t_0; elseif (z <= -6.5e-27) tmp = Float64(z * y); elseif (z <= 2.55e-101) tmp = Float64(1.0 * x); elseif (z <= 1.4e+279) tmp = Float64(z * y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -x * z; tmp = 0.0; if (z <= -33000000000000.0) tmp = t_0; elseif (z <= -6.5e-27) tmp = z * y; elseif (z <= 2.55e-101) tmp = 1.0 * x; elseif (z <= 1.4e+279) tmp = z * y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-x) * z), $MachinePrecision]}, If[LessEqual[z, -33000000000000.0], t$95$0, If[LessEqual[z, -6.5e-27], N[(z * y), $MachinePrecision], If[LessEqual[z, 2.55e-101], N[(1.0 * x), $MachinePrecision], If[LessEqual[z, 1.4e+279], N[(z * y), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-x\right) \cdot z\\
\mathbf{if}\;z \leq -33000000000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -6.5 \cdot 10^{-27}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq 2.55 \cdot 10^{-101}:\\
\;\;\;\;1 \cdot x\\
\mathbf{elif}\;z \leq 1.4 \cdot 10^{+279}:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -3.3e13 or 1.4000000000000001e279 < z Initial program 99.9%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6499.9
Applied rewrites99.9%
Taylor expanded in y around 0
Applied rewrites67.9%
if -3.3e13 < z < -6.50000000000000025e-27 or 2.5500000000000001e-101 < z < 1.4000000000000001e279Initial program 99.9%
Taylor expanded in y around inf
lower-*.f6461.6
Applied rewrites61.6%
if -6.50000000000000025e-27 < z < 2.5500000000000001e-101Initial 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--.f6477.6
Applied rewrites77.6%
Taylor expanded in z around 0
Applied rewrites77.6%
Final simplification69.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -16500000000.0) (not (<= z 1.4e-11))) (* z (- y x)) (+ (* z y) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -16500000000.0) || !(z <= 1.4e-11)) {
tmp = z * (y - x);
} else {
tmp = (z * y) + 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 <= (-16500000000.0d0)) .or. (.not. (z <= 1.4d-11))) then
tmp = z * (y - x)
else
tmp = (z * y) + x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -16500000000.0) || !(z <= 1.4e-11)) {
tmp = z * (y - x);
} else {
tmp = (z * y) + x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -16500000000.0) or not (z <= 1.4e-11): tmp = z * (y - x) else: tmp = (z * y) + x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -16500000000.0) || !(z <= 1.4e-11)) tmp = Float64(z * Float64(y - x)); else tmp = Float64(Float64(z * y) + x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -16500000000.0) || ~((z <= 1.4e-11))) tmp = z * (y - x); else tmp = (z * y) + x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -16500000000.0], N[Not[LessEqual[z, 1.4e-11]], $MachinePrecision]], N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision], N[(N[(z * y), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -16500000000 \lor \neg \left(z \leq 1.4 \cdot 10^{-11}\right):\\
\;\;\;\;z \cdot \left(y - x\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot y + x\\
\end{array}
\end{array}
if z < -1.65e10 or 1.4e-11 < z Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6499.3
Applied rewrites99.3%
if -1.65e10 < z < 1.4e-11Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6499.8
Applied rewrites99.8%
Final simplification99.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -6.5e-27) (not (<= z 2.55e-101))) (* z (- y x)) (* 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -6.5e-27) || !(z <= 2.55e-101)) {
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 <= (-6.5d-27)) .or. (.not. (z <= 2.55d-101))) 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 <= -6.5e-27) || !(z <= 2.55e-101)) {
tmp = z * (y - x);
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -6.5e-27) or not (z <= 2.55e-101): tmp = z * (y - x) else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -6.5e-27) || !(z <= 2.55e-101)) 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 <= -6.5e-27) || ~((z <= 2.55e-101))) tmp = z * (y - x); else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -6.5e-27], N[Not[LessEqual[z, 2.55e-101]], $MachinePrecision]], N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.5 \cdot 10^{-27} \lor \neg \left(z \leq 2.55 \cdot 10^{-101}\right):\\
\;\;\;\;z \cdot \left(y - x\right)\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if z < -6.50000000000000025e-27 or 2.5500000000000001e-101 < z Initial program 99.9%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6493.0
Applied rewrites93.0%
if -6.50000000000000025e-27 < z < 2.5500000000000001e-101Initial 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--.f6477.6
Applied rewrites77.6%
Taylor expanded in z around 0
Applied rewrites77.6%
Final simplification87.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.2e+39) (not (<= y 7.8e+142))) (* z y) (* (- 1.0 z) x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.2e+39) || !(y <= 7.8e+142)) {
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 <= (-4.2d+39)) .or. (.not. (y <= 7.8d+142))) 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 <= -4.2e+39) || !(y <= 7.8e+142)) {
tmp = z * y;
} else {
tmp = (1.0 - z) * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.2e+39) or not (y <= 7.8e+142): tmp = z * y else: tmp = (1.0 - z) * x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.2e+39) || !(y <= 7.8e+142)) 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 <= -4.2e+39) || ~((y <= 7.8e+142))) tmp = z * y; else tmp = (1.0 - z) * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.2e+39], N[Not[LessEqual[y, 7.8e+142]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(N[(1.0 - z), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.2 \cdot 10^{+39} \lor \neg \left(y \leq 7.8 \cdot 10^{+142}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;\left(1 - z\right) \cdot x\\
\end{array}
\end{array}
if y < -4.1999999999999997e39 or 7.8000000000000001e142 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f6478.9
Applied rewrites78.9%
if -4.1999999999999997e39 < y < 7.8000000000000001e142Initial program 99.9%
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--.f6480.6
Applied rewrites80.6%
Final simplification79.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -6.5e-27) (not (<= z 2.55e-101))) (* z y) (* 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -6.5e-27) || !(z <= 2.55e-101)) {
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 <= (-6.5d-27)) .or. (.not. (z <= 2.55d-101))) 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 <= -6.5e-27) || !(z <= 2.55e-101)) {
tmp = z * y;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -6.5e-27) or not (z <= 2.55e-101): tmp = z * y else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -6.5e-27) || !(z <= 2.55e-101)) 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 <= -6.5e-27) || ~((z <= 2.55e-101))) tmp = z * y; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -6.5e-27], N[Not[LessEqual[z, 2.55e-101]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.5 \cdot 10^{-27} \lor \neg \left(z \leq 2.55 \cdot 10^{-101}\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if z < -6.50000000000000025e-27 or 2.5500000000000001e-101 < z Initial program 99.9%
Taylor expanded in y around inf
lower-*.f6453.6
Applied rewrites53.6%
if -6.50000000000000025e-27 < z < 2.5500000000000001e-101Initial 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--.f6477.6
Applied rewrites77.6%
Taylor expanded in z around 0
Applied rewrites77.6%
Final simplification62.7%
(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-*.f6442.3
Applied rewrites42.3%
Final simplification42.3%
herbie shell --seed 2024271
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))