Average Error: 29.4 → 0.6
Time: 24.8s
Precision: 64
\[\left(e^{x} - 2\right) + e^{-x}\]
\[\mathsf{fma}\left(\left(\left(x \cdot x\right) \cdot x\right) \cdot \frac{1}{360}, \left(x \cdot x\right) \cdot x, \mathsf{fma}\left(\left(x \cdot x\right) \cdot \frac{1}{12}, x \cdot x, x \cdot x\right)\right)\]
\left(e^{x} - 2\right) + e^{-x}
\mathsf{fma}\left(\left(\left(x \cdot x\right) \cdot x\right) \cdot \frac{1}{360}, \left(x \cdot x\right) \cdot x, \mathsf{fma}\left(\left(x \cdot x\right) \cdot \frac{1}{12}, x \cdot x, x \cdot x\right)\right)
double f(double x) {
        double r5009306 = x;
        double r5009307 = exp(r5009306);
        double r5009308 = 2.0;
        double r5009309 = r5009307 - r5009308;
        double r5009310 = -r5009306;
        double r5009311 = exp(r5009310);
        double r5009312 = r5009309 + r5009311;
        return r5009312;
}

double f(double x) {
        double r5009313 = x;
        double r5009314 = r5009313 * r5009313;
        double r5009315 = r5009314 * r5009313;
        double r5009316 = 0.002777777777777778;
        double r5009317 = r5009315 * r5009316;
        double r5009318 = 0.08333333333333333;
        double r5009319 = r5009314 * r5009318;
        double r5009320 = fma(r5009319, r5009314, r5009314);
        double r5009321 = fma(r5009317, r5009315, r5009320);
        return r5009321;
}

Error

Bits error versus x

Target

Original29.4
Target0.0
Herbie0.6
\[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.6

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

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

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

Reproduce

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