Average Error: 29.8 → 0.7
Time: 18.0s
Precision: 64
\[\left(e^{x} - 2\right) + e^{-x}\]
\[\mathsf{fma}\left(\frac{1}{360}, \left(\left(x \cdot x\right) \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot x\right), \mathsf{fma}\left(\frac{1}{12}, \left(x \cdot x\right) \cdot \left(x \cdot x\right), x \cdot x\right)\right)\]
\left(e^{x} - 2\right) + e^{-x}
\mathsf{fma}\left(\frac{1}{360}, \left(\left(x \cdot x\right) \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot x\right), \mathsf{fma}\left(\frac{1}{12}, \left(x \cdot x\right) \cdot \left(x \cdot x\right), x \cdot x\right)\right)
double f(double x) {
        double r3761392 = x;
        double r3761393 = exp(r3761392);
        double r3761394 = 2.0;
        double r3761395 = r3761393 - r3761394;
        double r3761396 = -r3761392;
        double r3761397 = exp(r3761396);
        double r3761398 = r3761395 + r3761397;
        return r3761398;
}

double f(double x) {
        double r3761399 = 0.002777777777777778;
        double r3761400 = x;
        double r3761401 = r3761400 * r3761400;
        double r3761402 = r3761401 * r3761400;
        double r3761403 = r3761402 * r3761402;
        double r3761404 = 0.08333333333333333;
        double r3761405 = r3761401 * r3761401;
        double r3761406 = fma(r3761404, r3761405, r3761401);
        double r3761407 = fma(r3761399, r3761403, r3761406);
        return r3761407;
}

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. Simplified29.8

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

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

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

Reproduce

herbie shell --seed 2019169 +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))))