The Wishart distribution , Lebesgue measure on symmetric matrices, latent roots and
DefinitionMuirheadMST_WishartDefinitions for the Wishart chapter of Muirhead's Aspects of Multivariate Statistical Theory. Real matrices are represented as arrays with the product σ-algebra.
- Normal data matrix. For an matrix , the law of an matrix whose rows are independent vectors (Mathlib's
multivariateGaussian 0 Σ). - Wishart distribution. is the law of , (Muirhead, Definition 3.1.3).
- Multivariate gamma function, in product form,
Muirhead defines as the integral (§2.1.2, p. 61) and evaluates it as this product in Theorem 2.1.12; that theorem is a milestone of this mission. 4. Lebesgue measure on symmetric matrices, : the image of Lebesgue measure on the upper-triangular entries under symmetric completion. 5. Latent roots of a symmetric matrix: its eigenvalues in decreasing order. 6. The diagonal matrix and the Vandermonde product . 7. Bartlett's construction. Independent standard Gaussian vectors () and independent entries, assembled into the upper-triangular matrix with (so ) and the entries for .
Formalization Note Indices start at in Lean, so row there is row here, and . multivariateGaussian 0 Σ is the Gaussian with covariance only for positive semidefinite ; every theorem using these definitions assumes positive definite or . latentRoots returns on non-symmetric arrays, a null set for every law in this mission. Degrees of freedom are natural numbers because the Wishart law is defined through the data matrix.
import Mathlib
/-!
R. J. Muirhead, *Aspects of Multivariate Statistical Theory* (Wiley, 1982), Chapter 3: the Wishart
distribution and the latent roots of a Wishart matrix. Real `m × m` matrices are represented as arrays
`Fin m → Fin m → ℝ` (with the product σ-algebra and Lebesgue measure); matrix algebra goes through
`Matrix.of`.
-/
open MeasureTheory ProbabilityTheory
noncomputable section
namespace MuirheadMST
/-- The `n × m` normal data matrix `Z` with independent rows, each `N_m(0, Σ)` (the law `N(0, I_n ⊗ Σ)`
of Muirhead §3.1). Row `i` is `Z i`. -/
def normalDataMatrix (n m : ℕ) (S : Matrix (Fin m) (Fin m) ℝ) :
Measure (Fin n → EuclideanSpace ℝ (Fin m)) :=
Measure.pi fun _ => multivariateGaussian 0 S
/-- `Z'Z` for a data matrix `Z` with rows `Z i`: the entry `(j, k)` is `∑_i Z_{ij} Z_{ik}`. -/
def gram {n m : ℕ} (Z : Fin n → EuclideanSpace ℝ (Fin m)) : Fin m → Fin m → ℝ :=
fun j k => ∑ i, (Z i).ofLp j * (Z i).ofLp k
/-- The Wishart distribution `W_m(n, Σ)`: the law of `A = Z'Z` when `Z` is `n × m` with independent
`N_m(0, Σ)` rows (Muirhead, Definition 3.1.3). Meaningful for positive semidefinite `S`; for other `S`,
Mathlib's `multivariateGaussian` is a point mass, so this is the point mass at the zero array. -/
def wishart (m n : ℕ) (S : Matrix (Fin m) (Fin m) ℝ) : Measure (Fin m → Fin m → ℝ) :=
(normalDataMatrix n m S).map gram
/-- The multivariate gamma function in product form, `Γ_m(a) = π^{m(m-1)/4} ∏_{i=1}^m Γ(a - (i-1)/2)`.
Muirhead (§2.1.2, p. 61) defines `Γ_m(a)` as `∫_{A>0} etr(-A) (det A)^{a-(m+1)/2} (dA)`; Theorem 2.1.12
(pp. 62-63) evaluates that integral as this product for `a > (m - 1)/2`. Below that the integral diverges; the product
is then the meromorphic continuation, and at its poles `Real.Gamma` (hence this definition) returns `0`. -/
def multivariateGamma (m : ℕ) (a : ℝ) : ℝ :=
Real.pi ^ ((m : ℝ) * ((m : ℝ) - 1) / 4) * ∏ i : Fin m, Real.Gamma (a - (i : ℝ) / 2)
/-- Lebesgue measure on real symmetric `m × m` matrices, `(dA) = ∏_{i ≤ j} da_{ij}`: the image of
Lebesgue measure on the upper-triangular entries under symmetric completion. -/
def symVolume (m : ℕ) : Measure (Fin m → Fin m → ℝ) :=
(volume : Measure ({p : Fin m × Fin m // p.1 ≤ p.2} → ℝ)).map
fun a i j => if h : i ≤ j then a ⟨(i, j), h⟩ else a ⟨(j, i), le_of_not_ge h⟩
/-- The latent roots (eigenvalues) of a symmetric matrix, in decreasing order `l₁ ≥ ⋯ ≥ l_m`;
`0` for a non-symmetric array. -/
def latentRoots {m : ℕ} (A : Fin m → Fin m → ℝ) : Fin m → ℝ :=
if h : (Matrix.of A).IsHermitian then
fun i => h.eigenvalues₀ (Fin.cast (Fintype.card_fin m).symm i)
else 0
/-- The diagonal matrix `diag(l₁, …, l_m)` as an array. -/
def diagArray {m : ℕ} (l : Fin m → ℝ) : Fin m → Fin m → ℝ :=
fun i j => if i = j then l i else 0
/-- The sample space of Bartlett's construction: for each row index `i`, a vector in `ℝ^{n-i}` (whose norm
gives the diagonal entry `t_ii`), and an array of reals (whose entries above the diagonal give `t_ij`, `i < j`).
Indices start at `0`, so row `i` here is row `i + 1` in Muirhead's numbering. -/
abbrev BartlettSample (m n : ℕ) : Type :=
(∀ i : Fin m, EuclideanSpace ℝ (Fin (n - i))) × (Fin m → Fin m → ℝ)
/-- The law of Bartlett's sample: independent standard Gaussian vectors `g_i ∈ ℝ^{n-i}`, independent of an
array of independent `N(0, 1)` entries. -/
def bartlettLaw (m n : ℕ) : Measure (BartlettSample m n) :=
(Measure.pi fun i : Fin m => stdGaussian (EuclideanSpace ℝ (Fin (n - i)))).prod
(Measure.pi fun _ : Fin m => Measure.pi fun _ : Fin m => gaussianReal 0 1)
/-- The upper-triangular matrix `T` of Bartlett's decomposition: `t_ii = ‖g_i‖` (so `t_ii² ~ χ²_{n-i}`,
i.e. `χ²_{n-i+1}` in 1-based numbering), `t_ij` the given `N(0, 1)` entry for `i < j`, and `0` below the
diagonal. The entries of the array on and below the diagonal are sampled but never used. -/
def bartlettFactor {m n : ℕ} (ω : BartlettSample m n) : Fin m → Fin m → ℝ :=
fun i j => if i = j then ‖ω.1 i‖ else if i < j then ω.2 i j else 0
/-- The Vandermonde factor `∏_{i<j} (l_i - l_j)`. -/
def vandermondeProd {m : ℕ} (l : Fin m → ℝ) : ℝ :=
∏ i : Fin m, ∏ j : Fin m, if i < j then l i - l j else 1
end MuirheadMST
Read-back
What the Lean code literally says, in plain math · claude-opus-5-5
The file only makes definitions; it asserts no theorem. All declarations are in the namespace MuirheadMST. An " array" is a function with the product σ-algebra, not required to be symmetric; indices start at . Every pushforward uses Mathlib's convention that a map which is not almost-everywhere measurable gives the zero measure.
normalDataMatrix n m S. For naturals and an arbitrary real matrix (no symmetry or positivity assumed), the product measure on -tuples of vectors : the rows are independent with common law , Mathlib's pushforward of the standard Gaussian under . If is not positive semidefinite (Mathlib's notion includes symmetry), and is the point mass at . For it is the point mass on the empty tuple.
gram Z. The array ; the zero array for .
wishart m n S. Argument order: dimension , sample size , then . The law of when has independent rows. No condition on or : for non-positive-semidefinite , or , it is the point mass at the zero array; is allowed.
multivariateGamma m a. For and any real , , with Mathlib's real Gamma function (analytic continuation at negative non-integers, junk value at ). For the value is .
symVolume m. Lebesgue measure on , ( pairs including the diagonal), pushed forward by symmetric completion ( for , for ). It is , carried by symmetric arrays; for the point mass on the empty array.
latentRoots A. For symmetric , the eigenvalues with multiplicity in non-increasing order (ties allowed, no sign restriction); for non-symmetric , the zero vector.
diagArray l. The array .
BartlettSample m n. A type abbreviation: pairs with for (truncated natural subtraction, so dimension ; for , lies in the zero space), and an arbitrary real array , all entries free. Product measurable structure.
bartlettLaw m n. The product measure , where is the standard Gaussian on ( the point mass at ). So the are independent with , the entries of are i.i.d. , and is independent of .
bartlettFactor ω. The upper-triangular array with (Euclidean norm), for , and for ; diagonal and below-diagonal entries of are ignored. For , . The definition only builds from and says nothing about its law.
vandermondeProd l. The signed product (earlier index minus later), for .
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.