
(FPCore (x y z) :precision binary64 (+ x (* y (+ z x))))
double code(double x, double y, double z) {
return x + (y * (z + 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 + (y * (z + x))
end function
public static double code(double x, double y, double z) {
return x + (y * (z + x));
}
def code(x, y, z): return x + (y * (z + x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z + x))) end
function tmp = code(x, y, z) tmp = x + (y * (z + x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z + x\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (* y (+ z x))))
double code(double x, double y, double z) {
return x + (y * (z + 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 + (y * (z + x))
end function
public static double code(double x, double y, double z) {
return x + (y * (z + x));
}
def code(x, y, z): return x + (y * (z + x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z + x))) end
function tmp = code(x, y, z) tmp = x + (y * (z + x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z + x\right)
\end{array}
(FPCore (x y z) :precision binary64 (fma (+ z x) y x))
double code(double x, double y, double z) {
return fma((z + x), y, x);
}
function code(x, y, z) return fma(Float64(z + x), y, x) end
code[x_, y_, z_] := N[(N[(z + x), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z + x, y, x\right)
\end{array}
Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.65e-16) (not (<= y 5e-33))) (* (+ z x) y) (fma y x x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.65e-16) || !(y <= 5e-33)) {
tmp = (z + x) * y;
} else {
tmp = fma(y, x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -1.65e-16) || !(y <= 5e-33)) tmp = Float64(Float64(z + x) * y); else tmp = fma(y, x, x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.65e-16], N[Not[LessEqual[y, 5e-33]], $MachinePrecision]], N[(N[(z + x), $MachinePrecision] * y), $MachinePrecision], N[(y * x + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.65 \cdot 10^{-16} \lor \neg \left(y \leq 5 \cdot 10^{-33}\right):\\
\;\;\;\;\left(z + x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\end{array}
\end{array}
if y < -1.64999999999999994e-16 or 5.00000000000000028e-33 < y Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-+.f64N/A
distribute-rgt-inN/A
associate-+l+N/A
lower-fma.f64N/A
*-commutativeN/A
lower-fma.f6498.6
Applied rewrites98.6%
Taylor expanded in y around -inf
mul-1-negN/A
distribute-lft-inN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
remove-double-negN/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6497.6
Applied rewrites97.6%
if -1.64999999999999994e-16 < y < 5.00000000000000028e-33Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6479.6
Applied rewrites79.6%
Final simplification90.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.3e-10) (not (<= x 3.2e-208))) (fma y x x) (* z y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.3e-10) || !(x <= 3.2e-208)) {
tmp = fma(y, x, x);
} else {
tmp = z * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -1.3e-10) || !(x <= 3.2e-208)) tmp = fma(y, x, x); else tmp = Float64(z * y); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.3e-10], N[Not[LessEqual[x, 3.2e-208]], $MachinePrecision]], N[(y * x + x), $MachinePrecision], N[(z * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.3 \cdot 10^{-10} \lor \neg \left(x \leq 3.2 \cdot 10^{-208}\right):\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if x < -1.29999999999999991e-10 or 3.2000000000000001e-208 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6481.7
Applied rewrites81.7%
if -1.29999999999999991e-10 < x < 3.2000000000000001e-208Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6482.9
Applied rewrites82.9%
Final simplification82.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.75e+14) (not (<= x 2.6e-89))) (* y x) (* z y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.75e+14) || !(x <= 2.6e-89)) {
tmp = y * x;
} else {
tmp = z * y;
}
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 <= (-2.75d+14)) .or. (.not. (x <= 2.6d-89))) then
tmp = y * x
else
tmp = z * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.75e+14) || !(x <= 2.6e-89)) {
tmp = y * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.75e+14) or not (x <= 2.6e-89): tmp = y * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.75e+14) || !(x <= 2.6e-89)) tmp = Float64(y * x); else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.75e+14) || ~((x <= 2.6e-89))) tmp = y * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.75e+14], N[Not[LessEqual[x, 2.6e-89]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(z * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.75 \cdot 10^{+14} \lor \neg \left(x \leq 2.6 \cdot 10^{-89}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if x < -2.75e14 or 2.5999999999999999e-89 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6486.4
Applied rewrites86.4%
Taylor expanded in y around inf
Applied rewrites42.9%
if -2.75e14 < x < 2.5999999999999999e-89Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6469.8
Applied rewrites69.8%
Final simplification56.5%
(FPCore (x y z) :precision binary64 (* y x))
double code(double x, double y, double z) {
return y * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y * x
end function
public static double code(double x, double y, double z) {
return y * x;
}
def code(x, y, z): return y * x
function code(x, y, z) return Float64(y * x) end
function tmp = code(x, y, z) tmp = y * x; end
code[x_, y_, z_] := N[(y * x), $MachinePrecision]
\begin{array}{l}
\\
y \cdot x
\end{array}
Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6459.3
Applied rewrites59.3%
Taylor expanded in y around inf
Applied rewrites26.4%
Final simplification26.4%
herbie shell --seed 2024318
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))