0.76159416
1.17520119
1.54308063
0.64805427
0.76159416
1.17520119
1.54308063
0.64805427
The Hyperbolic Tangent Calculator computes $$\tanh(x)$$ for any real number $$x$$. The hyperbolic tangent is defined as the ratio of hyperbolic sine to hyperbolic cosine and is one of the most important activation functions in modern machine learning and neural networks.
The hyperbolic tangent is defined as:
$$\tanh(x) = \frac{\sinh(x)}{\cosh(x)} = \frac{e^x - e^{-x}}{e^x + e^{-x}}$$
This function maps any real number to a value strictly between -1 and 1, producing a smooth, S-shaped (sigmoid-like) curve that passes through the origin. It smoothly saturates to $$\pm 1$$ as $$x \to \pm\infty$$.
The hyperbolic tangent is closely related to the logistic sigmoid function $$\sigma(x) = \frac{1}{1 + e^{-x}}$$:
$$\tanh(x) = 2\sigma(2x) - 1$$
Both functions are sigmoid-shaped, but $$\tanh$$ is zero-centered (output range $$(-1,1)$$) while the logistic sigmoid maps to $$(0,1)$$. This zero-centered property often makes $$\tanh$$ preferable as an activation function in neural networks, since it helps keep the mean of activations near zero.
In deep learning, $$\tanh$$ was historically one of the most popular activation functions before ReLU became dominant. Its advantages include:
However, tanh suffers from the vanishing gradient problem: for large $$|x|$$, the derivative $$1 - \tanh^2(x)$$ approaches zero, making gradient-based learning extremely slow in deep networks.
Beyond machine learning, $$\tanh$$ appears in many scientific contexts. In special relativity, the velocity addition formula for collinear velocities uses $$\tanh$$: if rapidities add as $$\phi = \phi_1 + \phi_2$$, then $$v/c = \tanh(\phi)$$. In fluid dynamics, $$\tanh$$ profiles describe shear layers and mixing zones. In magnetism, the Brillouin function (which describes paramagnetic magnetization) reduces to $$\tanh$$ for spin-1/2 particles. In electrical engineering, $$\tanh$$ appears in impedance matching and transmission line calculations. The function also models dose-response curves in pharmacology and population saturation in ecology.
Enter any real number $$x$$. The calculator computes $$\tanh(x) = \frac{e^x - e^{-x}}{e^x + e^{-x}}$$ and also displays the underlying $$\sinh(x)$$ and $$\cosh(x)$$ values.
The result is always between -1 and 1. Values near 0 indicate the input is small; values near $$\pm 1$$ indicate the input is large in magnitude. The function transitions most steeply around $$x = 0$$, where the derivative equals 1. For $$|x| > 3$$, tanh is nearly saturated at $$\pm 1$$.
Inputs
Results
tanh(0) = sinh(0)/cosh(0) = 0/1 = 0. The function passes through the origin.
Inputs
Results
tanh(2) ≈ 0.964, already close to the asymptotic limit of 1, showing rapid saturation.
The $$\tanh$$ function is zero-centered (outputs range from -1 to 1), smooth, and differentiable. Zero-centering helps optimization by keeping layer outputs balanced. However, it suffers from vanishing gradients for large inputs, which is why ReLU and its variants are now more common in deep networks.
For large $$|x|$$, $$\tanh(x)$$ saturates near $$\pm 1$$ and its derivative $$1 - \tanh^2(x)$$ approaches 0. During backpropagation, these near-zero gradients multiply across layers, causing weights in early layers to update extremely slowly or not at all.
$$\tanh(x) = 2\sigma(2x) - 1$$, where $$\sigma$$ is the logistic sigmoid. Equivalently, $$\sigma(x) = \frac{\tanh(x/2) + 1}{2}$$. The tanh maps to $$(-1, 1)$$ while the sigmoid maps to $$(0, 1)$$.
No. The function approaches these values asymptotically but never reaches them. For any finite $$x$$, $$|\tanh(x)| < 1$$. Only in the limit as $$x \to \pm\infty$$ does the value reach $$\pm 1$$.
The inverse hyperbolic tangent is $$\text{arctanh}(x) = \frac{1}{2}\ln\left(\frac{1+x}{1-x}\right)$$ for $$|x| < 1$$. It maps the interval $$(-1, 1)$$ back to all real numbers.
In special relativity, velocity as a fraction of light speed is $$v/c = \tanh(\phi)$$ where $$\phi$$ is the rapidity. In magnetism, the magnetization of spin-1/2 particles follows $$M = M_s \tanh\left(\frac{\mu B}{k_B T}\right)$$. It also models shear layers in fluid dynamics and soliton solutions of the KdV equation.
Roboculator Team
The Roboculator Team explains calculations, planning tools, and practical formulas in clear language for real-life situations.
How helpful was this calculator?
Be the first to rate!