Average Error: 29.6 → 0.6
Time: 15.4s
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 r1798386 = x;
        double r1798387 = exp(r1798386);
        double r1798388 = 2.0;
        double r1798389 = r1798387 - r1798388;
        double r1798390 = -r1798386;
        double r1798391 = exp(r1798390);
        double r1798392 = r1798389 + r1798391;
        return r1798392;
}

double f(double x) {
        double r1798393 = 0.08333333333333333;
        double r1798394 = x;
        double r1798395 = r1798394 * r1798394;
        double r1798396 = r1798395 * r1798395;
        double r1798397 = r1798395 * r1798394;
        double r1798398 = r1798397 * r1798397;
        double r1798399 = 0.002777777777777778;
        double r1798400 = fma(r1798398, r1798399, r1798395);
        double r1798401 = fma(r1798393, r1798396, r1798400);
        return r1798401;
}

Error

Bits error versus x

Target

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

Derivation

  1. Initial program 29.6

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

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

    \[\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.6

    \[\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 2019156 +o rules:numerics
(FPCore (x)
  :name "exp2 (problem 3.3.7)"

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

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