The hyperbolic tangent of x, written tanh x, can be expressed exactly using the mathematical constant e (Euler’s number) via the formula tanh x = (eˣ − e⁻ˣ) / (eˣ + e⁻ˣ). This representation connects hyperbolic functions to exponential growth and decay, enabling algebraic manipulation, calculus operations, and numerical evaluation without relying on built-in trigonometric functions. To derive or apply it, you need only basic algebra, the definition of eˣ, and awareness of domain restrictions (x must be a real number; division by zero never occurs since eˣ + e⁻ˣ > 0 for all real x).
What You'll Need
- Basic algebra skills (especially working with exponents and fractions)
- Understanding of Euler’s number e ≈ 2.71828 and its properties
- A calculator or computational tool (optional, for numerical verification)
- Paper or a digital document for step-by-step work
Step-by-Step
- Recall the definitions of sinh x and cosh x in terms of e: Begin with the standard hyperbolic sine and cosine definitions: sinh x = (eˣ − e⁻ˣ) / 2 and cosh x = (eˣ + e⁻ˣ) / 2. These are foundational—tanh x is defined as the ratio sinh x / cosh x, so you must start here.
- Write tanh x as sinh x divided by cosh x: Substitute the exponential forms into the ratio: tanh x = sinh x / cosh x = [(eˣ − e⁻ˣ) / 2] / [(eˣ + e⁻ˣ) / 2]. This step expresses tanh x purely in terms of exponentials, though the 2s in numerator and denominator are still present.
- Simplify the complex fraction: Divide the two fractions by multiplying the numerator by the reciprocal of the denominator: [(eˣ − e⁻ˣ) / 2] × [2 / (eˣ + e⁻ˣ)]. The factor of 2 appears in both numerator and denominator, so cancel them: (eˣ − e⁻ˣ) × (1 / (eˣ + e⁻ˣ)) = (eˣ − e⁻ˣ) / (eˣ + e⁻ˣ). You now have the simplified exponential form.
- Verify domain and non-zero denominator: Confirm that eˣ + e⁻ˣ ≠ 0 for all real x. Since eˣ > 0 for any real x, both eˣ and e⁻ˣ = 1/eˣ are positive, so their sum is always greater than zero. This means tanh x is defined for all real x, with no vertical asymptotes or undefined points.
- Optionally, rewrite using substitution for clarity: Let u = eˣ. Then e⁻ˣ = 1/u, so tanh x = (u − 1/u) / (u + 1/u). Multiply numerator and denominator by u to eliminate fractions: (u² − 1) / (u² + 1). This alternative form is useful in integration or substitution problems but is equivalent to the original expression.
- Test with a known value to confirm: Choose x = 0. Compute manually: e⁰ = 1, e⁻⁰ = 1, so tanh 0 = (1 − 1) / (1 + 1) = 0 / 2 = 0. Since tanh 0 is known to be 0, this validates the formula. Try x = ln 2 (≈0.693): eˣ = 2, e⁻ˣ = 1/2, so tanh x = (2 − 0.5) / (2 + 0.5) = 1.5 / 2.5 = 0.6. A calculator’s tanh(ln 2) also yields ≈0.6, confirming correctness.
Common Mistakes
- Confusing signs: Mixing up the sign in the numerator—tanh x uses (eˣ − e⁻ˣ), not (eˣ + e⁻ˣ). The plus sign belongs only in the denominator.
- Forgetting to cancel the 2s: When writing sinh x / cosh x, the /2 terms cancel, but some leave them in, writing (eˣ − e⁻ˣ) / (eˣ + e⁻ˣ) incorrectly as [(eˣ − e⁻ˣ)/2] / [(eˣ + e⁻ˣ)/2] without simplifying.
- Misapplying to complex x: While the formula holds for complex x, division by zero can occur if eˣ + e⁻ˣ = 0, which happens when x is purely imaginary and equal to iπ/2 + iπn (n integer). For real x, this never happens, but assuming it’s always safe for complex arguments is a pitfall.
- Assuming symmetry incorrectly: tanh(−x) = −tanh x (odd function), but confusing this with even symmetry (like cosh x) leads to sign errors in substitutions.
- Using degrees instead of radians: If computing numerically, ensure your calculator is in radian mode. While eˣ itself is unitless, many computational tools expect x in radians for hyperbolic functions.
Tips
- Memorize the core exponential forms: sinh x, cosh x, and tanh x are often easier to derive than memorize separately. Remember: sinh has a minus, cosh has a plus, and tanh is their ratio.
- Use symmetry for mental checks: For large positive x, e⁻ˣ ≈ 0, so tanh x ≈ eˣ / eˣ = 1. For large negative x, eˣ ≈ 0, so tanh x ≈ (−e⁻ˣ) / e⁻ˣ = −1. This confirms the horizontal asymptotes at ±1.
- Apply in calculus: When integrating 1/(1 − x²), partial fractions lead to (1/2) ln|(1+x)/(1−x)|, whose derivative is sech²x, and differentiating tanh x = (eˣ − e⁻ˣ)/(eˣ + e⁻ˣ) via quotient rule yields sech²x—reinforcing the formula’s validity.
- Use software for visualization: Plot (eˣ − e⁻ˣ)/(eˣ + e⁻ˣ) in tools like Desmos or Python’s matplotlib to see the sigmoid shape, which helps intuition for its behavior.
Troubleshooting
If your computed value doesn’t match known results, follow these checks:
- Verify exponent signs: Double-check that e⁻ˣ is correctly calculated as 1/(eˣ). A common error is entering e^(−x) as −eˣ on calculators without parentheses.
- Check floating-point precision: For very large |x| (e.g., |x| > 20), eˣ or e⁻ˣ may overflow or underflow in finite-precision arithmetic. Use software functions like tanh(x) directly instead of manual computation for such values.
- Ensure real inputs: If x is complex, confirm your calculator or library supports complex arithmetic. Standard scientific calculators often assume real inputs only.
- Confirm input mode: If using a graphing calculator, verify radian mode. Entering x = π/2 in degree mode gives a different result than expected for tanh(π/2).
- Recompute step-by-step: Break the expression into parts: compute eˣ first, then e⁻ˣ, then numerator and denominator separately before division.
Frequently Asked Questions
Why is tanh x defined as (eˣ − e⁻ˣ)/(eˣ + e⁻ˣ) and not something else?
This definition arises naturally from the hyperbolic angle parameterization of the unit hyperbola x² − y² = 1, analogous to how sin and cos arise from the unit circle. It ensures identities like tanh x = sinh x / cosh x hold, and it satisfies differential equations such as y′ = 1 − y², with y(0) = 0.
Does the formula work for x = 0?
Yes. Substituting x = 0 gives (e⁰ − e⁰)/(e⁰ + e⁰) = (1 − 1)/(1 + 1) = 0/2 = 0, which matches the known value tanh 0 = 0 and the function’s odd symmetry.
Can I use this formula to compute tanh x without a calculator?
Yes, for small |x|, approximate eˣ ≈ 1 + x + x²/2 and e⁻ˣ ≈ 1 − x + x²/2. Then tanh x ≈ [(1 + x + x²/2) − (1 − x + x²/2)] / [(1 + x + x²/2) + (1 − x + x²/2)] = (2x) / (2 + x²) = 2x/(2 + x²), giving a rational approximation near zero.
Is tanh x ever undefined?
For real x, no. The denominator eˣ + e⁻ˣ is always positive (sum of two positive numbers), so there are no vertical asymptotes. The function is defined and smooth for all real numbers.
How does this formula relate to the sigmoid function in machine learning?
The sigmoid function is often σ(x) = 1/(1 + e⁻ˣ), while tanh x = (eˣ − e⁻ˣ)/(eˣ + e⁻ˣ). They are related by tanh x = 2σ(2x) − 1. This scaling shifts and rescales the sigmoid to output values between −1 and 1 instead of 0 and 1, making tanh zero-centered—a useful property in neural networks.
Why do some sources write tanh x as (e²ˣ − 1)/(e²ˣ + 1)?
This is an algebraically equivalent form. Multiply numerator and denominator of (eˣ − e⁻ˣ)/(eˣ + e⁻ˣ) by eˣ: numerator becomes e²ˣ − 1, denominator becomes e²ˣ + 1. This version avoids negative exponents and is often preferred in integration or when solving differential equations where e²ˣ appears naturally.