ENA, Section 1.4, Exercise 4b, n=5

Percentage Accurate: 88.3% → 99.4%
Time: 6.6s
Alternatives: 3
Speedup: N/A×

Specification

?
\[\left(-1000000000 \leq x \land x \leq 1000000000\right) \land \left(-1 \leq \varepsilon \land \varepsilon \leq 1\right)\]
\[\begin{array}{l} \\ {\left(x + \varepsilon\right)}^{5} - {x}^{5} \end{array} \]
(FPCore (x eps) :precision binary64 (- (pow (+ x eps) 5.0) (pow x 5.0)))
double code(double x, double eps) {
	return pow((x + eps), 5.0) - pow(x, 5.0);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, eps)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    code = ((x + eps) ** 5.0d0) - (x ** 5.0d0)
end function
public static double code(double x, double eps) {
	return Math.pow((x + eps), 5.0) - Math.pow(x, 5.0);
}
def code(x, eps):
	return math.pow((x + eps), 5.0) - math.pow(x, 5.0)
function code(x, eps)
	return Float64((Float64(x + eps) ^ 5.0) - (x ^ 5.0))
end
function tmp = code(x, eps)
	tmp = ((x + eps) ^ 5.0) - (x ^ 5.0);
end
code[x_, eps_] := N[(N[Power[N[(x + eps), $MachinePrecision], 5.0], $MachinePrecision] - N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
{\left(x + \varepsilon\right)}^{5} - {x}^{5}
\end{array}

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 3 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 88.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ {\left(x + \varepsilon\right)}^{5} - {x}^{5} \end{array} \]
(FPCore (x eps) :precision binary64 (- (pow (+ x eps) 5.0) (pow x 5.0)))
double code(double x, double eps) {
	return pow((x + eps), 5.0) - pow(x, 5.0);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, eps)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    code = ((x + eps) ** 5.0d0) - (x ** 5.0d0)
end function
public static double code(double x, double eps) {
	return Math.pow((x + eps), 5.0) - Math.pow(x, 5.0);
}
def code(x, eps):
	return math.pow((x + eps), 5.0) - math.pow(x, 5.0)
function code(x, eps)
	return Float64((Float64(x + eps) ^ 5.0) - (x ^ 5.0))
end
function tmp = code(x, eps)
	tmp = ((x + eps) ^ 5.0) - (x ^ 5.0);
end
code[x_, eps_] := N[(N[Power[N[(x + eps), $MachinePrecision], 5.0], $MachinePrecision] - N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
{\left(x + \varepsilon\right)}^{5} - {x}^{5}
\end{array}

Alternative 1: 99.4% accurate, N/A× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {\left(x + \varepsilon\right)}^{5} - {x}^{5}\\ \mathbf{if}\;t\_0 \leq -2 \cdot 10^{-308}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;t\_0 \leq 0:\\ \;\;\;\;\mathsf{fma}\left({x}^{4}, 4, x \cdot \mathsf{fma}\left(5, {\varepsilon}^{3}, x \cdot \mathsf{fma}\left(10, \varepsilon \cdot \varepsilon, x \cdot \mathsf{fma}\left(10, \varepsilon, x\right)\right)\right)\right) \cdot \varepsilon\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (- (pow (+ x eps) 5.0) (pow x 5.0))))
   (if (<= t_0 -2e-308)
     t_0
     (if (<= t_0 0.0)
       (*
        (fma
         (pow x 4.0)
         4.0
         (*
          x
          (fma
           5.0
           (pow eps 3.0)
           (* x (fma 10.0 (* eps eps) (* x (fma 10.0 eps x)))))))
        eps)
       t_0))))
double code(double x, double eps) {
	double t_0 = pow((x + eps), 5.0) - pow(x, 5.0);
	double tmp;
	if (t_0 <= -2e-308) {
		tmp = t_0;
	} else if (t_0 <= 0.0) {
		tmp = fma(pow(x, 4.0), 4.0, (x * fma(5.0, pow(eps, 3.0), (x * fma(10.0, (eps * eps), (x * fma(10.0, eps, x))))))) * eps;
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(x, eps)
	t_0 = Float64((Float64(x + eps) ^ 5.0) - (x ^ 5.0))
	tmp = 0.0
	if (t_0 <= -2e-308)
		tmp = t_0;
	elseif (t_0 <= 0.0)
		tmp = Float64(fma((x ^ 4.0), 4.0, Float64(x * fma(5.0, (eps ^ 3.0), Float64(x * fma(10.0, Float64(eps * eps), Float64(x * fma(10.0, eps, x))))))) * eps);
	else
		tmp = t_0;
	end
	return tmp
end
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, -2e-308], t$95$0, If[LessEqual[t$95$0, 0.0], N[(N[(N[Power[x, 4.0], $MachinePrecision] * 4.0 + N[(x * N[(5.0 * N[Power[eps, 3.0], $MachinePrecision] + N[(x * N[(10.0 * N[(eps * eps), $MachinePrecision] + N[(x * N[(10.0 * eps + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * eps), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {\left(x + \varepsilon\right)}^{5} - {x}^{5}\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{-308}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;t\_0 \leq 0:\\
\;\;\;\;\mathsf{fma}\left({x}^{4}, 4, x \cdot \mathsf{fma}\left(5, {\varepsilon}^{3}, x \cdot \mathsf{fma}\left(10, \varepsilon \cdot \varepsilon, x \cdot \mathsf{fma}\left(10, \varepsilon, x\right)\right)\right)\right) \cdot \varepsilon\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (pow.f64 (+.f64 x eps) #s(literal 5 binary64)) (pow.f64 x #s(literal 5 binary64))) < -1.9999999999999998e-308 or 0.0 < (-.f64 (pow.f64 (+.f64 x eps) #s(literal 5 binary64)) (pow.f64 x #s(literal 5 binary64)))

    1. Initial program 97.9%

      \[{\left(x + \varepsilon\right)}^{5} - {x}^{5} \]

    if -1.9999999999999998e-308 < (-.f64 (pow.f64 (+.f64 x eps) #s(literal 5 binary64)) (pow.f64 x #s(literal 5 binary64))) < 0.0

    1. Initial program 86.0%

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

      \[\leadsto \color{blue}{\varepsilon \cdot \left(4 \cdot {x}^{4} + \left(\varepsilon \cdot \left(4 \cdot {x}^{3} + \left(\varepsilon \cdot \left(2 \cdot {x}^{2} + \left(8 \cdot {x}^{2} + \varepsilon \cdot \left(x + 4 \cdot x\right)\right)\right) + x \cdot \left(2 \cdot {x}^{2} + 4 \cdot {x}^{2}\right)\right)\right) + {x}^{4}\right)\right)} \]
    3. Applied rewrites99.7%

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

      \[\leadsto \mathsf{fma}\left({x}^{4}, 4, x \cdot \left(5 \cdot {\varepsilon}^{3} + x \cdot \left(10 \cdot {\varepsilon}^{2} + x \cdot \left(x + 10 \cdot \varepsilon\right)\right)\right)\right) \cdot \varepsilon \]
    5. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left({x}^{4}, 4, x \cdot \left(5 \cdot {\varepsilon}^{3} + x \cdot \left(10 \cdot {\varepsilon}^{2} + x \cdot \left(x + 10 \cdot \varepsilon\right)\right)\right)\right) \cdot \varepsilon \]
      2. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left({x}^{4}, 4, x \cdot \mathsf{fma}\left(5, {\varepsilon}^{3}, x \cdot \left(10 \cdot {\varepsilon}^{2} + x \cdot \left(x + 10 \cdot \varepsilon\right)\right)\right)\right) \cdot \varepsilon \]
      3. lift-pow.f64N/A

        \[\leadsto \mathsf{fma}\left({x}^{4}, 4, x \cdot \mathsf{fma}\left(5, {\varepsilon}^{3}, x \cdot \left(10 \cdot {\varepsilon}^{2} + x \cdot \left(x + 10 \cdot \varepsilon\right)\right)\right)\right) \cdot \varepsilon \]
      4. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left({x}^{4}, 4, x \cdot \mathsf{fma}\left(5, {\varepsilon}^{3}, x \cdot \left(10 \cdot {\varepsilon}^{2} + x \cdot \left(x + 10 \cdot \varepsilon\right)\right)\right)\right) \cdot \varepsilon \]
      5. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left({x}^{4}, 4, x \cdot \mathsf{fma}\left(5, {\varepsilon}^{3}, x \cdot \mathsf{fma}\left(10, {\varepsilon}^{2}, x \cdot \left(x + 10 \cdot \varepsilon\right)\right)\right)\right) \cdot \varepsilon \]
      6. pow2N/A

        \[\leadsto \mathsf{fma}\left({x}^{4}, 4, x \cdot \mathsf{fma}\left(5, {\varepsilon}^{3}, x \cdot \mathsf{fma}\left(10, \varepsilon \cdot \varepsilon, x \cdot \left(x + 10 \cdot \varepsilon\right)\right)\right)\right) \cdot \varepsilon \]
      7. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left({x}^{4}, 4, x \cdot \mathsf{fma}\left(5, {\varepsilon}^{3}, x \cdot \mathsf{fma}\left(10, \varepsilon \cdot \varepsilon, x \cdot \left(x + 10 \cdot \varepsilon\right)\right)\right)\right) \cdot \varepsilon \]
      8. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left({x}^{4}, 4, x \cdot \mathsf{fma}\left(5, {\varepsilon}^{3}, x \cdot \mathsf{fma}\left(10, \varepsilon \cdot \varepsilon, x \cdot \left(x + 10 \cdot \varepsilon\right)\right)\right)\right) \cdot \varepsilon \]
      9. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left({x}^{4}, 4, x \cdot \mathsf{fma}\left(5, {\varepsilon}^{3}, x \cdot \mathsf{fma}\left(10, \varepsilon \cdot \varepsilon, x \cdot \left(10 \cdot \varepsilon + x\right)\right)\right)\right) \cdot \varepsilon \]
      10. lower-fma.f6499.7

        \[\leadsto \mathsf{fma}\left({x}^{4}, 4, x \cdot \mathsf{fma}\left(5, {\varepsilon}^{3}, x \cdot \mathsf{fma}\left(10, \varepsilon \cdot \varepsilon, x \cdot \mathsf{fma}\left(10, \varepsilon, x\right)\right)\right)\right) \cdot \varepsilon \]
    6. Applied rewrites99.7%

      \[\leadsto \mathsf{fma}\left({x}^{4}, 4, x \cdot \mathsf{fma}\left(5, {\varepsilon}^{3}, x \cdot \mathsf{fma}\left(10, \varepsilon \cdot \varepsilon, x \cdot \mathsf{fma}\left(10, \varepsilon, x\right)\right)\right)\right) \cdot \varepsilon \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 2: 98.7% accurate, N/A× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {\left(x + \varepsilon\right)}^{5} - {x}^{5}\\ t_1 := \mathsf{fma}\left(\mathsf{fma}\left({\varepsilon}^{4}, 4, \mathsf{fma}\left(\mathsf{fma}\left({\varepsilon}^{3}, 4, \mathsf{fma}\left(\left(\varepsilon \cdot \varepsilon\right) \cdot 10, x, \left(\left(\varepsilon \cdot \varepsilon\right) \cdot 6\right) \cdot \varepsilon\right)\right), x, {\varepsilon}^{4}\right)\right), x, {\varepsilon}^{5}\right)\\ \mathbf{if}\;t\_0 \leq -2 \cdot 10^{-308}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 \leq 0:\\ \;\;\;\;\mathsf{fma}\left({x}^{4}, 4, x \cdot \mathsf{fma}\left(5, {\varepsilon}^{3}, x \cdot \mathsf{fma}\left(10, \varepsilon \cdot \varepsilon, x \cdot \mathsf{fma}\left(10, \varepsilon, x\right)\right)\right)\right) \cdot \varepsilon\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (- (pow (+ x eps) 5.0) (pow x 5.0)))
        (t_1
         (fma
          (fma
           (pow eps 4.0)
           4.0
           (fma
            (fma
             (pow eps 3.0)
             4.0
             (fma (* (* eps eps) 10.0) x (* (* (* eps eps) 6.0) eps)))
            x
            (pow eps 4.0)))
          x
          (pow eps 5.0))))
   (if (<= t_0 -2e-308)
     t_1
     (if (<= t_0 0.0)
       (*
        (fma
         (pow x 4.0)
         4.0
         (*
          x
          (fma
           5.0
           (pow eps 3.0)
           (* x (fma 10.0 (* eps eps) (* x (fma 10.0 eps x)))))))
        eps)
       t_1))))
double code(double x, double eps) {
	double t_0 = pow((x + eps), 5.0) - pow(x, 5.0);
	double t_1 = fma(fma(pow(eps, 4.0), 4.0, fma(fma(pow(eps, 3.0), 4.0, fma(((eps * eps) * 10.0), x, (((eps * eps) * 6.0) * eps))), x, pow(eps, 4.0))), x, pow(eps, 5.0));
	double tmp;
	if (t_0 <= -2e-308) {
		tmp = t_1;
	} else if (t_0 <= 0.0) {
		tmp = fma(pow(x, 4.0), 4.0, (x * fma(5.0, pow(eps, 3.0), (x * fma(10.0, (eps * eps), (x * fma(10.0, eps, x))))))) * eps;
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x, eps)
	t_0 = Float64((Float64(x + eps) ^ 5.0) - (x ^ 5.0))
	t_1 = fma(fma((eps ^ 4.0), 4.0, fma(fma((eps ^ 3.0), 4.0, fma(Float64(Float64(eps * eps) * 10.0), x, Float64(Float64(Float64(eps * eps) * 6.0) * eps))), x, (eps ^ 4.0))), x, (eps ^ 5.0))
	tmp = 0.0
	if (t_0 <= -2e-308)
		tmp = t_1;
	elseif (t_0 <= 0.0)
		tmp = Float64(fma((x ^ 4.0), 4.0, Float64(x * fma(5.0, (eps ^ 3.0), Float64(x * fma(10.0, Float64(eps * eps), Float64(x * fma(10.0, eps, x))))))) * eps);
	else
		tmp = t_1;
	end
	return tmp
end
code[x_, eps_] := Block[{t$95$0 = N[(N[Power[N[(x + eps), $MachinePrecision], 5.0], $MachinePrecision] - N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Power[eps, 4.0], $MachinePrecision] * 4.0 + N[(N[(N[Power[eps, 3.0], $MachinePrecision] * 4.0 + N[(N[(N[(eps * eps), $MachinePrecision] * 10.0), $MachinePrecision] * x + N[(N[(N[(eps * eps), $MachinePrecision] * 6.0), $MachinePrecision] * eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * x + N[Power[eps, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * x + N[Power[eps, 5.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e-308], t$95$1, If[LessEqual[t$95$0, 0.0], N[(N[(N[Power[x, 4.0], $MachinePrecision] * 4.0 + N[(x * N[(5.0 * N[Power[eps, 3.0], $MachinePrecision] + N[(x * N[(10.0 * N[(eps * eps), $MachinePrecision] + N[(x * N[(10.0 * eps + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * eps), $MachinePrecision], t$95$1]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {\left(x + \varepsilon\right)}^{5} - {x}^{5}\\
t_1 := \mathsf{fma}\left(\mathsf{fma}\left({\varepsilon}^{4}, 4, \mathsf{fma}\left(\mathsf{fma}\left({\varepsilon}^{3}, 4, \mathsf{fma}\left(\left(\varepsilon \cdot \varepsilon\right) \cdot 10, x, \left(\left(\varepsilon \cdot \varepsilon\right) \cdot 6\right) \cdot \varepsilon\right)\right), x, {\varepsilon}^{4}\right)\right), x, {\varepsilon}^{5}\right)\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{-308}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_0 \leq 0:\\
\;\;\;\;\mathsf{fma}\left({x}^{4}, 4, x \cdot \mathsf{fma}\left(5, {\varepsilon}^{3}, x \cdot \mathsf{fma}\left(10, \varepsilon \cdot \varepsilon, x \cdot \mathsf{fma}\left(10, \varepsilon, x\right)\right)\right)\right) \cdot \varepsilon\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (pow.f64 (+.f64 x eps) #s(literal 5 binary64)) (pow.f64 x #s(literal 5 binary64))) < -1.9999999999999998e-308 or 0.0 < (-.f64 (pow.f64 (+.f64 x eps) #s(literal 5 binary64)) (pow.f64 x #s(literal 5 binary64)))

    1. Initial program 97.9%

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

      \[\leadsto \color{blue}{x \cdot \left(4 \cdot {\varepsilon}^{4} + \left(x \cdot \left(4 \cdot {\varepsilon}^{3} + \left(\varepsilon \cdot \left(2 \cdot {\varepsilon}^{2} + 4 \cdot {\varepsilon}^{2}\right) + x \cdot \left(2 \cdot {\varepsilon}^{2} + 8 \cdot {\varepsilon}^{2}\right)\right)\right) + {\varepsilon}^{4}\right)\right) + {\varepsilon}^{5}} \]
    3. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \left(4 \cdot {\varepsilon}^{4} + \left(x \cdot \left(4 \cdot {\varepsilon}^{3} + \left(\varepsilon \cdot \left(2 \cdot {\varepsilon}^{2} + 4 \cdot {\varepsilon}^{2}\right) + x \cdot \left(2 \cdot {\varepsilon}^{2} + 8 \cdot {\varepsilon}^{2}\right)\right)\right) + {\varepsilon}^{4}\right)\right) \cdot x + {\color{blue}{\varepsilon}}^{5} \]
      2. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(4 \cdot {\varepsilon}^{4} + \left(x \cdot \left(4 \cdot {\varepsilon}^{3} + \left(\varepsilon \cdot \left(2 \cdot {\varepsilon}^{2} + 4 \cdot {\varepsilon}^{2}\right) + x \cdot \left(2 \cdot {\varepsilon}^{2} + 8 \cdot {\varepsilon}^{2}\right)\right)\right) + {\varepsilon}^{4}\right), \color{blue}{x}, {\varepsilon}^{5}\right) \]
    4. Applied rewrites94.3%

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

    if -1.9999999999999998e-308 < (-.f64 (pow.f64 (+.f64 x eps) #s(literal 5 binary64)) (pow.f64 x #s(literal 5 binary64))) < 0.0

    1. Initial program 86.0%

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

      \[\leadsto \color{blue}{\varepsilon \cdot \left(4 \cdot {x}^{4} + \left(\varepsilon \cdot \left(4 \cdot {x}^{3} + \left(\varepsilon \cdot \left(2 \cdot {x}^{2} + \left(8 \cdot {x}^{2} + \varepsilon \cdot \left(x + 4 \cdot x\right)\right)\right) + x \cdot \left(2 \cdot {x}^{2} + 4 \cdot {x}^{2}\right)\right)\right) + {x}^{4}\right)\right)} \]
    3. Applied rewrites99.7%

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

      \[\leadsto \mathsf{fma}\left({x}^{4}, 4, x \cdot \left(5 \cdot {\varepsilon}^{3} + x \cdot \left(10 \cdot {\varepsilon}^{2} + x \cdot \left(x + 10 \cdot \varepsilon\right)\right)\right)\right) \cdot \varepsilon \]
    5. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left({x}^{4}, 4, x \cdot \left(5 \cdot {\varepsilon}^{3} + x \cdot \left(10 \cdot {\varepsilon}^{2} + x \cdot \left(x + 10 \cdot \varepsilon\right)\right)\right)\right) \cdot \varepsilon \]
      2. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left({x}^{4}, 4, x \cdot \mathsf{fma}\left(5, {\varepsilon}^{3}, x \cdot \left(10 \cdot {\varepsilon}^{2} + x \cdot \left(x + 10 \cdot \varepsilon\right)\right)\right)\right) \cdot \varepsilon \]
      3. lift-pow.f64N/A

        \[\leadsto \mathsf{fma}\left({x}^{4}, 4, x \cdot \mathsf{fma}\left(5, {\varepsilon}^{3}, x \cdot \left(10 \cdot {\varepsilon}^{2} + x \cdot \left(x + 10 \cdot \varepsilon\right)\right)\right)\right) \cdot \varepsilon \]
      4. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left({x}^{4}, 4, x \cdot \mathsf{fma}\left(5, {\varepsilon}^{3}, x \cdot \left(10 \cdot {\varepsilon}^{2} + x \cdot \left(x + 10 \cdot \varepsilon\right)\right)\right)\right) \cdot \varepsilon \]
      5. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left({x}^{4}, 4, x \cdot \mathsf{fma}\left(5, {\varepsilon}^{3}, x \cdot \mathsf{fma}\left(10, {\varepsilon}^{2}, x \cdot \left(x + 10 \cdot \varepsilon\right)\right)\right)\right) \cdot \varepsilon \]
      6. pow2N/A

        \[\leadsto \mathsf{fma}\left({x}^{4}, 4, x \cdot \mathsf{fma}\left(5, {\varepsilon}^{3}, x \cdot \mathsf{fma}\left(10, \varepsilon \cdot \varepsilon, x \cdot \left(x + 10 \cdot \varepsilon\right)\right)\right)\right) \cdot \varepsilon \]
      7. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left({x}^{4}, 4, x \cdot \mathsf{fma}\left(5, {\varepsilon}^{3}, x \cdot \mathsf{fma}\left(10, \varepsilon \cdot \varepsilon, x \cdot \left(x + 10 \cdot \varepsilon\right)\right)\right)\right) \cdot \varepsilon \]
      8. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left({x}^{4}, 4, x \cdot \mathsf{fma}\left(5, {\varepsilon}^{3}, x \cdot \mathsf{fma}\left(10, \varepsilon \cdot \varepsilon, x \cdot \left(x + 10 \cdot \varepsilon\right)\right)\right)\right) \cdot \varepsilon \]
      9. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left({x}^{4}, 4, x \cdot \mathsf{fma}\left(5, {\varepsilon}^{3}, x \cdot \mathsf{fma}\left(10, \varepsilon \cdot \varepsilon, x \cdot \left(10 \cdot \varepsilon + x\right)\right)\right)\right) \cdot \varepsilon \]
      10. lower-fma.f6499.7

        \[\leadsto \mathsf{fma}\left({x}^{4}, 4, x \cdot \mathsf{fma}\left(5, {\varepsilon}^{3}, x \cdot \mathsf{fma}\left(10, \varepsilon \cdot \varepsilon, x \cdot \mathsf{fma}\left(10, \varepsilon, x\right)\right)\right)\right) \cdot \varepsilon \]
    6. Applied rewrites99.7%

      \[\leadsto \mathsf{fma}\left({x}^{4}, 4, x \cdot \mathsf{fma}\left(5, {\varepsilon}^{3}, x \cdot \mathsf{fma}\left(10, \varepsilon \cdot \varepsilon, x \cdot \mathsf{fma}\left(10, \varepsilon, x\right)\right)\right)\right) \cdot \varepsilon \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 3: 82.8% accurate, N/A× speedup?

\[\begin{array}{l} \\ \left(x \cdot x\right) \cdot \mathsf{fma}\left(4, {\varepsilon}^{3}, \mathsf{fma}\left(x, \mathsf{fma}\left(-1, \left(\varepsilon \cdot \varepsilon\right) \cdot -10, x \cdot \left(5 \cdot \varepsilon\right)\right), 6 \cdot {\varepsilon}^{3}\right)\right) \end{array} \]
(FPCore (x eps)
 :precision binary64
 (*
  (* x x)
  (fma
   4.0
   (pow eps 3.0)
   (fma
    x
    (fma -1.0 (* (* eps eps) -10.0) (* x (* 5.0 eps)))
    (* 6.0 (pow eps 3.0))))))
double code(double x, double eps) {
	return (x * x) * fma(4.0, pow(eps, 3.0), fma(x, fma(-1.0, ((eps * eps) * -10.0), (x * (5.0 * eps))), (6.0 * pow(eps, 3.0))));
}
function code(x, eps)
	return Float64(Float64(x * x) * fma(4.0, (eps ^ 3.0), fma(x, fma(-1.0, Float64(Float64(eps * eps) * -10.0), Float64(x * Float64(5.0 * eps))), Float64(6.0 * (eps ^ 3.0)))))
end
code[x_, eps_] := N[(N[(x * x), $MachinePrecision] * N[(4.0 * N[Power[eps, 3.0], $MachinePrecision] + N[(x * N[(-1.0 * N[(N[(eps * eps), $MachinePrecision] * -10.0), $MachinePrecision] + N[(x * N[(5.0 * eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(6.0 * N[Power[eps, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(x \cdot x\right) \cdot \mathsf{fma}\left(4, {\varepsilon}^{3}, \mathsf{fma}\left(x, \mathsf{fma}\left(-1, \left(\varepsilon \cdot \varepsilon\right) \cdot -10, x \cdot \left(5 \cdot \varepsilon\right)\right), 6 \cdot {\varepsilon}^{3}\right)\right)
\end{array}
Derivation
  1. Initial program 88.3%

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

    \[\leadsto \color{blue}{{x}^{4} \cdot \left(\varepsilon + \left(-1 \cdot \frac{-4 \cdot {\varepsilon}^{2} + \left(-1 \cdot \left(2 \cdot {\varepsilon}^{2} + 4 \cdot {\varepsilon}^{2}\right) + -1 \cdot \frac{4 \cdot {\varepsilon}^{3} + \varepsilon \cdot \left(2 \cdot {\varepsilon}^{2} + 4 \cdot {\varepsilon}^{2}\right)}{x}\right)}{x} + 4 \cdot \varepsilon\right)\right)} \]
  3. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \left(\varepsilon + \left(-1 \cdot \frac{-4 \cdot {\varepsilon}^{2} + \left(-1 \cdot \left(2 \cdot {\varepsilon}^{2} + 4 \cdot {\varepsilon}^{2}\right) + -1 \cdot \frac{4 \cdot {\varepsilon}^{3} + \varepsilon \cdot \left(2 \cdot {\varepsilon}^{2} + 4 \cdot {\varepsilon}^{2}\right)}{x}\right)}{x} + 4 \cdot \varepsilon\right)\right) \cdot \color{blue}{{x}^{4}} \]
    2. lower-*.f64N/A

      \[\leadsto \left(\varepsilon + \left(-1 \cdot \frac{-4 \cdot {\varepsilon}^{2} + \left(-1 \cdot \left(2 \cdot {\varepsilon}^{2} + 4 \cdot {\varepsilon}^{2}\right) + -1 \cdot \frac{4 \cdot {\varepsilon}^{3} + \varepsilon \cdot \left(2 \cdot {\varepsilon}^{2} + 4 \cdot {\varepsilon}^{2}\right)}{x}\right)}{x} + 4 \cdot \varepsilon\right)\right) \cdot \color{blue}{{x}^{4}} \]
  4. Applied rewrites81.2%

    \[\leadsto \color{blue}{\left(\mathsf{fma}\left(\frac{\mathsf{fma}\left(-4, \varepsilon \cdot \varepsilon, \mathsf{fma}\left(\frac{\mathsf{fma}\left(\left(\varepsilon \cdot \varepsilon\right) \cdot 6, \varepsilon, {\varepsilon}^{3} \cdot 4\right)}{x}, -1, -1 \cdot \left(\left(\varepsilon \cdot \varepsilon\right) \cdot 6\right)\right)\right)}{x}, -1, 4 \cdot \varepsilon\right) + \varepsilon\right) \cdot {x}^{4}} \]
  5. Taylor expanded in x around 0

    \[\leadsto {x}^{2} \cdot \color{blue}{\left(4 \cdot {\varepsilon}^{3} + \left(6 \cdot {\varepsilon}^{3} + x \cdot \left(-1 \cdot \left(-6 \cdot {\varepsilon}^{2} + -4 \cdot {\varepsilon}^{2}\right) + x \cdot \left(\varepsilon + 4 \cdot \varepsilon\right)\right)\right)\right)} \]
  6. Step-by-step derivation
    1. lower-*.f64N/A

      \[\leadsto {x}^{2} \cdot \left(4 \cdot {\varepsilon}^{3} + \color{blue}{\left(6 \cdot {\varepsilon}^{3} + x \cdot \left(-1 \cdot \left(-6 \cdot {\varepsilon}^{2} + -4 \cdot {\varepsilon}^{2}\right) + x \cdot \left(\varepsilon + 4 \cdot \varepsilon\right)\right)\right)}\right) \]
    2. pow2N/A

      \[\leadsto \left(x \cdot x\right) \cdot \left(4 \cdot {\varepsilon}^{3} + \left(\color{blue}{6 \cdot {\varepsilon}^{3}} + x \cdot \left(-1 \cdot \left(-6 \cdot {\varepsilon}^{2} + -4 \cdot {\varepsilon}^{2}\right) + x \cdot \left(\varepsilon + 4 \cdot \varepsilon\right)\right)\right)\right) \]
    3. lift-*.f64N/A

      \[\leadsto \left(x \cdot x\right) \cdot \left(4 \cdot {\varepsilon}^{3} + \left(\color{blue}{6 \cdot {\varepsilon}^{3}} + x \cdot \left(-1 \cdot \left(-6 \cdot {\varepsilon}^{2} + -4 \cdot {\varepsilon}^{2}\right) + x \cdot \left(\varepsilon + 4 \cdot \varepsilon\right)\right)\right)\right) \]
    4. lower-fma.f64N/A

      \[\leadsto \left(x \cdot x\right) \cdot \mathsf{fma}\left(4, {\varepsilon}^{\color{blue}{3}}, 6 \cdot {\varepsilon}^{3} + x \cdot \left(-1 \cdot \left(-6 \cdot {\varepsilon}^{2} + -4 \cdot {\varepsilon}^{2}\right) + x \cdot \left(\varepsilon + 4 \cdot \varepsilon\right)\right)\right) \]
    5. lift-pow.f64N/A

      \[\leadsto \left(x \cdot x\right) \cdot \mathsf{fma}\left(4, {\varepsilon}^{3}, 6 \cdot {\varepsilon}^{3} + x \cdot \left(-1 \cdot \left(-6 \cdot {\varepsilon}^{2} + -4 \cdot {\varepsilon}^{2}\right) + x \cdot \left(\varepsilon + 4 \cdot \varepsilon\right)\right)\right) \]
    6. +-commutativeN/A

      \[\leadsto \left(x \cdot x\right) \cdot \mathsf{fma}\left(4, {\varepsilon}^{3}, x \cdot \left(-1 \cdot \left(-6 \cdot {\varepsilon}^{2} + -4 \cdot {\varepsilon}^{2}\right) + x \cdot \left(\varepsilon + 4 \cdot \varepsilon\right)\right) + 6 \cdot {\varepsilon}^{3}\right) \]
    7. lower-fma.f64N/A

      \[\leadsto \left(x \cdot x\right) \cdot \mathsf{fma}\left(4, {\varepsilon}^{3}, \mathsf{fma}\left(x, -1 \cdot \left(-6 \cdot {\varepsilon}^{2} + -4 \cdot {\varepsilon}^{2}\right) + x \cdot \left(\varepsilon + 4 \cdot \varepsilon\right), 6 \cdot {\varepsilon}^{3}\right)\right) \]
  7. Applied rewrites82.8%

    \[\leadsto \left(x \cdot x\right) \cdot \color{blue}{\mathsf{fma}\left(4, {\varepsilon}^{3}, \mathsf{fma}\left(x, \mathsf{fma}\left(-1, \left(\varepsilon \cdot \varepsilon\right) \cdot -10, x \cdot \left(5 \cdot \varepsilon\right)\right), 6 \cdot {\varepsilon}^{3}\right)\right)} \]
  8. Add Preprocessing

Reproduce

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