Average Error: 29.7 → 0.6
Time: 9.9s
Precision: binary64
\[\left(e^{x} - 2\right) + e^{-x} \]
\[\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{fma}\left(4.96031746031746 \cdot 10^{-5}, {x}^{8}, \mathsf{fma}\left(0.002777777777777778, {x}^{6}, \mathsf{fma}\left(x, x, 0.08333333333333333 \cdot {x}^{4}\right)\right)\right)\right)\right) \]
\left(e^{x} - 2\right) + e^{-x}
\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{fma}\left(4.96031746031746 \cdot 10^{-5}, {x}^{8}, \mathsf{fma}\left(0.002777777777777778, {x}^{6}, \mathsf{fma}\left(x, x, 0.08333333333333333 \cdot {x}^{4}\right)\right)\right)\right)\right)
(FPCore (x) :precision binary64 (+ (- (exp x) 2.0) (exp (- x))))
(FPCore (x)
 :precision binary64
 (expm1
  (log1p
   (fma
    4.96031746031746e-5
    (pow x 8.0)
    (fma
     0.002777777777777778
     (pow x 6.0)
     (fma x x (* 0.08333333333333333 (pow x 4.0))))))))
double code(double x) {
	return (exp(x) - 2.0) + exp(-x);
}
double code(double x) {
	return expm1(log1p(fma(4.96031746031746e-5, pow(x, 8.0), fma(0.002777777777777778, pow(x, 6.0), fma(x, x, (0.08333333333333333 * pow(x, 4.0)))))));
}

Error

Bits error versus x

Target

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

Derivation

  1. Initial program 29.7

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

    \[\leadsto \color{blue}{0.08333333333333333 \cdot {x}^{4} + \left(0.002777777777777778 \cdot {x}^{6} + \left(4.96031746031746 \cdot 10^{-5} \cdot {x}^{8} + {x}^{2}\right)\right)} \]
  3. Simplified0.6

    \[\leadsto \color{blue}{\mathsf{fma}\left(0.08333333333333333, {x}^{4}, \mathsf{fma}\left(0.002777777777777778, {x}^{6}, \mathsf{fma}\left(x, x, 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right)\right)\right)} \]
  4. Applied expm1-log1p-u_binary640.6

    \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{fma}\left(0.08333333333333333, {x}^{4}, \mathsf{fma}\left(0.002777777777777778, {x}^{6}, \mathsf{fma}\left(x, x, 4.96031746031746 \cdot 10^{-5} \cdot {x}^{8}\right)\right)\right)\right)\right)} \]
  5. Simplified0.6

    \[\leadsto \mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(\mathsf{fma}\left(4.96031746031746 \cdot 10^{-5}, {x}^{8}, \mathsf{fma}\left(0.002777777777777778, {x}^{6}, \mathsf{fma}\left(x, x, 0.08333333333333333 \cdot {x}^{4}\right)\right)\right)\right)}\right) \]
  6. Final simplification0.6

    \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{fma}\left(4.96031746031746 \cdot 10^{-5}, {x}^{8}, \mathsf{fma}\left(0.002777777777777778, {x}^{6}, \mathsf{fma}\left(x, x, 0.08333333333333333 \cdot {x}^{4}\right)\right)\right)\right)\right) \]

Reproduce

herbie shell --seed 2021275 
(FPCore (x)
  :name "exp2 (problem 3.3.7)"
  :precision binary64

  :herbie-target
  (* 4.0 (pow (sinh (/ x 2.0)) 2.0))

  (+ (- (exp x) 2.0) (exp (- x))))