Average Error: 29.8 → 0.5
Time: 15.0s
Precision: 64
\[\left(e^{x} - 2\right) + e^{-x}\]
\[\mathsf{log1p}\left(\mathsf{expm1}\left(\mathsf{fma}\left(x, x, \mathsf{fma}\left(\frac{1}{12}, {x}^{4}, {x}^{6} \cdot \frac{1}{360}\right)\right)\right)\right)\]
\left(e^{x} - 2\right) + e^{-x}
\mathsf{log1p}\left(\mathsf{expm1}\left(\mathsf{fma}\left(x, x, \mathsf{fma}\left(\frac{1}{12}, {x}^{4}, {x}^{6} \cdot \frac{1}{360}\right)\right)\right)\right)
double f(double x) {
        double r144887 = x;
        double r144888 = exp(r144887);
        double r144889 = 2.0;
        double r144890 = r144888 - r144889;
        double r144891 = -r144887;
        double r144892 = exp(r144891);
        double r144893 = r144890 + r144892;
        return r144893;
}

double f(double x) {
        double r144894 = x;
        double r144895 = 0.08333333333333333;
        double r144896 = 4.0;
        double r144897 = pow(r144894, r144896);
        double r144898 = 6.0;
        double r144899 = pow(r144894, r144898);
        double r144900 = 0.002777777777777778;
        double r144901 = r144899 * r144900;
        double r144902 = fma(r144895, r144897, r144901);
        double r144903 = fma(r144894, r144894, r144902);
        double r144904 = expm1(r144903);
        double r144905 = log1p(r144904);
        return r144905;
}

Error

Bits error versus x

Target

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

Derivation

  1. Initial program 29.8

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{12}, {x}^{4}, \mathsf{fma}\left(\frac{1}{360}, {x}^{6}, x \cdot x\right)\right)}\]
  4. Using strategy rm
  5. Applied log1p-expm1-u0.5

    \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\mathsf{fma}\left(\frac{1}{12}, {x}^{4}, \mathsf{fma}\left(\frac{1}{360}, {x}^{6}, x \cdot x\right)\right)\right)\right)}\]
  6. Simplified0.5

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

    \[\leadsto \mathsf{log1p}\left(\mathsf{expm1}\left(\mathsf{fma}\left(x, x, \mathsf{fma}\left(\frac{1}{12}, {x}^{4}, {x}^{6} \cdot \frac{1}{360}\right)\right)\right)\right)\]

Reproduce

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