Average Error: 58.4 → 0.6
Time: 6.6s
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 r75121 = x;
        double r75122 = exp(r75121);
        double r75123 = -r75121;
        double r75124 = exp(r75123);
        double r75125 = r75122 - r75124;
        double r75126 = r75122 + r75124;
        double r75127 = r75125 / r75126;
        return r75127;
}

double f(double x) {
        double r75128 = x;
        double r75129 = r75128 + r75128;
        double r75130 = expm1(r75129);
        double r75131 = 1.0;
        double r75132 = exp(r75129);
        double r75133 = fma(r75131, r75131, r75132);
        double r75134 = r75130 / r75133;
        return r75134;
}

Error

Bits error versus x

Derivation

  1. Initial program 58.4

    \[\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. Final simplification0.6

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

Reproduce

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