Average Error: 58.4 → 0.7
Time: 5.5s
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 r39833 = x;
        double r39834 = exp(r39833);
        double r39835 = -r39833;
        double r39836 = exp(r39835);
        double r39837 = r39834 - r39836;
        double r39838 = r39834 + r39836;
        double r39839 = r39837 / r39838;
        return r39839;
}

double f(double x) {
        double r39840 = x;
        double r39841 = r39840 + r39840;
        double r39842 = expm1(r39841);
        double r39843 = 1.0;
        double r39844 = exp(r39841);
        double r39845 = fma(r39843, r39843, r39844);
        double r39846 = r39842 / r39845;
        return r39846;
}

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)))))