Average Error: 58.1 → 0.6
Time: 5.6s
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 r79017 = x;
        double r79018 = exp(r79017);
        double r79019 = -r79017;
        double r79020 = exp(r79019);
        double r79021 = r79018 - r79020;
        double r79022 = r79018 + r79020;
        double r79023 = r79021 / r79022;
        return r79023;
}

double f(double x) {
        double r79024 = x;
        double r79025 = r79024 + r79024;
        double r79026 = expm1(r79025);
        double r79027 = 1.0;
        double r79028 = exp(r79025);
        double r79029 = fma(r79027, r79027, r79028);
        double r79030 = r79026 / r79029;
        return r79030;
}

Error

Bits error versus x

Derivation

  1. Initial program 58.1

    \[\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 2020003 +o rules:numerics
(FPCore (x)
  :name "Hyperbolic tangent"
  :precision binary64
  (/ (- (exp x) (exp (- x))) (+ (exp x) (exp (- x)))))