Average Error: 58.0 → 0.7
Time: 5.8s
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 r40184 = x;
        double r40185 = exp(r40184);
        double r40186 = -r40184;
        double r40187 = exp(r40186);
        double r40188 = r40185 - r40187;
        double r40189 = r40185 + r40187;
        double r40190 = r40188 / r40189;
        return r40190;
}

double f(double x) {
        double r40191 = x;
        double r40192 = r40191 + r40191;
        double r40193 = expm1(r40192);
        double r40194 = 1.0;
        double r40195 = exp(r40192);
        double r40196 = fma(r40194, r40194, r40195);
        double r40197 = r40193 / r40196;
        return r40197;
}

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