Average Error: 29.2 → 0.6
Time: 36.5s
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(\left(x \cdot x\right) \cdot \frac{1}{12}, x \cdot x, 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(\left(x \cdot x\right) \cdot \frac{1}{12}, x \cdot x, x \cdot x\right)\right)
double f(double x) {
        double r2212714 = x;
        double r2212715 = exp(r2212714);
        double r2212716 = 2.0;
        double r2212717 = r2212715 - r2212716;
        double r2212718 = -r2212714;
        double r2212719 = exp(r2212718);
        double r2212720 = r2212717 + r2212719;
        return r2212720;
}

double f(double x) {
        double r2212721 = 0.002777777777777778;
        double r2212722 = x;
        double r2212723 = r2212722 * r2212722;
        double r2212724 = r2212723 * r2212722;
        double r2212725 = r2212724 * r2212724;
        double r2212726 = 0.08333333333333333;
        double r2212727 = r2212723 * r2212726;
        double r2212728 = fma(r2212727, r2212723, r2212723);
        double r2212729 = fma(r2212721, r2212725, r2212728);
        return r2212729;
}

Error

Bits error versus x

Target

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

Derivation

  1. Initial program 29.2

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

    \[\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(\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} \cdot \left(x \cdot x\right), x \cdot x, x \cdot x\right)\right)}\]
  5. Final simplification0.6

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

Reproduce

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

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

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