
(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 6 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) -2e-249) (* (+ 1.0 y) x) (fma y x y)))
double code(double x, double y) {
double tmp;
if ((((x * y) + x) + y) <= -2e-249) {
tmp = (1.0 + y) * x;
} else {
tmp = fma(y, x, y);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (Float64(Float64(Float64(x * y) + x) + y) <= -2e-249) tmp = Float64(Float64(1.0 + y) * 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], -2e-249], N[(N[(1.0 + y), $MachinePrecision] * x), $MachinePrecision], N[(y * x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(x \cdot y + x\right) + y \leq -2 \cdot 10^{-249}:\\
\;\;\;\;\left(1 + y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\
\end{array}
\end{array}
if (+.f64 (+.f64 (*.f64 x y) x) y) < -2.00000000000000011e-249Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6464.6
Applied rewrites64.6%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6465.8
Applied rewrites65.8%
Applied rewrites65.8%
if -2.00000000000000011e-249 < (+.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.f6464.5
Applied rewrites64.5%
(FPCore (x y) :precision binary64 (if (<= (+ (+ (* x y) x) y) -2e-249) (fma y x x) (fma y x y)))
double code(double x, double y) {
double tmp;
if ((((x * y) + x) + y) <= -2e-249) {
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) <= -2e-249) 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], -2e-249], 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 -2 \cdot 10^{-249}:\\
\;\;\;\;\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) < -2.00000000000000011e-249Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6464.6
Applied rewrites64.6%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6465.8
Applied rewrites65.8%
if -2.00000000000000011e-249 < (+.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.f6464.5
Applied rewrites64.5%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 1700000000000.0))) (* y x) (* 1.0 x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 1700000000000.0)) {
tmp = y * x;
} else {
tmp = 1.0 * x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-1.0d0)) .or. (.not. (y <= 1700000000000.0d0))) then
tmp = y * x
else
tmp = 1.0d0 * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 1700000000000.0)) {
tmp = y * x;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.0) or not (y <= 1700000000000.0): tmp = y * x else: tmp = 1.0 * x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.0) || !(y <= 1700000000000.0)) tmp = Float64(y * x); else tmp = Float64(1.0 * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.0) || ~((y <= 1700000000000.0))) tmp = y * x; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 1700000000000.0]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1700000000000\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if y < -1 or 1.7e12 < y Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in x around inf
Applied rewrites51.2%
if -1 < y < 1.7e12Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6423.7
Applied rewrites23.7%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6478.3
Applied rewrites78.3%
Applied rewrites78.3%
Taylor expanded in y around 0
Applied rewrites76.6%
Final simplification63.0%
(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.f6464.5
Applied rewrites64.5%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6463.8
Applied rewrites63.8%
(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.f6464.5
Applied rewrites64.5%
Taylor expanded in x around inf
Applied rewrites29.3%
herbie shell --seed 2024307
(FPCore (x y)
:name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
:precision binary64
(+ (+ (* x y) x) y))