Average Error: 58.0 → 0.0
Time: 7.1s
Precision: 64
\[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.0045269632343894351:\\ \;\;\;\;\left(\sqrt[3]{\tanh x} \cdot \sqrt[3]{\tanh x}\right) \cdot \sqrt[3]{\tanh x}\\ \mathbf{elif}\;x \le 0.00178597432163403046:\\ \;\;\;\;x + \left(\frac{2}{15} \cdot {x}^{5} - \frac{1}{3} \cdot {x}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\tanh x} \cdot \sqrt{\tanh x}\\ \end{array}\]
\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}
\begin{array}{l}
\mathbf{if}\;x \le -0.0045269632343894351:\\
\;\;\;\;\left(\sqrt[3]{\tanh x} \cdot \sqrt[3]{\tanh x}\right) \cdot \sqrt[3]{\tanh x}\\

\mathbf{elif}\;x \le 0.00178597432163403046:\\
\;\;\;\;x + \left(\frac{2}{15} \cdot {x}^{5} - \frac{1}{3} \cdot {x}^{3}\right)\\

\mathbf{else}:\\
\;\;\;\;\sqrt{\tanh x} \cdot \sqrt{\tanh x}\\

\end{array}
double f(double x) {
        double r36738 = x;
        double r36739 = exp(r36738);
        double r36740 = -r36738;
        double r36741 = exp(r36740);
        double r36742 = r36739 - r36741;
        double r36743 = r36739 + r36741;
        double r36744 = r36742 / r36743;
        return r36744;
}

double f(double x) {
        double r36745 = x;
        double r36746 = -0.004526963234389435;
        bool r36747 = r36745 <= r36746;
        double r36748 = tanh(r36745);
        double r36749 = cbrt(r36748);
        double r36750 = r36749 * r36749;
        double r36751 = r36750 * r36749;
        double r36752 = 0.0017859743216340305;
        bool r36753 = r36745 <= r36752;
        double r36754 = 0.13333333333333333;
        double r36755 = 5.0;
        double r36756 = pow(r36745, r36755);
        double r36757 = r36754 * r36756;
        double r36758 = 0.3333333333333333;
        double r36759 = 3.0;
        double r36760 = pow(r36745, r36759);
        double r36761 = r36758 * r36760;
        double r36762 = r36757 - r36761;
        double r36763 = r36745 + r36762;
        double r36764 = sqrt(r36748);
        double r36765 = r36764 * r36764;
        double r36766 = r36753 ? r36763 : r36765;
        double r36767 = r36747 ? r36751 : r36766;
        return r36767;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if x < -0.004526963234389435

    1. Initial program 35.5

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

      \[\leadsto \color{blue}{\tanh x}\]
    4. Using strategy rm
    5. Applied add-cube-cbrt0.4

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

    if -0.004526963234389435 < x < 0.0017859743216340305

    1. Initial program 59.0

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

      \[\leadsto \color{blue}{\left(x + \frac{2}{15} \cdot {x}^{5}\right) - \frac{1}{3} \cdot {x}^{3}}\]
    3. Using strategy rm
    4. Applied associate--l+0.0

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

    if 0.0017859743216340305 < x

    1. Initial program 30.8

      \[\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-sqr-sqrt0.3

      \[\leadsto \color{blue}{\sqrt{\tanh x} \cdot \sqrt{\tanh x}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.0

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

Reproduce

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