
(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%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.6e+78) (not (<= x 1550000.0))) (* x (- 1.0 z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.6e+78) || !(x <= 1550000.0)) {
tmp = x * (1.0 - 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 <= (-1.6d+78)) .or. (.not. (x <= 1550000.0d0))) then
tmp = x * (1.0d0 - 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 <= -1.6e+78) || !(x <= 1550000.0)) {
tmp = x * (1.0 - z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.6e+78) or not (x <= 1550000.0): tmp = x * (1.0 - z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.6e+78) || !(x <= 1550000.0)) tmp = Float64(x * Float64(1.0 - z)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.6e+78) || ~((x <= 1550000.0))) tmp = x * (1.0 - z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.6e+78], N[Not[LessEqual[x, 1550000.0]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{+78} \lor \neg \left(x \leq 1550000\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -1.59999999999999997e78 or 1.55e6 < x Initial program 100.0%
Taylor expanded in x around inf 87.5%
mul-1-neg87.5%
unsub-neg87.5%
Simplified87.5%
if -1.59999999999999997e78 < x < 1.55e6Initial program 100.0%
Taylor expanded in y around inf 88.7%
*-commutative88.7%
Simplified88.7%
Final simplification88.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -4600000000000.0) (not (<= x 56.0))) (* x (- 1.0 z)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4600000000000.0) || !(x <= 56.0)) {
tmp = x * (1.0 - z);
} 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 ((x <= (-4600000000000.0d0)) .or. (.not. (x <= 56.0d0))) then
tmp = x * (1.0d0 - z)
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4600000000000.0) || !(x <= 56.0)) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4600000000000.0) or not (x <= 56.0): tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4600000000000.0) || !(x <= 56.0)) tmp = Float64(x * Float64(1.0 - z)); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4600000000000.0) || ~((x <= 56.0))) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4600000000000.0], N[Not[LessEqual[x, 56.0]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4600000000000 \lor \neg \left(x \leq 56\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -4.6e12 or 56 < x Initial program 100.0%
Taylor expanded in x around inf 84.4%
mul-1-neg84.4%
unsub-neg84.4%
Simplified84.4%
if -4.6e12 < x < 56Initial program 100.0%
Taylor expanded in y around inf 89.0%
*-commutative89.0%
Simplified89.0%
Taylor expanded in y around inf 88.9%
Taylor expanded in z around inf 69.4%
Final simplification76.2%
(FPCore (x y z) :precision binary64 (if (<= x -1.75e+78) (* x (- 1.0 z)) (if (<= x 4100000.0) (+ x (* y z)) (- x (* x z)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.75e+78) {
tmp = x * (1.0 - z);
} else if (x <= 4100000.0) {
tmp = x + (y * z);
} else {
tmp = x - (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 <= (-1.75d+78)) then
tmp = x * (1.0d0 - z)
else if (x <= 4100000.0d0) then
tmp = x + (y * z)
else
tmp = x - (x * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.75e+78) {
tmp = x * (1.0 - z);
} else if (x <= 4100000.0) {
tmp = x + (y * z);
} else {
tmp = x - (x * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.75e+78: tmp = x * (1.0 - z) elif x <= 4100000.0: tmp = x + (y * z) else: tmp = x - (x * z) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.75e+78) tmp = Float64(x * Float64(1.0 - z)); elseif (x <= 4100000.0) tmp = Float64(x + Float64(y * z)); else tmp = Float64(x - Float64(x * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.75e+78) tmp = x * (1.0 - z); elseif (x <= 4100000.0) tmp = x + (y * z); else tmp = x - (x * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.75e+78], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 4100000.0], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x - N[(x * z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.75 \cdot 10^{+78}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{elif}\;x \leq 4100000:\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x - x \cdot z\\
\end{array}
\end{array}
if x < -1.7500000000000001e78Initial program 100.0%
Taylor expanded in x around inf 93.0%
mul-1-neg93.0%
unsub-neg93.0%
Simplified93.0%
if -1.7500000000000001e78 < x < 4.1e6Initial program 100.0%
Taylor expanded in y around inf 88.7%
*-commutative88.7%
Simplified88.7%
if 4.1e6 < x Initial program 100.0%
Taylor expanded in x around inf 82.3%
mul-1-neg82.3%
unsub-neg82.3%
Simplified82.3%
sub-neg82.3%
distribute-rgt-in82.3%
*-un-lft-identity82.3%
distribute-lft-neg-in82.3%
unsub-neg82.3%
Applied egg-rr82.3%
Final simplification88.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.95e-26) (not (<= z 7e-107))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.95e-26) || !(z <= 7e-107)) {
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 <= (-1.95d-26)) .or. (.not. (z <= 7d-107))) 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 <= -1.95e-26) || !(z <= 7e-107)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.95e-26) or not (z <= 7e-107): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.95e-26) || !(z <= 7e-107)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.95e-26) || ~((z <= 7e-107))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.95e-26], N[Not[LessEqual[z, 7e-107]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.95 \cdot 10^{-26} \lor \neg \left(z \leq 7 \cdot 10^{-107}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.94999999999999993e-26 or 6.99999999999999971e-107 < z Initial program 100.0%
Taylor expanded in y around inf 64.6%
*-commutative64.6%
Simplified64.6%
Taylor expanded in y around inf 66.9%
Taylor expanded in z around inf 59.5%
if -1.94999999999999993e-26 < z < 6.99999999999999971e-107Initial program 100.0%
Taylor expanded in z around 0 79.0%
Final simplification66.4%
(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 z around 0 32.5%
herbie shell --seed 2024157
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))