Average Error: 30.1 → 0.6
Time: 19.6s
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 r3881494 = x;
        double r3881495 = exp(r3881494);
        double r3881496 = 2.0;
        double r3881497 = r3881495 - r3881496;
        double r3881498 = -r3881494;
        double r3881499 = exp(r3881498);
        double r3881500 = r3881497 + r3881499;
        return r3881500;
}

double f(double x) {
        double r3881501 = x;
        double r3881502 = r3881501 * r3881501;
        double r3881503 = r3881502 * r3881501;
        double r3881504 = 0.002777777777777778;
        double r3881505 = r3881503 * r3881504;
        double r3881506 = 0.08333333333333333;
        double r3881507 = r3881502 * r3881506;
        double r3881508 = fma(r3881507, r3881502, r3881502);
        double r3881509 = fma(r3881505, r3881503, r3881508);
        return r3881509;
}

Error

Bits error versus x

Target

Original30.1
Target0.0
Herbie0.6
\[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. Simplified30.1

    \[\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 2019172 +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))))