Average Error: 58.2 → 0.8
Time: 4.5s
Precision: 64
\[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}\]
\[\frac{1}{\frac{\mathsf{fma}\left(1, 1, e^{x + x}\right)}{\mathsf{expm1}\left(x + x\right)}}\]
\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}
\frac{1}{\frac{\mathsf{fma}\left(1, 1, e^{x + x}\right)}{\mathsf{expm1}\left(x + x\right)}}
double f(double x) {
        double r36252 = x;
        double r36253 = exp(r36252);
        double r36254 = -r36252;
        double r36255 = exp(r36254);
        double r36256 = r36253 - r36255;
        double r36257 = r36253 + r36255;
        double r36258 = r36256 / r36257;
        return r36258;
}

double f(double x) {
        double r36259 = 1.0;
        double r36260 = x;
        double r36261 = r36260 + r36260;
        double r36262 = exp(r36261);
        double r36263 = fma(r36259, r36259, r36262);
        double r36264 = expm1(r36261);
        double r36265 = r36263 / r36264;
        double r36266 = r36259 / r36265;
        return r36266;
}

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. Using strategy rm
  4. Applied clear-num0.8

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

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

Reproduce

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