Average Error: 29.5 → 0.6
Time: 18.0s
Precision: 64
\[\left(e^{x} - 2\right) + e^{-x}\]
\[\mathsf{fma}\left(x \cdot \left(x \cdot x\right), \left(x \cdot \left(x \cdot x\right)\right) \cdot \frac{1}{360}, \mathsf{fma}\left(\log \left(e^{\frac{1}{12} \cdot \left(x \cdot x\right)}\right), x \cdot x, x \cdot x\right)\right)\]
\left(e^{x} - 2\right) + e^{-x}
\mathsf{fma}\left(x \cdot \left(x \cdot x\right), \left(x \cdot \left(x \cdot x\right)\right) \cdot \frac{1}{360}, \mathsf{fma}\left(\log \left(e^{\frac{1}{12} \cdot \left(x \cdot x\right)}\right), x \cdot x, x \cdot x\right)\right)
double f(double x) {
        double r4650268 = x;
        double r4650269 = exp(r4650268);
        double r4650270 = 2.0;
        double r4650271 = r4650269 - r4650270;
        double r4650272 = -r4650268;
        double r4650273 = exp(r4650272);
        double r4650274 = r4650271 + r4650273;
        return r4650274;
}

double f(double x) {
        double r4650275 = x;
        double r4650276 = r4650275 * r4650275;
        double r4650277 = r4650275 * r4650276;
        double r4650278 = 0.002777777777777778;
        double r4650279 = r4650277 * r4650278;
        double r4650280 = 0.08333333333333333;
        double r4650281 = r4650280 * r4650276;
        double r4650282 = exp(r4650281);
        double r4650283 = log(r4650282);
        double r4650284 = fma(r4650283, r4650276, r4650276);
        double r4650285 = fma(r4650277, r4650279, r4650284);
        return r4650285;
}

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

    \[\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(\left(x \cdot x\right) \cdot x, \left(\left(x \cdot x\right) \cdot x\right) \cdot \frac{1}{360}, \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(\left(x \cdot x\right) \cdot x, \left(\left(x \cdot x\right) \cdot x\right) \cdot \frac{1}{360}, \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(x \cdot \left(x \cdot x\right), \left(x \cdot \left(x \cdot x\right)\right) \cdot \frac{1}{360}, \mathsf{fma}\left(\log \left(e^{\frac{1}{12} \cdot \left(x \cdot x\right)}\right), x \cdot x, x \cdot x\right)\right)\]

Reproduce

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