Average Error: 29.3 → 0.7
Time: 30.8s
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 r2329416 = x;
        double r2329417 = exp(r2329416);
        double r2329418 = 2.0;
        double r2329419 = r2329417 - r2329418;
        double r2329420 = -r2329416;
        double r2329421 = exp(r2329420);
        double r2329422 = r2329419 + r2329421;
        return r2329422;
}

double f(double x) {
        double r2329423 = 0.002777777777777778;
        double r2329424 = x;
        double r2329425 = r2329424 * r2329424;
        double r2329426 = r2329425 * r2329425;
        double r2329427 = r2329425 * r2329426;
        double r2329428 = 0.08333333333333333;
        double r2329429 = fma(r2329426, r2329428, r2329425);
        double r2329430 = fma(r2329423, r2329427, r2329429);
        return r2329430;
}

Error

Bits error versus x

Target

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

Derivation

  1. Initial program 29.3

    \[\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(\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.7

    \[\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 2019151 +o rules:numerics
(FPCore (x)
  :name "exp2 (problem 3.3.7)"

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

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