
(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 (* (* 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}
Initial program 99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (* y z) z)))
(if (or (<= t_0 -2e-118) (not (<= t_0 4e+88)))
(* (* z y) z)
(* -1.0 (- x)))))
double code(double x, double y, double z) {
double t_0 = (y * z) * z;
double tmp;
if ((t_0 <= -2e-118) || !(t_0 <= 4e+88)) {
tmp = (z * y) * z;
} else {
tmp = -1.0 * -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 = (y * z) * z
if ((t_0 <= (-2d-118)) .or. (.not. (t_0 <= 4d+88))) then
tmp = (z * y) * z
else
tmp = (-1.0d0) * -x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (y * z) * z;
double tmp;
if ((t_0 <= -2e-118) || !(t_0 <= 4e+88)) {
tmp = (z * y) * z;
} else {
tmp = -1.0 * -x;
}
return tmp;
}
def code(x, y, z): t_0 = (y * z) * z tmp = 0 if (t_0 <= -2e-118) or not (t_0 <= 4e+88): tmp = (z * y) * z else: tmp = -1.0 * -x return tmp
function code(x, y, z) t_0 = Float64(Float64(y * z) * z) tmp = 0.0 if ((t_0 <= -2e-118) || !(t_0 <= 4e+88)) tmp = Float64(Float64(z * y) * z); else tmp = Float64(-1.0 * Float64(-x)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (y * z) * z; tmp = 0.0; if ((t_0 <= -2e-118) || ~((t_0 <= 4e+88))) tmp = (z * y) * z; else tmp = -1.0 * -x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y * z), $MachinePrecision] * z), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -2e-118], N[Not[LessEqual[t$95$0, 4e+88]], $MachinePrecision]], N[(N[(z * y), $MachinePrecision] * z), $MachinePrecision], N[(-1.0 * (-x)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y \cdot z\right) \cdot z\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{-118} \lor \neg \left(t\_0 \leq 4 \cdot 10^{+88}\right):\\
\;\;\;\;\left(z \cdot y\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;-1 \cdot \left(-x\right)\\
\end{array}
\end{array}
if (*.f64 (*.f64 y z) z) < -1.99999999999999997e-118 or 3.99999999999999984e88 < (*.f64 (*.f64 y z) z) Initial program 99.8%
Taylor expanded in x around 0
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6486.8
Applied rewrites86.8%
if -1.99999999999999997e-118 < (*.f64 (*.f64 y z) z) < 3.99999999999999984e88Initial program 99.9%
Taylor expanded in x around 0
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f649.5
Applied rewrites9.5%
Applied rewrites6.0%
Taylor expanded in x around -inf
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.1%
Taylor expanded in x around inf
Applied rewrites93.1%
Final simplification89.5%
(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 (* -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%
Taylor expanded in x around 0
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6453.3
Applied rewrites53.3%
Applied rewrites27.5%
Taylor expanded in x around -inf
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites92.2%
Taylor expanded in x around inf
Applied rewrites48.8%
(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 rewrites6.0%
Taylor expanded in x around inf
mul-1-negN/A
lower-neg.f642.2
Applied rewrites2.2%
herbie shell --seed 2024339
(FPCore (x y z)
:name "Statistics.Sample:robustSumVarWeighted from math-functions-0.1.5.2"
:precision binary64
(+ x (* (* y z) z)))