Average Error: 58.2 → 0.6
Time: 6.0s
Precision: 64
\[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}\]
\[\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\mathsf{expm1}\left(x + x\right)}{\mathsf{fma}\left(1, 1, e^{x + x}\right)}\right)\right)\]
\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}
\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\mathsf{expm1}\left(x + x\right)}{\mathsf{fma}\left(1, 1, e^{x + x}\right)}\right)\right)
double f(double x) {
        double r39699 = x;
        double r39700 = exp(r39699);
        double r39701 = -r39699;
        double r39702 = exp(r39701);
        double r39703 = r39700 - r39702;
        double r39704 = r39700 + r39702;
        double r39705 = r39703 / r39704;
        return r39705;
}

double f(double x) {
        double r39706 = x;
        double r39707 = r39706 + r39706;
        double r39708 = expm1(r39707);
        double r39709 = 1.0;
        double r39710 = exp(r39707);
        double r39711 = fma(r39709, r39709, r39710);
        double r39712 = r39708 / r39711;
        double r39713 = expm1(r39712);
        double r39714 = log1p(r39713);
        return r39714;
}

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 log1p-expm1-u0.6

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

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

Reproduce

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