Average Error: 58.1 → 0.8
Time: 5.4s
Precision: 64
\[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}\]
\[\frac{\mathsf{expm1}\left(x + x\right)}{e^{\mathsf{log1p}\left(e^{2 \cdot x}\right)}}\]
\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}
\frac{\mathsf{expm1}\left(x + x\right)}{e^{\mathsf{log1p}\left(e^{2 \cdot x}\right)}}
double f(double x) {
        double r38680 = x;
        double r38681 = exp(r38680);
        double r38682 = -r38680;
        double r38683 = exp(r38682);
        double r38684 = r38681 - r38683;
        double r38685 = r38681 + r38683;
        double r38686 = r38684 / r38685;
        return r38686;
}

double f(double x) {
        double r38687 = x;
        double r38688 = r38687 + r38687;
        double r38689 = expm1(r38688);
        double r38690 = 2.0;
        double r38691 = r38690 * r38687;
        double r38692 = exp(r38691);
        double r38693 = log1p(r38692);
        double r38694 = exp(r38693);
        double r38695 = r38689 / r38694;
        return r38695;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 58.1

    \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}\]
  2. Simplified0.8

    \[\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 add-exp-log0.8

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

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

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

Reproduce

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