
(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 (+ (* z (- y x)) x))
double code(double x, double y, double z) {
return (z * (y - x)) + x;
}
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 - x)) + x
end function
public static double code(double x, double y, double z) {
return (z * (y - x)) + x;
}
def code(x, y, z): return (z * (y - x)) + x
function code(x, y, z) return Float64(Float64(z * Float64(y - x)) + x) end
function tmp = code(x, y, z) tmp = (z * (y - x)) + x; end
code[x_, y_, z_] := N[(N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \left(y - x\right) + x
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (<= z -3.7e+257) (* (- x) z) (if (<= z -3.1e-165) (* z y) (if (<= z 8.5e-52) (* 1.0 x) (* z y)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.7e+257) {
tmp = -x * z;
} else if (z <= -3.1e-165) {
tmp = z * y;
} else if (z <= 8.5e-52) {
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.7d+257)) then
tmp = -x * z
else if (z <= (-3.1d-165)) then
tmp = z * y
else if (z <= 8.5d-52) 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.7e+257) {
tmp = -x * z;
} else if (z <= -3.1e-165) {
tmp = z * y;
} else if (z <= 8.5e-52) {
tmp = 1.0 * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3.7e+257: tmp = -x * z elif z <= -3.1e-165: tmp = z * y elif z <= 8.5e-52: tmp = 1.0 * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3.7e+257) tmp = Float64(Float64(-x) * z); elseif (z <= -3.1e-165) tmp = Float64(z * y); elseif (z <= 8.5e-52) 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.7e+257) tmp = -x * z; elseif (z <= -3.1e-165) tmp = z * y; elseif (z <= 8.5e-52) tmp = 1.0 * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3.7e+257], N[((-x) * z), $MachinePrecision], If[LessEqual[z, -3.1e-165], N[(z * y), $MachinePrecision], If[LessEqual[z, 8.5e-52], N[(1.0 * x), $MachinePrecision], N[(z * y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.7 \cdot 10^{+257}:\\
\;\;\;\;\left(-x\right) \cdot z\\
\mathbf{elif}\;z \leq -3.1 \cdot 10^{-165}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq 8.5 \cdot 10^{-52}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if z < -3.69999999999999991e257Initial 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 rewrites75.3%
if -3.69999999999999991e257 < z < -3.09999999999999996e-165 or 8.50000000000000006e-52 < z Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6455.5
Applied rewrites55.5%
if -3.09999999999999996e-165 < z < 8.50000000000000006e-52Initial 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--.f6479.7
Applied rewrites79.7%
Taylor expanded in z around 0
Applied rewrites79.7%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* z (- y x)))) (if (<= z -28.5) 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 <= -28.5) {
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 <= (-28.5d0)) 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 <= -28.5) {
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 <= -28.5: 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 <= -28.5) 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 <= -28.5) 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, -28.5], 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 -28.5:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;z \cdot y + x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -28.5 or 1 < z Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6499.1
Applied rewrites99.1%
if -28.5 < z < 1Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6498.7
Applied rewrites98.7%
Final simplification98.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* z (- y x)))) (if (<= z -1.02e-190) t_0 (if (<= z 2.0) (* (- 1.0 z) x) t_0))))
double code(double x, double y, double z) {
double t_0 = z * (y - x);
double tmp;
if (z <= -1.02e-190) {
tmp = t_0;
} else if (z <= 2.0) {
tmp = (1.0 - z) * 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.02d-190)) then
tmp = t_0
else if (z <= 2.0d0) then
tmp = (1.0d0 - z) * 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.02e-190) {
tmp = t_0;
} else if (z <= 2.0) {
tmp = (1.0 - z) * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * (y - x) tmp = 0 if z <= -1.02e-190: tmp = t_0 elif z <= 2.0: tmp = (1.0 - z) * 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.02e-190) tmp = t_0; elseif (z <= 2.0) tmp = Float64(Float64(1.0 - z) * 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.02e-190) tmp = t_0; elseif (z <= 2.0) tmp = (1.0 - z) * 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.02e-190], t$95$0, If[LessEqual[z, 2.0], N[(N[(1.0 - z), $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.02 \cdot 10^{-190}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 2:\\
\;\;\;\;\left(1 - z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.02e-190 or 2 < z Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6493.9
Applied rewrites93.9%
if -1.02e-190 < z < 2Initial 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.7
Applied rewrites77.7%
Final simplification88.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- 1.0 z) x))) (if (<= x -1.8e-76) t_0 (if (<= x 7.4e-9) (* z y) t_0))))
double code(double x, double y, double z) {
double t_0 = (1.0 - z) * x;
double tmp;
if (x <= -1.8e-76) {
tmp = t_0;
} else if (x <= 7.4e-9) {
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 = (1.0d0 - z) * x
if (x <= (-1.8d-76)) then
tmp = t_0
else if (x <= 7.4d-9) 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 = (1.0 - z) * x;
double tmp;
if (x <= -1.8e-76) {
tmp = t_0;
} else if (x <= 7.4e-9) {
tmp = z * y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (1.0 - z) * x tmp = 0 if x <= -1.8e-76: tmp = t_0 elif x <= 7.4e-9: tmp = z * y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(1.0 - z) * x) tmp = 0.0 if (x <= -1.8e-76) tmp = t_0; elseif (x <= 7.4e-9) tmp = Float64(z * y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (1.0 - z) * x; tmp = 0.0; if (x <= -1.8e-76) tmp = t_0; elseif (x <= 7.4e-9) tmp = z * y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(1.0 - z), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -1.8e-76], t$95$0, If[LessEqual[x, 7.4e-9], N[(z * y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - z\right) \cdot x\\
\mathbf{if}\;x \leq -1.8 \cdot 10^{-76}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 7.4 \cdot 10^{-9}:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.8e-76 or 7.4e-9 < x Initial 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--.f6485.5
Applied rewrites85.5%
if -1.8e-76 < x < 7.4e-9Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6473.6
Applied rewrites73.6%
(FPCore (x y z) :precision binary64 (if (<= z -3.1e-165) (* z y) (if (<= z 8.5e-52) (* 1.0 x) (* z y))))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.1e-165) {
tmp = z * y;
} else if (z <= 8.5e-52) {
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-165)) then
tmp = z * y
else if (z <= 8.5d-52) 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-165) {
tmp = z * y;
} else if (z <= 8.5e-52) {
tmp = 1.0 * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3.1e-165: tmp = z * y elif z <= 8.5e-52: tmp = 1.0 * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3.1e-165) tmp = Float64(z * y); elseif (z <= 8.5e-52) 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-165) tmp = z * y; elseif (z <= 8.5e-52) tmp = 1.0 * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3.1e-165], N[(z * y), $MachinePrecision], If[LessEqual[z, 8.5e-52], N[(1.0 * x), $MachinePrecision], N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.1 \cdot 10^{-165}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq 8.5 \cdot 10^{-52}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if z < -3.09999999999999996e-165 or 8.50000000000000006e-52 < z Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6453.9
Applied rewrites53.9%
if -3.09999999999999996e-165 < z < 8.50000000000000006e-52Initial 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--.f6479.7
Applied rewrites79.7%
Taylor expanded in z around 0
Applied rewrites79.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
*-commutativeN/A
lower-*.f6444.7
Applied rewrites44.7%
herbie shell --seed 2024276
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))