Average Error: 58.0 → 0.7
Time: 6.2s
Precision: 64
\[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}\]
\[\frac{1}{e^{2 \cdot x} + 1} \cdot \mathsf{expm1}\left(x + x\right)\]
\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}
\frac{1}{e^{2 \cdot x} + 1} \cdot \mathsf{expm1}\left(x + x\right)
double f(double x) {
        double r29362 = x;
        double r29363 = exp(r29362);
        double r29364 = -r29362;
        double r29365 = exp(r29364);
        double r29366 = r29363 - r29365;
        double r29367 = r29363 + r29365;
        double r29368 = r29366 / r29367;
        return r29368;
}

double f(double x) {
        double r29369 = 1.0;
        double r29370 = 2.0;
        double r29371 = x;
        double r29372 = r29370 * r29371;
        double r29373 = exp(r29372);
        double r29374 = r29373 + r29369;
        double r29375 = r29369 / r29374;
        double r29376 = r29371 + r29371;
        double r29377 = expm1(r29376);
        double r29378 = r29375 * r29377;
        return r29378;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 58.0

    \[\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 associate-/r/0.7

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

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

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

Reproduce

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