NLA-lib Explorer

Gram–Schmidt orthogonalization

Construct an orthonormal basis from input vectors.

Implementation guides

Implementations

Definition

Definition (Gram–Schmidt orthogonalization). Process the input columns in order. Remove from each column its components along the earlier nonzero orthonormal columns, then normalize a nonzero residual. A zero residual represents a dependent column and remains zero in the library's rank-revealing convention. Classical Gram–Schmidt forms projection coefficients from a common input residual; modified Gram–Schmidt updates that residual after each projection. Repeated passes are separate implementation choices.

Lean statement and details
NLAlib.gramSchmidtQ.{u_1, u_2, u_3} {𝕜 : Type u_1} [RCLike 𝕜] {m : Type u_2} {n : Type u_3}
  [Fintype m] [Fintype n] [LinearOrder n] [LocallyFiniteOrderBot n] (A : Matrix m n 𝕜) :
  Matrix m n 𝕜

Full source on GitHub

Copy link

Results

Theorem (Triangular coefficients of modified Gram–Schmidt).

The product of \mathbf{q}_i with the residual of column j after the first i projections gives r_{ij} of classical Gram–Schmidt. This holds at every step of \mathsf{mgsSweep}, also for dependent columns. [GolubVanLoan2013, §5.2.8].

Lean statement and details
NLAlib.dotProduct_mgsSweep_gramSchmidtQ_col.{u_1, u_4} {𝕜 : Type u_1} [RCLike 𝕜] {m : Type u_4}
  [Fintype m] {k : ℕ} (A : Matrix m (Fin k) 𝕜) (i j : Fin k) :
  star ((gramSchmidtQ A).col i) ⬝ᵥ
      mgsSweep (fun l a ↦ if h : l < k then gramSchmidtQ A a ⟨l, h⟩ else 0) (A.col j) ↑i =
    gramSchmidtR A i j

Full source on GitHub

Copy link

Theorem (Twice is enough).

two passes with coefficient, residual and projection-error bounds (the second on \mathbf{w}_1), and coefficients summed with relative error u, meet NLAlib.IsOrthErr with \varepsilon_1 = 2c_1, \varepsilon_2 = 3c_1, \varepsilon_3 = 2(\eta_0 + c_1)^2, for \eta_0 \le 1/100, c_1 \le 1/100, 4u \le c_1. [GiraudLangouRozloznikVandenEshof2005, Theorem 2]; [Parlett1998, §6.9].

Lean statement and details
NLAlib.isOrthErr_of_two_passes {n j : ℕ} {V : Matrix (Fin n) (Fin j) ℝ} {w w₁ w₂ : Fin n → ℝ}
  {h₁ h₂ h : Fin j → ℝ} {η₀ c₁ u : ℝ} (hη : η₀ ≤ 1 / 100) (hc₁ : c₁ ≤ 1 / 100) (hu : 0 ≤ u)
  (hu₁ : 4 * u ≤ c₁)
  (hp₁ :
    specNorm (Vᵀ * V - 1) ≤ η₀ →
      ‖WithLp.toLp 2 (h₁ - Vᵀ *ᵥ w)‖ ≤ c₁ * ‖WithLp.toLp 2 w‖ ∧
        ‖WithLp.toLp 2 (w - V *ᵥ h₁ - w₁)‖ ≤ c₁ * ‖WithLp.toLp 2 w‖ ∧
          ‖WithLp.toLp 2 (w₁ - (w - V *ᵥ Vᵀ *ᵥ w))‖ ≤ c₁ * ‖WithLp.toLp 2 w‖)
  (hp₂ :
    specNorm (Vᵀ * V - 1) ≤ η₀ →
      ‖WithLp.toLp 2 (h₂ - Vᵀ *ᵥ w₁)‖ ≤ c₁ * ‖WithLp.toLp 2 w₁‖ ∧
        ‖WithLp.toLp 2 (w₁ - V *ᵥ h₂ - w₂)‖ ≤ c₁ * ‖WithLp.toLp 2 w₁‖ ∧
          ‖WithLp.toLp 2 (w₂ - (w₁ - V *ᵥ Vᵀ *ᵥ w₁))‖ ≤ c₁ * ‖WithLp.toLp 2 w₁‖)
  (hsum : ∀ (i : Fin j), |h i - (h₁ i + h₂ i)| ≤ u * |h₁ i + h₂ i|) :
  IsOrthErr η₀ (2 * c₁) (3 * c₁) (2 * (η₀ + c₁) ^ 2) V w h w₂

Full source on GitHub

Copy link

Theorem (The QR construction of the Haar frame).

the Gram–Schmidt factor of a tall standard Gaussian matrix (\lvert k \rvert \le \lvert n \rvert) is a Haar frame. [Meckes2019, Ch. 1], there for square matrices; here any tall shape.

General form: sizes are index types

Lean statement and details
NLAlib.hasLaw_gramSchmidtQ_of_hasLaw_gaussianMatrix.{u_1, u_2, u_3} {Ω : Type u_1}
  {mΩ : MeasurableSpace Ω} {μ : Measure Ω} {n : Type u_2} {k : Type u_3} [Fintype n] [Fintype k]
  [LinearOrder k] [LocallyFiniteOrderBot k] {G : Ω → Matrix n k ℝ}
  (hG : HasLaw G (gaussianMatrix n k) μ) (hk : Fintype.card k ≤ Fintype.card n) :
  HasLaw (fun ω ↦ gramSchmidtQ (G ω)) (haarFrame n k) μ

Full source on GitHub

Copy link

Used by other algorithms

Mathematical background

Appears under these tasks