Average Error: 29.5 → 0.6
Time: 56.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(\frac{1}{360}, \left(x \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right), 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(\frac{1}{360}, \left(x \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right), x \cdot x\right)\right)
double f(double x) {
        double r2857123 = x;
        double r2857124 = exp(r2857123);
        double r2857125 = 2.0;
        double r2857126 = r2857124 - r2857125;
        double r2857127 = -r2857123;
        double r2857128 = exp(r2857127);
        double r2857129 = r2857126 + r2857128;
        return r2857129;
}

double f(double x) {
        double r2857130 = 0.08333333333333333;
        double r2857131 = x;
        double r2857132 = r2857131 * r2857131;
        double r2857133 = r2857132 * r2857132;
        double r2857134 = 0.002777777777777778;
        double r2857135 = r2857132 * r2857133;
        double r2857136 = fma(r2857134, r2857135, r2857132);
        double r2857137 = fma(r2857130, r2857133, r2857136);
        return r2857137;
}

Error

Bits error versus x

Target

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

Derivation

  1. Initial program 29.5

    \[\left(e^{x} - 2\right) + e^{-x}\]
  2. Taylor expanded around 0 0.6

    \[\leadsto \color{blue}{{x}^{2} + \left(\frac{1}{360} \cdot {x}^{6} + \frac{1}{12} \cdot {x}^{4}\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(\frac{1}{360}, \left(x \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right), 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(\frac{1}{360}, \left(x \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right), x \cdot x\right)\right)\]

Reproduce

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