Average Error: 29.9 → 0.6
Time: 1.0m
Precision: 64
\[\left(e^{x} - 2.0\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.0\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 r5602870 = x;
        double r5602871 = exp(r5602870);
        double r5602872 = 2.0;
        double r5602873 = r5602871 - r5602872;
        double r5602874 = -r5602870;
        double r5602875 = exp(r5602874);
        double r5602876 = r5602873 + r5602875;
        return r5602876;
}

double f(double x) {
        double r5602877 = 0.002777777777777778;
        double r5602878 = x;
        double r5602879 = r5602878 * r5602878;
        double r5602880 = r5602879 * r5602878;
        double r5602881 = r5602880 * r5602880;
        double r5602882 = 0.08333333333333333;
        double r5602883 = r5602879 * r5602879;
        double r5602884 = fma(r5602882, r5602883, r5602879);
        double r5602885 = fma(r5602877, r5602881, r5602884);
        return r5602885;
}

Error

Bits error versus x

Target

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

Derivation

  1. Initial program 29.9

    \[\left(e^{x} - 2.0\right) + e^{-x}\]
  2. 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)}\]
  3. 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}, \left(x \cdot x\right) \cdot \left(x \cdot x\right), x \cdot x\right)\right)}\]
  4. 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(\frac{1}{12}, \left(x \cdot x\right) \cdot \left(x \cdot x\right), x \cdot x\right)\right)\]

Reproduce

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