
(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}
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -1.95e+33) (fma y x x) (if (<= x 9.5e-16) (fma 1.0 y x) (fma y x y))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -1.95e+33) {
tmp = fma(y, x, x);
} else if (x <= 9.5e-16) {
tmp = fma(1.0, y, x);
} else {
tmp = fma(y, x, y);
}
return tmp;
}
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -1.95e+33) tmp = fma(y, x, x); elseif (x <= 9.5e-16) tmp = fma(1.0, y, x); else tmp = fma(y, x, y); end return tmp end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[x, -1.95e+33], N[(y * x + x), $MachinePrecision], If[LessEqual[x, 9.5e-16], N[(1.0 * y + x), $MachinePrecision], N[(y * x + y), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.95 \cdot 10^{+33}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{elif}\;x \leq 9.5 \cdot 10^{-16}:\\
\;\;\;\;\mathsf{fma}\left(1, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\end{array}
\end{array}
if x < -1.9500000000000001e33Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6449.4
Applied rewrites49.4%
Taylor expanded in x around inf
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64100.0
Applied rewrites100.0%
if -1.9500000000000001e33 < x < 9.5000000000000005e-16Initial 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 rewrites96.9%
if 9.5000000000000005e-16 < x Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6448.0
Applied rewrites48.0%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= (+ (+ (* y x) x) y) -2e-257) (fma y x x) (fma y x y)))
assert(x < y);
double code(double x, double y) {
double tmp;
if ((((y * x) + x) + y) <= -2e-257) {
tmp = fma(y, x, x);
} else {
tmp = fma(y, x, y);
}
return tmp;
}
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (Float64(Float64(Float64(y * x) + x) + y) <= -2e-257) tmp = fma(y, x, x); else tmp = fma(y, x, y); end return tmp end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[N[(N[(N[(y * x), $MachinePrecision] + x), $MachinePrecision] + y), $MachinePrecision], -2e-257], N[(y * x + x), $MachinePrecision], N[(y * x + y), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;\left(y \cdot x + x\right) + y \leq -2 \cdot 10^{-257}:\\
\;\;\;\;\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) < -2e-257Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6460.2
Applied rewrites60.2%
Taylor expanded in x around inf
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6466.6
Applied rewrites66.6%
if -2e-257 < (+.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.f6461.7
Applied rewrites61.7%
Final simplification64.1%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (fma (+ 1.0 x) y x))
assert(x < y);
double code(double x, double y) {
return fma((1.0 + x), y, x);
}
x, y = sort([x, y]) function code(x, y) return fma(Float64(1.0 + x), y, x) end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(N[(1.0 + x), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\mathsf{fma}\left(1 + x, 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%
Final simplification100.0%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (fma y x x))
assert(x < y);
double code(double x, double y) {
return fma(y, x, x);
}
x, y = sort([x, y]) function code(x, y) return fma(y, x, x) end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(y * x + x), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\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.f6461.0
Applied rewrites61.0%
Taylor expanded in x around inf
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6464.5
Applied rewrites64.5%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (* y x))
assert(x < y);
double code(double x, double y) {
return y * x;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y * x
end function
assert x < y;
public static double code(double x, double y) {
return y * x;
}
[x, y] = sort([x, y]) def code(x, y): return y * x
x, y = sort([x, y]) function code(x, y) return Float64(y * x) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
tmp = y * x;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(y * x), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
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.f6461.0
Applied rewrites61.0%
Taylor expanded in x around inf
Applied rewrites26.4%
herbie shell --seed 2024294
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))