
(FPCore (x y z) :precision binary64 (+ x (* (* y z) z)))
double code(double x, double y, double z) {
return x + ((y * z) * 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) * z)
end function
public static double code(double x, double y, double z) {
return x + ((y * z) * z);
}
def code(x, y, z): return x + ((y * z) * z)
function code(x, y, z) return Float64(x + Float64(Float64(y * z) * z)) end
function tmp = code(x, y, z) tmp = x + ((y * z) * z); end
code[x_, y_, z_] := N[(x + N[(N[(y * z), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y \cdot z\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (* (* y z) z)))
double code(double x, double y, double z) {
return x + ((y * z) * 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) * z)
end function
public static double code(double x, double y, double z) {
return x + ((y * z) * z);
}
def code(x, y, z): return x + ((y * z) * z)
function code(x, y, z) return Float64(x + Float64(Float64(y * z) * z)) end
function tmp = code(x, y, z) tmp = x + ((y * z) * z); end
code[x_, y_, z_] := N[(x + N[(N[(y * z), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y \cdot z\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (+ x (* z (* y z))))
double code(double x, double y, double z) {
return x + (z * (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 + (z * (y * z))
end function
public static double code(double x, double y, double z) {
return x + (z * (y * z));
}
def code(x, y, z): return x + (z * (y * z))
function code(x, y, z) return Float64(x + Float64(z * Float64(y * z))) end
function tmp = code(x, y, z) tmp = x + (z * (y * z)); end
code[x_, y_, z_] := N[(x + N[(z * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + z \cdot \left(y \cdot z\right)
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* z (* y z)))) (if (or (<= t_0 -2e+85) (not (<= t_0 1e-95))) t_0 x)))
double code(double x, double y, double z) {
double t_0 = z * (y * z);
double tmp;
if ((t_0 <= -2e+85) || !(t_0 <= 1e-95)) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = z * (y * z)
if ((t_0 <= (-2d+85)) .or. (.not. (t_0 <= 1d-95))) then
tmp = t_0
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * (y * z);
double tmp;
if ((t_0 <= -2e+85) || !(t_0 <= 1e-95)) {
tmp = t_0;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = z * (y * z) tmp = 0 if (t_0 <= -2e+85) or not (t_0 <= 1e-95): tmp = t_0 else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(z * Float64(y * z)) tmp = 0.0 if ((t_0 <= -2e+85) || !(t_0 <= 1e-95)) tmp = t_0; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * (y * z); tmp = 0.0; if ((t_0 <= -2e+85) || ~((t_0 <= 1e-95))) tmp = t_0; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -2e+85], N[Not[LessEqual[t$95$0, 1e-95]], $MachinePrecision]], t$95$0, x]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(y \cdot z\right)\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{+85} \lor \neg \left(t\_0 \leq 10^{-95}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 (*.f64 y z) z) < -2e85 or 9.99999999999999989e-96 < (*.f64 (*.f64 y z) z) Initial program 99.8%
Taylor expanded in x around inf 84.3%
Taylor expanded in y around inf 73.1%
associate-*r/71.5%
Simplified71.5%
associate-*r*76.3%
associate-*r/76.0%
*-commutative76.0%
*-commutative76.0%
Applied egg-rr76.0%
*-commutative76.0%
*-commutative76.0%
associate-*r/76.3%
unpow276.3%
associate-*r/77.0%
*-commutative77.0%
associate-*r*79.3%
*-commutative79.3%
Applied egg-rr79.3%
Taylor expanded in y around 0 87.8%
if -2e85 < (*.f64 (*.f64 y z) z) < 9.99999999999999989e-96Initial program 99.9%
Taylor expanded in x around inf 80.8%
Final simplification84.3%
(FPCore (x y z) :precision binary64 (if (or (<= z 2.1e-77) (and (not (<= z 3.5e+15)) (<= z 1.48e+16))) x (* y (* z z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= 2.1e-77) || (!(z <= 3.5e+15) && (z <= 1.48e+16))) {
tmp = x;
} else {
tmp = y * (z * 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 <= 2.1d-77) .or. (.not. (z <= 3.5d+15)) .and. (z <= 1.48d+16)) then
tmp = x
else
tmp = y * (z * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= 2.1e-77) || (!(z <= 3.5e+15) && (z <= 1.48e+16))) {
tmp = x;
} else {
tmp = y * (z * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= 2.1e-77) or (not (z <= 3.5e+15) and (z <= 1.48e+16)): tmp = x else: tmp = y * (z * z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= 2.1e-77) || (!(z <= 3.5e+15) && (z <= 1.48e+16))) tmp = x; else tmp = Float64(y * Float64(z * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= 2.1e-77) || (~((z <= 3.5e+15)) && (z <= 1.48e+16))) tmp = x; else tmp = y * (z * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, 2.1e-77], And[N[Not[LessEqual[z, 3.5e+15]], $MachinePrecision], LessEqual[z, 1.48e+16]]], x, N[(y * N[(z * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 2.1 \cdot 10^{-77} \lor \neg \left(z \leq 3.5 \cdot 10^{+15}\right) \land z \leq 1.48 \cdot 10^{+16}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z \cdot z\right)\\
\end{array}
\end{array}
if z < 2.10000000000000015e-77 or 3.5e15 < z < 1.48e16Initial program 99.9%
Taylor expanded in x around inf 57.9%
if 2.10000000000000015e-77 < z < 3.5e15 or 1.48e16 < z Initial program 99.8%
Taylor expanded in x around inf 92.2%
Taylor expanded in y around inf 70.0%
associate-*r/64.8%
Simplified64.8%
unpow264.8%
associate-/l*64.8%
Applied egg-rr64.8%
associate-*r*65.4%
associate-*r*66.7%
clear-num66.7%
un-div-inv66.7%
*-commutative66.7%
*-commutative66.7%
Applied egg-rr66.7%
associate-/r/66.9%
*-commutative66.9%
associate-*r/66.8%
associate-*l*71.1%
associate-*l*70.0%
associate-*r/73.9%
Applied egg-rr73.9%
Taylor expanded in x around 0 73.9%
Final simplification62.5%
(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 99.9%
Taylor expanded in x around inf 48.0%
herbie shell --seed 2024107
(FPCore (x y z)
:name "Statistics.Sample:robustSumVarWeighted from math-functions-0.1.5.2"
:precision binary64
(+ x (* (* y z) z)))