Average Error: 58.1 → 0.7
Time: 6.3s
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 r40766 = x;
        double r40767 = exp(r40766);
        double r40768 = -r40766;
        double r40769 = exp(r40768);
        double r40770 = r40767 - r40769;
        double r40771 = r40767 + r40769;
        double r40772 = r40770 / r40771;
        return r40772;
}

double f(double x) {
        double r40773 = x;
        double r40774 = r40773 + r40773;
        double r40775 = expm1(r40774);
        double r40776 = 1.0;
        double r40777 = exp(r40774);
        double r40778 = fma(r40776, r40776, r40777);
        double r40779 = r40775 / r40778;
        return r40779;
}

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