Average Error: 29.4 → 0.5
Time: 14.9s
Precision: 64
\[\left(e^{x} - 2\right) + e^{-x}\]
\[\mathsf{fma}\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right), \frac{1}{12}, \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)\]
\left(e^{x} - 2\right) + e^{-x}
\mathsf{fma}\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right), \frac{1}{12}, \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)
double f(double x) {
        double r3177530 = x;
        double r3177531 = exp(r3177530);
        double r3177532 = 2.0;
        double r3177533 = r3177531 - r3177532;
        double r3177534 = -r3177530;
        double r3177535 = exp(r3177534);
        double r3177536 = r3177533 + r3177535;
        return r3177536;
}

double f(double x) {
        double r3177537 = x;
        double r3177538 = r3177537 * r3177537;
        double r3177539 = r3177538 * r3177538;
        double r3177540 = 0.08333333333333333;
        double r3177541 = r3177537 * r3177538;
        double r3177542 = r3177541 * r3177541;
        double r3177543 = 0.002777777777777778;
        double r3177544 = fma(r3177542, r3177543, r3177538);
        double r3177545 = fma(r3177539, r3177540, r3177544);
        return r3177545;
}

Error

Bits error versus x

Target

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

Derivation

  1. Initial program 29.4

    \[\left(e^{x} - 2\right) + e^{-x}\]
  2. Simplified29.4

    \[\leadsto \color{blue}{\left(e^{x} - 2\right) - \frac{-1}{e^{x}}}\]
  3. Taylor expanded around 0 0.5

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

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

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

Reproduce

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

  :herbie-target
  (* 4.0 (pow (sinh (/ x 2.0)) 2.0))

  (+ (- (exp x) 2.0) (exp (- x))))