Average Error: 29.2 → 0.8
Time: 5.1s
Precision: binary64
\[\left(e^{x} - 2\right) + e^{-x} \]
\[\mathsf{fma}\left(x, x, 0.08333333333333333 \cdot {x}^{4}\right) \]
\left(e^{x} - 2\right) + e^{-x}
\mathsf{fma}\left(x, x, 0.08333333333333333 \cdot {x}^{4}\right)
(FPCore (x) :precision binary64 (+ (- (exp x) 2.0) (exp (- x))))
(FPCore (x) :precision binary64 (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 fma(x, x, (0.08333333333333333 * pow(x, 4.0)));
}

Error

Bits error versus x

Target

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

Derivation

  1. Initial program 29.2

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

    \[\leadsto \color{blue}{0.08333333333333333 \cdot {x}^{4} + {x}^{2}} \]
  3. Simplified0.8

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, 0.08333333333333333 \cdot {x}^{4}\right)} \]
  4. Final simplification0.8

    \[\leadsto \mathsf{fma}\left(x, x, 0.08333333333333333 \cdot {x}^{4}\right) \]

Reproduce

herbie shell --seed 2022130 
(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))))