Average Error: 29.3 → 0.0
Time: 4.4s
Precision: binary64
\[\left(e^{x} - 2\right) + e^{-x} \]
\[\begin{array}{l} t_0 := e^{-x}\\ \mathbf{if}\;\left(e^{x} - 2\right) + t_0 \leq 0.003195701986808186:\\ \;\;\;\;\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)\\ \mathbf{else}:\\ \;\;\;\;t_0 + \frac{{\left(e^{x}\right)}^{3} - 8}{\mathsf{fma}\left(e^{x}, e^{x} + 2, 4\right)}\\ \end{array} \]
\left(e^{x} - 2\right) + e^{-x}
\begin{array}{l}
t_0 := e^{-x}\\
\mathbf{if}\;\left(e^{x} - 2\right) + t_0 \leq 0.003195701986808186:\\
\;\;\;\;\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)\\

\mathbf{else}:\\
\;\;\;\;t_0 + \frac{{\left(e^{x}\right)}^{3} - 8}{\mathsf{fma}\left(e^{x}, e^{x} + 2, 4\right)}\\


\end{array}
(FPCore (x) :precision binary64 (+ (- (exp x) 2.0) (exp (- x))))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (exp (- x))))
   (if (<= (+ (- (exp x) 2.0) t_0) 0.003195701986808186)
     (fma
      0.08333333333333333
      (pow x 4.0)
      (fma
       0.002777777777777778
       (pow x 6.0)
       (fma x x (* 4.96031746031746e-5 (pow x 8.0)))))
     (+ t_0 (/ (- (pow (exp x) 3.0) 8.0) (fma (exp x) (+ (exp x) 2.0) 4.0))))))
double code(double x) {
	return (exp(x) - 2.0) + exp(-x);
}
double code(double x) {
	double t_0 = exp(-x);
	double tmp;
	if (((exp(x) - 2.0) + t_0) <= 0.003195701986808186) {
		tmp = fma(0.08333333333333333, pow(x, 4.0), fma(0.002777777777777778, pow(x, 6.0), fma(x, x, (4.96031746031746e-5 * pow(x, 8.0)))));
	} else {
		tmp = t_0 + ((pow(exp(x), 3.0) - 8.0) / fma(exp(x), (exp(x) + 2.0), 4.0));
	}
	return tmp;
}

Error

Bits error versus x

Target

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

Derivation

  1. Split input into 2 regimes
  2. if (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x))) < 0.003195701986808186

    1. Initial program 29.7

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

      \[\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.0

      \[\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)} \]

    if 0.003195701986808186 < (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x)))

    1. Initial program 1.1

      \[\left(e^{x} - 2\right) + e^{-x} \]
    2. Applied flip3--_binary643.0

      \[\leadsto \color{blue}{\frac{{\left(e^{x}\right)}^{3} - {2}^{3}}{e^{x} \cdot e^{x} + \left(2 \cdot 2 + e^{x} \cdot 2\right)}} + e^{-x} \]
    3. Simplified3.0

      \[\leadsto \frac{\color{blue}{{\left(e^{x}\right)}^{3} - 8}}{e^{x} \cdot e^{x} + \left(2 \cdot 2 + e^{x} \cdot 2\right)} + e^{-x} \]
    4. Simplified2.9

      \[\leadsto \frac{{\left(e^{x}\right)}^{3} - 8}{\color{blue}{\mathsf{fma}\left(e^{x}, 2 + e^{x}, 4\right)}} + e^{-x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(e^{x} - 2\right) + e^{-x} \leq 0.003195701986808186:\\ \;\;\;\;\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)\\ \mathbf{else}:\\ \;\;\;\;e^{-x} + \frac{{\left(e^{x}\right)}^{3} - 8}{\mathsf{fma}\left(e^{x}, e^{x} + 2, 4\right)}\\ \end{array} \]

Reproduce

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