
(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 5 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.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (* y z))))
(if (or (<= t_0 -1e+137)
(not
(or (<= t_0 -1e+35) (and (not (<= t_0 -2e-143)) (<= t_0 5e-24)))))
t_0
x)))
double code(double x, double y, double z) {
double t_0 = z * (y * z);
double tmp;
if ((t_0 <= -1e+137) || !((t_0 <= -1e+35) || (!(t_0 <= -2e-143) && (t_0 <= 5e-24)))) {
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 <= (-1d+137)) .or. (.not. (t_0 <= (-1d+35)) .or. (.not. (t_0 <= (-2d-143))) .and. (t_0 <= 5d-24))) 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 <= -1e+137) || !((t_0 <= -1e+35) || (!(t_0 <= -2e-143) && (t_0 <= 5e-24)))) {
tmp = t_0;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = z * (y * z) tmp = 0 if (t_0 <= -1e+137) or not ((t_0 <= -1e+35) or (not (t_0 <= -2e-143) and (t_0 <= 5e-24))): 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 <= -1e+137) || !((t_0 <= -1e+35) || (!(t_0 <= -2e-143) && (t_0 <= 5e-24)))) 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 <= -1e+137) || ~(((t_0 <= -1e+35) || (~((t_0 <= -2e-143)) && (t_0 <= 5e-24))))) 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, -1e+137], N[Not[Or[LessEqual[t$95$0, -1e+35], And[N[Not[LessEqual[t$95$0, -2e-143]], $MachinePrecision], LessEqual[t$95$0, 5e-24]]]], $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 -1 \cdot 10^{+137} \lor \neg \left(t_0 \leq -1 \cdot 10^{+35} \lor \neg \left(t_0 \leq -2 \cdot 10^{-143}\right) \land t_0 \leq 5 \cdot 10^{-24}\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 (*.f64 y z) z) < -1e137 or -9.9999999999999997e34 < (*.f64 (*.f64 y z) z) < -1.9999999999999999e-143 or 4.9999999999999998e-24 < (*.f64 (*.f64 y z) z) Initial program 99.8%
associate-*l*92.2%
Simplified92.2%
+-commutative92.2%
associate-*r*99.8%
add-sqr-sqrt45.0%
associate-*r*45.0%
fma-def45.0%
Applied egg-rr45.0%
Taylor expanded in y around inf 82.7%
unpow282.7%
Simplified82.7%
*-commutative82.7%
pow282.7%
add-sqr-sqrt44.9%
pow244.9%
pow-prod-down47.3%
Applied egg-rr47.3%
unpow247.3%
swap-sqr44.9%
add-sqr-sqrt82.7%
*-commutative82.7%
associate-*l*90.2%
Applied egg-rr90.2%
if -1e137 < (*.f64 (*.f64 y z) z) < -9.9999999999999997e34 or -1.9999999999999999e-143 < (*.f64 (*.f64 y z) z) < 4.9999999999999998e-24Initial program 99.9%
associate-*l*98.5%
Simplified98.5%
Taylor expanded in x around inf 87.6%
Final simplification89.1%
(FPCore (x y z) :precision binary64 (if (<= z 1.85e-66) x (if (or (<= z 3.8e-47) (not (<= z 2.9e-17))) (* y (* z z)) x)))
double code(double x, double y, double z) {
double tmp;
if (z <= 1.85e-66) {
tmp = x;
} else if ((z <= 3.8e-47) || !(z <= 2.9e-17)) {
tmp = y * (z * 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.85d-66) then
tmp = x
else if ((z <= 3.8d-47) .or. (.not. (z <= 2.9d-17))) then
tmp = y * (z * 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.85e-66) {
tmp = x;
} else if ((z <= 3.8e-47) || !(z <= 2.9e-17)) {
tmp = y * (z * z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 1.85e-66: tmp = x elif (z <= 3.8e-47) or not (z <= 2.9e-17): tmp = y * (z * z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= 1.85e-66) tmp = x; elseif ((z <= 3.8e-47) || !(z <= 2.9e-17)) tmp = Float64(y * Float64(z * z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 1.85e-66) tmp = x; elseif ((z <= 3.8e-47) || ~((z <= 2.9e-17))) tmp = y * (z * z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 1.85e-66], x, If[Or[LessEqual[z, 3.8e-47], N[Not[LessEqual[z, 2.9e-17]], $MachinePrecision]], N[(y * N[(z * z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.85 \cdot 10^{-66}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 3.8 \cdot 10^{-47} \lor \neg \left(z \leq 2.9 \cdot 10^{-17}\right):\\
\;\;\;\;y \cdot \left(z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < 1.8500000000000001e-66 or 3.80000000000000015e-47 < z < 2.9000000000000003e-17Initial program 99.9%
associate-*l*96.2%
Simplified96.2%
Taylor expanded in x around inf 54.1%
if 1.8500000000000001e-66 < z < 3.80000000000000015e-47 or 2.9000000000000003e-17 < z Initial program 99.7%
associate-*l*91.1%
Simplified91.1%
+-commutative91.1%
associate-*r*99.7%
add-sqr-sqrt99.6%
associate-*r*99.5%
fma-def99.6%
Applied egg-rr99.6%
Taylor expanded in y around inf 79.7%
unpow279.7%
Simplified79.7%
Final simplification60.5%
(FPCore (x y z) :precision binary64 (if (<= z 2.45e+148) (+ x (* y (* z z))) (* z (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= 2.45e+148) {
tmp = x + (y * (z * z));
} else {
tmp = z * (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 <= 2.45d+148) then
tmp = x + (y * (z * z))
else
tmp = z * (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 2.45e+148) {
tmp = x + (y * (z * z));
} else {
tmp = z * (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 2.45e+148: tmp = x + (y * (z * z)) else: tmp = z * (y * z) return tmp
function code(x, y, z) tmp = 0.0 if (z <= 2.45e+148) tmp = Float64(x + Float64(y * Float64(z * z))); else tmp = Float64(z * Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 2.45e+148) tmp = x + (y * (z * z)); else tmp = z * (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 2.45e+148], N[(x + N[(y * N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 2.45 \cdot 10^{+148}:\\
\;\;\;\;x + y \cdot \left(z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(y \cdot z\right)\\
\end{array}
\end{array}
if z < 2.45e148Initial program 99.8%
associate-*l*96.8%
Simplified96.8%
if 2.45e148 < z Initial program 99.9%
associate-*l*76.8%
Simplified76.8%
+-commutative76.8%
associate-*r*99.9%
add-sqr-sqrt99.9%
associate-*r*99.9%
fma-def99.9%
Applied egg-rr99.9%
Taylor expanded in y around inf 76.8%
unpow276.8%
Simplified76.8%
*-commutative76.8%
pow276.8%
add-sqr-sqrt42.0%
pow242.0%
pow-prod-down45.8%
Applied egg-rr45.8%
unpow245.8%
swap-sqr42.0%
add-sqr-sqrt76.8%
*-commutative76.8%
associate-*l*99.9%
Applied egg-rr99.9%
Final simplification97.1%
(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.8%
associate-*l*94.9%
Simplified94.9%
Taylor expanded in x around inf 43.6%
Final simplification43.6%
herbie shell --seed 2023229
(FPCore (x y z)
:name "Statistics.Sample:robustSumVarWeighted from math-functions-0.1.5.2"
:precision binary64
(+ x (* (* y z) z)))