Average Error: 29.8 → 0.5
Time: 25.2s
Precision: 64
\[\left(e^{x} - 2\right) + e^{-x}\]
\[\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}, \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(\left(x \cdot \left(x \cdot x\right)\right) \cdot \left(x \cdot \left(x \cdot x\right)\right), \frac{1}{360}, \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 r4273823 = x;
        double r4273824 = exp(r4273823);
        double r4273825 = 2.0;
        double r4273826 = r4273824 - r4273825;
        double r4273827 = -r4273823;
        double r4273828 = exp(r4273827);
        double r4273829 = r4273826 + r4273828;
        return r4273829;
}

double f(double x) {
        double r4273830 = x;
        double r4273831 = r4273830 * r4273830;
        double r4273832 = r4273830 * r4273831;
        double r4273833 = r4273832 * r4273832;
        double r4273834 = 0.002777777777777778;
        double r4273835 = 0.08333333333333333;
        double r4273836 = r4273831 * r4273831;
        double r4273837 = fma(r4273835, r4273836, r4273831);
        double r4273838 = fma(r4273833, r4273834, r4273837);
        return r4273838;
}

Error

Bits error versus x

Target

Original29.8
Target0.0
Herbie0.5
\[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. Taylor expanded around 0 0.5

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

    \[\leadsto \color{blue}{\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}, \mathsf{fma}\left(\frac{1}{12}, \left(x \cdot x\right) \cdot \left(x \cdot x\right), x \cdot x\right)\right)}\]
  4. Final simplification0.5

    \[\leadsto \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}, \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 2019192 +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))))