Average Error: 58.1 → 0.7
Time: 5.5s
Precision: 64
\[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}\]
\[\mathsf{expm1}\left(x + x\right) \cdot e^{0 - \mathsf{log1p}\left(e^{2 \cdot x}\right)}\]
\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}
\mathsf{expm1}\left(x + x\right) \cdot e^{0 - \mathsf{log1p}\left(e^{2 \cdot x}\right)}
double f(double x) {
        double r34958 = x;
        double r34959 = exp(r34958);
        double r34960 = -r34958;
        double r34961 = exp(r34960);
        double r34962 = r34959 - r34961;
        double r34963 = r34959 + r34961;
        double r34964 = r34962 / r34963;
        return r34964;
}

double f(double x) {
        double r34965 = x;
        double r34966 = r34965 + r34965;
        double r34967 = expm1(r34966);
        double r34968 = 0.0;
        double r34969 = 2.0;
        double r34970 = r34969 * r34965;
        double r34971 = exp(r34970);
        double r34972 = log1p(r34971);
        double r34973 = r34968 - r34972;
        double r34974 = exp(r34973);
        double r34975 = r34967 * r34974;
        return r34975;
}

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.7

    \[\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 div-inv0.7

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

    \[\leadsto 1 \cdot \left(\mathsf{expm1}\left(x + x\right) \cdot \color{blue}{\frac{1}{e^{2 \cdot x} + 1}}\right)\]
  6. Using strategy rm
  7. Applied add-exp-log0.7

    \[\leadsto 1 \cdot \left(\mathsf{expm1}\left(x + x\right) \cdot \frac{1}{\color{blue}{e^{\log \left(e^{2 \cdot x} + 1\right)}}}\right)\]
  8. Applied rec-exp0.7

    \[\leadsto 1 \cdot \left(\mathsf{expm1}\left(x + x\right) \cdot \color{blue}{e^{-\log \left(e^{2 \cdot x} + 1\right)}}\right)\]
  9. Simplified0.7

    \[\leadsto 1 \cdot \left(\mathsf{expm1}\left(x + x\right) \cdot e^{\color{blue}{0 - \mathsf{log1p}\left(e^{2 \cdot x}\right)}}\right)\]
  10. Final simplification0.7

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

Reproduce

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