Average Error: 7.5 → 1.0
Time: 5.5s
Precision: binary64
Cost: 53256
\[\left(-1000000000 \leq x \land x \leq 1000000000\right) \land \left(-1 \leq \varepsilon \land \varepsilon \leq 1\right)\]
\[{\left(x + \varepsilon\right)}^{5} - {x}^{5} \]
\[\begin{array}{l} t_0 := {\left(x + \varepsilon\right)}^{5} - {x}^{5}\\ \mathbf{if}\;t_0 \leq -5 \cdot 10^{-324}:\\ \;\;\;\;{\varepsilon}^{5}\\ \mathbf{elif}\;t_0 \leq 0:\\ \;\;\;\;\varepsilon \cdot \left(5 \cdot {x}^{4}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left({\varepsilon}^{4}, x \cdot 5, {\varepsilon}^{5} + \left(x \cdot \left(x \cdot 10\right)\right) \cdot {\varepsilon}^{3}\right)\\ \end{array} \]
(FPCore (x eps) :precision binary64 (- (pow (+ x eps) 5.0) (pow x 5.0)))
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (- (pow (+ x eps) 5.0) (pow x 5.0))))
   (if (<= t_0 -5e-324)
     (pow eps 5.0)
     (if (<= t_0 0.0)
       (* eps (* 5.0 (pow x 4.0)))
       (fma
        (pow eps 4.0)
        (* x 5.0)
        (+ (pow eps 5.0) (* (* x (* x 10.0)) (pow eps 3.0))))))))
double code(double x, double eps) {
	return pow((x + eps), 5.0) - pow(x, 5.0);
}
double code(double x, double eps) {
	double t_0 = pow((x + eps), 5.0) - pow(x, 5.0);
	double tmp;
	if (t_0 <= -5e-324) {
		tmp = pow(eps, 5.0);
	} else if (t_0 <= 0.0) {
		tmp = eps * (5.0 * pow(x, 4.0));
	} else {
		tmp = fma(pow(eps, 4.0), (x * 5.0), (pow(eps, 5.0) + ((x * (x * 10.0)) * pow(eps, 3.0))));
	}
	return tmp;
}
function code(x, eps)
	return Float64((Float64(x + eps) ^ 5.0) - (x ^ 5.0))
end
function code(x, eps)
	t_0 = Float64((Float64(x + eps) ^ 5.0) - (x ^ 5.0))
	tmp = 0.0
	if (t_0 <= -5e-324)
		tmp = eps ^ 5.0;
	elseif (t_0 <= 0.0)
		tmp = Float64(eps * Float64(5.0 * (x ^ 4.0)));
	else
		tmp = fma((eps ^ 4.0), Float64(x * 5.0), Float64((eps ^ 5.0) + Float64(Float64(x * Float64(x * 10.0)) * (eps ^ 3.0))));
	end
	return tmp
end
code[x_, eps_] := N[(N[Power[N[(x + eps), $MachinePrecision], 5.0], $MachinePrecision] - N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision]
code[x_, eps_] := Block[{t$95$0 = N[(N[Power[N[(x + eps), $MachinePrecision], 5.0], $MachinePrecision] - N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -5e-324], N[Power[eps, 5.0], $MachinePrecision], If[LessEqual[t$95$0, 0.0], N[(eps * N[(5.0 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[eps, 4.0], $MachinePrecision] * N[(x * 5.0), $MachinePrecision] + N[(N[Power[eps, 5.0], $MachinePrecision] + N[(N[(x * N[(x * 10.0), $MachinePrecision]), $MachinePrecision] * N[Power[eps, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
{\left(x + \varepsilon\right)}^{5} - {x}^{5}
\begin{array}{l}
t_0 := {\left(x + \varepsilon\right)}^{5} - {x}^{5}\\
\mathbf{if}\;t_0 \leq -5 \cdot 10^{-324}:\\
\;\;\;\;{\varepsilon}^{5}\\

\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;\varepsilon \cdot \left(5 \cdot {x}^{4}\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left({\varepsilon}^{4}, x \cdot 5, {\varepsilon}^{5} + \left(x \cdot \left(x \cdot 10\right)\right) \cdot {\varepsilon}^{3}\right)\\


\end{array}

Error

Derivation

  1. Split input into 3 regimes
  2. if (-.f64 (pow.f64 (+.f64 x eps) 5) (pow.f64 x 5)) < -4.94066e-324

    1. Initial program 1.6

      \[{\left(x + \varepsilon\right)}^{5} - {x}^{5} \]
    2. Taylor expanded in x around 0 5.4

      \[\leadsto \color{blue}{{\varepsilon}^{5}} \]

    if -4.94066e-324 < (-.f64 (pow.f64 (+.f64 x eps) 5) (pow.f64 x 5)) < 0.0

    1. Initial program 9.0

      \[{\left(x + \varepsilon\right)}^{5} - {x}^{5} \]
    2. Taylor expanded in eps around 0 0.1

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

      \[\leadsto \varepsilon \cdot \color{blue}{\left({x}^{4} \cdot 5\right)} \]

    if 0.0 < (-.f64 (pow.f64 (+.f64 x eps) 5) (pow.f64 x 5))

    1. Initial program 1.7

      \[{\left(x + \varepsilon\right)}^{5} - {x}^{5} \]
    2. Taylor expanded in x around 0 4.4

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

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

      \[\leadsto \mathsf{fma}\left({\varepsilon}^{4}, 5 \cdot x, \color{blue}{{\varepsilon}^{5} + \left(x \cdot \left(x \cdot 10\right)\right) \cdot {\varepsilon}^{3}}\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;{\left(x + \varepsilon\right)}^{5} - {x}^{5} \leq -5 \cdot 10^{-324}:\\ \;\;\;\;{\varepsilon}^{5}\\ \mathbf{elif}\;{\left(x + \varepsilon\right)}^{5} - {x}^{5} \leq 0:\\ \;\;\;\;\varepsilon \cdot \left(5 \cdot {x}^{4}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left({\varepsilon}^{4}, x \cdot 5, {\varepsilon}^{5} + \left(x \cdot \left(x \cdot 10\right)\right) \cdot {\varepsilon}^{3}\right)\\ \end{array} \]

Alternatives

Alternative 1
Error0.8
Cost39880
\[\begin{array}{l} t_0 := {\left(x + \varepsilon\right)}^{5} - {x}^{5}\\ \mathbf{if}\;t_0 \leq -5 \cdot 10^{-324}:\\ \;\;\;\;{\varepsilon}^{5}\\ \mathbf{elif}\;t_0 \leq 0:\\ \;\;\;\;\varepsilon \cdot \left(5 \cdot {x}^{4}\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error2.7
Cost7048
\[\begin{array}{l} t_0 := \varepsilon \cdot \left(5 \cdot {x}^{4}\right)\\ \mathbf{if}\;x \leq -3.4543307649496044 \cdot 10^{-21}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 4.833899510803369 \cdot 10^{-67}:\\ \;\;\;\;{\varepsilon}^{5}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error2.7
Cost6792
\[\begin{array}{l} t_0 := \varepsilon \cdot \left(\left(x \cdot x\right) \cdot \left(5 \cdot \left(x \cdot x\right)\right)\right)\\ \mathbf{if}\;x \leq -3.4543307649496044 \cdot 10^{-21}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 4.833899510803369 \cdot 10^{-67}:\\ \;\;\;\;{\varepsilon}^{5}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error11.4
Cost704
\[\varepsilon \cdot \left(\left(x \cdot x\right) \cdot \left(5 \cdot \left(x \cdot x\right)\right)\right) \]

Error

Reproduce

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