Average Error: 58.2 → 0.6
Time: 5.2s
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 r37396 = x;
        double r37397 = exp(r37396);
        double r37398 = -r37396;
        double r37399 = exp(r37398);
        double r37400 = r37397 - r37399;
        double r37401 = r37397 + r37399;
        double r37402 = r37400 / r37401;
        return r37402;
}

double f(double x) {
        double r37403 = x;
        double r37404 = r37403 + r37403;
        double r37405 = expm1(r37404);
        double r37406 = 1.0;
        double r37407 = exp(r37404);
        double r37408 = fma(r37406, r37406, r37407);
        double r37409 = r37405 / r37408;
        return r37409;
}

Error

Bits error versus x

Derivation

  1. Initial program 58.2

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

    \[\leadsto \color{blue}{1 \cdot \frac{\mathsf{expm1}\left(x + x\right)}{\mathsf{fma}\left(1, 1, e^{x + x}\right)}}\]
  3. Final simplification0.6

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

Reproduce

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