Average Error: 58.2 → 0.6
Time: 5.3s
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 r37893 = x;
        double r37894 = exp(r37893);
        double r37895 = -r37893;
        double r37896 = exp(r37895);
        double r37897 = r37894 - r37896;
        double r37898 = r37894 + r37896;
        double r37899 = r37897 / r37898;
        return r37899;
}

double f(double x) {
        double r37900 = x;
        double r37901 = r37900 + r37900;
        double r37902 = expm1(r37901);
        double r37903 = 1.0;
        double r37904 = exp(r37901);
        double r37905 = fma(r37903, r37903, r37904);
        double r37906 = r37902 / r37905;
        double r37907 = expm1(r37906);
        double r37908 = log1p(r37907);
        return r37908;
}

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