Average Error: 15.7 → 0.0
Time: 4.3s
Precision: binary64
Cost: 576
\[\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 \varepsilon + \left(2 \cdot x\right) \cdot \varepsilon \]
(FPCore (x eps) :precision binary64 (- (pow (+ x eps) 2.0) (pow x 2.0)))
(FPCore (x eps) :precision binary64 (+ (* eps eps) (* (* 2.0 x) eps)))
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) + ((2.0 * x) * eps);
}
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) + ((2.0d0 * x) * eps)
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) + ((2.0 * x) * eps);
}
def code(x, eps):
	return math.pow((x + eps), 2.0) - math.pow(x, 2.0)
def code(x, eps):
	return (eps * eps) + ((2.0 * x) * eps)
function code(x, eps)
	return Float64((Float64(x + eps) ^ 2.0) - (x ^ 2.0))
end
function code(x, eps)
	return Float64(Float64(eps * eps) + Float64(Float64(2.0 * x) * eps))
end
function tmp = code(x, eps)
	tmp = ((x + eps) ^ 2.0) - (x ^ 2.0);
end
function tmp = code(x, eps)
	tmp = (eps * eps) + ((2.0 * x) * 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[(eps * eps), $MachinePrecision] + N[(N[(2.0 * x), $MachinePrecision] * eps), $MachinePrecision]), $MachinePrecision]
{\left(x + \varepsilon\right)}^{2} - {x}^{2}
\varepsilon \cdot \varepsilon + \left(2 \cdot x\right) \cdot \varepsilon

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 15.7

    \[{\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)))): 1 points increase in error, 0 points decrease in error
    (Rewrite<= distribute-rgt-out_binary64 (+.f64 (*.f64 x eps) (*.f64 (+.f64 x eps) eps))): 2 points increase in error, 1 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))): 78 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)): 1 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)): 0 points increase in error, 0 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)): 0 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. Final simplification0.0

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

Alternatives

Alternative 1
Error6.4
Cost584
\[\begin{array}{l} t_0 := \left(2 \cdot x\right) \cdot \varepsilon\\ \mathbf{if}\;x \leq -8.413253253555421 \cdot 10^{-74}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.8742865165642487 \cdot 10^{-123}:\\ \;\;\;\;\varepsilon \cdot \varepsilon\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error17.4
Cost192
\[\varepsilon \cdot \varepsilon \]

Error

Reproduce

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