What is the hyperbolic tangent?
The hyperbolic tangent, written \(\tanh(x)\), is one of the basic hyperbolic functions. It is defined as the ratio of the hyperbolic sine to the hyperbolic cosine, \(\tanh(x) = \sinh(x)/\cosh(x)\). For real inputs its output is always strictly between -1 and 1, and the function passes smoothly through the origin. Because it is smooth, bounded and S-shaped, tanh is widely used as an activation function in neural networks and as a soft saturation curve in signal processing.
How to use this calculator
Enter a value of x to instantly read \(\tanh(x)\), its first derivative \(\tanh'(x)\), and its second derivative \(\tanh''(x)\). To explore the shape of the curves, fill in the range fields: a start value, an end value, and a positive step size. The calculator then builds a table of \(x\), \(\tanh(x)\), \(\tanh'(x)\) and \(\tanh''(x)\) across the range. The step must be greater than zero and the end must be at least the start, otherwise the table is skipped.
The formulas explained
The function is $$\tanh(x) = \frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}.$$ Its derivative has the elegant form $$\tanh'(x) = 1 - \tanh^{2}(x) = \operatorname{sech}^{2}(x),$$ which is always positive and peaks at 1 when \(x = 0\). Differentiating once more gives $$\tanh''(x) = -2\,\tanh(x)\left(1 - \tanh^{2}(x)\right).$$ For numerical stability with large \(|x|\) we use the standard library tanh, which avoids exponential overflow.
Worked example
Take \(x = 1\). Then \(e^{1} = 2.718281828\) and \(e^{-1} = 0.367879441\), so $$\tanh(1) = \frac{2.718281828 - 0.367879441}{2.718281828 + 0.367879441} = 0.761594156.$$ The first derivative is $$1 - 0.761594156^{2} = 0.419974341,$$ and the second derivative is $$-2 \times 0.761594156 \times 0.419974341 = -0.639700.$$
FAQ
What is tanh(0)? \(\tanh(0) = 0\), \(\tanh'(0) = 1\) (the steepest slope), and \(\tanh''(0) = 0\).
Is tanh odd or even? tanh is an odd function, \(\tanh(-x) = -\tanh(x)\). Its first derivative is even and its second derivative is odd.
What is the range of tanh? The output approaches -1 as x goes to negative infinity and 1 as x goes to positive infinity, but never reaches them, so the range is the open interval \((-1, 1)\).