Carroll's GR in coordinates: metric, Christoffel symbols, covariant derivatives, curvature, Schwarzschild and Kruskal
DefinitionCarrollGR_DefsThis definition file fixes the coordinate language used by the whole No-Nonsense Introduction to General Relativity series. Everything is written in one coordinate chart of a four-dimensional spacetime, following S. M. Carroll's notes equation by equation.
- Points and fields. A point of the chart is (
Coord). A two-index tensor field (TensorField2), such as the metric , assigns a real matrix to each point; a four-index field (TensorField4) assigns an array . The partial derivative (partialD) is the derivative of at in the -th coordinate direction. - Minkowski metric (eq. (3)): (
minkowskiEta). A matrix is Lorentzian (IsLorentzian) if for some invertible , i.e. it is a symmetric nondegenerate form of signature . A field is a spacetime metric on an open set (IsSpacetimeMetricOn) if its components are smooth on and is Lorentzian for every . - Inverse metric (eq. (23)): is the matrix inverse of (
invMetric). - Christoffel symbols (eq. (36)):
- Covariant derivatives (eq. (35)) of two-index tensors with lower or upper indices and of four-index tensors with lower indices (
covDerivLower2,covDerivUpper2,covDerivLower4): one term per upper index and one term per lower index. - Curvature: the Riemann tensor (eq. (44))
its all-lower form , the Ricci tensor (eq. (45)), the Ricci scalar (eq. (46)), the Einstein tensor (eq. (50)) and its raised form .
7. Einstein's equation (eq. (57)) at a point: for all (EinsteinEq), with the trace (metricTrace).
8. Changes of coordinates: the Jacobian matrix (jacobian); spherical coordinates (eq. (18)) (sphericalToCartesian).
9. Spherically symmetric metrics (eq. (71)): in coordinates ,
(sphericalMetric A B), and the Schwarzschild metric (eq. (72)), the case , (schwarzschild G m).
10. Kruskal coordinates (eqs. (73)–(74)): , , the map , and the Kruskal-form components with , written as a function of the values of and .
These definitions are the shared vocabulary of every statement in the mission; the curvature formulas are transcribed with Carroll's index placement exactly.
Formalization Note All objects are total functions: a derivative at a point where the function is not differentiable is , the inverse of a singular matrix is the zero matrix, and . Theorems that use these definitions therefore state explicitly the open region (smoothness, nondegeneracy, , , ) on which they are claimed. Coordinates are and, in the spherical charts, , , .
import Mathlib
/-!
# Coordinate general relativity after Carroll, "A No-Nonsense Introduction to General Relativity"
All objects are written in a single coordinate chart of a 4-dimensional spacetime.
A point of the chart is `x : Fin 4 → ℝ`, with `x 0 = t`, `x 1`, `x 2`, `x 3` the remaining
coordinates (for the spherical charts of §3 and §6: `x 1 = r`, `x 2 = θ`, `x 3 = φ`).
A (0,2)-tensor field (such as the metric `g_{μν}`) is a function giving at each point the
`4 × 4` matrix of its components. Partial derivatives are Fréchet derivatives in the
coordinate directions. Formulas follow Carroll's equation numbers.
-/
open scoped ContDiff
namespace CarrollGR
open Finset
/-- A point `(x⁰, x¹, x², x³)` of a coordinate chart of four-dimensional spacetime. -/
abbrev Coord : Type := Fin 4 → ℝ
/-- The components `T_{μν}(x)` of a two-index tensor field in a chart (e.g. the metric `g_{μν}`). -/
abbrev TensorField2 : Type := Coord → Matrix (Fin 4) (Fin 4) ℝ
/-- The components `T_{μνρσ}(x)` of a four-index tensor field in a chart. -/
abbrev TensorField4 : Type := Coord → Fin 4 → Fin 4 → Fin 4 → Fin 4 → ℝ
/-- The coordinate partial derivative `∂_μ f(x) = ∂f/∂x^μ (x)`. -/
noncomputable def partialD (μ : Fin 4) (f : Coord → ℝ) (x : Coord) : ℝ :=
fderiv ℝ f x (Pi.single μ 1)
/-- The Minkowski metric `η_{μν} = diag(-1, 1, 1, 1)` (Carroll eq. (3)). -/
def minkowskiEta : Matrix (Fin 4) (Fin 4) ℝ := Matrix.diagonal ![-1, 1, 1, 1]
/-- A symmetric matrix `M` has Lorentzian signature `(− + + +)`: it is congruent to the
Minkowski metric, i.e. `Pᵀ M P = η` for some invertible matrix `P`. -/
def IsLorentzian (M : Matrix (Fin 4) (Fin 4) ℝ) : Prop :=
∃ P : Matrix (Fin 4) (Fin 4) ℝ, IsUnit P.det ∧ P.transpose * M * P = minkowskiEta
/-- `g` is a spacetime metric on the open set `U` of the chart: its components are smooth on `U`
and at every point of `U` it is a (symmetric) metric of signature `(− + + +)`. -/
def IsSpacetimeMetricOn (g : TensorField2) (U : Set Coord) : Prop :=
IsOpen U ∧ (∀ μ ν : Fin 4, ContDiffOn ℝ ∞ (fun y => g y μ ν) U) ∧ ∀ y ∈ U, IsLorentzian (g y)
/-- The inverse metric `g^{μν}(x)`, the matrix inverse of `g_{μν}(x)` (Carroll eq. (23)). -/
noncomputable def invMetric (g : TensorField2) : TensorField2 := fun x => (g x)⁻¹
/-- The Christoffel symbols (Carroll eq. (36)):
`Γ^σ_{μν} = ½ g^{σρ} (∂_μ g_{νρ} + ∂_ν g_{ρμ} − ∂_ρ g_{μν})`. -/
noncomputable def christoffel (g : TensorField2) (σ μ ν : Fin 4) (x : Coord) : ℝ :=
(1 / 2 : ℝ) * ∑ ρ : Fin 4, invMetric g x σ ρ *
(partialD μ (fun y => g y ν ρ) x + partialD ν (fun y => g y ρ μ) x
- partialD ρ (fun y => g y μ ν) x)
/-- The covariant derivative of a two-index tensor with lower indices (Carroll eq. (35)):
`∇_σ T_{μν} = ∂_σ T_{μν} − Γ^λ_{σμ} T_{λν} − Γ^λ_{σν} T_{μλ}`. -/
noncomputable def covDerivLower2 (g T : TensorField2) (σ μ ν : Fin 4) (x : Coord) : ℝ :=
partialD σ (fun y => T y μ ν) x
- ∑ l : Fin 4, christoffel g l σ μ x * T x l ν
- ∑ l : Fin 4, christoffel g l σ ν x * T x μ l
/-- The covariant derivative of a two-index tensor with upper indices (Carroll eq. (35)):
`∇_σ T^{μν} = ∂_σ T^{μν} + Γ^μ_{σλ} T^{λν} + Γ^ν_{σλ} T^{μλ}`. -/
noncomputable def covDerivUpper2 (g T : TensorField2) (σ μ ν : Fin 4) (x : Coord) : ℝ :=
partialD σ (fun y => T y μ ν) x
+ ∑ l : Fin 4, christoffel g μ σ l x * T x l ν
+ ∑ l : Fin 4, christoffel g ν σ l x * T x μ l
/-- The covariant derivative of a four-index tensor with lower indices (Carroll eq. (35)):
`∇_λ T_{μνρσ} = ∂_λ T_{μνρσ} − Γ^κ_{λμ} T_{κνρσ} − Γ^κ_{λν} T_{μκρσ} − Γ^κ_{λρ} T_{μνκσ}
− Γ^κ_{λσ} T_{μνρκ}`. -/
noncomputable def covDerivLower4 (g : TensorField2) (T : TensorField4) (l μ ν ρ σ : Fin 4)
(x : Coord) : ℝ :=
partialD l (fun y => T y μ ν ρ σ) x
- ∑ k : Fin 4, christoffel g k l μ x * T x k ν ρ σ
- ∑ k : Fin 4, christoffel g k l ν x * T x μ k ρ σ
- ∑ k : Fin 4, christoffel g k l ρ x * T x μ ν k σ
- ∑ k : Fin 4, christoffel g k l σ x * T x μ ν ρ k
/-- The Riemann curvature tensor (Carroll eq. (44)):
`R^σ_{μαβ} = ∂_α Γ^σ_{μβ} − ∂_β Γ^σ_{μα} + Γ^σ_{αλ} Γ^λ_{μβ} − Γ^σ_{βλ} Γ^λ_{μα}`. -/
noncomputable def riemann (g : TensorField2) (σ μ α β : Fin 4) (x : Coord) : ℝ :=
partialD α (christoffel g σ μ β) x - partialD β (christoffel g σ μ α) x
+ ∑ l : Fin 4, (christoffel g σ α l x * christoffel g l μ β x
- christoffel g σ β l x * christoffel g l μ α x)
/-- The Riemann tensor with all indices lowered, `R_{μνρσ} = g_{μλ} R^λ_{νρσ}` (Carroll, before
eq. (47)). -/
noncomputable def riemannLower (g : TensorField2) : TensorField4 :=
fun x μ ν ρ σ => ∑ l : Fin 4, g x μ l * riemann g l ν ρ σ x
/-- The Ricci tensor `R_{αβ} = R^λ_{αλβ}` (Carroll eq. (45)). -/
noncomputable def ricci (g : TensorField2) (α β : Fin 4) (x : Coord) : ℝ :=
∑ l : Fin 4, riemann g l α l β x
/-- The Ricci scalar `R = g^{μν} R_{μν}` (Carroll eq. (46)). -/
noncomputable def ricciScalar (g : TensorField2) (x : Coord) : ℝ :=
∑ μ : Fin 4, ∑ ν : Fin 4, invMetric g x μ ν * ricci g μ ν x
/-- The Einstein tensor `G_{μν} = R_{μν} − ½ R g_{μν}` (Carroll eq. (50)). -/
noncomputable def einstein (g : TensorField2) (μ ν : Fin 4) (x : Coord) : ℝ :=
ricci g μ ν x - (1 / 2 : ℝ) * ricciScalar g x * g x μ ν
/-- The Einstein tensor with both indices raised, `G^{μν} = g^{μα} g^{νβ} G_{αβ}`. -/
noncomputable def einsteinUpper (g : TensorField2) : TensorField2 :=
fun x => Matrix.of fun μ ν =>
∑ α : Fin 4, ∑ β : Fin 4, invMetric g x μ α * invMetric g x ν β * einstein g α β x
/-- The trace `T = g^{μν} T_{μν}` of a two-index tensor with respect to the metric `g`. -/
noncomputable def metricTrace (g T : TensorField2) (x : Coord) : ℝ :=
∑ μ : Fin 4, ∑ ν : Fin 4, invMetric g x μ ν * T x μ ν
/-- Einstein's equation `R_{μν} − ½ R g_{μν} = 8πG T_{μν}` at the point `x` (Carroll eq. (57)),
for the metric `g`, Newton's constant `GN` and energy-momentum tensor `T`. -/
def EinsteinEq (g : TensorField2) (GN : ℝ) (T : TensorField2) (x : Coord) : Prop :=
∀ μ ν : Fin 4, einstein g μ ν x = 8 * Real.pi * GN * T x μ ν
/-- The Jacobian matrix `∂F^a/∂x^μ (x)` of a change of coordinates `F` (row `a`, column `μ`). -/
noncomputable def jacobian (F : Coord → Coord) (x : Coord) : Matrix (Fin 4) (Fin 4) ℝ :=
Matrix.of fun a μ => partialD μ (fun y => F y a) x
/-- Spherical coordinates on space (Carroll eq. (18)):
`(t, r, θ, φ) ↦ (t, r sin θ cos φ, r sin θ sin φ, r cos θ)`. -/
noncomputable def sphericalToCartesian (x : Coord) : Coord :=
![x 0, x 1 * Real.sin (x 2) * Real.cos (x 3), x 1 * Real.sin (x 2) * Real.sin (x 3),
x 1 * Real.cos (x 2)]
/-- The general spherically symmetric metric in spherical coordinates `(t, r, θ, φ)`
(Carroll eq. (71)): `ds² = −A(r,t) dt² + B(r,t) dr² + r² (dθ² + sin²θ dφ²)`. -/
noncomputable def sphericalMetric (A B : ℝ → ℝ → ℝ) : TensorField2 := fun x =>
Matrix.diagonal ![-A (x 1) (x 0), B (x 1) (x 0), (x 1) ^ 2, (x 1) ^ 2 * Real.sin (x 2) ^ 2]
/-- The Schwarzschild metric (Carroll eq. (72)) with Newton's constant `GN` and mass `m`:
`ds² = −(1 − 2Gm/r) dt² + (1 − 2Gm/r)⁻¹ dr² + r² (dθ² + sin²θ dφ²)`. -/
noncomputable def schwarzschild (GN m : ℝ) : TensorField2 :=
sphericalMetric (fun r _ => 1 - 2 * GN * m / r) (fun r _ => (1 - 2 * GN * m / r)⁻¹)
/-- The Kruskal coordinate `u` (Carroll eq. (73)):
`u = (r/2Gm − 1)^{1/2} e^{r/4Gm} cosh(t/4Gm)`. -/
noncomputable def kruskalU (GN m t r : ℝ) : ℝ :=
Real.sqrt (r / (2 * GN * m) - 1) * Real.exp (r / (4 * GN * m)) * Real.cosh (t / (4 * GN * m))
/-- The Kruskal coordinate `v` (Carroll eq. (73)):
`v = (r/2Gm − 1)^{1/2} e^{r/4Gm} sinh(t/4Gm)`. -/
noncomputable def kruskalV (GN m t r : ℝ) : ℝ :=
Real.sqrt (r / (2 * GN * m) - 1) * Real.exp (r / (4 * GN * m)) * Real.sinh (t / (4 * GN * m))
/-- The change of coordinates `(t, r, θ, φ) ↦ (v, u, θ, φ)` from Schwarzschild to Kruskal
coordinates (Carroll eq. (73)); in Kruskal coordinates `v` is listed first. -/
noncomputable def schwarzschildToKruskal (GN m : ℝ) (x : Coord) : Coord :=
![kruskalV GN m (x 0) (x 1), kruskalU GN m (x 0) (x 1), x 2, x 3]
/-- The components of the Schwarzschild metric in Kruskal coordinates `(v, u, θ, φ)`
(Carroll eq. (74)), written as a function of the values of `r` and `θ` at the point:
`diag(−F, F, r², r² sin²θ)` with `F = 32 (Gm)³ / r · e^{−r/2Gm}`. -/
noncomputable def kruskalMetricAt (GN m r θ : ℝ) : Matrix (Fin 4) (Fin 4) ℝ :=
Matrix.diagonal
![-(32 * (GN * m) ^ 3 / r * Real.exp (-r / (2 * GN * m))),
32 * (GN * m) ^ 3 / r * Real.exp (-r / (2 * GN * m)), r ^ 2, r ^ 2 * Real.sin θ ^ 2]
end CarrollGR
Read-back
What the Lean code literally says, in plain math · Aristotle (Harmonic) - same agent as the drafter; non-blind
Non-blind read-back — not independent testimony. This read-back was written by the same agent that drafted the Lean statement, with full knowledge of the source text and of the intended meaning. It is not a blind audit by an independent reader and must not be treated as one; reviewers should compare the Lean code against the source themselves.
The file declares, inside the namespace CarrollGR, the following objects (no theorems).
- Coord is written as functions ; TensorField2 is the type of maps ; TensorField4 is the type of maps assigning to a point and four indices a real number.
- partialD is , the Fréchet derivative of at applied to the -th standard basis vector ; it equals if is not differentiable at .
- minkowskiEta is the diagonal matrix .
- IsLorentzian holds iff there is a real matrix with and .
- IsSpacetimeMetricOn holds iff is open, each component is on , and is Lorentzian for every .
- invMetric is the field (Mathlib's matrix inverse, which is the zero matrix when ).
- christoffel .
- covDerivLower2 .
- covDerivUpper2 (the matrix entries of play the role of upper-index components).
- covDerivLower4 , all at .
- riemann , where the derivatives are of the functions .
- riemannLower is .
- ricci ; ricciScalar ; einstein ; einsteinUpper is the field whose entry is .
- metricTrace .
- EinsteinEq is the proposition: for all , .
- jacobian is the matrix with entry equal to .
- sphericalToCartesian .
- sphericalMetric is the field for arbitrary functions (first argument , second ).
- schwarzschild is sphericalMetric with and (with Lean's conventions and , so at both equal and at ).
- kruskalU and kruskalV the same with ; here is the real square root, equal to on negative arguments.
- schwarzschildToKruskal .
- kruskalMetricAt with .