The math.atanh(x) function computes the inverse hyperbolic tangent (also known as arc hyperbolic tangent) of a numeric value x. Unlike circular trigonometry which computes angles, hyperbolic functions compute areas under hyperbolas: given a ratio strictly inside the open interval (-1.0, 1.0), math.atanh(x) returns a real number in the range (-∞, +∞).
Exact Inverse: math.atanh() reverses the forward hyperbolic tangent math.tanh() (math.tanh(math.atanh(x)) == x for any -1.0 < x < 1.0).
The math.atanh() function is part of the standard math module:
import math
result = math.atanh(x)
| Parameter | Type | Required? | Description |
|---|---|---|---|
x |
float or int |
Yes | A numeric ratio strictly bounded inside the open interval -1.0 < x < 1.0. |
Return Value: Returns a floating-point number (float) spanning (-∞, +∞).
Evaluating math.atanh() for positive, zero, and negative values:
import math
print("atanh(0): ", math.atanh(0)) # 0.0
print("atanh(0.5): ", math.atanh(0.5)) # 0.5493061443340548
print("atanh(-0.5):", math.atanh(-0.5)) # -0.5493061443340548 (odd symmetry)
print("atanh(0.95):", math.atanh(0.95)) # 1.8317808204646738
atanh(0): 0.0
atanh(0.5): 0.5493061443340548
atanh(-0.5): -0.5493061443340548
atanh(0.95): 1.8317808204646738
The inverse hyperbolic tangent is mathematically defined through the natural logarithm:
atanh(x) = 0.5 · ln((1 + x) / (1 - x))
You can verify this identity directly in Python:
import math
x = 0.6
val_builtin = math.atanh(x)
val_formula = 0.5 * math.log((1 + x) / (1 - x))
print("math.atanh(0.6):", val_builtin)
print("Log formula: ", val_formula)
print("Is close? ", math.isclose(val_builtin, val_formula)) # True
Unlike circular inverse trigonometry where endpoints are valid (e.g. arcsin(1.0) = π/2), the domain of math.atanh() is strictly an open interval:
ValueError: math domain error.import math
invalid_inputs = [-1.5, -1.0, 1.0, 2.0]
for val in invalid_inputs:
try:
math.atanh(val)
except ValueError as err:
print(f"atanh({val}) raises: {err}")
atanh(-1.5) raises: math domain error
atanh(-1.0) raises: math domain error
atanh(1.0) raises: math domain error
atanh(2.0) raises: math domain error
Learners often confuse circular arc tangent (math.atan) with hyperbolic arc tangent (math.atanh). Here is how their domains, outputs, and geometric meanings differ:
| Feature | math.atan(x) (Circular) |
math.atanh(x) (Hyperbolic) |
|---|---|---|
| Geometric Base | Unit Circle: x2 + y2 = 1 | Unit Hyperbola: x2 - y2 = 1 |
| Input Domain | Unrestricted: (-∞, +∞) | Strictly bounded open interval: (-1.0, 1.0) |
| Output Range | Angle in radians: (-π/2, π/2) | Real numbers: (-∞, +∞) |
| Involves Degrees? | Yes (angles can be converted with math.degrees) |
No (pure dimensionless hyperbolic parameter) |
Visualizing the asymptotic rise toward vertical asymptotes at x = ±1 using Matplotlib:
import math
import matplotlib.pyplot as plt
x_vals = [i * 0.02 - 0.98 for i in range(0, 99)] # -0.98 to +0.98
y_vals = [math.atanh(x) for x in x_vals]
plt.plot(x_vals, y_vals, label="atanh(x)", color="#1a73e8")
plt.axvline(1.0, color="red", linestyle="--", label="x = 1 asymptote")
plt.axvline(-1.0, color="red", linestyle="--", label="x = -1 asymptote")
plt.title("Inverse Hyperbolic Tangent Curve")
plt.xlabel("Input x in (-1, 1)")
plt.ylabel("atanh(x)")
plt.grid(True)
plt.legend()
plt.show()
In statistics, Pearson correlation coefficients r are bounded between -1.0 and +1.0, which causes sample correlations near ±1 to follow a skewed distribution. Fisher's z-transformation transforms r into an approximately normal distribution using atanh():
z = atanh(r) = 0.5 · ln((1 + r) / (1 - r))
import math
def fisher_z_transform(correlation_r):
if abs(correlation_r) >= 1.0:
raise ValueError("Pearson r must be strictly between -1.0 and 1.0.")
z_score = math.atanh(correlation_r)
return round(z_score, 4)
# Unit Assertions
assert fisher_z_transform(0.0) == 0.0 # Zero correlation maps to z=0
assert fisher_z_transform(0.5) == 0.5493 # Moderate positive correlation
assert fisher_z_transform(-0.5) == -0.5493 # Moderate negative correlation
assert fisher_z_transform(0.75) == 0.9730 # Strong correlation
assert fisher_z_transform(0.90) == 1.4722 # Very strong correlation
print("Fisher z for r=0.75:", fisher_z_transform(0.75))
print("Fisher z for r=0.90:", fisher_z_transform(0.90))
print("All Fisher z-transformation assertions passed successfully!")
Open in Google Colab View on GitHub
Run all math.atanh() examples interactively, test domain bounds, verify logarithmic formula equivalence, and calculate Fisher z-transformations directly in Google Colab.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.