Average Error: 58.1 → 0.6
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 r36499 = x;
        double r36500 = exp(r36499);
        double r36501 = -r36499;
        double r36502 = exp(r36501);
        double r36503 = r36500 - r36502;
        double r36504 = r36500 + r36502;
        double r36505 = r36503 / r36504;
        return r36505;
}

double f(double x) {
        double r36506 = x;
        double r36507 = r36506 + r36506;
        double r36508 = expm1(r36507);
        double r36509 = 1.0;
        double r36510 = exp(r36507);
        double r36511 = fma(r36509, r36509, r36510);
        double r36512 = r36508 / r36511;
        return r36512;
}

Error

Bits error versus x

Derivation

  1. Initial program 58.1

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