
(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 -850000.0) (not (<= y 0.48))) (* (+ z x) y) (fma y x x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -850000.0) || !(y <= 0.48)) {
tmp = (z + x) * y;
} else {
tmp = fma(y, x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -850000.0) || !(y <= 0.48)) tmp = Float64(Float64(z + x) * y); else tmp = fma(y, x, x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -850000.0], N[Not[LessEqual[y, 0.48]], $MachinePrecision]], N[(N[(z + x), $MachinePrecision] * y), $MachinePrecision], N[(y * x + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -850000 \lor \neg \left(y \leq 0.48\right):\\
\;\;\;\;\left(z + x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\end{array}
\end{array}
if y < -8.5e5 or 0.47999999999999998 < 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.f6497.8
Applied rewrites97.8%
Taylor expanded in y around -inf
distribute-lft-inN/A
mul-1-negN/A
*-commutativeN/A
*-commutativeN/A
associate-*l*N/A
distribute-rgt-neg-inN/A
mul-1-negN/A
remove-double-negN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6499.7
Applied rewrites99.7%
if -8.5e5 < y < 0.47999999999999998Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6476.7
Applied rewrites76.7%
Final simplification89.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.7e-73) (not (<= x 3.2e-79))) (fma y x x) (* z y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.7e-73) || !(x <= 3.2e-79)) {
tmp = fma(y, x, x);
} else {
tmp = z * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -4.7e-73) || !(x <= 3.2e-79)) tmp = fma(y, x, x); else tmp = Float64(z * y); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.7e-73], N[Not[LessEqual[x, 3.2e-79]], $MachinePrecision]], N[(y * x + x), $MachinePrecision], N[(z * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.7 \cdot 10^{-73} \lor \neg \left(x \leq 3.2 \cdot 10^{-79}\right):\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if x < -4.69999999999999994e-73 or 3.19999999999999988e-79 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6487.8
Applied rewrites87.8%
if -4.69999999999999994e-73 < x < 3.19999999999999988e-79Initial program 99.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6476.8
Applied rewrites76.8%
Final simplification83.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.9e+28) (not (<= x 1.2e-75))) (* y x) (* z y)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.9e+28) || !(x <= 1.2e-75)) {
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 <= (-1.9d+28)) .or. (.not. (x <= 1.2d-75))) 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 <= -1.9e+28) || !(x <= 1.2e-75)) {
tmp = y * x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.9e+28) or not (x <= 1.2e-75): tmp = y * x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.9e+28) || !(x <= 1.2e-75)) 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 <= -1.9e+28) || ~((x <= 1.2e-75))) tmp = y * x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.9e+28], N[Not[LessEqual[x, 1.2e-75]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(z * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.9 \cdot 10^{+28} \lor \neg \left(x \leq 1.2 \cdot 10^{-75}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if x < -1.8999999999999999e28 or 1.2000000000000001e-75 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6491.0
Applied rewrites91.0%
Taylor expanded in y around inf
Applied rewrites44.5%
if -1.8999999999999999e28 < x < 1.2000000000000001e-75Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6471.9
Applied rewrites71.9%
Final simplification55.8%
(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.f6465.4
Applied rewrites65.4%
Taylor expanded in y around inf
Applied rewrites31.9%
Final simplification31.9%
herbie shell --seed 2024327
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))