Average Error: 58.2 → 0.7
Time: 6.4s
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 r47406 = x;
        double r47407 = exp(r47406);
        double r47408 = -r47406;
        double r47409 = exp(r47408);
        double r47410 = r47407 - r47409;
        double r47411 = r47407 + r47409;
        double r47412 = r47410 / r47411;
        return r47412;
}

double f(double x) {
        double r47413 = x;
        double r47414 = r47413 + r47413;
        double r47415 = expm1(r47414);
        double r47416 = 1.0;
        double r47417 = exp(r47414);
        double r47418 = fma(r47416, r47416, r47417);
        double r47419 = r47415 / r47418;
        return r47419;
}

Error

Bits error versus x

Derivation

  1. Initial program 58.2

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