Average Error: 58.1 → 0.7
Time: 6.0s
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 r40224 = x;
        double r40225 = exp(r40224);
        double r40226 = -r40224;
        double r40227 = exp(r40226);
        double r40228 = r40225 - r40227;
        double r40229 = r40225 + r40227;
        double r40230 = r40228 / r40229;
        return r40230;
}

double f(double x) {
        double r40231 = x;
        double r40232 = r40231 + r40231;
        double r40233 = expm1(r40232);
        double r40234 = 1.0;
        double r40235 = exp(r40232);
        double r40236 = fma(r40234, r40234, r40235);
        double r40237 = r40233 / r40236;
        return r40237;
}

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