Average Error: 58.0 → 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 r41685 = x;
        double r41686 = exp(r41685);
        double r41687 = -r41685;
        double r41688 = exp(r41687);
        double r41689 = r41686 - r41688;
        double r41690 = r41686 + r41688;
        double r41691 = r41689 / r41690;
        return r41691;
}

double f(double x) {
        double r41692 = x;
        double r41693 = r41692 + r41692;
        double r41694 = expm1(r41693);
        double r41695 = 1.0;
        double r41696 = exp(r41693);
        double r41697 = fma(r41695, r41695, r41696);
        double r41698 = r41694 / r41697;
        return r41698;
}

Error

Bits error versus x

Derivation

  1. Initial program 58.0

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