Average Error: 58.2 → 0.4
Time: 46.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.493172855875965 \cdot 10^{-10}:\\ \;\;\;\;\left(\frac{2}{15} \cdot {x}^{5} + x\right) - \frac{1}{3} \cdot {x}^{3}\\ \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.493172855875965e-10

    1. Initial program 59.0

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

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

    if 3.493172855875965e-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: 46.6s)Debug logProfile

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