Average Error: 58.2 → 0.8
Time: 4.3s
Precision: 64
\[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}\]
\[\frac{\frac{1}{e^{2 \cdot x} + 1}}{\frac{1}{\mathsf{expm1}\left(x + x\right)}}\]
\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}
\frac{\frac{1}{e^{2 \cdot x} + 1}}{\frac{1}{\mathsf{expm1}\left(x + x\right)}}
double f(double x) {
        double r37472 = x;
        double r37473 = exp(r37472);
        double r37474 = -r37472;
        double r37475 = exp(r37474);
        double r37476 = r37473 - r37475;
        double r37477 = r37473 + r37475;
        double r37478 = r37476 / r37477;
        return r37478;
}

double f(double x) {
        double r37479 = 1.0;
        double r37480 = 2.0;
        double r37481 = x;
        double r37482 = r37480 * r37481;
        double r37483 = exp(r37482);
        double r37484 = r37483 + r37479;
        double r37485 = r37479 / r37484;
        double r37486 = r37481 + r37481;
        double r37487 = expm1(r37486);
        double r37488 = r37479 / r37487;
        double r37489 = r37485 / r37488;
        return r37489;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

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 clear-num0.8

    \[\leadsto 1 \cdot \color{blue}{\frac{1}{\frac{\mathsf{fma}\left(1, 1, e^{x + x}\right)}{\mathsf{expm1}\left(x + x\right)}}}\]
  5. Using strategy rm
  6. Applied div-inv0.8

    \[\leadsto 1 \cdot \frac{1}{\color{blue}{\mathsf{fma}\left(1, 1, e^{x + x}\right) \cdot \frac{1}{\mathsf{expm1}\left(x + x\right)}}}\]
  7. Applied associate-/r*0.8

    \[\leadsto 1 \cdot \color{blue}{\frac{\frac{1}{\mathsf{fma}\left(1, 1, e^{x + x}\right)}}{\frac{1}{\mathsf{expm1}\left(x + x\right)}}}\]
  8. Simplified0.8

    \[\leadsto 1 \cdot \frac{\color{blue}{\frac{1}{e^{2 \cdot x} + 1}}}{\frac{1}{\mathsf{expm1}\left(x + x\right)}}\]
  9. Final simplification0.8

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

Reproduce

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