Average Error: 16.1 → 0.0
Time: 5.4s
Precision: binary64
Cost: 448
\[\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} \]
\[\varepsilon \cdot \left(\varepsilon + x \cdot 2\right) \]
(FPCore (x eps) :precision binary64 (- (pow (+ x eps) 2.0) (pow x 2.0)))
(FPCore (x eps) :precision binary64 (* eps (+ eps (* x 2.0))))
double code(double x, double eps) {
	return pow((x + eps), 2.0) - pow(x, 2.0);
}
double code(double x, double eps) {
	return eps * (eps + (x * 2.0));
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    code = ((x + eps) ** 2.0d0) - (x ** 2.0d0)
end function
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    code = eps * (eps + (x * 2.0d0))
end function
public static double code(double x, double eps) {
	return Math.pow((x + eps), 2.0) - Math.pow(x, 2.0);
}
public static double code(double x, double eps) {
	return eps * (eps + (x * 2.0));
}
def code(x, eps):
	return math.pow((x + eps), 2.0) - math.pow(x, 2.0)
def code(x, eps):
	return eps * (eps + (x * 2.0))
function code(x, eps)
	return Float64((Float64(x + eps) ^ 2.0) - (x ^ 2.0))
end
function code(x, eps)
	return Float64(eps * Float64(eps + Float64(x * 2.0)))
end
function tmp = code(x, eps)
	tmp = ((x + eps) ^ 2.0) - (x ^ 2.0);
end
function tmp = code(x, eps)
	tmp = eps * (eps + (x * 2.0));
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[(eps * N[(eps + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
{\left(x + \varepsilon\right)}^{2} - {x}^{2}
\varepsilon \cdot \left(\varepsilon + x \cdot 2\right)

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

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)))): 5 points increase in error, 3 points decrease in error
    (Rewrite<= distribute-rgt-out_binary64 (+.f64 (*.f64 x eps) (*.f64 (+.f64 x eps) eps))): 7 points increase in error, 2 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))): 79 points increase in error, 0 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)): 5 points increase in error, 1 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)): 2 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)): 1 points increase in error, 2 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-rr9.4

    \[\leadsto \color{blue}{{\left(\sqrt{\varepsilon \cdot \mathsf{fma}\left(2, x, \varepsilon\right)}\right)}^{2}} \]
  4. Taylor expanded in eps around inf 0.0

    \[\leadsto \color{blue}{{\varepsilon}^{2} + 2 \cdot \left(\varepsilon \cdot x\right)} \]
  5. Simplified0.0

    \[\leadsto \color{blue}{\varepsilon \cdot \left(\varepsilon + x \cdot 2\right)} \]
    Proof
    (*.f64 eps (+.f64 eps (*.f64 x 2))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= distribute-lft-out_binary64 (+.f64 (*.f64 eps eps) (*.f64 eps (*.f64 x 2)))): 5 points increase in error, 1 points decrease in error
    (+.f64 (Rewrite<= unpow2_binary64 (pow.f64 eps 2)) (*.f64 eps (*.f64 x 2))): 0 points increase in error, 0 points decrease in error
    (+.f64 (pow.f64 eps 2) (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 eps x) 2))): 3 points increase in error, 0 points decrease in error
    (+.f64 (pow.f64 eps 2) (Rewrite<= *-commutative_binary64 (*.f64 2 (*.f64 eps x)))): 0 points increase in error, 0 points decrease in error
  6. Final simplification0.0

    \[\leadsto \varepsilon \cdot \left(\varepsilon + x \cdot 2\right) \]

Alternatives

Alternative 1
Error5.8
Cost584
\[\begin{array}{l} t_0 := \varepsilon \cdot \left(x \cdot 2\right)\\ \mathbf{if}\;x \leq -4.749882866018889 \cdot 10^{-102}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 4.500055914425196 \cdot 10^{-97}:\\ \;\;\;\;\varepsilon \cdot \varepsilon\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error17.5
Cost192
\[\varepsilon \cdot \varepsilon \]

Error

Reproduce

herbie shell --seed 2022317 
(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)))