Average Error: 29.8 → 0.7
Time: 27.6s
Precision: 64
\[\left(e^{x} - 2\right) + e^{-x}\]
\[\mathsf{fma}\left(\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right) \cdot \left(x \cdot x\right), \frac{1}{360}, \mathsf{fma}\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right), \frac{1}{12}, x \cdot x\right)\right)\]
\left(e^{x} - 2\right) + e^{-x}
\mathsf{fma}\left(\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right) \cdot \left(x \cdot x\right), \frac{1}{360}, \mathsf{fma}\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right), \frac{1}{12}, x \cdot x\right)\right)
double f(double x) {
        double r3778454 = x;
        double r3778455 = exp(r3778454);
        double r3778456 = 2.0;
        double r3778457 = r3778455 - r3778456;
        double r3778458 = -r3778454;
        double r3778459 = exp(r3778458);
        double r3778460 = r3778457 + r3778459;
        return r3778460;
}

double f(double x) {
        double r3778461 = x;
        double r3778462 = r3778461 * r3778461;
        double r3778463 = r3778462 * r3778462;
        double r3778464 = r3778463 * r3778462;
        double r3778465 = 0.002777777777777778;
        double r3778466 = 0.08333333333333333;
        double r3778467 = fma(r3778463, r3778466, r3778462);
        double r3778468 = fma(r3778464, r3778465, r3778467);
        return r3778468;
}

Error

Bits error versus x

Target

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

Derivation

  1. Initial program 29.8

    \[\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(\left(x \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right), \frac{1}{360}, \mathsf{fma}\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right), \frac{1}{12}, x \cdot x\right)\right)}\]
  4. Final simplification0.7

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

Reproduce

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

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

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