Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Residual of a standard Gaussian vector against a fixed nnn-dimensional row space is χk−n2\chi^2_{k-n}χk−n2​

Proved
GaussianMatrix.residual_law

by tc · Oct 9, 2026 · Mathlib 0df444a (Lean v4.33.1)

chi-squaregaussianprobabilityrandom-matricesrotation-invariance

Let H∈Rn×kH \in \mathbb{R}^{n \times k}H∈Rn×k be a fixed real matrix of full row rank, rank⁡H=n\operatorname{rank} H = nrankH=n (so n≤kn \le kn≤k and HH⊤HH^\topHH⊤ is invertible), and let g∼N(0,Ik)g \sim \mathcal{N}(0, I_k)g∼N(0,Ik​) be a standard Gaussian vector in Rk\mathbb{R}^kRk (independent N(0,1)\mathcal{N}(0,1)N(0,1) coordinates). Define the squared residual

QH(g)  =  g⊤g−(Hg)⊤(HH⊤)−1(Hg)  =  ∥(I−PH) g∥22,PH=H⊤(HH⊤)−1H,Q_H(g) \;=\; g^\top g - (Hg)^\top (HH^\top)^{-1} (Hg) \;=\; \|(I - P_H)\,g\|_2^2, \qquad P_H = H^\top (HH^\top)^{-1} H,QH​(g)=g⊤g−(Hg)⊤(HH⊤)−1(Hg)=∥(I−PH​)g∥22​,PH​=H⊤(HH⊤)−1H,

the squared length of the component of ggg orthogonal to the row space of HHH. Then QH(g)Q_H(g)QH​(g) has the chi-square distribution with k−nk-nk−n degrees of freedom:

Law⁡(QH(g))  =  Law⁡(∑j=1k−nxj2),x∼N(0,Ik−n).\operatorname{Law}\big(Q_H(g)\big) \;=\; \operatorname{Law}\Big(\textstyle\sum_{j=1}^{k-n} x_j^2\Big), \qquad x \sim \mathcal{N}(0, I_{k-n}).Law(QH​(g))=Law(∑j=1k−n​xj2​),x∼N(0,Ik−n​).

This is the probabilistic step in the computation of E (GG⊤)−1\mathbb{E}\,(GG^\top)^{-1}E(GG⊤)−1: conditionally on the other rows of a Gaussian matrix, the residual of one row has a χ2\chi^2χ2 law whose degrees of freedom do not depend on those rows. It follows from rotation invariance of the standard Gaussian: if the columns of V∈Rk×(k−n)V \in \mathbb{R}^{k \times (k-n)}V∈Rk×(k−n) form an orthonormal basis of ker⁡H\ker HkerH, then QH(g)=∥V⊤g∥2Q_H(g) = \|V^\top g\|^2QH​(g)=∥V⊤g∥2 and V⊤g∼N(0,Ik−n)V^\top g \sim \mathcal{N}(0, I_{k-n})V⊤g∼N(0,Ik−n​).

Formalization Note. Both laws are expressed as push-forward measures on R\mathbb{R}R (Measure.map) of the product measures Measure.pi fun _ => gaussianReal 0 1; the subtraction k−nk - nk−n is natural-number subtraction, which is exact because rank⁡H=n\operatorname{rank} H = nrankH=n forces n≤kn \le kn≤k.

Preamble
import Definitions.Def_GaussianMatrix_basic

open MeasureTheory ProbabilityTheory
open scoped Matrix
Formal statement
namespace GaussianMatrix

theorem residual_law {n k : ℕ} (H : Matrix (Fin n) (Fin k) ℝ) (hH : H.rank = n) :
    Measure.map (fun g : Fin k → ℝ => g ⬝ᵥ g - (H *ᵥ g) ⬝ᵥ ((H * Hᵀ)⁻¹ *ᵥ (H *ᵥ g)))
        (Measure.pi fun _ : Fin k => gaussianReal 0 1)
      = Measure.map (fun x : Fin (k - n) → ℝ => ∑ j, x j ^ 2)
        (Measure.pi fun _ : Fin (k - n) => gaussianReal 0 1) := by sorry

end GaussianMatrix
Source
standard fact: if g∼N(0,Ik)g \sim N(0, I_k)g∼N(0,Ik​) and PPP is an orthogonal projector on Rk\mathbb{R}^kRk of rank k−nk-nk−n, then g⊤Pg∼χk−n2g^\top P g \sim \chi^2_{k-n}g⊤Pg∼χk−n2​ (rotation invariance of the standard Gaussian; cf. R. J. Muirhead, Aspects of Multivariate Statistical Theory, Wiley 1982, Ch. 1, and Halko–Martinsson–Tropp, SIAM Review 53(2) 2011, Appendix A).

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 paper
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me