Rank.lean
Lean 4 source, lean/DataMiningAsObservation/Rank.lean at commit bccca4f. Appendix C, Machine-checked statements, says what each file proves. All Lean files.
/-
Rank.lean. Chapter 0 section 0.2 and chapter 2 section 2.2, the rank.
The rank of a matrix is the dimension of its column space. It is at most the number of
rows and at most the number of columns, an outer product has rank at most one, a product
has rank at most the rank of either factor, the zero matrix has rank zero, and transposing
does not change it. The chain rule of chapter 2, that a composed read operator's rank
cannot exceed either stage's, is the product bound.
-/
import Mathlib
namespace DMO.Rank
open Matrix
variable {m n k : ℕ}
/-- **The rank is at most the number of columns.** -/
theorem rank_le_width (A : Matrix (Fin m) (Fin n) ℝ) : A.rank ≤ n := by
simpa using Matrix.rank_le_card_width A
/-- **The rank is at most the number of rows.** -/
theorem rank_le_height (A : Matrix (Fin m) (Fin n) ℝ) : A.rank ≤ m := by
simpa using Matrix.rank_le_card_height A
/-- **An outer product has rank at most one.** -/
theorem rank_outer_le_one (u v : Fin n → ℝ) : (vecMulVec u v).rank ≤ 1 := by
rw [Matrix.vecMulVec_eq (Fin 1)]
calc (Matrix.replicateCol (Fin 1) u * Matrix.replicateRow (Fin 1) v).rank
≤ (Matrix.replicateCol (Fin 1) u).rank := Matrix.rank_mul_le_left _ _
_ ≤ Fintype.card (Fin 1) := Matrix.rank_le_card_width _
_ = 1 := Fintype.card_fin 1
/-- **A product has rank at most the rank of either factor.** -/
theorem rank_mul_le (A : Matrix (Fin m) (Fin n) ℝ) (B : Matrix (Fin n) (Fin k) ℝ) :
(A * B).rank ≤ min A.rank B.rank :=
le_min (Matrix.rank_mul_le_left A B) (Matrix.rank_mul_le_right A B)
/-- **The zero matrix has rank zero.** -/
theorem rank_zero' : (0 : Matrix (Fin m) (Fin n) ℝ).rank = 0 :=
Matrix.rank_zero
/-- **Transposing does not change the rank.** -/
theorem rank_transpose' (A : Matrix (Fin m) (Fin n) ℝ) : Aᵀ.rank = A.rank :=
Matrix.rank_transpose A
end DMO.Rank