Average Error: 29.4 → 0.6
Time: 15.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(\log \left(e^{\left(x \cdot x\right) \cdot \frac{1}{12}}\right), 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(\log \left(e^{\left(x \cdot x\right) \cdot \frac{1}{12}}\right), x \cdot x, x \cdot x\right)\right)
double f(double x) {
        double r4731444 = x;
        double r4731445 = exp(r4731444);
        double r4731446 = 2.0;
        double r4731447 = r4731445 - r4731446;
        double r4731448 = -r4731444;
        double r4731449 = exp(r4731448);
        double r4731450 = r4731447 + r4731449;
        return r4731450;
}

double f(double x) {
        double r4731451 = x;
        double r4731452 = r4731451 * r4731451;
        double r4731453 = r4731452 * r4731451;
        double r4731454 = 0.002777777777777778;
        double r4731455 = r4731453 * r4731454;
        double r4731456 = 0.08333333333333333;
        double r4731457 = r4731452 * r4731456;
        double r4731458 = exp(r4731457);
        double r4731459 = log(r4731458);
        double r4731460 = fma(r4731459, r4731452, r4731452);
        double r4731461 = fma(r4731455, r4731453, r4731460);
        return r4731461;
}

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.5

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

    \[\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. Using strategy rm
  6. Applied add-log-exp0.6

    \[\leadsto \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(\color{blue}{\log \left(e^{\frac{1}{12} \cdot \left(x \cdot x\right)}\right)}, x \cdot x, x \cdot x\right)\right)\]
  7. 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(\log \left(e^{\left(x \cdot x\right) \cdot \frac{1}{12}}\right), x \cdot x, x \cdot x\right)\right)\]

Reproduce

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