Average Error: 58.2 → 0.3
Time: 44.6s
Precision: 64
Internal Precision: 1344
\[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}\]
\[\begin{array}{l} \mathbf{if}\;\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \le 3.6280725755208906 \cdot 10^{-10}:\\ \;\;\;\;\frac{\frac{1}{3} \cdot {x}^{3} + \left(\frac{1}{60} \cdot {x}^{5} + 2 \cdot x\right)}{e^{x} + e^{-x}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{{\left(\tanh x\right)}^{3}}\\ \end{array}\]

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if (/ (- (exp x) (exp (- x))) (+ (exp x) (exp (- x)))) < 3.6280725755208906e-10

    1. Initial program 59.0

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

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

    if 3.6280725755208906e-10 < (/ (- (exp x) (exp (- x))) (+ (exp x) (exp (- x))))

    1. Initial program 37.2

      \[\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. Applied simplify0.3

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

Runtime

Time bar (total: 44.6s)Debug logProfile

herbie shell --seed 2018195 
(FPCore (x)
  :name "Hyperbolic tangent"
  (/ (- (exp x) (exp (- x))) (+ (exp x) (exp (- x)))))