
(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 5 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 (<= z -3.2e+234) (and (not (<= z -3.2e+85)) (<= z 6.8e+20))) (+ x (* y z)) (* z (- x))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.2e+234) || (!(z <= -3.2e+85) && (z <= 6.8e+20))) {
tmp = x + (y * z);
} else {
tmp = 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 ((z <= (-3.2d+234)) .or. (.not. (z <= (-3.2d+85))) .and. (z <= 6.8d+20)) then
tmp = x + (y * z)
else
tmp = z * -x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3.2e+234) || (!(z <= -3.2e+85) && (z <= 6.8e+20))) {
tmp = x + (y * z);
} else {
tmp = z * -x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.2e+234) or (not (z <= -3.2e+85) and (z <= 6.8e+20)): tmp = x + (y * z) else: tmp = z * -x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.2e+234) || (!(z <= -3.2e+85) && (z <= 6.8e+20))) tmp = Float64(x + Float64(y * z)); else tmp = Float64(z * Float64(-x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.2e+234) || (~((z <= -3.2e+85)) && (z <= 6.8e+20))) tmp = x + (y * z); else tmp = z * -x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.2e+234], And[N[Not[LessEqual[z, -3.2e+85]], $MachinePrecision], LessEqual[z, 6.8e+20]]], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(z * (-x)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.2 \cdot 10^{+234} \lor \neg \left(z \leq -3.2 \cdot 10^{+85}\right) \land z \leq 6.8 \cdot 10^{+20}:\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-x\right)\\
\end{array}
\end{array}
if z < -3.19999999999999992e234 or -3.20000000000000018e85 < z < 6.8e20Initial program 100.0%
Taylor expanded in y around inf 93.2%
*-commutative93.2%
Simplified93.2%
if -3.19999999999999992e234 < z < -3.20000000000000018e85 or 6.8e20 < z Initial program 100.0%
Taylor expanded in y around 0 67.7%
mul-1-neg67.7%
distribute-lft-neg-out67.7%
*-commutative67.7%
Simplified67.7%
Taylor expanded in z around inf 67.7%
associate-*r*67.7%
mul-1-neg67.7%
Simplified67.7%
Final simplification85.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.2e+44) (not (<= x 3.45e+44))) (- x (* x z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.2e+44) || !(x <= 3.45e+44)) {
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 <= (-5.2d+44)) .or. (.not. (x <= 3.45d+44))) 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 <= -5.2e+44) || !(x <= 3.45e+44)) {
tmp = x - (x * z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.2e+44) or not (x <= 3.45e+44): tmp = x - (x * z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.2e+44) || !(x <= 3.45e+44)) 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 <= -5.2e+44) || ~((x <= 3.45e+44))) tmp = x - (x * z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.2e+44], N[Not[LessEqual[x, 3.45e+44]], $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 -5.2 \cdot 10^{+44} \lor \neg \left(x \leq 3.45 \cdot 10^{+44}\right):\\
\;\;\;\;x - x \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -5.1999999999999998e44 or 3.4499999999999999e44 < x Initial program 100.0%
Taylor expanded in y around 0 91.3%
mul-1-neg91.3%
distribute-lft-neg-out91.3%
*-commutative91.3%
Simplified91.3%
distribute-rgt-neg-out91.3%
unsub-neg91.3%
*-commutative91.3%
Applied egg-rr91.3%
if -5.1999999999999998e44 < x < 3.4499999999999999e44Initial program 100.0%
Taylor expanded in y around inf 88.3%
*-commutative88.3%
Simplified88.3%
Final simplification89.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -14000000000.0) (not (<= z 3.3e+17))) (* z (- x)) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -14000000000.0) || !(z <= 3.3e+17)) {
tmp = z * -x;
} 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 <= (-14000000000.0d0)) .or. (.not. (z <= 3.3d+17))) then
tmp = z * -x
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -14000000000.0) || !(z <= 3.3e+17)) {
tmp = z * -x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -14000000000.0) or not (z <= 3.3e+17): tmp = z * -x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -14000000000.0) || !(z <= 3.3e+17)) tmp = Float64(z * Float64(-x)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -14000000000.0) || ~((z <= 3.3e+17))) tmp = z * -x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -14000000000.0], N[Not[LessEqual[z, 3.3e+17]], $MachinePrecision]], N[(z * (-x)), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -14000000000 \lor \neg \left(z \leq 3.3 \cdot 10^{+17}\right):\\
\;\;\;\;z \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.4e10 or 3.3e17 < z Initial program 100.0%
Taylor expanded in y around 0 55.9%
mul-1-neg55.9%
distribute-lft-neg-out55.9%
*-commutative55.9%
Simplified55.9%
Taylor expanded in z around inf 55.9%
associate-*r*55.9%
mul-1-neg55.9%
Simplified55.9%
if -1.4e10 < z < 3.3e17Initial program 100.0%
Taylor expanded in y around 0 63.6%
mul-1-neg63.6%
distribute-lft-neg-out63.6%
*-commutative63.6%
Simplified63.6%
Taylor expanded in z around 0 62.8%
Final simplification59.7%
(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 0 60.1%
mul-1-neg60.1%
distribute-lft-neg-out60.1%
*-commutative60.1%
Simplified60.1%
Taylor expanded in z around 0 35.8%
Final simplification35.8%
herbie shell --seed 2023310
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))