Average Error: 58.2 → 0.7
Time: 3.6s
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 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) (((double) expm1(((double) (x + x)))) / ((double) exp(((double) log1p(((double) exp(((double) (2.0 * 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.2

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

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

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

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

Reproduce

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