Average Error: 29.6 → 0.8
Time: 21.1s
Precision: 64
\[\left(e^{x} - 2\right) + e^{-x}\]
\[\mathsf{fma}\left(\frac{1}{12}, \left(x \cdot x\right) \cdot \left(x \cdot x\right), \mathsf{fma}\left(\left(\left(x \cdot x\right) \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot x\right), \frac{1}{360}, x \cdot x\right)\right)\]
\left(e^{x} - 2\right) + e^{-x}
\mathsf{fma}\left(\frac{1}{12}, \left(x \cdot x\right) \cdot \left(x \cdot x\right), \mathsf{fma}\left(\left(\left(x \cdot x\right) \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot x\right), \frac{1}{360}, x \cdot x\right)\right)
double f(double x) {
        double r2830955 = x;
        double r2830956 = exp(r2830955);
        double r2830957 = 2.0;
        double r2830958 = r2830956 - r2830957;
        double r2830959 = -r2830955;
        double r2830960 = exp(r2830959);
        double r2830961 = r2830958 + r2830960;
        return r2830961;
}

double f(double x) {
        double r2830962 = 0.08333333333333333;
        double r2830963 = x;
        double r2830964 = r2830963 * r2830963;
        double r2830965 = r2830964 * r2830964;
        double r2830966 = r2830964 * r2830963;
        double r2830967 = r2830966 * r2830966;
        double r2830968 = 0.002777777777777778;
        double r2830969 = fma(r2830967, r2830968, r2830964);
        double r2830970 = fma(r2830962, r2830965, r2830969);
        return r2830970;
}

Error

Bits error versus x

Target

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

Derivation

  1. Initial program 29.6

    \[\left(e^{x} - 2\right) + e^{-x}\]
  2. Taylor expanded around 0 0.8

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

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

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

Reproduce

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

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

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