Average Error: 29.5 → 0.7
Time: 16.2s
Precision: 64
\[\left(e^{x} - 2\right) + e^{-x}\]
\[\mathsf{fma}\left(\frac{1}{12}, \left(x \cdot x\right) \cdot \left(x \cdot x\right), \mathsf{fma}\left(\left(\left(x \cdot x\right) \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot x\right), \frac{1}{360}, x \cdot x\right)\right)\]
\left(e^{x} - 2\right) + e^{-x}
\mathsf{fma}\left(\frac{1}{12}, \left(x \cdot x\right) \cdot \left(x \cdot x\right), \mathsf{fma}\left(\left(\left(x \cdot x\right) \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot x\right), \frac{1}{360}, x \cdot x\right)\right)
double f(double x) {
        double r1750596 = x;
        double r1750597 = exp(r1750596);
        double r1750598 = 2.0;
        double r1750599 = r1750597 - r1750598;
        double r1750600 = -r1750596;
        double r1750601 = exp(r1750600);
        double r1750602 = r1750599 + r1750601;
        return r1750602;
}

double f(double x) {
        double r1750603 = 0.08333333333333333;
        double r1750604 = x;
        double r1750605 = r1750604 * r1750604;
        double r1750606 = r1750605 * r1750605;
        double r1750607 = r1750605 * r1750604;
        double r1750608 = r1750607 * r1750607;
        double r1750609 = 0.002777777777777778;
        double r1750610 = fma(r1750608, r1750609, r1750605);
        double r1750611 = fma(r1750603, r1750606, r1750610);
        return r1750611;
}

Error

Bits error versus x

Target

Original29.5
Target0.0
Herbie0.7
\[4 \cdot {\left(\sinh \left(\frac{x}{2}\right)\right)}^{2}\]

Derivation

  1. Initial program 29.5

    \[\left(e^{x} - 2\right) + e^{-x}\]
  2. Taylor expanded around 0 0.7

    \[\leadsto \color{blue}{{x}^{2} + \left(\frac{1}{12} \cdot {x}^{4} + \frac{1}{360} \cdot {x}^{6}\right)}\]
  3. Simplified0.7

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{12}, \left(x \cdot x\right) \cdot \left(x \cdot x\right), \mathsf{fma}\left(\left(x \cdot \left(x \cdot x\right)\right) \cdot \left(x \cdot \left(x \cdot x\right)\right), \frac{1}{360}, x \cdot x\right)\right)}\]
  4. Final simplification0.7

    \[\leadsto \mathsf{fma}\left(\frac{1}{12}, \left(x \cdot x\right) \cdot \left(x \cdot x\right), \mathsf{fma}\left(\left(\left(x \cdot x\right) \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot x\right), \frac{1}{360}, x \cdot x\right)\right)\]

Reproduce

herbie shell --seed 2019155 +o rules:numerics
(FPCore (x)
  :name "exp2 (problem 3.3.7)"

  :herbie-target
  (* 4 (pow (sinh (/ x 2)) 2))

  (+ (- (exp x) 2) (exp (- x))))