Average Error: 58.2 → 1.0
Time: 23.6s
Precision: 64
\[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}\]
\[\begin{array}{l} \mathbf{if}\;x \le 5.249326471263704397071782830437244871113 \cdot 10^{-9}:\\ \;\;\;\;\mathsf{fma}\left(\left(\frac{-1}{3} \cdot x\right) \cdot x, x, \mathsf{fma}\left(\frac{2}{15}, {x}^{5}, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{\tanh x \cdot \left(\tanh x \cdot \tanh x\right)}\\ \end{array}\]
\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}
\begin{array}{l}
\mathbf{if}\;x \le 5.249326471263704397071782830437244871113 \cdot 10^{-9}:\\
\;\;\;\;\mathsf{fma}\left(\left(\frac{-1}{3} \cdot x\right) \cdot x, x, \mathsf{fma}\left(\frac{2}{15}, {x}^{5}, x\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\tanh x \cdot \left(\tanh x \cdot \tanh x\right)}\\

\end{array}
double f(double x) {
        double r2990941 = x;
        double r2990942 = exp(r2990941);
        double r2990943 = -r2990941;
        double r2990944 = exp(r2990943);
        double r2990945 = r2990942 - r2990944;
        double r2990946 = r2990942 + r2990944;
        double r2990947 = r2990945 / r2990946;
        return r2990947;
}

double f(double x) {
        double r2990948 = x;
        double r2990949 = 5.249326471263704e-09;
        bool r2990950 = r2990948 <= r2990949;
        double r2990951 = -0.3333333333333333;
        double r2990952 = r2990951 * r2990948;
        double r2990953 = r2990952 * r2990948;
        double r2990954 = 0.13333333333333333;
        double r2990955 = 5.0;
        double r2990956 = pow(r2990948, r2990955);
        double r2990957 = fma(r2990954, r2990956, r2990948);
        double r2990958 = fma(r2990953, r2990948, r2990957);
        double r2990959 = tanh(r2990948);
        double r2990960 = r2990959 * r2990959;
        double r2990961 = r2990959 * r2990960;
        double r2990962 = cbrt(r2990961);
        double r2990963 = r2990950 ? r2990958 : r2990962;
        return r2990963;
}

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < 5.249326471263704e-09

    1. Initial program 59.0

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

      \[\leadsto \color{blue}{\tanh x}\]
    4. Taylor expanded around 0 1.0

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

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

    if 5.249326471263704e-09 < x

    1. Initial program 28.3

      \[\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.4

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

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

Reproduce

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