Average Error: 0.0 → 0.0
Time: 2.6s
Precision: binary64
Cost: 6720
\[\left(x \cdot y + x\right) + y \]
\[\mathsf{fma}\left(y, x, y + x\right) \]
(FPCore (x y) :precision binary64 (+ (+ (* x y) x) y))
(FPCore (x y) :precision binary64 (fma y x (+ y x)))
double code(double x, double y) {
	return ((x * y) + x) + y;
}
double code(double x, double y) {
	return fma(y, x, (y + x));
}
function code(x, y)
	return Float64(Float64(Float64(x * y) + x) + y)
end
function code(x, y)
	return fma(y, x, Float64(y + x))
end
code[x_, y_] := N[(N[(N[(x * y), $MachinePrecision] + x), $MachinePrecision] + y), $MachinePrecision]
code[x_, y_] := N[(y * x + N[(y + x), $MachinePrecision]), $MachinePrecision]
\left(x \cdot y + x\right) + y
\mathsf{fma}\left(y, x, y + x\right)

Error

Derivation

  1. Initial program 0.0

    \[\left(x \cdot y + x\right) + y \]
  2. Taylor expanded in x around 0 0.0

    \[\leadsto \color{blue}{y + \left(1 + y\right) \cdot x} \]
  3. Simplified0.0

    \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, y + x\right)} \]
    Proof
    (fma.f64 y x (+.f64 y x)): 0 points increase in error, 0 points decrease in error
    (fma.f64 y x (Rewrite=> +-commutative_binary64 (+.f64 x y))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= fma-def_binary64 (+.f64 (*.f64 y x) (+.f64 x y))): 3 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (*.f64 y x) x) y)): 1 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite=> distribute-lft1-in_binary64 (*.f64 (+.f64 y 1) x)) y): 1 points increase in error, 3 points decrease in error
    (+.f64 (*.f64 (Rewrite<= +-commutative_binary64 (+.f64 1 y)) x) y): 0 points increase in error, 0 points decrease in error
    (Rewrite<= +-commutative_binary64 (+.f64 y (*.f64 (+.f64 1 y) x))): 0 points increase in error, 0 points decrease in error
  4. Final simplification0.0

    \[\leadsto \mathsf{fma}\left(y, x, y + x\right) \]

Alternatives

Alternative 1
Error10.3
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -4.000993296654992 \cdot 10^{-12}:\\ \;\;\;\;x + y \cdot x\\ \mathbf{elif}\;y \leq 4.48726757577527 \cdot 10^{-13}:\\ \;\;\;\;y + x\\ \mathbf{else}:\\ \;\;\;\;y + y \cdot x\\ \end{array} \]
Alternative 2
Error0.0
Cost448
\[y + x \cdot \left(y + 1\right) \]
Alternative 3
Error27.9
Cost196
\[\begin{array}{l} \mathbf{if}\;x \leq -1.3655412448310195 \cdot 10^{-86}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \]

Error

Reproduce

herbie shell --seed 2022291 
(FPCore (x y)
  :name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
  :precision binary64
  (+ (+ (* x y) x) y))