
(FPCore (x y) :precision binary64 (+ (+ (* x y) x) y))
double code(double x, double y) {
return ((x * y) + x) + y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * y) + x) + y
end function
public static double code(double x, double y) {
return ((x * y) + x) + y;
}
def code(x, y): return ((x * y) + x) + y
function code(x, y) return Float64(Float64(Float64(x * y) + x) + y) end
function tmp = code(x, y) tmp = ((x * y) + x) + y; end
code[x_, y_] := N[(N[(N[(x * y), $MachinePrecision] + x), $MachinePrecision] + y), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y + x\right) + y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (+ (+ (* x y) x) y))
double code(double x, double y) {
return ((x * y) + x) + y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * y) + x) + y
end function
public static double code(double x, double y) {
return ((x * y) + x) + y;
}
def code(x, y): return ((x * y) + x) + y
function code(x, y) return Float64(Float64(Float64(x * y) + x) + y) end
function tmp = code(x, y) tmp = ((x * y) + x) + y; end
code[x_, y_] := N[(N[(N[(x * y), $MachinePrecision] + x), $MachinePrecision] + y), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot y + x\right) + y
\end{array}
(FPCore (x y) :precision binary64 (fma (+ x 1.0) y x))
double code(double x, double y) {
return fma((x + 1.0), y, x);
}
function code(x, y) return fma(Float64(x + 1.0), y, x) end
code[x_, y_] := N[(N[(x + 1.0), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x + 1, y, x\right)
\end{array}
Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-+.f64N/A
associate-+r+N/A
lift-*.f64N/A
distribute-rgt1-inN/A
lower-fma.f64N/A
lower-+.f64100.0
Applied rewrites100.0%
(FPCore (x y) :precision binary64 (if (<= (+ (+ (* x y) x) y) -1e-239) (fma y x x) (fma y x y)))
double code(double x, double y) {
double tmp;
if ((((x * y) + x) + y) <= -1e-239) {
tmp = fma(y, x, x);
} else {
tmp = fma(y, x, y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(Float64(Float64(x * y) + x) + y) <= -1e-239) tmp = fma(y, x, x); else tmp = fma(y, x, y); end return tmp end
code[x_, y_] := If[LessEqual[N[(N[(N[(x * y), $MachinePrecision] + x), $MachinePrecision] + y), $MachinePrecision], -1e-239], N[(y * x + x), $MachinePrecision], N[(y * x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(x \cdot y + x\right) + y \leq -1 \cdot 10^{-239}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\end{array}
\end{array}
if (+.f64 (+.f64 (*.f64 x y) x) y) < -1.0000000000000001e-239Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6463.6
Applied rewrites63.6%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6459.6
Applied rewrites59.6%
if -1.0000000000000001e-239 < (+.f64 (+.f64 (*.f64 x y) x) y) Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6463.3
Applied rewrites63.3%
(FPCore (x y) :precision binary64 (if (<= y -0.0035) (fma y x x) (if (<= y 4.2e-18) (fma 1.0 y x) (fma y x y))))
double code(double x, double y) {
double tmp;
if (y <= -0.0035) {
tmp = fma(y, x, x);
} else if (y <= 4.2e-18) {
tmp = fma(1.0, y, x);
} else {
tmp = fma(y, x, y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -0.0035) tmp = fma(y, x, x); elseif (y <= 4.2e-18) tmp = fma(1.0, y, x); else tmp = fma(y, x, y); end return tmp end
code[x_, y_] := If[LessEqual[y, -0.0035], N[(y * x + x), $MachinePrecision], If[LessEqual[y, 4.2e-18], N[(1.0 * y + x), $MachinePrecision], N[(y * x + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0035:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{elif}\;y \leq 4.2 \cdot 10^{-18}:\\
\;\;\;\;\mathsf{fma}\left(1, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\end{array}
\end{array}
if y < -0.00350000000000000007Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6496.2
Applied rewrites96.2%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6445.3
Applied rewrites45.3%
if -0.00350000000000000007 < y < 4.19999999999999999e-18Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-+.f64N/A
associate-+r+N/A
lift-*.f64N/A
distribute-rgt1-inN/A
lower-fma.f64N/A
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
if 4.19999999999999999e-18 < y Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6498.8
Applied rewrites98.8%
(FPCore (x y) :precision binary64 (fma y x x))
double code(double x, double y) {
return fma(y, x, x);
}
function code(x, y) return fma(y, x, x) end
code[x_, y_] := N[(y * x + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, x\right)
\end{array}
Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6463.4
Applied rewrites63.4%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6460.7
Applied rewrites60.7%
(FPCore (x y) :precision binary64 (* y x))
double code(double x, double y) {
return y * x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y * x
end function
public static double code(double x, double y) {
return y * x;
}
def code(x, y): return y * x
function code(x, y) return Float64(y * x) end
function tmp = code(x, y) tmp = y * x; end
code[x_, y_] := N[(y * x), $MachinePrecision]
\begin{array}{l}
\\
y \cdot x
\end{array}
Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6463.4
Applied rewrites63.4%
Taylor expanded in x around inf
Applied rewrites25.5%
herbie shell --seed 2024313
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))