
(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 (<= z -7e+237)
(* y z)
(if (<= z -8.2e+44)
(* z (- x))
(if (or (<= z -2.1e-16) (not (<= z 3.1e-66))) (* y z) x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -7e+237) {
tmp = y * z;
} else if (z <= -8.2e+44) {
tmp = z * -x;
} else if ((z <= -2.1e-16) || !(z <= 3.1e-66)) {
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 (z <= (-7d+237)) then
tmp = y * z
else if (z <= (-8.2d+44)) then
tmp = z * -x
else if ((z <= (-2.1d-16)) .or. (.not. (z <= 3.1d-66))) 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 (z <= -7e+237) {
tmp = y * z;
} else if (z <= -8.2e+44) {
tmp = z * -x;
} else if ((z <= -2.1e-16) || !(z <= 3.1e-66)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -7e+237: tmp = y * z elif z <= -8.2e+44: tmp = z * -x elif (z <= -2.1e-16) or not (z <= 3.1e-66): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -7e+237) tmp = Float64(y * z); elseif (z <= -8.2e+44) tmp = Float64(z * Float64(-x)); elseif ((z <= -2.1e-16) || !(z <= 3.1e-66)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -7e+237) tmp = y * z; elseif (z <= -8.2e+44) tmp = z * -x; elseif ((z <= -2.1e-16) || ~((z <= 3.1e-66))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -7e+237], N[(y * z), $MachinePrecision], If[LessEqual[z, -8.2e+44], N[(z * (-x)), $MachinePrecision], If[Or[LessEqual[z, -2.1e-16], N[Not[LessEqual[z, 3.1e-66]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7 \cdot 10^{+237}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -8.2 \cdot 10^{+44}:\\
\;\;\;\;z \cdot \left(-x\right)\\
\mathbf{elif}\;z \leq -2.1 \cdot 10^{-16} \lor \neg \left(z \leq 3.1 \cdot 10^{-66}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6.99999999999999976e237 or -8.1999999999999993e44 < z < -2.1000000000000001e-16 or 3.0999999999999997e-66 < z Initial program 100.0%
Taylor expanded in y around inf 73.2%
*-commutative73.2%
Simplified73.2%
Taylor expanded in x around 0 70.3%
if -6.99999999999999976e237 < z < -8.1999999999999993e44Initial program 100.0%
Taylor expanded in y around 0 63.8%
mul-1-neg63.8%
distribute-lft-neg-out63.8%
*-commutative63.8%
Simplified63.8%
Taylor expanded in z around inf 63.8%
mul-1-neg63.8%
*-commutative63.8%
distribute-rgt-neg-in63.8%
Simplified63.8%
if -2.1000000000000001e-16 < z < 3.0999999999999997e-66Initial program 100.0%
Taylor expanded in y around inf 100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 73.1%
Final simplification70.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -2e+83) (not (<= x 9e+177))) (- x (* x z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2e+83) || !(x <= 9e+177)) {
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 <= (-2d+83)) .or. (.not. (x <= 9d+177))) 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 <= -2e+83) || !(x <= 9e+177)) {
tmp = x - (x * z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2e+83) or not (x <= 9e+177): tmp = x - (x * z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2e+83) || !(x <= 9e+177)) 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 <= -2e+83) || ~((x <= 9e+177))) tmp = x - (x * z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2e+83], N[Not[LessEqual[x, 9e+177]], $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 -2 \cdot 10^{+83} \lor \neg \left(x \leq 9 \cdot 10^{+177}\right):\\
\;\;\;\;x - x \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -2.00000000000000006e83 or 8.9999999999999994e177 < x Initial program 100.0%
Taylor expanded in y around 0 96.9%
mul-1-neg96.9%
distribute-lft-neg-out96.9%
*-commutative96.9%
Simplified96.9%
distribute-rgt-neg-out96.9%
unsub-neg96.9%
*-commutative96.9%
Applied egg-rr96.9%
if -2.00000000000000006e83 < x < 8.9999999999999994e177Initial program 100.0%
Taylor expanded in y around inf 89.3%
*-commutative89.3%
Simplified89.3%
Final simplification91.4%
(FPCore (x y z) :precision binary64 (if (<= z -1e+235) (* y z) (if (<= z -1.4e+44) (* z (- x)) (+ x (* y z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1e+235) {
tmp = y * z;
} else if (z <= -1.4e+44) {
tmp = z * -x;
} 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 (z <= (-1d+235)) then
tmp = y * z
else if (z <= (-1.4d+44)) then
tmp = z * -x
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1e+235) {
tmp = y * z;
} else if (z <= -1.4e+44) {
tmp = z * -x;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1e+235: tmp = y * z elif z <= -1.4e+44: tmp = z * -x else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1e+235) tmp = Float64(y * z); elseif (z <= -1.4e+44) tmp = Float64(z * Float64(-x)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1e+235) tmp = y * z; elseif (z <= -1.4e+44) tmp = z * -x; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1e+235], N[(y * z), $MachinePrecision], If[LessEqual[z, -1.4e+44], N[(z * (-x)), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \cdot 10^{+235}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -1.4 \cdot 10^{+44}:\\
\;\;\;\;z \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if z < -1.0000000000000001e235Initial program 100.0%
Taylor expanded in y around inf 88.9%
*-commutative88.9%
Simplified88.9%
Taylor expanded in x around 0 88.9%
if -1.0000000000000001e235 < z < -1.4e44Initial program 100.0%
Taylor expanded in y around 0 63.8%
mul-1-neg63.8%
distribute-lft-neg-out63.8%
*-commutative63.8%
Simplified63.8%
Taylor expanded in z around inf 63.8%
mul-1-neg63.8%
*-commutative63.8%
distribute-rgt-neg-in63.8%
Simplified63.8%
if -1.4e44 < z Initial program 100.0%
Taylor expanded in y around inf 90.0%
*-commutative90.0%
Simplified90.0%
Final simplification86.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -2e-18) (not (<= z 5.5e-68))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2e-18) || !(z <= 5.5e-68)) {
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 ((z <= (-2d-18)) .or. (.not. (z <= 5.5d-68))) 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 ((z <= -2e-18) || !(z <= 5.5e-68)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2e-18) or not (z <= 5.5e-68): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2e-18) || !(z <= 5.5e-68)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2e-18) || ~((z <= 5.5e-68))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2e-18], N[Not[LessEqual[z, 5.5e-68]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2 \cdot 10^{-18} \lor \neg \left(z \leq 5.5 \cdot 10^{-68}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.0000000000000001e-18 or 5.5000000000000003e-68 < z Initial program 100.0%
Taylor expanded in y around inf 63.6%
*-commutative63.6%
Simplified63.6%
Taylor expanded in x around 0 61.2%
if -2.0000000000000001e-18 < z < 5.5000000000000003e-68Initial program 100.0%
Taylor expanded in y around inf 100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 73.1%
Final simplification67.6%
(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 83.2%
*-commutative83.2%
Simplified83.2%
Taylor expanded in x around inf 41.8%
Final simplification41.8%
herbie shell --seed 2023331
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))