Average Error: 58.1 → 0.8
Time: 4.1s
Precision: 64
\[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}\]
\[\frac{1}{\frac{\mathsf{fma}\left(1, 1, e^{x + x}\right)}{\mathsf{expm1}\left(x + x\right)}}\]
\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}
\frac{1}{\frac{\mathsf{fma}\left(1, 1, e^{x + x}\right)}{\mathsf{expm1}\left(x + x\right)}}
double code(double x) {
	return ((double) (((double) (((double) exp(x)) - ((double) exp(((double) -(x)))))) / ((double) (((double) exp(x)) + ((double) exp(((double) -(x))))))));
}
double code(double x) {
	return ((double) (1.0 / ((double) (((double) fma(1.0, 1.0, ((double) exp(((double) (x + x)))))) / ((double) expm1(((double) (x + x))))))));
}

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.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. Final simplification0.8

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

Reproduce

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