Average Error: 14.9 → 0.0
Time: 4.6s
Precision: binary64
\[\left(e^{x} - 2\right) + e^{-x} \]
\[\begin{array}{l} t_0 := \left(e^{x} - 2\right) + e^{-x}\\ \mathbf{if}\;t_0 \leq 3.4703577132866315 \cdot 10^{-5}:\\ \;\;\;\;0.08333333333333333 \cdot {x}^{4} + \left(0.002777777777777778 \cdot {x}^{6} + {x}^{2}\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
\left(e^{x} - 2\right) + e^{-x}
\begin{array}{l}
t_0 := \left(e^{x} - 2\right) + e^{-x}\\
\mathbf{if}\;t_0 \leq 3.4703577132866315 \cdot 10^{-5}:\\
\;\;\;\;0.08333333333333333 \cdot {x}^{4} + \left(0.002777777777777778 \cdot {x}^{6} + {x}^{2}\right)\\

\mathbf{else}:\\
\;\;\;\;t_0\\


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

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original14.9
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))) < 3.47035771329e-5

    1. Initial program 29.8

      \[\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} + {x}^{2}\right)} \]

    if 3.47035771329e-5 < (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x)))

    1. Initial program 0.1

      \[\left(e^{x} - 2\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 3.4703577132866315 \cdot 10^{-5}:\\ \;\;\;\;0.08333333333333333 \cdot {x}^{4} + \left(0.002777777777777778 \cdot {x}^{6} + {x}^{2}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(e^{x} - 2\right) + e^{-x}\\ \end{array} \]

Reproduce

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