Average Error: 58.3 → 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 r44154 = x;
        double r44155 = exp(r44154);
        double r44156 = -r44154;
        double r44157 = exp(r44156);
        double r44158 = r44155 - r44157;
        double r44159 = r44155 + r44157;
        double r44160 = r44158 / r44159;
        return r44160;
}

double f(double x) {
        double r44161 = x;
        double r44162 = r44161 + r44161;
        double r44163 = expm1(r44162);
        double r44164 = 2.0;
        double r44165 = r44164 * r44161;
        double r44166 = exp(r44165);
        double r44167 = log1p(r44166);
        double r44168 = exp(r44167);
        double r44169 = r44163 / r44168;
        return r44169;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 58.3

    \[\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 2020081 +o rules:numerics
(FPCore (x)
  :name "Hyperbolic tangent"
  :precision binary64
  (/ (- (exp x) (exp (- x))) (+ (exp x) (exp (- x)))))