
(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 (<= x -7.8e+18)
(not
(or (<= x 530000000000.0)
(and (not (<= x 3.1e+50)) (<= x 1.5e+116)))))
(- x (* x z))
(+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7.8e+18) || !((x <= 530000000000.0) || (!(x <= 3.1e+50) && (x <= 1.5e+116)))) {
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 <= (-7.8d+18)) .or. (.not. (x <= 530000000000.0d0) .or. (.not. (x <= 3.1d+50)) .and. (x <= 1.5d+116))) 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 <= -7.8e+18) || !((x <= 530000000000.0) || (!(x <= 3.1e+50) && (x <= 1.5e+116)))) {
tmp = x - (x * z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7.8e+18) or not ((x <= 530000000000.0) or (not (x <= 3.1e+50) and (x <= 1.5e+116))): tmp = x - (x * z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7.8e+18) || !((x <= 530000000000.0) || (!(x <= 3.1e+50) && (x <= 1.5e+116)))) 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 <= -7.8e+18) || ~(((x <= 530000000000.0) || (~((x <= 3.1e+50)) && (x <= 1.5e+116))))) tmp = x - (x * z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7.8e+18], N[Not[Or[LessEqual[x, 530000000000.0], And[N[Not[LessEqual[x, 3.1e+50]], $MachinePrecision], LessEqual[x, 1.5e+116]]]], $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 -7.8 \cdot 10^{+18} \lor \neg \left(x \leq 530000000000 \lor \neg \left(x \leq 3.1 \cdot 10^{+50}\right) \land x \leq 1.5 \cdot 10^{+116}\right):\\
\;\;\;\;x - x \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -7.8e18 or 5.3e11 < x < 3.10000000000000003e50 or 1.4999999999999999e116 < x Initial program 100.0%
Taylor expanded in y around 0 89.5%
mul-1-neg89.5%
distribute-rgt-neg-out89.5%
Simplified89.5%
if -7.8e18 < x < 5.3e11 or 3.10000000000000003e50 < x < 1.4999999999999999e116Initial program 100.0%
Taylor expanded in y around inf 95.3%
*-commutative95.3%
Simplified95.3%
Final simplification92.6%
(FPCore (x y z) :precision binary64 (if (<= z -9.5e-19) (* y z) (if (<= z 7e-68) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -9.5e-19) {
tmp = y * z;
} else if (z <= 7e-68) {
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 (z <= (-9.5d-19)) then
tmp = y * z
else if (z <= 7d-68) 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 (z <= -9.5e-19) {
tmp = y * z;
} else if (z <= 7e-68) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -9.5e-19: tmp = y * z elif z <= 7e-68: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -9.5e-19) tmp = Float64(y * z); elseif (z <= 7e-68) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -9.5e-19) tmp = y * z; elseif (z <= 7e-68) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -9.5e-19], N[(y * z), $MachinePrecision], If[LessEqual[z, 7e-68], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.5 \cdot 10^{-19}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 7 \cdot 10^{-68}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -9.4999999999999995e-19 or 7.00000000000000026e-68 < z Initial program 100.0%
Taylor expanded in y around inf 60.0%
*-commutative60.0%
Simplified60.0%
Taylor expanded in x around 0 56.6%
if -9.4999999999999995e-19 < z < 7.00000000000000026e-68Initial program 100.0%
Taylor expanded in y around inf 100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 74.2%
Final simplification64.5%
(FPCore (x y z) :precision binary64 (+ x (* y z)))
double code(double x, double y, double z) {
return x + (y * 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 * z)
end function
public static double code(double x, double y, double z) {
return x + (y * z);
}
def code(x, y, z): return x + (y * z)
function code(x, y, z) return Float64(x + Float64(y * z)) end
function tmp = code(x, y, z) tmp = x + (y * z); end
code[x_, y_, z_] := N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot z
\end{array}
Initial program 100.0%
Taylor expanded in y around inf 78.0%
*-commutative78.0%
Simplified78.0%
Final simplification78.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 78.0%
*-commutative78.0%
Simplified78.0%
Taylor expanded in x around inf 36.6%
Final simplification36.6%
herbie shell --seed 2023207
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))