Average Error: 57.8 → 2.0
Time: 6.1s
Precision: 64
\[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}\]
\[\mathsf{expm1}\left(\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{log1p}\left(\mathsf{fma}\left({x}^{5}, \frac{2}{15}, x - \frac{1}{3} \cdot {x}^{3}\right)\right)\right)\right)\right)\]
\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}
\mathsf{expm1}\left(\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{log1p}\left(\mathsf{fma}\left({x}^{5}, \frac{2}{15}, x - \frac{1}{3} \cdot {x}^{3}\right)\right)\right)\right)\right)
double code(double x) {
	return ((exp(x) - exp(-x)) / (exp(x) + exp(-x)));
}
double code(double x) {
	return expm1(expm1(log1p(log1p(fma(pow(x, 5.0), 0.13333333333333333, (x - (0.3333333333333333 * pow(x, 3.0))))))));
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 57.8

    \[\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. Taylor expanded around 0 1.9

    \[\leadsto 1 \cdot \color{blue}{\left(\left(x + \frac{2}{15} \cdot {x}^{5}\right) - \frac{1}{3} \cdot {x}^{3}\right)}\]
  4. Simplified1.9

    \[\leadsto 1 \cdot \color{blue}{\mathsf{fma}\left({x}^{5}, \frac{2}{15}, x - \frac{1}{3} \cdot {x}^{3}\right)}\]
  5. Using strategy rm
  6. Applied expm1-log1p-u2.0

    \[\leadsto 1 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{fma}\left({x}^{5}, \frac{2}{15}, x - \frac{1}{3} \cdot {x}^{3}\right)\right)\right)}\]
  7. Using strategy rm
  8. Applied expm1-log1p-u2.0

    \[\leadsto 1 \cdot \mathsf{expm1}\left(\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{log1p}\left(\mathsf{fma}\left({x}^{5}, \frac{2}{15}, x - \frac{1}{3} \cdot {x}^{3}\right)\right)\right)\right)}\right)\]
  9. Final simplification2.0

    \[\leadsto \mathsf{expm1}\left(\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{log1p}\left(\mathsf{fma}\left({x}^{5}, \frac{2}{15}, x - \frac{1}{3} \cdot {x}^{3}\right)\right)\right)\right)\right)\]

Reproduce

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