Average Error: 29.5 → 0.6
Time: 51.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 r2902197 = x;
        double r2902198 = exp(r2902197);
        double r2902199 = 2.0;
        double r2902200 = r2902198 - r2902199;
        double r2902201 = -r2902197;
        double r2902202 = exp(r2902201);
        double r2902203 = r2902200 + r2902202;
        return r2902203;
}

double f(double x) {
        double r2902204 = 0.002777777777777778;
        double r2902205 = x;
        double r2902206 = r2902205 * r2902205;
        double r2902207 = r2902206 * r2902205;
        double r2902208 = r2902207 * r2902207;
        double r2902209 = 0.08333333333333333;
        double r2902210 = r2902206 * r2902209;
        double r2902211 = fma(r2902210, r2902206, r2902206);
        double r2902212 = fma(r2902204, r2902208, r2902211);
        return r2902212;
}

Error

Bits error versus x

Target

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

Derivation

  1. Initial program 29.5

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

    \[\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 2019138 +o rules:numerics
(FPCore (x)
  :name "exp2 (problem 3.3.7)"

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

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