Average Error: 7.5 → 0.5
Time: 4.5s
Precision: binary64
\[\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}\\ t_1 := t_0 - {x}^{5}\\ \mathbf{if}\;t_1 \leq -3.0312 \cdot 10^{-319}:\\ \;\;\;\;\begin{array}{l} t_2 := \sqrt[3]{{x}^{5}}\\ t_0 - t_2 \cdot \left(t_2 \cdot t_2\right) \end{array}\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_3 := x \cdot {\varepsilon}^{4}\\ \mathbf{if}\;t_1 \leq 0:\\ \;\;\;\;\mathsf{fma}\left(\varepsilon, 5 \cdot {x}^{4}, \mathsf{fma}\left(5, t_3, \left(x \cdot x\right) \cdot \left(10 \cdot {\varepsilon}^{3}\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;{\varepsilon}^{5} + \mathsf{fma}\left(5, t_3, \left(x \cdot x\right) \cdot \left(\left(x + \varepsilon\right) \cdot \left(10 \cdot \left(\varepsilon \cdot \varepsilon\right)\right)\right)\right)\\ \end{array}\\ \end{array} \]
{\left(x + \varepsilon\right)}^{5} - {x}^{5}
\begin{array}{l}
t_0 := {\left(x + \varepsilon\right)}^{5}\\
t_1 := t_0 - {x}^{5}\\
\mathbf{if}\;t_1 \leq -3.0312 \cdot 10^{-319}:\\
\;\;\;\;\begin{array}{l}
t_2 := \sqrt[3]{{x}^{5}}\\
t_0 - t_2 \cdot \left(t_2 \cdot t_2\right)
\end{array}\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_3 := x \cdot {\varepsilon}^{4}\\
\mathbf{if}\;t_1 \leq 0:\\
\;\;\;\;\mathsf{fma}\left(\varepsilon, 5 \cdot {x}^{4}, \mathsf{fma}\left(5, t_3, \left(x \cdot x\right) \cdot \left(10 \cdot {\varepsilon}^{3}\right)\right)\right)\\

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


\end{array}\\


\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)) (t_1 (- t_0 (pow x 5.0))))
   (if (<= t_1 -3.0312e-319)
     (let* ((t_2 (cbrt (pow x 5.0)))) (- t_0 (* t_2 (* t_2 t_2))))
     (let* ((t_3 (* x (pow eps 4.0))))
       (if (<= t_1 0.0)
         (fma
          eps
          (* 5.0 (pow x 4.0))
          (fma 5.0 t_3 (* (* x x) (* 10.0 (pow eps 3.0)))))
         (+
          (pow eps 5.0)
          (fma 5.0 t_3 (* (* x x) (* (+ x eps) (* 10.0 (* eps eps)))))))))))
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);
	double t_1 = t_0 - pow(x, 5.0);
	double tmp;
	if (t_1 <= -3.0312e-319) {
		double t_2_1 = cbrt(pow(x, 5.0));
		tmp = t_0 - (t_2_1 * (t_2_1 * t_2_1));
	} else {
		double t_3 = x * pow(eps, 4.0);
		double tmp_2;
		if (t_1 <= 0.0) {
			tmp_2 = fma(eps, (5.0 * pow(x, 4.0)), fma(5.0, t_3, ((x * x) * (10.0 * pow(eps, 3.0)))));
		} else {
			tmp_2 = pow(eps, 5.0) + fma(5.0, t_3, ((x * x) * ((x + eps) * (10.0 * (eps * eps)))));
		}
		tmp = tmp_2;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus eps

Derivation

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

    1. Initial program 1.6

      \[{\left(x + \varepsilon\right)}^{5} - {x}^{5} \]
    2. Applied add-cube-cbrt_binary641.7

      \[\leadsto {\left(x + \varepsilon\right)}^{5} - \color{blue}{\left(\sqrt[3]{{x}^{5}} \cdot \sqrt[3]{{x}^{5}}\right) \cdot \sqrt[3]{{x}^{5}}} \]
    3. Applied cancel-sign-sub-inv_binary641.7

      \[\leadsto \color{blue}{{\left(x + \varepsilon\right)}^{5} + \left(-\sqrt[3]{{x}^{5}} \cdot \sqrt[3]{{x}^{5}}\right) \cdot \sqrt[3]{{x}^{5}}} \]

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

    1. Initial program 8.9

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\varepsilon, 5 \cdot {x}^{4}, \mathsf{fma}\left(5, {\varepsilon}^{4} \cdot x, \left(x \cdot x\right) \cdot \left(\left(10 \cdot \left(\varepsilon \cdot \varepsilon\right)\right) \cdot \left(\varepsilon + x\right)\right)\right)\right)} \]
    4. Taylor expanded in eps around inf 0.1

      \[\leadsto \mathsf{fma}\left(\varepsilon, 5 \cdot {x}^{4}, \mathsf{fma}\left(5, {\varepsilon}^{4} \cdot x, \left(x \cdot x\right) \cdot \color{blue}{\left(10 \cdot {\varepsilon}^{3}\right)}\right)\right) \]

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

    1. Initial program 1.4

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

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

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

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

Reproduce

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