Average Error: 58.1 → 0.7
Time: 4.0s
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 r39922 = x;
        double r39923 = exp(r39922);
        double r39924 = -r39922;
        double r39925 = exp(r39924);
        double r39926 = r39923 - r39925;
        double r39927 = r39923 + r39925;
        double r39928 = r39926 / r39927;
        return r39928;
}

double f(double x) {
        double r39929 = x;
        double r39930 = r39929 + r39929;
        double r39931 = expm1(r39930);
        double r39932 = 1.0;
        double r39933 = exp(r39930);
        double r39934 = fma(r39932, r39932, r39933);
        double r39935 = r39931 / r39934;
        return r39935;
}

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