Average Error: 29.8 → 0.1
Time: 4.9s
Precision: binary64
\[\left(e^{x} - 2\right) + e^{-x}\]
\[\begin{array}{l} \mathbf{if}\;\left(e^{x} - 2\right) + e^{-x} \leq 2.5407595170001684 \cdot 10^{-06}:\\ \;\;\;\;x \cdot x + \left(0.08333333333333333 \cdot {x}^{4} + 0.002777777777777778 \cdot {x}^{6}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{x} \cdot \left({\left(e^{x}\right)}^{3} - 8\right) + \left(e^{x} \cdot e^{x} + \left(4 + e^{x} \cdot 2\right)\right)}{e^{x} \cdot \left(e^{x} \cdot e^{x} + \left(4 + e^{x} \cdot 2\right)\right)}\\ \end{array}\]
\left(e^{x} - 2\right) + e^{-x}
\begin{array}{l}
\mathbf{if}\;\left(e^{x} - 2\right) + e^{-x} \leq 2.5407595170001684 \cdot 10^{-06}:\\
\;\;\;\;x \cdot x + \left(0.08333333333333333 \cdot {x}^{4} + 0.002777777777777778 \cdot {x}^{6}\right)\\

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

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

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original29.8
Target0.0
Herbie0.1
\[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))) < 2.540759517e-6

    1. Initial program 30.2

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

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

      \[\leadsto \color{blue}{x \cdot x + \left(0.08333333333333333 \cdot {x}^{4} + 0.002777777777777778 \cdot {x}^{6}\right)}\]

    if 2.540759517e-6 < (+.f64 (-.f64 (exp.f64 x) 2) (exp.f64 (neg.f64 x)))

    1. Initial program 3.4

      \[\left(e^{x} - 2\right) + e^{-x}\]
    2. Using strategy rm
    3. Applied exp-neg_binary643.3

      \[\leadsto \left(e^{x} - 2\right) + \color{blue}{\frac{1}{e^{x}}}\]
    4. Applied flip3--_binary647.6

      \[\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)}} + \frac{1}{e^{x}}\]
    5. Applied frac-add_binary647.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(e^{x} - 2\right) + e^{-x} \leq 2.5407595170001684 \cdot 10^{-06}:\\ \;\;\;\;x \cdot x + \left(0.08333333333333333 \cdot {x}^{4} + 0.002777777777777778 \cdot {x}^{6}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{x} \cdot \left({\left(e^{x}\right)}^{3} - 8\right) + \left(e^{x} \cdot e^{x} + \left(4 + e^{x} \cdot 2\right)\right)}{e^{x} \cdot \left(e^{x} \cdot e^{x} + \left(4 + e^{x} \cdot 2\right)\right)}\\ \end{array}\]

Alternatives

Reproduce

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