Average Error: 58.3 → 1.4
Time: 3.6s
Precision: binary64
\[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
\[\frac{0.016666666666666666 \cdot {x}^{5} + \left(0.0003968253968253968 \cdot {x}^{7} + \left(0.3333333333333333 \cdot {x}^{3} + x \cdot 2\right)\right)}{e^{x} + e^{-x}} \]
\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}
\frac{0.016666666666666666 \cdot {x}^{5} + \left(0.0003968253968253968 \cdot {x}^{7} + \left(0.3333333333333333 \cdot {x}^{3} + x \cdot 2\right)\right)}{e^{x} + e^{-x}}
(FPCore (x)
 :precision binary64
 (/ (- (exp x) (exp (- x))) (+ (exp x) (exp (- x)))))
(FPCore (x)
 :precision binary64
 (/
  (+
   (* 0.016666666666666666 (pow x 5.0))
   (+
    (* 0.0003968253968253968 (pow x 7.0))
    (+ (* 0.3333333333333333 (pow x 3.0)) (* x 2.0))))
  (+ (exp x) (exp (- x)))))
double code(double x) {
	return (exp(x) - exp(-x)) / (exp(x) + exp(-x));
}
double code(double x) {
	return ((0.016666666666666666 * pow(x, 5.0)) + ((0.0003968253968253968 * pow(x, 7.0)) + ((0.3333333333333333 * pow(x, 3.0)) + (x * 2.0)))) / (exp(x) + exp(-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.3

    \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} \]
  2. Taylor expanded in x around 0 1.4

    \[\leadsto \frac{\color{blue}{0.016666666666666666 \cdot {x}^{5} + \left(0.0003968253968253968 \cdot {x}^{7} + \left(0.3333333333333333 \cdot {x}^{3} + 2 \cdot x\right)\right)}}{e^{x} + e^{-x}} \]
  3. Final simplification1.4

    \[\leadsto \frac{0.016666666666666666 \cdot {x}^{5} + \left(0.0003968253968253968 \cdot {x}^{7} + \left(0.3333333333333333 \cdot {x}^{3} + x \cdot 2\right)\right)}{e^{x} + e^{-x}} \]

Reproduce

herbie shell --seed 2022129 
(FPCore (x)
  :name "Hyperbolic tangent"
  :precision binary64
  (/ (- (exp x) (exp (- x))) (+ (exp x) (exp (- x)))))