
(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 (fma (* z y) z x))
double code(double x, double y, double z) {
return fma((z * y), z, x);
}
function code(x, y, z) return fma(Float64(z * y), z, x) end
code[x_, y_, z_] := N[(N[(z * y), $MachinePrecision] * z + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z \cdot y, z, x\right)
\end{array}
Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6499.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.9%
(FPCore (x y z) :precision binary64 (if (<= z 3.5e+42) (* -1.0 (- x)) (* (* z y) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= 3.5e+42) {
tmp = -1.0 * -x;
} 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 <= 3.5d+42) then
tmp = (-1.0d0) * -x
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 <= 3.5e+42) {
tmp = -1.0 * -x;
} else {
tmp = (z * y) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 3.5e+42: tmp = -1.0 * -x else: tmp = (z * y) * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 3.5e+42) tmp = Float64(-1.0 * Float64(-x)); else tmp = Float64(Float64(z * y) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 3.5e+42) tmp = -1.0 * -x; else tmp = (z * y) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 3.5e+42], N[(-1.0 * (-x)), $MachinePrecision], N[(N[(z * y), $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 3.5 \cdot 10^{+42}:\\
\;\;\;\;-1 \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(z \cdot y\right) \cdot z\\
\end{array}
\end{array}
if z < 3.50000000000000023e42Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64100.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in x around -inf
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
associate-/l*N/A
distribute-lft-neg-inN/A
lower--.f64N/A
lower-*.f64N/A
lower-neg.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6490.3
Applied rewrites90.3%
Taylor expanded in x around inf
Applied rewrites65.6%
if 3.50000000000000023e42 < z Initial program 99.8%
Taylor expanded in x around 0
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6490.0
Applied rewrites90.0%
Final simplification70.2%
(FPCore (x y z) :precision binary64 (* -1.0 (- x)))
double code(double x, double y, double z) {
return -1.0 * -x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (-1.0d0) * -x
end function
public static double code(double x, double y, double z) {
return -1.0 * -x;
}
def code(x, y, z): return -1.0 * -x
function code(x, y, z) return Float64(-1.0 * Float64(-x)) end
function tmp = code(x, y, z) tmp = -1.0 * -x; end
code[x_, y_, z_] := N[(-1.0 * (-x)), $MachinePrecision]
\begin{array}{l}
\\
-1 \cdot \left(-x\right)
\end{array}
Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6499.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.9%
Taylor expanded in x around -inf
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
associate-/l*N/A
distribute-lft-neg-inN/A
lower--.f64N/A
lower-*.f64N/A
lower-neg.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6489.5
Applied rewrites89.5%
Taylor expanded in x around inf
Applied rewrites55.5%
Final simplification55.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 Float64(-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%
Applied rewrites11.5%
Taylor expanded in x around inf
mul-1-negN/A
lower-neg.f642.3
Applied rewrites2.3%
herbie shell --seed 2024326
(FPCore (x y z)
:name "Statistics.Sample:robustSumVarWeighted from math-functions-0.1.5.2"
:precision binary64
(+ x (* (* y z) z)))