Average Error: 58.1 → 0.7
Time: 5.3s
Precision: 64
\[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}\]
\[\frac{\mathsf{expm1}\left(x + x\right)}{{\left(e^{2 \cdot x}\right)}^{3} + 1} \cdot \left(e^{2 \cdot x} \cdot e^{2 \cdot x} + \left(1 - e^{2 \cdot x} \cdot 1\right)\right)\]
\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}
\frac{\mathsf{expm1}\left(x + x\right)}{{\left(e^{2 \cdot x}\right)}^{3} + 1} \cdot \left(e^{2 \cdot x} \cdot e^{2 \cdot x} + \left(1 - e^{2 \cdot x} \cdot 1\right)\right)
double code(double x) {
	return ((exp(x) - exp(-x)) / (exp(x) + exp(-x)));
}
double code(double x) {
	return ((expm1((x + x)) / (pow(exp((2.0 * x)), 3.0) + 1.0)) * ((exp((2.0 * x)) * exp((2.0 * x))) + (1.0 - (exp((2.0 * x)) * 1.0))));
}

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. Taylor expanded around inf 0.6

    \[\leadsto 1 \cdot \frac{\mathsf{expm1}\left(x + x\right)}{\color{blue}{e^{2 \cdot x} + 1}}\]
  4. Using strategy rm
  5. Applied flip3-+0.7

    \[\leadsto 1 \cdot \frac{\mathsf{expm1}\left(x + x\right)}{\color{blue}{\frac{{\left(e^{2 \cdot x}\right)}^{3} + {1}^{3}}{e^{2 \cdot x} \cdot e^{2 \cdot x} + \left(1 \cdot 1 - e^{2 \cdot x} \cdot 1\right)}}}\]
  6. Applied associate-/r/0.7

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

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

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

Reproduce

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