Average Error: 29.4 → 0.7
Time: 39.8s
Precision: 64
\[\left(e^{x} - 2\right) + e^{-x}\]
\[\mathsf{fma}\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right), \frac{1}{12}, \mathsf{fma}\left(\frac{1}{360}, \left(x \cdot \left(x \cdot x\right)\right) \cdot \left(x \cdot \left(x \cdot x\right)\right), x \cdot x\right)\right)\]
\left(e^{x} - 2\right) + e^{-x}
\mathsf{fma}\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right), \frac{1}{12}, \mathsf{fma}\left(\frac{1}{360}, \left(x \cdot \left(x \cdot x\right)\right) \cdot \left(x \cdot \left(x \cdot x\right)\right), x \cdot x\right)\right)
double f(double x) {
        double r3746868 = x;
        double r3746869 = exp(r3746868);
        double r3746870 = 2.0;
        double r3746871 = r3746869 - r3746870;
        double r3746872 = -r3746868;
        double r3746873 = exp(r3746872);
        double r3746874 = r3746871 + r3746873;
        return r3746874;
}

double f(double x) {
        double r3746875 = x;
        double r3746876 = r3746875 * r3746875;
        double r3746877 = r3746876 * r3746876;
        double r3746878 = 0.08333333333333333;
        double r3746879 = 0.002777777777777778;
        double r3746880 = r3746875 * r3746876;
        double r3746881 = r3746880 * r3746880;
        double r3746882 = fma(r3746879, r3746881, r3746876);
        double r3746883 = fma(r3746877, r3746878, r3746882);
        return r3746883;
}

Error

Bits error versus x

Target

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

Derivation

  1. Initial program 29.4

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

    \[\leadsto \color{blue}{\left(e^{x} - 2\right) - \frac{-1}{e^{x}}}\]
  3. Taylor expanded around 0 0.7

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

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

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

Reproduce

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