Average Error: 58.1 → 0.7
Time: 6.1s
Precision: 64
\[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}\]
\[\frac{\mathsf{expm1}\left(x + x\right)}{\mathsf{fma}\left(1, 1, e^{x + x}\right)}\]
\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}
\frac{\mathsf{expm1}\left(x + x\right)}{\mathsf{fma}\left(1, 1, e^{x + x}\right)}
double f(double x) {
        double r44755 = x;
        double r44756 = exp(r44755);
        double r44757 = -r44755;
        double r44758 = exp(r44757);
        double r44759 = r44756 - r44758;
        double r44760 = r44756 + r44758;
        double r44761 = r44759 / r44760;
        return r44761;
}

double f(double x) {
        double r44762 = x;
        double r44763 = r44762 + r44762;
        double r44764 = expm1(r44763);
        double r44765 = 1.0;
        double r44766 = exp(r44763);
        double r44767 = fma(r44765, r44765, r44766);
        double r44768 = r44764 / r44767;
        return r44768;
}

Error

Bits error versus x

Derivation

  1. Initial program 58.1

    \[\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. Final simplification0.7

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

Reproduce

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