Average Error: 58.3 → 0.7
Time: 5.5s
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 r41892 = x;
        double r41893 = exp(r41892);
        double r41894 = -r41892;
        double r41895 = exp(r41894);
        double r41896 = r41893 - r41895;
        double r41897 = r41893 + r41895;
        double r41898 = r41896 / r41897;
        return r41898;
}

double f(double x) {
        double r41899 = x;
        double r41900 = r41899 + r41899;
        double r41901 = expm1(r41900);
        double r41902 = 1.0;
        double r41903 = exp(r41900);
        double r41904 = fma(r41902, r41902, r41903);
        double r41905 = r41901 / r41904;
        double r41906 = expm1(r41905);
        double r41907 = log1p(r41906);
        return r41907;
}

Error

Bits error versus x

Derivation

  1. Initial program 58.3

    \[\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. Using strategy rm
  4. Applied log1p-expm1-u0.7

    \[\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.7

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