Average Error: 15.6 → 0.0
Time: 6.1s
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.6

    \[{\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))): 12 points increase in error, 3 points decrease in error
    (*.f64 eps (+.f64 (Rewrite<= count-2_binary64 (+.f64 x x)) eps)): 0 points increase in error, 15 points decrease in error
    (*.f64 eps (Rewrite<= +-commutative_binary64 (+.f64 eps (+.f64 x x)))): 5 points increase in error, 0 points decrease in error
    (*.f64 eps (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 eps x) x))): 0 points increase in error, 5 points decrease in error
    (*.f64 eps (+.f64 (Rewrite<= +-commutative_binary64 (+.f64 x eps)) x)): 0 points increase in error, 0 points decrease in error
    (Rewrite=> *-commutative_binary64 (*.f64 (+.f64 (+.f64 x eps) x) eps)): 0 points increase in error, 0 points decrease in error
    (*.f64 (+.f64 (+.f64 x eps) x) (Rewrite<= +-lft-identity_binary64 (+.f64 0 eps))): 0 points increase in error, 0 points decrease in error
    (*.f64 (+.f64 (+.f64 x eps) x) (+.f64 (Rewrite<= +-inverses_binary64 (-.f64 x x)) eps)): 0 points increase in error, 0 points decrease in error
    (*.f64 (+.f64 (+.f64 x eps) x) (Rewrite<= +-commutative_binary64 (+.f64 eps (-.f64 x x)))): 0 points increase in error, 0 points decrease in error
    (*.f64 (+.f64 (+.f64 x eps) x) (Rewrite<= associate--l+_binary64 (-.f64 (+.f64 eps x) x))): 0 points increase in error, 0 points decrease in error
    (*.f64 (+.f64 (+.f64 x eps) x) (-.f64 (Rewrite<= +-commutative_binary64 (+.f64 x eps)) x)): 0 points increase in error, 0 points decrease in error
    (Rewrite<= difference-of-squares_binary64 (-.f64 (*.f64 (+.f64 x eps) (+.f64 x eps)) (*.f64 x x))): 5 points increase in error, 0 points decrease in error
    (-.f64 (Rewrite<= unpow2_binary64 (pow.f64 (+.f64 x eps) 2)) (*.f64 x x)): 0 points increase in error, 5 points decrease in error
    (-.f64 (pow.f64 (+.f64 x eps) 2) (Rewrite<= unpow2_binary64 (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.2
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -5.2 \cdot 10^{-86} \lor \neg \left(x \leq 8.4 \cdot 10^{-117}\right):\\ \;\;\;\;\left(2 \cdot x\right) \cdot \varepsilon\\ \mathbf{else}:\\ \;\;\;\;\varepsilon \cdot \varepsilon\\ \end{array} \]
Alternative 2
Error0.0
Cost448
\[\varepsilon \cdot \left(\varepsilon + \left(x + x\right)\right) \]
Alternative 3
Error17.2
Cost192
\[\varepsilon \cdot \varepsilon \]

Error

Reproduce

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