
(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 6 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 (+ 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}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (or (<= x -8e+121)
(not (or (<= x -8.5e+23) (and (not (<= x -3e-14)) (<= x 2.6e+23)))))
(- x (* x z))
(+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8e+121) || !((x <= -8.5e+23) || (!(x <= -3e-14) && (x <= 2.6e+23)))) {
tmp = x - (x * z);
} else {
tmp = x + (y * z);
}
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 ((x <= (-8d+121)) .or. (.not. (x <= (-8.5d+23)) .or. (.not. (x <= (-3d-14))) .and. (x <= 2.6d+23))) then
tmp = x - (x * z)
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -8e+121) || !((x <= -8.5e+23) || (!(x <= -3e-14) && (x <= 2.6e+23)))) {
tmp = x - (x * z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8e+121) or not ((x <= -8.5e+23) or (not (x <= -3e-14) and (x <= 2.6e+23))): tmp = x - (x * z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8e+121) || !((x <= -8.5e+23) || (!(x <= -3e-14) && (x <= 2.6e+23)))) tmp = Float64(x - Float64(x * z)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -8e+121) || ~(((x <= -8.5e+23) || (~((x <= -3e-14)) && (x <= 2.6e+23))))) tmp = x - (x * z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8e+121], N[Not[Or[LessEqual[x, -8.5e+23], And[N[Not[LessEqual[x, -3e-14]], $MachinePrecision], LessEqual[x, 2.6e+23]]]], $MachinePrecision]], N[(x - N[(x * z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8 \cdot 10^{+121} \lor \neg \left(x \leq -8.5 \cdot 10^{+23} \lor \neg \left(x \leq -3 \cdot 10^{-14}\right) \land x \leq 2.6 \cdot 10^{+23}\right):\\
\;\;\;\;x - x \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -8.0000000000000003e121 or -8.5000000000000001e23 < x < -2.9999999999999998e-14 or 2.59999999999999992e23 < x Initial program 100.0%
Taylor expanded in y around 0 89.9%
mul-1-neg89.9%
distribute-lft-neg-out89.9%
*-commutative89.9%
Simplified89.9%
distribute-rgt-neg-out89.9%
unsub-neg89.9%
*-commutative89.9%
Applied egg-rr89.9%
if -8.0000000000000003e121 < x < -8.5000000000000001e23 or -2.9999999999999998e-14 < x < 2.59999999999999992e23Initial program 100.0%
Taylor expanded in y around inf 97.1%
*-commutative97.1%
Simplified97.1%
Final simplification93.8%
(FPCore (x y z)
:precision binary64
(if (<= y -2.4e-112)
(* y z)
(if (<= y 5.2e-227)
x
(if (<= y 2.4e-131) (* x (- z)) (if (<= y 2.4e-76) x (* y z))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.4e-112) {
tmp = y * z;
} else if (y <= 5.2e-227) {
tmp = x;
} else if (y <= 2.4e-131) {
tmp = x * -z;
} else if (y <= 2.4e-76) {
tmp = x;
} else {
tmp = y * z;
}
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 <= (-2.4d-112)) then
tmp = y * z
else if (y <= 5.2d-227) then
tmp = x
else if (y <= 2.4d-131) then
tmp = x * -z
else if (y <= 2.4d-76) then
tmp = x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2.4e-112) {
tmp = y * z;
} else if (y <= 5.2e-227) {
tmp = x;
} else if (y <= 2.4e-131) {
tmp = x * -z;
} else if (y <= 2.4e-76) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.4e-112: tmp = y * z elif y <= 5.2e-227: tmp = x elif y <= 2.4e-131: tmp = x * -z elif y <= 2.4e-76: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.4e-112) tmp = Float64(y * z); elseif (y <= 5.2e-227) tmp = x; elseif (y <= 2.4e-131) tmp = Float64(x * Float64(-z)); elseif (y <= 2.4e-76) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.4e-112) tmp = y * z; elseif (y <= 5.2e-227) tmp = x; elseif (y <= 2.4e-131) tmp = x * -z; elseif (y <= 2.4e-76) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.4e-112], N[(y * z), $MachinePrecision], If[LessEqual[y, 5.2e-227], x, If[LessEqual[y, 2.4e-131], N[(x * (-z)), $MachinePrecision], If[LessEqual[y, 2.4e-76], x, N[(y * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.4 \cdot 10^{-112}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{-227}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 2.4 \cdot 10^{-131}:\\
\;\;\;\;x \cdot \left(-z\right)\\
\mathbf{elif}\;y \leq 2.4 \cdot 10^{-76}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -2.4000000000000001e-112 or 2.40000000000000013e-76 < y Initial program 100.0%
Taylor expanded in y around inf 85.5%
*-commutative85.5%
Simplified85.5%
Taylor expanded in x around 0 64.9%
if -2.4000000000000001e-112 < y < 5.20000000000000023e-227 or 2.4e-131 < y < 2.40000000000000013e-76Initial program 100.0%
Taylor expanded in y around inf 68.2%
*-commutative68.2%
Simplified68.2%
Taylor expanded in x around inf 66.5%
if 5.20000000000000023e-227 < y < 2.4e-131Initial program 100.0%
Taylor expanded in y around 0 100.0%
mul-1-neg100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in z around inf 62.9%
mul-1-neg62.9%
*-commutative62.9%
distribute-rgt-neg-in62.9%
Simplified62.9%
Final simplification65.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.5e-113) (not (<= y 1.55e-74))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.5e-113) || !(y <= 1.55e-74)) {
tmp = y * z;
} else {
tmp = 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 <= (-2.5d-113)) .or. (.not. (y <= 1.55d-74))) then
tmp = y * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -2.5e-113) || !(y <= 1.55e-74)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.5e-113) or not (y <= 1.55e-74): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.5e-113) || !(y <= 1.55e-74)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.5e-113) || ~((y <= 1.55e-74))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.5e-113], N[Not[LessEqual[y, 1.55e-74]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{-113} \lor \neg \left(y \leq 1.55 \cdot 10^{-74}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.4999999999999999e-113 or 1.5500000000000001e-74 < y Initial program 100.0%
Taylor expanded in y around inf 85.5%
*-commutative85.5%
Simplified85.5%
Taylor expanded in x around 0 64.9%
if -2.4999999999999999e-113 < y < 1.5500000000000001e-74Initial program 100.0%
Taylor expanded in y around inf 62.3%
*-commutative62.3%
Simplified62.3%
Taylor expanded in x around inf 61.0%
Final simplification63.6%
(FPCore (x y z) :precision binary64 (if (<= x 7e+186) (+ x (* y z)) (* x (- z))))
double code(double x, double y, double z) {
double tmp;
if (x <= 7e+186) {
tmp = x + (y * z);
} else {
tmp = x * -z;
}
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 (x <= 7d+186) then
tmp = x + (y * z)
else
tmp = x * -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= 7e+186) {
tmp = x + (y * z);
} else {
tmp = x * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= 7e+186: tmp = x + (y * z) else: tmp = x * -z return tmp
function code(x, y, z) tmp = 0.0 if (x <= 7e+186) tmp = Float64(x + Float64(y * z)); else tmp = Float64(x * Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= 7e+186) tmp = x + (y * z); else tmp = x * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, 7e+186], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x * (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 7 \cdot 10^{+186}:\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-z\right)\\
\end{array}
\end{array}
if x < 6.99999999999999974e186Initial program 100.0%
Taylor expanded in y around inf 82.2%
*-commutative82.2%
Simplified82.2%
if 6.99999999999999974e186 < x Initial program 100.0%
Taylor expanded in y around 0 99.1%
mul-1-neg99.1%
distribute-lft-neg-out99.1%
*-commutative99.1%
Simplified99.1%
Taylor expanded in z around inf 69.3%
mul-1-neg69.3%
*-commutative69.3%
distribute-rgt-neg-in69.3%
Simplified69.3%
Final simplification81.0%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in y around inf 77.6%
*-commutative77.6%
Simplified77.6%
Taylor expanded in x around inf 35.5%
Final simplification35.5%
herbie shell --seed 2024020
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))