Average Error: 58.2 → 0.6
Time: 5.1s
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 r35655 = x;
        double r35656 = exp(r35655);
        double r35657 = -r35655;
        double r35658 = exp(r35657);
        double r35659 = r35656 - r35658;
        double r35660 = r35656 + r35658;
        double r35661 = r35659 / r35660;
        return r35661;
}

double f(double x) {
        double r35662 = x;
        double r35663 = r35662 + r35662;
        double r35664 = expm1(r35663);
        double r35665 = 1.0;
        double r35666 = exp(r35663);
        double r35667 = fma(r35665, r35665, r35666);
        double r35668 = r35664 / r35667;
        return r35668;
}

Error

Bits error versus x

Derivation

  1. Initial program 58.2

    \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}\]
  2. Simplified0.6

    \[\leadsto \color{blue}{1 \cdot \frac{\mathsf{expm1}\left(x + x\right)}{\mathsf{fma}\left(1, 1, e^{x + x}\right)}}\]
  3. Final simplification0.6

    \[\leadsto \frac{\mathsf{expm1}\left(x + x\right)}{\mathsf{fma}\left(1, 1, e^{x + x}\right)}\]

Reproduce

herbie shell --seed 2020047 +o rules:numerics
(FPCore (x)
  :name "Hyperbolic tangent"
  :precision binary64
  (/ (- (exp x) (exp (- x))) (+ (exp x) (exp (- x)))))