Average Error: 58.2 → 0.0
Time: 3.6s
Precision: binary64
Cost: 6464
\[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}\]
\[\tanh x\]
\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}
\tanh x
(FPCore (x)
 :precision binary64
 (/ (- (exp x) (exp (- x))) (+ (exp x) (exp (- x)))))
(FPCore (x) :precision binary64 (tanh x))
double code(double x) {
	return (exp(x) - exp(-x)) / (exp(x) + exp(-x));
}
double code(double x) {
	return tanh(x);
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Alternatives

Alternative 1
Error1.4
Cost385
\[\begin{array}{l} \mathbf{if}\;x \leq 0.9975721750512928:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]
Alternative 2
Error59.1
Cost385
\[\begin{array}{l} \mathbf{if}\;x \leq 1.0964452542503893 \cdot 10^{-154}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]
Alternative 3
Error60.6
Cost64
\[1\]

Error

Derivation

  1. Initial program 58.2

    \[\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}\]
  2. Using strategy rm
  3. Applied tanh-undef_binary64_12960.0

    \[\leadsto \color{blue}{\tanh x}\]
  4. Simplified0.0

    \[\leadsto \color{blue}{\tanh x}\]
  5. Final simplification0.0

    \[\leadsto \tanh x\]

Reproduce

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