Connection
A connection (or covariant derivative) tells you how to differentiate vector fields on a manifold; the fundamental structure needed to define curvature and the Riemannian Hessian.
Definition
The Levi-Civita connection $\nabla$ is the unique affine connection on a Riemannian manifold $(M, g)$ that is:
- Torsion-free: $\nabla_X Y - \nabla_Y X = [X, Y]$
- Metric-compatible: $X\langle Y, Z\rangle = \langle \nabla_X Y, Z\rangle + \langle Y, \nabla_X Z\rangle$
In local coordinates it is encoded by the Christoffel symbols .
The Connection Trait
pub trait Connection: Manifold {
/// Covariant derivative of V along the curve with velocity X at p.
fn covariant_derivative(
&self,
p: &Self::Point,
x: &Self::Tangent, // velocity direction
v: &Self::Tangent, // vector field to differentiate
) -> Self::Tangent;
/// Christoffel symbols Γ^k_ij at p (optional override for efficiency).
fn christoffel(
&self,
p: &Self::Point,
) -> [[[f64; Self::AMBIENT_DIM]; Self::AMBIENT_DIM]; Self::AMBIENT_DIM] {
// default: computed from covariant_derivative via finite differences
todo!()
}
}Sphere<N>, Euclidean<N>, SO<N>, SE<N>Euclidean Connection (Trivial Case)
On , the Levi-Civita connection is just the ordinary directional derivative; all Christoffel symbols vanish:
For a vector field $V(p) = Ap$ (linear), $\nabla_X V = AX$, just matrix-vector multiplication.
use cartan::prelude::*;
use cartan::manifolds::Euclidean;
let r3 = Euclidean::<3>;
let p = [1.0_f64, 0.0, 0.0];
let x = [0.0_f64, 1.0, 0.0]; // differentiate in y-direction
let v = [0.0_f64, 0.0, 1.0]; // constant vector field
// Covariant derivative of a constant field = 0.
let dv = r3.covariant_derivative(&p, &x, &v);
assert!(dv.iter().all(|&c| c.abs() < 1e-12));Sphere Connection (Weingarten Map)
On , the Levi-Civita connection is the tangential projection of the ambient derivative:
The term $\langle DV \cdot X, p \rangle p$ is the Weingarten correction - it removes the normal (radial) component.
Riemannian Hessian
The connection enables second-order optimization via the Riemannian Hessian:
For , the Riemannian Hessian at $p$ is the symmetric operator defined by:
The Hessian-vector product (HVP) can be computed efficiently via a single Pearlmutter forward-over-reverse pass without materialising the full Hessian.
// HVP callback pattern used by cartan-optim.
let hvp = |u: &Tangent| manifold.covariant_derivative(&p, u, &grad_f);Geodesics via Connection
The geodesic equation is precisely the condition that the velocity field is parallel along itself:
In coordinates this becomes
- a second-order ODE whose solutions are the geodesics.
cartansolves this analytically for each manifold rather than numerically integrating.