Tensor Operations
Tensor Operations
Tensors are the natural language of modern physics — from the stress tensor in continuum mechanics to the Riemann curvature tensor in general relativity.
Transformation Law
A rank-2 contravariant tensor transforms as:
where is the transformation matrix (Jacobian). This is just a double matrix multiplication.
The Metric Tensor
The metric tensor encodes the geometry of space. It raises and lowers indices:
where is the inverse metric. In flat 3D Cartesian space (identity).
Polar Coordinates (2D)
In polar coordinates , the metric is:
The inverse is , .
Christoffel Symbols
The Christoffel symbols encode how basis vectors change across the manifold:
For 2D polar coordinates, the non-zero Christoffel symbols are:
All other components vanish. These give rise to the fictitious forces (centripetal, Coriolis) in rotating frames.
Index Raising
Given a covariant tensor and the inverse metric , we raise the first index:
Implementation
tensor_contract(A, B)— matrix multiply two 2D lists (works for any square size)metric_polar(r)— returns the 2x2 polar metric as a list of listschristoffel_polar_r_theta_theta(r)— returnschristoffel_polar_theta_r_theta(r)— returnsraise_index(T_lower, g_inv)— computes
def metric_polar(r):
return [[1.0, 0.0], [0.0, r**2]]
def christoffel_polar_r_theta_theta(r):
return -r