Average Error: 58.2 → 0.6
Time: 5.4s
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 r38147 = x;
        double r38148 = exp(r38147);
        double r38149 = -r38147;
        double r38150 = exp(r38149);
        double r38151 = r38148 - r38150;
        double r38152 = r38148 + r38150;
        double r38153 = r38151 / r38152;
        return r38153;
}

double f(double x) {
        double r38154 = x;
        double r38155 = r38154 + r38154;
        double r38156 = expm1(r38155);
        double r38157 = 1.0;
        double r38158 = exp(r38155);
        double r38159 = fma(r38157, r38157, r38158);
        double r38160 = r38156 / r38159;
        return r38160;
}

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

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

Reproduce

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