Average Error: 30.1 → 0.6
Time: 22.0s
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 r5587308 = x;
        double r5587309 = exp(r5587308);
        double r5587310 = 2.0;
        double r5587311 = r5587309 - r5587310;
        double r5587312 = -r5587308;
        double r5587313 = exp(r5587312);
        double r5587314 = r5587311 + r5587313;
        return r5587314;
}

double f(double x) {
        double r5587315 = x;
        double r5587316 = r5587315 * r5587315;
        double r5587317 = r5587316 * r5587316;
        double r5587318 = 0.08333333333333333;
        double r5587319 = r5587315 * r5587316;
        double r5587320 = r5587319 * r5587319;
        double r5587321 = 0.002777777777777778;
        double r5587322 = fma(r5587320, r5587321, r5587316);
        double r5587323 = fma(r5587317, r5587318, r5587322);
        return r5587323;
}

Error

Bits error versus x

Target

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

Derivation

  1. Initial program 30.1

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

    \[\leadsto \color{blue}{\left(e^{x} - 2\right) - \frac{-1}{e^{x}}}\]
  3. 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)}\]
  4. Simplified0.6

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

    \[\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 2019172 +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))))