Average Error: 58.4 → 0.7
Time: 5.4s
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 r38771 = x;
        double r38772 = exp(r38771);
        double r38773 = -r38771;
        double r38774 = exp(r38773);
        double r38775 = r38772 - r38774;
        double r38776 = r38772 + r38774;
        double r38777 = r38775 / r38776;
        return r38777;
}

double f(double x) {
        double r38778 = x;
        double r38779 = r38778 + r38778;
        double r38780 = expm1(r38779);
        double r38781 = 1.0;
        double r38782 = exp(r38779);
        double r38783 = fma(r38781, r38781, r38782);
        double r38784 = r38780 / r38783;
        return r38784;
}

Error

Bits error versus x

Derivation

  1. Initial program 58.4

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