Average Error: 29.4 → 0.7
Time: 22.6s
Precision: 64
\[\left(e^{x} - 2\right) + e^{-x}\]
\[\mathsf{fma}\left(\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right) \cdot \left(x \cdot x\right), \frac{1}{360}, \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(\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right) \cdot \left(x \cdot x\right), \frac{1}{360}, \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 r3541167 = x;
        double r3541168 = exp(r3541167);
        double r3541169 = 2.0;
        double r3541170 = r3541168 - r3541169;
        double r3541171 = -r3541167;
        double r3541172 = exp(r3541171);
        double r3541173 = r3541170 + r3541172;
        return r3541173;
}

double f(double x) {
        double r3541174 = x;
        double r3541175 = r3541174 * r3541174;
        double r3541176 = r3541175 * r3541175;
        double r3541177 = r3541176 * r3541175;
        double r3541178 = 0.002777777777777778;
        double r3541179 = 0.08333333333333333;
        double r3541180 = fma(r3541176, r3541179, r3541175);
        double r3541181 = fma(r3541177, r3541178, r3541180);
        return r3541181;
}

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. 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)}\]
  3. Simplified0.7

    \[\leadsto \color{blue}{\mathsf{fma}\left(\left(x \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right), \frac{1}{360}, \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.7

    \[\leadsto \mathsf{fma}\left(\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right) \cdot \left(x \cdot x\right), \frac{1}{360}, \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 2019162 +o rules:numerics
(FPCore (x)
  :name "exp2 (problem 3.3.7)"

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

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