Average Error: 30.1 → 0.5
Time: 33.0s
Precision: 64
\[\left(e^{x} - 2\right) + e^{-x}\]
\[\mathsf{fma}\left(\frac{1}{360}, \left(x \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right), \mathsf{fma}\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right), \frac{1}{12}, x \cdot x\right)\right)\]
\left(e^{x} - 2\right) + e^{-x}
\mathsf{fma}\left(\frac{1}{360}, \left(x \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right), \mathsf{fma}\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right), \frac{1}{12}, x \cdot x\right)\right)
double f(double x) {
        double r3847822 = x;
        double r3847823 = exp(r3847822);
        double r3847824 = 2.0;
        double r3847825 = r3847823 - r3847824;
        double r3847826 = -r3847822;
        double r3847827 = exp(r3847826);
        double r3847828 = r3847825 + r3847827;
        return r3847828;
}

double f(double x) {
        double r3847829 = 0.002777777777777778;
        double r3847830 = x;
        double r3847831 = r3847830 * r3847830;
        double r3847832 = r3847831 * r3847831;
        double r3847833 = r3847831 * r3847832;
        double r3847834 = 0.08333333333333333;
        double r3847835 = fma(r3847832, r3847834, r3847831);
        double r3847836 = fma(r3847829, r3847833, r3847835);
        return r3847836;
}

Error

Bits error versus x

Target

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

Derivation

  1. Initial program 30.1

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

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

Reproduce

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

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

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