Average Error: 57.9 → 0.8
Time: 4.4s
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 r36714 = x;
        double r36715 = exp(r36714);
        double r36716 = -r36714;
        double r36717 = exp(r36716);
        double r36718 = r36715 - r36717;
        double r36719 = r36715 + r36717;
        double r36720 = r36718 / r36719;
        return r36720;
}

double f(double x) {
        double r36721 = x;
        double r36722 = r36721 + r36721;
        double r36723 = expm1(r36722);
        double r36724 = 2.0;
        double r36725 = r36724 * r36721;
        double r36726 = exp(r36725);
        double r36727 = 1.0;
        double r36728 = r36726 + r36727;
        double r36729 = r36723 / r36728;
        return r36729;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 57.9

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

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

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

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

Reproduce

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