Chapter 12: ufunc Hyperbolic
1. What are hyperbolic functions? (intuition first)
Hyperbolic functions are the hyperbolic analogues of ordinary trigonometric functions (sin, cos, tan).
While ordinary trig functions are related to the unit circle (x² + y² = 1), hyperbolic functions are related to the unit hyperbola (x² − y² = 1).
Very simple mental picture:
- sin, cos → circle → periodic, bounded between −1 and 1
- sinh, cosh → hyperbola → not periodic, grow exponentially
They appear naturally whenever you have:
- exponential growth combined with exponential decay
- special relativity (rapidity, Lorentz factor)
- catenary curves (hanging chains, power lines)
- hyperbolic geometry
- certain differential equations
- neural network activations (very rare now, but historically)
2. The six main hyperbolic ufuncs in NumPy
| Function | Computes | Input range | Output range | Inverse function |
|---|---|---|---|---|
| np.sinh | hyperbolic sine | any real | (−∞, +∞) | np.arcsinh |
| np.cosh | hyperbolic cosine | any real | [1, +∞) | np.arccosh (≥0) |
| np.tanh | hyperbolic tangent | any real | (−1, 1) | np.arctanh (−1,1) |
| np.arcsinh | inverse sinh | any real | (−∞, +∞) | — |
| np.arccosh | inverse cosh | [1, +∞) | [0, +∞) | — |
| np.arctanh | inverse tanh | (−1, 1) | (−∞, +∞) | — |
3. Basic behavior and important identities
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
x = np.linspace(-5, 5, 200) sinh_x = np.sinh(x) cosh_x = np.cosh(x) tanh_x = np.tanh(x) # Very important identity: cosh²(x) - sinh²(x) = 1 print("cosh² - sinh² should be ≈ 1 everywhere") print(np.allclose(cosh_x**2 - sinh_x**2, 1, atol=1e-10)) # True |
Quick intuition comparison table
| Function | Behavior as x → +∞ | Behavior as x → −∞ | At x = 0 | Odd / Even |
|---|---|---|---|---|
| sinh(x) | grows like e^x / 2 | grows negative like -e^ | x | / 2 |
| cosh(x) | grows like e^x / 2 | grows like e^ | x | / 2 |
| tanh(x) | approaches +1 | approaches −1 | 0 | odd |
4. Visual comparison – the best way to understand
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(14, 5.5)) # Left: sinh & cosh ax1.plot(x, sinh_x, label='sinh(x)', lw=2.5, color='teal') ax1.plot(x, cosh_x, label='cosh(x)', lw=2.5, color='coral') ax1.plot(x, np.abs(x), '--', lw=1.2, color='gray', label='|x| (for scale)') ax1.set_title("sinh(x) and cosh(x)", fontsize=13) ax1.set_xlabel("x") ax1.set_ylabel("Value") ax1.set_ylim(-10, 10) ax1.legend() ax1.grid(True, alpha=0.3) # Right: tanh ax2.plot(x, tanh_x, lw=2.5, color='purple', label='tanh(x)') ax2.plot(x, np.tanh(x*2), lw=1.8, alpha=0.7, label='tanh(2x)') ax2.plot(x, np.tanh(x*0.5), lw=1.8, alpha=0.7, label='tanh(0.5x)') ax2.set_title("tanh(x) – sigmoid-like", fontsize=13) ax2.set_xlabel("x") ax2.set_ylabel("Value") ax2.set_ylim(-1.1, 1.1) ax2.legend() ax2.grid(True, alpha=0.3) plt.tight_layout() plt.show() |
Key observations you should make:
- sinh(x) is odd, passes through origin, grows exponentially
- cosh(x) is even, minimum value = 1 at x=0, grows exponentially
- tanh(x) is odd, bounded between −1 and +1, looks like a stretched sigmoid
- Larger coefficients make tanh saturate faster
5. Realistic examples & code patterns you will actually use
Pattern 1 – Hyperbolic distance / rapidity in special relativity
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
v_over_c = np.linspace(0, 0.999, 200) # velocity / speed of light rapidity = np.arctanh(v_over_c) # this is hyperbolic angle lorentz_factor = np.cosh(rapidity) # γ = 1/√(1-v²/c²) plt.plot(v_over_c, lorentz_factor, lw=2.5, color='darkblue') plt.title("Lorentz factor γ from rapidity (arctanh)") plt.xlabel("v/c") plt.ylabel("γ") plt.grid(True, alpha=0.3) plt.show() |
Pattern 2 – Catenary curve (hanging chain / power cable)
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
x = np.linspace(-5, 5, 300) a = 2.0 # scale parameter y = a * np.cosh(x / a) plt.plot(x, y, lw=2.8, color='sienna') plt.title("Catenary curve: y = a × cosh(x/a)") plt.xlabel("x") plt.ylabel("y") plt.grid(True, alpha=0.3) plt.show() |
Pattern 3 – Hyperbolic tangent as activation function
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
x = np.linspace(-6, 6, 400) tanh_x = np.tanh(x) sigmoid = 1 / (1 + np.exp(-x)) plt.plot(x, tanh_x, lw=2.5, label='tanh(x)') plt.plot(x, sigmoid, lw=2.0, ls='--', label='sigmoid(x)') plt.title("tanh vs sigmoid activation") plt.xlabel("input") plt.ylabel("output") plt.legend() plt.axhline(0, color='gray', lw=0.8) plt.axvline(0, color='gray', lw=0.8) plt.show() |
Pattern 4 – Inverse hyperbolic functions (solving for parameters)
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
sinh_values = np.array([-3.62686, 0, 3.62686]) # sinh(±2) ≈ ±3.62686 print("arcsinh =", np.arcsinh(sinh_values).round(5)) # → [-2. 0. 2. ] cosh_values = np.array([1, 3.7622, 10.06766]) # cosh(0)=1, cosh(2)≈3.762 print("arccosh =", np.arccosh(cosh_values).round(5)) # → [0. 2. 3. ] |
Summary – Hyperbolic ufuncs Quick Reference
| Function | Input range | Output range | Odd/Even | Most common use case |
|---|---|---|---|---|
| np.sinh | any real | (−∞, +∞) | odd | hyperbolic sine, rapidity |
| np.cosh | any real | [1, +∞) | even | hyperbolic cosine, catenary |
| np.tanh | any real | (−1, 1) | odd | activation, bounded output |
| np.arcsinh | any real | (−∞, +∞) | odd | inverse sinh |
| np.arccosh | [1, +∞) | [0, +∞) | — | inverse cosh |
| np.arctanh | (−1, 1) | (−∞, +∞) | odd | inverse tanh |
Final teacher advice (very important)
Golden rule #1 Hyperbolic functions grow exponentially — they are not bounded (except tanh). Be careful when plotting or using them for activation (tanh saturates, sinh/cosh explode).
Golden rule #2 Use np.arctanh for bounded inputs — very useful when you need to invert tanh.
Golden rule #3 cosh(x) is always ≥ 1 — this is a very useful identity: cosh²(x) − sinh²(x) = 1 (hyperbolic analogue of cos² + sin² = 1)
Golden rule #4 When you see exponential growth combined with exponential decay, or S-shaped curves that are not sigmoid, think hyperbolic functions.
Would you like to continue with any of these next?
- Hyperbolic identities and numerical identities check
- How tanh became popular as activation function (and why it’s less used now)
- Realistic mini-project: catenary curve fitting or rapidity calculation
- Hyperbolic functions in special relativity (Lorentz transformation)
- Comparing hyperbolic vs trigonometric functions side-by-side
Just tell me what you want to focus on next! 😊
