Average Error: 58.2 → 0.9
Time: 3.1s
Precision: binary64
\[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}\]
\[\begin{array}{l} \mathbf{if}\;x \le 3.04088380892254773 \cdot 10^{-6}:\\ \;\;\;\;x + \left({x}^{5} \cdot \frac{2}{15} - \frac{1}{3} \cdot {x}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{{\left(\tanh x\right)}^{3}}\\ \end{array}\]

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < 3.04088380892254773e-6

    1. Initial program 58.9

      \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}\]
    2. Taylor expanded around 0 1.0

      \[\leadsto \color{blue}{\left(x + \frac{2}{15} \cdot {x}^{5}\right) - \frac{1}{3} \cdot {x}^{3}}\]
    3. Simplified1.0

      \[\leadsto \color{blue}{x + \left({x}^{5} \cdot \frac{2}{15} - \frac{1}{3} \cdot {x}^{3}\right)}\]

    if 3.04088380892254773e-6 < x

    1. Initial program 31.6

      \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}\]
    2. Using strategy rm
    3. Applied tanh-undef0.1

      \[\leadsto \color{blue}{\tanh x}\]
    4. Using strategy rm
    5. Applied add-cbrt-cube0.3

      \[\leadsto \color{blue}{\sqrt[3]{\left(\tanh x \cdot \tanh x\right) \cdot \tanh x}}\]
    6. Simplified0.3

      \[\leadsto \sqrt[3]{\color{blue}{{\left(\tanh x\right)}^{3}}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le 3.04088380892254773 \cdot 10^{-6}:\\ \;\;\;\;x + \left({x}^{5} \cdot \frac{2}{15} - \frac{1}{3} \cdot {x}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{{\left(\tanh x\right)}^{3}}\\ \end{array}\]

Reproduce

herbie shell --seed 2020179 
(FPCore (x)
  :name "Hyperbolic tangent"
  :precision binary64
  (/ (- (exp x) (exp (neg x))) (+ (exp x) (exp (neg x)))))