Average Error: 29.2 → 0.6
Time: 16.7s
Precision: 64
\[\left(e^{x} - 2\right) + e^{-x}\]
\[\mathsf{fma}\left(\frac{1}{12}, \left(x \cdot x\right) \cdot \left(x \cdot x\right), \mathsf{fma}\left(\left(\left(x \cdot x\right) \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot x\right), \frac{1}{360}, x \cdot x\right)\right)\]
\left(e^{x} - 2\right) + e^{-x}
\mathsf{fma}\left(\frac{1}{12}, \left(x \cdot x\right) \cdot \left(x \cdot x\right), \mathsf{fma}\left(\left(\left(x \cdot x\right) \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot x\right), \frac{1}{360}, x \cdot x\right)\right)
double f(double x) {
        double r1601538 = x;
        double r1601539 = exp(r1601538);
        double r1601540 = 2.0;
        double r1601541 = r1601539 - r1601540;
        double r1601542 = -r1601538;
        double r1601543 = exp(r1601542);
        double r1601544 = r1601541 + r1601543;
        return r1601544;
}

double f(double x) {
        double r1601545 = 0.08333333333333333;
        double r1601546 = x;
        double r1601547 = r1601546 * r1601546;
        double r1601548 = r1601547 * r1601547;
        double r1601549 = r1601547 * r1601546;
        double r1601550 = r1601549 * r1601549;
        double r1601551 = 0.002777777777777778;
        double r1601552 = fma(r1601550, r1601551, r1601547);
        double r1601553 = fma(r1601545, r1601548, r1601552);
        return r1601553;
}

Error

Bits error versus x

Target

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

Derivation

  1. Initial program 29.2

    \[\left(e^{x} - 2\right) + e^{-x}\]
  2. 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)}\]
  3. Simplified0.6

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

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

Reproduce

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

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

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