Average Error: 29.2 → 0.4
Time: 3.8s
Precision: binary64
\[\left(e^{x} - 2\right) + e^{-x}\]
\[\begin{array}{l} \mathbf{if}\;\left(e^{x} - 2\right) + e^{-x} \le 8.44613 \cdot 10^{-12}:\\ \;\;\;\;{x}^{2} + \left(\frac{1}{360} \cdot {x}^{6} + \frac{1}{12} \cdot {x}^{4}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(e^{x} + 2\right) \cdot \left(1 + e^{x} \cdot \left(e^{x} - 2\right)\right)}{\left(e^{x} + 2\right) \cdot e^{x}}\\ \end{array}\]

Error

Bits error versus x

Target

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

Derivation

  1. Split input into 2 regimes
  2. if (+ (- (exp x) 2.0) (exp (neg x))) < 8.44613e-12

    1. Initial program 29.8

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

      \[\leadsto \color{blue}{{x}^{2} + \left(\frac{1}{360} \cdot {x}^{6} + \frac{1}{12} \cdot {x}^{4}\right)}\]

    if 8.44613e-12 < (+ (- (exp x) 2.0) (exp (neg x)))

    1. Initial program 12.2

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

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

      \[\leadsto \color{blue}{\frac{e^{x} \cdot e^{x} - 2 \cdot 2}{e^{x} + 2}} + \frac{1}{e^{x}}\]
    5. Applied frac-add14.1

      \[\leadsto \color{blue}{\frac{\left(e^{x} \cdot e^{x} - 2 \cdot 2\right) \cdot e^{x} + \left(e^{x} + 2\right) \cdot 1}{\left(e^{x} + 2\right) \cdot e^{x}}}\]
    6. Simplified13.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(e^{x} - 2\right) + e^{-x} \le 8.44613 \cdot 10^{-12}:\\ \;\;\;\;{x}^{2} + \left(\frac{1}{360} \cdot {x}^{6} + \frac{1}{12} \cdot {x}^{4}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(e^{x} + 2\right) \cdot \left(1 + e^{x} \cdot \left(e^{x} - 2\right)\right)}{\left(e^{x} + 2\right) \cdot e^{x}}\\ \end{array}\]

Reproduce

herbie shell --seed 2020173 
(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 (neg x))))