Average Error: 57.8 → 2.0
Time: 5.9s
Precision: 64
\[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}\]
\[\mathsf{expm1}\left(\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{log1p}\left(\mathsf{fma}\left({x}^{5}, \frac{2}{15}, x - \frac{1}{3} \cdot {x}^{3}\right)\right)\right)\right)\right)\]
\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}
\mathsf{expm1}\left(\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{log1p}\left(\mathsf{fma}\left({x}^{5}, \frac{2}{15}, x - \frac{1}{3} \cdot {x}^{3}\right)\right)\right)\right)\right)
double f(double x) {
        double r43214 = x;
        double r43215 = exp(r43214);
        double r43216 = -r43214;
        double r43217 = exp(r43216);
        double r43218 = r43215 - r43217;
        double r43219 = r43215 + r43217;
        double r43220 = r43218 / r43219;
        return r43220;
}

double f(double x) {
        double r43221 = x;
        double r43222 = 5.0;
        double r43223 = pow(r43221, r43222);
        double r43224 = 0.13333333333333333;
        double r43225 = 0.3333333333333333;
        double r43226 = 3.0;
        double r43227 = pow(r43221, r43226);
        double r43228 = r43225 * r43227;
        double r43229 = r43221 - r43228;
        double r43230 = fma(r43223, r43224, r43229);
        double r43231 = log1p(r43230);
        double r43232 = log1p(r43231);
        double r43233 = expm1(r43232);
        double r43234 = expm1(r43233);
        return r43234;
}

Error

Bits error versus x

Derivation

  1. Initial program 57.8

    \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}\]
  2. Simplified0.7

    \[\leadsto \color{blue}{1 \cdot \frac{\mathsf{expm1}\left(x + x\right)}{\mathsf{fma}\left(1, 1, e^{x + x}\right)}}\]
  3. Taylor expanded around 0 1.9

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

    \[\leadsto 1 \cdot \color{blue}{\mathsf{fma}\left({x}^{5}, \frac{2}{15}, x - \frac{1}{3} \cdot {x}^{3}\right)}\]
  5. Using strategy rm
  6. Applied expm1-log1p-u2.0

    \[\leadsto 1 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{fma}\left({x}^{5}, \frac{2}{15}, x - \frac{1}{3} \cdot {x}^{3}\right)\right)\right)}\]
  7. Using strategy rm
  8. Applied expm1-log1p-u2.0

    \[\leadsto 1 \cdot \mathsf{expm1}\left(\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{log1p}\left(\mathsf{fma}\left({x}^{5}, \frac{2}{15}, x - \frac{1}{3} \cdot {x}^{3}\right)\right)\right)\right)}\right)\]
  9. Final simplification2.0

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

Reproduce

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