Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

PhysLib coordinate Einstein and curvature operators

Definition
PhyslibCoordinateCurvatureExtensions

by scuba8684 · Nov 28, 2026 · Mathlib 0df444a (Lean v4.33.1)

general-relativityphyslib-exact-spacetimes

Additional curvature operations, tensor contractions, and regular-chart metric data used by the Schwarzschild and Reissner–Nordström statements.

Definition code
import Definitions.Def_PhyslibCoordinateGeometry
import Definitions.Def_PhyslibStaticSphericalCoordinates
import Mathlib.Algebra.BigOperators.Fin
import Mathlib.Algebra.BigOperators.Ring.Finset
import Mathlib.Algebra.Lie.Classical
import Mathlib.Analysis.Calculus.ContDiff.Deriv
import Mathlib.Analysis.Calculus.Deriv.Add
import Mathlib.Analysis.Calculus.Deriv.Basic
import Mathlib.Analysis.Calculus.Deriv.Inv
import Mathlib.Analysis.Calculus.Deriv.Mul
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.Deriv.Prod
import Mathlib.Analysis.Calculus.FDeriv.Symmetric
import Mathlib.Analysis.ODE.ExistUnique
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic
import Mathlib.Data.Matrix.Basic
import Mathlib.Data.Real.Basic
import Mathlib.Data.Set.Basic
import Mathlib.LinearAlgebra.Matrix.Notation
import Mathlib.LinearAlgebra.Matrix.Symmetric
import Mathlib.Logic.Equiv.Fin.Basic
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.FinCases
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.NoncommRing
import Mathlib.Tactic.NormNum
import Mathlib.Tactic.Ring

section

/-
Copyright (c) 2026 Alex Vergara Gil. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex Vergara Gil
-/


/-!

# Nondegenerate metric tensors with explicit inverses

Pseudo-Riemannian metric components paired with a certified two-sided inverse matrix.

## i. Overview

A nondegenerate metric (`MetricTensor n`) consists of covariant metric components `g : Tensor2 n`
together with an explicit two-sided inverse matrix `ginv : Tensor2 n` and component symmetry,
so contractions and trace operations use an inverse certified for that metric.

## ii. Key results

- `MetricTensor` : nondegenerate metric with its explicit two-sided inverse.
- `MetricTensor.ginv_symm` : the inverse of a symmetric metric is symmetric.
- `MetricTensor.sum_ginv_mul_g_left`, `MetricTensor.sum_ginv_mul_g_right`,
  `MetricTensor.sum_ginv_mul_g_apply`, `MetricTensor.sum_mul_ginv_g_apply` :
  componentwise inverse-metric contraction identities.

## iii. Table of contents

- A. Metric tensors with explicit inverses

## iv. References

* R. M. Wald, *General Relativity* (1984), Ch. 2 (Sec. 2.3). [ref: wald_1984_general_relativity]
* C. W. Misner, K. S. Thorne, and J. A. Wheeler, *Gravitation* (1973), Ch. 13.
  [ref: mtw_1973_gravitation]
* B. O'Neill, *Semi-Riemannian Geometry With Applications to Relativity* (1983), Ch. 2.
  [ref: oneill_1983_semi_riemannian]
* S. M. Carroll, *Lecture Notes on General Relativity* (1997), Ch. 2
  (https://arxiv.org/pdf/gr-qc/9712019#page=48). [ref: Carroll1997]
-/


namespace GeneralRelativity

/-!

## A. Metric tensors with explicit inverses

Packaging the covariant metric and its two-sided inverse in `MetricTensor` supplies symmetric
index-contraction lemmas used throughout curvature calculations.

-/

/-- A nondegenerate metric in components, carried together with an explicit two-sided
inverse. -/
structure MetricTensor (n : ℕ) where
  /-- The covariant metric components `g_{ij}`. -/
  g : Tensor2 n
  /-- The contravariant inverse metric components `g^{ij}`. -/
  ginv : Tensor2 n
  /-- Symmetry of the covariant metric components. -/
  symm : IsSymm g
  /-- Left-to-right inverse relation `g * ginv = 1`. -/
  inv_left : g * ginv = 1
  /-- Right-to-left inverse relation `ginv * g = 1`. -/
  inv_right : ginv * g = 1













end GeneralRelativity

end

section

/-
Copyright (c) 2026 Alex Vergara Gil. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex Vergara Gil
-/


/-!

# Coordinate Ricci curvature

Ricci tensor and scalar curvature obtained by contracting the coordinate Riemann tensor.

## i. Overview

The Ricci tensor `Ric_{σν} = ∑ ρ, R^ρ_{σρν}` contracts the coordinate Riemann tensor, and the
scalar curvature `R = ∑ σ ν, g^{σν} Ric_{σν}` contracts the Ricci tensor with the inverse metric.
The chart-level wrappers `CoordinateMetric.ricciTensor` and `CoordinateMetric.ricciScalar` live in
`Metrics/CoordinateMetric.lean`.

## ii. Key results

- `CoordinateCurvature.ricciTensor` : coordinate Ricci tensor.
- `CoordinateCurvature.ricciScalar` : coordinate scalar curvature.
- `CoordinateCurvature.ricciTensor_const`, `CoordinateCurvature.ricciScalar_const` : vanishing
  Ricci curvature for a constant metric.

## iii. Table of contents

- A. Ricci tensor and scalar curvature

## iv. References

* R. M. Wald, *General Relativity* (1984), Ch. 3 (Sec. 3.2). [ref: wald_1984_general_relativity]
* C. W. Misner, K. S. Thorne, and J. A. Wheeler, *Gravitation* (1973), Ch. 8 & Ch. 13.
  [ref: mtw_1973_gravitation]
* S. M. Carroll, *Lecture Notes on General Relativity* (1997), Ch. 3 (Sec. 3.7)
  (https://arxiv.org/pdf/gr-qc/9712019#page=80). [ref: Carroll1997]
-/


namespace GeneralRelativity

namespace CoordinateCurvature

/-!

## A. Ricci tensor and scalar curvature

Contracting the Riemann tensor in its first and third indices gives the Ricci tensor, and a
further contraction with the inverse metric gives the scalar curvature.

-/



/-- The coordinate scalar curvature `R = ∑ σ ν, g^{σν} Ric_{σν}`. -/
noncomputable def ricciScalar {n : ℕ} (g ginv : (Fin n → ℝ) → Tensor2 n)
    (x : Fin n → ℝ) : ℝ :=
  ∑ σ, ∑ ν, ginv x σ ν * ricciTensor g ginv x σ ν





end CoordinateCurvature


end GeneralRelativity

end

section

/-
Copyright (c) 2026 Alex Vergara Gil. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex Vergara Gil
-/


/-!

# Coordinate Einstein tensor

Einstein tensor of a coordinate metric and vanishing of connection and curvature for constant
metrics.

## i. Overview

The Einstein tensor `G_{ij} = Ric_{ij} - (1/2) R g_{ij}` combines the coordinate Ricci tensor and
scalar curvature. When every metric component is constant, all coordinate partial derivatives
vanish, so the Christoffel symbols, Riemann tensor, Ricci tensor, scalar curvature, and Einstein
tensor vanish identically. The chart-level wrapper `CoordinateMetric.einsteinTensor` lives in
`Metrics/CoordinateMetric.lean`.

## ii. Key results

- `CoordinateCurvature.einsteinTensor` : coordinate Einstein tensor.
- `CoordinateCurvature.christoffel_const`, `CoordinateCurvature.riemann_const`,
  `CoordinateCurvature.ricciTensor_const`, `CoordinateCurvature.ricciScalar_const`,
  `CoordinateCurvature.einsteinTensor_const` : vanishing connection and curvature for any constant
  metric.

## iii. Table of contents

- A. The Einstein tensor
- B. Flatness of constant metrics

## iv. References

* R. M. Wald, *General Relativity* (1984), Ch. 3 (Sec. 3.2). [ref: wald_1984_general_relativity]
* C. W. Misner, K. S. Thorne, and J. A. Wheeler, *Gravitation* (1973), Ch. 8 & Ch. 13.
  [ref: mtw_1973_gravitation]
* S. M. Carroll, *Lecture Notes on General Relativity* (1997), Ch. 3
  (https://arxiv.org/pdf/gr-qc/9712019#page=72). [ref: Carroll1997]
-/


namespace GeneralRelativity

namespace CoordinateCurvature

/-!

## A. The Einstein tensor

The trace-reversed Ricci tensor defines the Einstein tensor of the coordinate metric.

-/

/-- The coordinate Einstein tensor `G_{ij} = Ric_{ij} - (1/2) R g_{ij}`. -/
noncomputable def einsteinTensor {n : ℕ} (g ginv : (Fin n → ℝ) → Tensor2 n)
    (x : Fin n → ℝ) (i j : Fin n) : ℝ :=
  ricciTensor g ginv x i j - (1 / 2) * ricciScalar g ginv x * g x i j

/-!

## B. Flatness of constant metrics

When all metric components are constant across spacetime, every partial derivative vanishes, so the
connection, Riemann, Ricci, scalar, and Einstein curvature tensors all vanish identically. The
`christoffel_const`, `riemann_const`, `ricciTensor_const`, and `ricciScalar_const` cases sit next to
their definitions in the `Christoffel`, `Riemann`, and `Ricci` modules; `einsteinTensor_const` is
proved here.

-/



end CoordinateCurvature


end GeneralRelativity

end

section

/-
Copyright (c) 2026 Alex Vergara Gil. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex Vergara Gil
-/


/-!

# Algebraic Riemann curvature tensor

Covariant Riemann curvature tensor with its algebraic symmetries and flat-space specialization.

## i. Overview

The Riemann tensor (`RiemannTensor n`) carries its covariant components together with three
structural laws: antisymmetry in the last pair, pair symmetry `R_{ijkl} = R_{klij}`, and the
first (algebraic) Bianchi identity. Antisymmetry in the *first* pair (`RiemannTensor.skew_first`)
is derived from the other two rather than assumed.

## ii. Key results

- `RiemannTensor` : covariant Riemann tensor carrying antisymmetry in the last pair, pair
  symmetry, and the first Bianchi identity.
- `RiemannTensor.skew_first` : antisymmetry in the first pair, proved from pair symmetry and
  antisymmetry in the last pair.
- `RiemannTensor.zero_of_repeated_first`, `RiemannTensor.zero_of_repeated_last`,
  `RiemannTensor.swap_mixed` : vanishing and mixed-swap identities.
- `RiemannTensor.flat`, `RiemannTensor.flat_comp` : flat curvature tensor.

## iii. Table of contents

- A. The Riemann curvature tensor
  - A.1. Algebraic symmetries and vanishing components
  - A.2. The flat curvature tensor

## iv. References

* R. M. Wald, *General Relativity* (1984), Ch. 3 (Sec. 3.2). [ref: wald_1984_general_relativity]
* C. W. Misner, K. S. Thorne, and J. A. Wheeler, *Gravitation* (1973), Ch. 11 & Ch. 13.
  [ref: mtw_1973_gravitation]
* B. O'Neill, *Semi-Riemannian Geometry With Applications to Relativity* (1983), Ch. 3.
  [ref: oneill_1983_semi_riemannian]
* S. M. Carroll, *Lecture Notes on General Relativity* (1997), Ch. 3
  (https://arxiv.org/pdf/gr-qc/9712019#page=72). [ref: Carroll1997]
-/


namespace GeneralRelativity

/-!

## A. The Riemann curvature tensor

An algebraic `RiemannTensor n` carries last-pair antisymmetry, pair-exchange symmetry, and the
first Bianchi identity, inducing the full component symmetry relations.

-/

/-- Covariant components of the Riemann tensor with its algebraic symmetries. `bianchi` is the
first (algebraic) Bianchi identity `R_{ijkl} + R_{iklj} + R_{iljk} = 0`. -/
structure RiemannTensor (n : ℕ) where
  /-- Component function `R_{ijkl}` on `Fin n`. -/
  comp : Fin n → Fin n → Fin n → Fin n → ℝ
  /-- Antisymmetry in the last pair of indices: `R_{ijkl} = -R_{ijlk}`. -/
  skew_last : ∀ i j k l, comp i j k l = -comp i j l k
  /-- Symmetry under exchange of the first and second index pairs: `R_{ijkl} = R_{klij}`. -/
  pair_symm : ∀ i j k l, comp i j k l = comp k l i j
  /-- First (algebraic) Bianchi identity: `R_{ijkl} + R_{iklj} + R_{iljk} = 0`. -/
  bianchi : ∀ i j k l, comp i j k l + comp i k l j + comp i l j k = 0

namespace RiemannTensor

/-!

### A.1. Algebraic symmetries and vanishing components

-/

variable {n : ℕ} (R : RiemannTensor n)











/-!

### A.2. The flat curvature tensor

-/





end RiemannTensor

end GeneralRelativity

end

section

/-
Copyright (c) 2026 Alex Vergara Gil. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex Vergara Gil
-/


/-!

# Coordinate metrics

Coordinate-chart metric fields, their pointwise `MetricTensor` restrictions, and the chart-level
connection and curvature operators.

## i. Overview

A `CoordinateMetric n` collects a coordinate-dependent symmetric metric field `g_{ij}(x)`, its
inverse `g^{ij}(x)`, and the regular chart domain on which the two are two-sided inverses. At a
point of that domain `CoordinateMetric.metricTensor` restricts the field to a pointwise
`MetricTensor n`. On the chart, `CoordinateMetric.christoffel` assembles the Levi-Civita symbols
from the field and its inverse, `CoordinateMetric.geodesicAccel` gives the geodesic acceleration,
and `CoordinateMetric.riemann`, `CoordinateMetric.ricciTensor`, `CoordinateMetric.ricciScalar`,
and `CoordinateMetric.einsteinTensor` evaluate the curvature componentwise.

## ii. Key results

- `CoordinateMetric`, `CoordinateMetric.metricTensor` : coordinate metric field with its regular
  domain and pointwise `MetricTensor` restriction.
- `CoordinateMetric.christoffel`, `CoordinateMetric.geodesicAccel`, `CoordinateMetric.IsGeodesic`,
  `CoordinateMetric.isGeodesic_iff` : chart connection and geodesic motion.
- `CoordinateMetric.riemann`, `CoordinateMetric.ricciTensor`, `CoordinateMetric.ricciScalar`,
  `CoordinateMetric.einsteinTensor` : Levi-Civita curvature of a coordinate metric.

## iii. Table of contents

- A. Coordinate metrics and pointwise restrictions
- B. Connection, geodesics, and curvature

## iv. References

* R. M. Wald, *General Relativity* (1984), Ch. 3 (Sec. 3.1). [ref: wald_1984_general_relativity]
* C. W. Misner, K. S. Thorne, and J. A. Wheeler, *Gravitation* (1973), Ch. 8 & Ch. 13.
  [ref: mtw_1973_gravitation]
* B. O'Neill, *Semi-Riemannian Geometry With Applications to Relativity* (1983), Ch. 3.
  [ref: oneill_1983_semi_riemannian]
* S. M. Carroll, *Lecture Notes on General Relativity* (1997), Ch. 3 (Sec. 3.1)
  (https://arxiv.org/pdf/gr-qc/9712019#page=58). [ref: Carroll1997]
-/


namespace GeneralRelativity

/-!

## A. Coordinate metrics and pointwise restrictions

A coordinate metric field carries its own regularity domain, so pointwise `MetricTensor`s — and
with them the inverse-metric contractions — exist exactly at the chart points where `g` and
`ginv` are two-sided inverses.

-/









/-!

## B. Connection, geodesics, and curvature

The Levi-Civita connection is assembled from the metric field and its explicit inverse;
contracting the derivatives of the symbols gives the Riemann, Ricci, scalar, and Einstein tensors
componentwise, and the same symbols give the affine geodesic equation of the chart.

-/























/-- Einstein tensor of a `CoordinateMetric`. -/
noncomputable def CoordinateMetric.einsteinTensor {n : ℕ} (C : CoordinateMetric n)
    (x : Fin n → ℝ) (i j : Fin n) : ℝ :=
  CoordinateCurvature.einsteinTensor C.g C.ginv x i j



end GeneralRelativity

end

section

/-
Copyright (c) 2026 Alex Vergara Gil. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex Vergara Gil
-/


/-!

# Static spherically symmetric metrics

Static spherically symmetric metric `StaticSphericalMetric`, its diagonal coordinate metric and
inverse in `(t, r, θ, φ)` coordinates, symmetry, two-sided invertibility, and `CoordinateMetric 4`
instance.

## i. Overview

A general static spherically symmetric four-dimensional metric in coordinates `(t, r, θ, φ)` is
parameterized by a single radial metric function `f(r) = S.metricFn r`:

`ds² = -f(r) dt² + f(r)⁻¹ dr² + r² dθ² + r² sin²θ dφ²`.

This module defines `StaticSphericalMetric` in terms of `f` and establishes the nondegeneracy of the
metric on the regular chart `{x | x 1 ≠ 0 ∧ S.metricFn (x 1) ≠ 0 ∧ Real.sin (x 2) ≠ 0}`,
yielding both pointwise `MetricTensor 4` instances and a `CoordinateMetric 4`.

## ii. Key results

- `StaticSphericalMetric` : a static spherically symmetric metric parameterized by its radial metric
  function `metricFn`.
- `StaticSphericalMetric.metric`, `StaticSphericalMetric.metricInv`,
  `StaticSphericalMetric.metric_symm`, `StaticSphericalMetric.metric_mul_inv`,
  `StaticSphericalMetric.metricInv_mul` : coordinate metric, inverse, symmetry, and invertibility.
- `StaticSphericalMetric.metricTensor`, `StaticSphericalMetric.toCoordinateMetric` : certified
  `MetricTensor 4` and `CoordinateMetric 4` instances.

## iii. Table of contents

- A. Metric, inverse, and MetricTensor

## iv. References

* R. M. Wald, *General Relativity* (1984), Ch. 6 (Sec. 6.1). [ref: wald_1984_general_relativity]
* C. W. Misner, K. S. Thorne, and J. A. Wheeler, *Gravitation* (1973), Ch. 23 (Sec. 23.2).
  [ref: mtw_1973_gravitation]
* B. O'Neill, *Semi-Riemannian Geometry With Applications to Relativity* (1983), Ch. 13.
  [ref: oneill_1983_semi_riemannian]
* S. M. Carroll, *Lecture Notes on General Relativity* (1997), Ch. 7
  (https://arxiv.org/pdf/gr-qc/9712019#page=168). [ref: Carroll1997]
-/


namespace GeneralRelativity

namespace StaticSpherical

/-!

## A. Metric, inverse, and MetricTensor

On a static spherically symmetric spacetime parameterized by a single radial metric function
`f(r)`, the diagonal metric `diag(-f, f⁻¹, r², r² sin²θ)` is nondegenerate everywhere away from the
origin (`r = 0`), Killing horizons (`f = 0`), and polar coordinate axis (`sin θ = 0`).

-/



namespace StaticSphericalMetric















/-- The metric as a `MetricTensor 4` at a point away from coordinate and horizon
singularities. -/
noncomputable def metricTensor (S : StaticSphericalMetric) (x : Fin 4 → ℝ) (hr : x 1 ≠ 0)
    (hf : S.metricFn (x 1) ≠ 0) (hsin : Real.sin (x 2) ≠ 0) : MetricTensor 4 where
  g := S.metric x
  ginv := S.metricInv x
  symm := S.metric_symm x
  inv_left := S.metric_mul_inv x hr hf hsin
  inv_right := S.metricInv_mul x hr hf hsin













end StaticSphericalMetric

end StaticSpherical

end GeneralRelativity

end
Source
https://github.com/BishopWolf/physlib/blob/8046e2b0cb30f5fa25306a69ff29e91ab5711f6b/PhyslibAlpha/Relativity/Metrics/Basic.lean https://github.com/BishopWolf/physlib/blob/8046e2b0cb30f5fa25306a69ff29e91ab5711f6b/PhyslibAlpha/Relativity/Metrics/CoordinateMetric.lean https://github.com/BishopWolf/physlib/blob/8046e2b0cb30f5fa25306a69ff29e91ab5711f6b/PhyslibAlpha/Relativity/Metrics/Einstein.lean https://github.com/BishopWolf/physlib/blob/8046e2b0cb30f5fa25306a69ff29e91ab5711f6b/PhyslibAlpha/Relativity/Metrics/Ricci.lean https://github.com/BishopWolf/physlib/blob/8046e2b0cb30f5fa25306a69ff29e91ab5711f6b/PhyslibAlpha/Relativity/Metrics/StaticSphericalMetric/Basic.lean https://github.com/BishopWolf/physlib/blob/8046e2b0cb30f5fa25306a69ff29e91ab5711f6b/PhyslibAlpha/Relativity/Tensors/RiemannTensor.lean

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me