Average Error: 16.1 → 0.0
Time: 5.7s
Precision: binary64
Cost: 6848
\[\left(-1000000000 \leq x \land x \leq 1000000000\right) \land \left(-1 \leq \varepsilon \land \varepsilon \leq 1\right)\]
\[{\left(x + \varepsilon\right)}^{2} - {x}^{2} \]
\[\mathsf{fma}\left(2 \cdot x, \varepsilon, \varepsilon \cdot \varepsilon\right) \]
(FPCore (x eps) :precision binary64 (- (pow (+ x eps) 2.0) (pow x 2.0)))
(FPCore (x eps) :precision binary64 (fma (* 2.0 x) eps (* eps eps)))
double code(double x, double eps) {
	return pow((x + eps), 2.0) - pow(x, 2.0);
}
double code(double x, double eps) {
	return fma((2.0 * x), eps, (eps * eps));
}
function code(x, eps)
	return Float64((Float64(x + eps) ^ 2.0) - (x ^ 2.0))
end
function code(x, eps)
	return fma(Float64(2.0 * x), eps, Float64(eps * eps))
end
code[x_, eps_] := N[(N[Power[N[(x + eps), $MachinePrecision], 2.0], $MachinePrecision] - N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]
code[x_, eps_] := N[(N[(2.0 * x), $MachinePrecision] * eps + N[(eps * eps), $MachinePrecision]), $MachinePrecision]
{\left(x + \varepsilon\right)}^{2} - {x}^{2}
\mathsf{fma}\left(2 \cdot x, \varepsilon, \varepsilon \cdot \varepsilon\right)

Error

Derivation

  1. Initial program 16.1

    \[{\left(x + \varepsilon\right)}^{2} - {x}^{2} \]
  2. Simplified0.0

    \[\leadsto \color{blue}{\varepsilon \cdot \mathsf{fma}\left(2, x, \varepsilon\right)} \]
    Proof
    (*.f64 eps (fma.f64 2 x eps)): 0 points increase in error, 0 points decrease in error
    (*.f64 eps (Rewrite<= fma-def_binary64 (+.f64 (*.f64 2 x) eps))): 0 points increase in error, 0 points decrease in error
    (*.f64 eps (+.f64 (Rewrite<= count-2_binary64 (+.f64 x x)) eps)): 0 points increase in error, 0 points decrease in error
    (*.f64 eps (Rewrite<= associate-+r+_binary64 (+.f64 x (+.f64 x eps)))): 3 points increase in error, 1 points decrease in error
    (Rewrite<= distribute-rgt-out_binary64 (+.f64 (*.f64 x eps) (*.f64 (+.f64 x eps) eps))): 6 points increase in error, 5 points decrease in error
    (Rewrite<= +-rgt-identity_binary64 (+.f64 (+.f64 (*.f64 x eps) (*.f64 (+.f64 x eps) eps)) 0)): 0 points increase in error, 0 points decrease in error
    (+.f64 (+.f64 (*.f64 x eps) (*.f64 (+.f64 x eps) eps)) (Rewrite<= +-inverses_binary64 (-.f64 (pow.f64 x 2) (pow.f64 x 2)))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate--l+_binary64 (-.f64 (+.f64 (+.f64 (*.f64 x eps) (*.f64 (+.f64 x eps) eps)) (pow.f64 x 2)) (pow.f64 x 2))): 72 points increase in error, 1 points decrease in error
    (-.f64 (Rewrite<= +-commutative_binary64 (+.f64 (pow.f64 x 2) (+.f64 (*.f64 x eps) (*.f64 (+.f64 x eps) eps)))) (pow.f64 x 2)): 0 points increase in error, 0 points decrease in error
    (-.f64 (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (pow.f64 x 2) (*.f64 x eps)) (*.f64 (+.f64 x eps) eps))) (pow.f64 x 2)): 2 points increase in error, 0 points decrease in error
    (-.f64 (+.f64 (+.f64 (Rewrite=> unpow2_binary64 (*.f64 x x)) (*.f64 x eps)) (*.f64 (+.f64 x eps) eps)) (pow.f64 x 2)): 0 points increase in error, 0 points decrease in error
    (-.f64 (+.f64 (Rewrite<= distribute-lft-in_binary64 (*.f64 x (+.f64 x eps))) (*.f64 (+.f64 x eps) eps)) (pow.f64 x 2)): 3 points increase in error, 1 points decrease in error
    (-.f64 (+.f64 (*.f64 x (+.f64 x eps)) (Rewrite=> *-commutative_binary64 (*.f64 eps (+.f64 x eps)))) (pow.f64 x 2)): 0 points increase in error, 0 points decrease in error
    (-.f64 (Rewrite<= distribute-rgt-in_binary64 (*.f64 (+.f64 x eps) (+.f64 x eps))) (pow.f64 x 2)): 4 points increase in error, 0 points decrease in error
    (-.f64 (Rewrite<= unpow2_binary64 (pow.f64 (+.f64 x eps) 2)) (pow.f64 x 2)): 0 points increase in error, 0 points decrease in error
  3. Applied egg-rr0.0

    \[\leadsto \color{blue}{\left(2 \cdot x\right) \cdot \varepsilon + \varepsilon \cdot \varepsilon} \]
  4. Applied egg-rr0.0

    \[\leadsto \color{blue}{\mathsf{fma}\left(2 \cdot x, \varepsilon, \varepsilon \cdot \varepsilon\right)} \]
  5. Final simplification0.0

    \[\leadsto \mathsf{fma}\left(2 \cdot x, \varepsilon, \varepsilon \cdot \varepsilon\right) \]

Alternatives

Alternative 1
Error6.8
Cost584
\[\begin{array}{l} t_0 := \left(2 \cdot x\right) \cdot \varepsilon\\ \mathbf{if}\;x \leq -1.4310766438970817 \cdot 10^{-78}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 9.414703533642896 \cdot 10^{-64}:\\ \;\;\;\;\varepsilon \cdot \varepsilon\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error0.0
Cost448
\[\varepsilon \cdot \left(2 \cdot x + \varepsilon\right) \]
Alternative 3
Error17.8
Cost192
\[\varepsilon \cdot \varepsilon \]

Error

Reproduce

herbie shell --seed 2022294 
(FPCore (x eps)
  :name "ENA, Section 1.4, Exercise 4b, n=2"
  :precision binary64
  :pre (and (and (<= -1000000000.0 x) (<= x 1000000000.0)) (and (<= -1.0 eps) (<= eps 1.0)))
  (- (pow (+ x eps) 2.0) (pow x 2.0)))