Average Error: 58.2 → 0.7
Time: 5.6s
Precision: 64
\[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}\]
\[\frac{\mathsf{expm1}\left(x + x\right)}{e^{2 \cdot x} + 1}\]
\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}
\frac{\mathsf{expm1}\left(x + x\right)}{e^{2 \cdot x} + 1}
double f(double x) {
        double r68353 = x;
        double r68354 = exp(r68353);
        double r68355 = -r68353;
        double r68356 = exp(r68355);
        double r68357 = r68354 - r68356;
        double r68358 = r68354 + r68356;
        double r68359 = r68357 / r68358;
        return r68359;
}

double f(double x) {
        double r68360 = x;
        double r68361 = r68360 + r68360;
        double r68362 = expm1(r68361);
        double r68363 = 2.0;
        double r68364 = r68363 * r68360;
        double r68365 = exp(r68364);
        double r68366 = 1.0;
        double r68367 = r68365 + r68366;
        double r68368 = r68362 / r68367;
        return r68368;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 58.2

    \[\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 inf 0.7

    \[\leadsto 1 \cdot \frac{\mathsf{expm1}\left(x + x\right)}{\color{blue}{e^{2 \cdot x} + 1}}\]
  4. Final simplification0.7

    \[\leadsto \frac{\mathsf{expm1}\left(x + x\right)}{e^{2 \cdot x} + 1}\]

Reproduce

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