Average Error: 58.1 → 0.7
Time: 5.9s
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 r66837 = x;
        double r66838 = exp(r66837);
        double r66839 = -r66837;
        double r66840 = exp(r66839);
        double r66841 = r66838 - r66840;
        double r66842 = r66838 + r66840;
        double r66843 = r66841 / r66842;
        return r66843;
}

double f(double x) {
        double r66844 = x;
        double r66845 = r66844 + r66844;
        double r66846 = expm1(r66845);
        double r66847 = 1.0;
        double r66848 = exp(r66845);
        double r66849 = fma(r66847, r66847, r66848);
        double r66850 = r66846 / r66849;
        return r66850;
}

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