Quelle Nonsingular.lean
Sprache: Lean
|
|
/-
Copyright (c) 2026 Junyan Xu. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Junyan Xu
-/
module
public import Mathlib.LinearAlgebra.InvariantBasisNumber
public import Mathlib.LinearAlgebra.Matrix.Determinant.Basic
import Mathlib.LinearAlgebra.Matrix.ToLin
/-!
# Linear independence and nonsingularity of matrices
In this file we formalize several theorems proved by Yi-Jia Tan in his paper [Tan2016]
*Free sets and free subsemimodules in a semimodule*. As consequences, we show that
commutative semirings satisfy the strong rank condition, and that the columns of a square matrix
are linearly independent if and only if the matrix is nonsingular (over a commutative ring,
a matrix is nonsingular if and only if its determinant is not a zero divisor).
## Main theorems
* `Matrix.Nonsingular.of_linearIndependent_col`: if the columns of a square matrix are linearly
independent, then the matrix is nonsingular. Corollary 3.2(1) of [Tan2016].
* `Matrix.Nonsingular.linearIndependent_col`: if a matrix over a commutative semiring with
cancellative addition is nonsingular, then its columns are linearly independent.
Corollary 3.2(2) of [Tan2016].
* `CommSemiring.strongRankCondition_of_nontrivial`: a commutative semiring satisfies the strong
rank condition.
-/
public section
variable {R m n : Type*} [CommSemiring R] [Fintype m] [Fintype n] [DecidableEq m] [DecidableEq n]
variable {A : Matrix n n R}
namespace Matrix
lemma isDetpBalanced_iff_sub_mul_det_eq_zero {R : Type*} [CommRing R] {A : Matrix n n R} {a b : R} :
A.IsDetpBalanced a b ↔ (a - b) * A.det = 0 := by
grind [IsDetpBalanced, det_eq_detp_sub_detp]
lemma nonsingular_iff_det_mem_nonZeroDivisors {R : Type*} [CommRing R]
{A : Matrix n n R} : A.Nonsingular ↔ A.det ∈ nonZeroDivisors R := by
simp_rw [Nonsingular, isDetpBalanced_iff_sub_mul_det_eq_zero, mem_nonZeroDivisors_iff_right]
exact ⟨fun h x eq ↦ h x 0 (by simpa), fun h a b eq ↦ sub_eq_zero.mp <| h _ (by simpa)⟩
lemma nonsingular_iff_det_ne_zero {R : Type*} [CommRing R] [IsDomain R]
{A : Matrix n n R} : A.Nonsingular ↔ A.det ≠ 0 := by
rw [nonsingular_iff_det_mem_nonZeroDivisors, mem_nonZeroDivisors_iff_ne_zero]
/-- If the columns of a square matrix are linearly independent, then the matrix is nonsingular. -/
theorem Nonsingular.of_linearIndependent_col (ind : LinearIndependent R A.col) : A.Nonsingular := by
intro a b bal
let P (r : ℕ) : Prop := ∀ f g : Fin r → n, (A.submatrix f g).IsDetpBalanced a b
suffices h : P 0 by simpa [IsDetpBalanced] using h Fin.elim0 Fin.elim0
refine Nat.decreasingInduction' (n := Fintype.card n) (fun r _ _ ih f g ↦ ?_) (Nat.zero_le _) <|
bal.submatrix_of_card_le (Fintype.card_fin _).ge
by_cases hg : g.Surjective
· exact bal.submatrix_of_card_le (Fintype.card_le_of_surjective g hg) f g
obtain ⟨j₀, h₀⟩ := by simpa [Function.Surjective] using hg
let D := A.submatrix f g
let Aj (j : Fin r) := A.submatrix f (Function.update g j j₀)
let v (a b : R) : n →₀ R := ∑ j, .single (g j) (a * (Aj j).detp (-1) + b * (Aj j).detp 1) +
.single j₀ (a * D.detp 1 + b * D.detp (-1))
suffices h : v a b = v b a by simpa [IsDetpBalanced, v, h₀] using congr($h j₀)
refine ind (funext fun i ↦ ?_)
let Ai := A.submatrix (Option.rec i f) (Option.rec j₀ g)
have (s : ℤˣ) : Ai.detp s = ∑ j, (Aj j).detp (-s) * A.col (g j) i + D.detp s * A.col j₀ i := by
simp_rw [mul_comm <| detp ..]; rw [detp_option_expand_row_none, add_comm]
congr!; aesop (add simp Function.update)
have (a b : R) : (v a b).linearCombination R A.col i = a * Ai.detp 1 + b * Ai.detp (-1) := by
simp [v, Finset.sum_add_distrib, mul_assoc, ← Finset.mul_sum, add_add_add_comm, mul_add, this]
simpa [this, IsDetpBalanced, ← submatrix_submatrix] using
ih (Option.rec i f ∘ finSuccEquiv r) (Option.rec j₀ g ∘ finSuccEquiv r)
theorem Nonsingular.of_linearIndependent_row (ind : LinearIndependent R A.row) : A.Nonsingular := by
simpa using Nonsingular.of_linearIndependent_col (A := Aᵀ) ind
theorem Nonsingular.of_leftRegular (h : IsLeftRegular A) : A.Nonsingular :=
.of_linearIndependent_col (by rwa [← mulVec_injective_iff, ← isLeftRegular_iff_mulVec_injective])
theorem Nonsingular.of_rightRegular (h : IsRightRegular A) : A.Nonsingular :=
.of_linearIndependent_row (by rwa [← vecMul_injective_iff, ← isRightRegular_iff_vecMul_injective])
variable [IsCancelAdd R]
/-- If a matrix over a commutative semiring with cancellative addition is nonsingular, then its
columns are linearly independent. Generalizes `Matrix.linearIndependent_cols_of_det_ne_zero`. -/
theorem Nonsingular.linearIndependent_col (hA : A.Nonsingular) : LinearIndependent R A.col :=
mulVec_injective_iff.mp fun x y eq ↦ funext fun k ↦ hA _ _ <| show _ = _ by
have h v : ((A.adjp 1 * A + A.detp (-1) • 1) *ᵥ v) k =
((A.adjp (-1) * A + A.detp 1 • 1) *ᵥ v) k := by
congr 1; ext k i
obtain (h | h) := eq_or_ne k i <;> simp [adjp_mul_apply_eq, add_comm, adjp_mul_apply_ne, h]
simp [add_mulVec, smul_mulVec, ← mulVec_mulVec] at h; grind
theorem Nonsingular.linearIndependent_row (hA : A.Nonsingular) : LinearIndependent R A.row :=
hA.transpose.linearIndependent_col
theorem linearIndependent_col_iff : LinearIndependent R A.col ↔ A.Nonsingular :=
⟨.of_linearIndependent_col, (·.linearIndependent_col)⟩
theorem linearIndependent_row_iff : LinearIndependent R A.row ↔ A.Nonsingular :=
⟨.of_linearIndependent_row, (·.linearIndependent_row)⟩
theorem isLeftRegular_iff_nonsingular : IsLeftRegular A ↔ A.Nonsingular := by
rw [isLeftRegular_iff_mulVec_injective, mulVec_injective_iff, linearIndependent_col_iff]
theorem isRightRegular_iff_nonsingular : IsRightRegular A ↔ A.Nonsingular := by
rw [isRightRegular_iff_vecMul_injective, vecMul_injective_iff, linearIndependent_row_iff]
lemma Nonsingular.mul {B : Matrix n n R} (hA : A.Nonsingular) (hB : B.Nonsingular) :
(A * B).Nonsingular := by
rw [← isLeftRegular_iff_nonsingular] at *
exact hA.mul hB
lemma nonsingular_mul_iff {A B : Matrix n n R} :
(A * B).Nonsingular ↔ A.Nonsingular ∧ B.Nonsingular where
mp h := ⟨isRightRegular_iff_nonsingular.mp <| .of_mul <| isRightRegular_iff_nonsingular.mpr h,
isLeftRegular_iff_nonsingular.mp <| .of_mul <| isLeftRegular_iff_nonsingular.mpr h⟩
mpr h := h.1.mul h.2
lemma Nonsingular.pow (hA : A.Nonsingular) : ∀ k, (A ^ k).Nonsingular
| 0 => by simp
| k + 1 => by simp [pow_succ, (hA.pow k).mul hA]
omit [DecidableEq n] in
theorem isLeftRegular_iff_isRightRegular : IsLeftRegular A ↔ IsRightRegular A := by
classical rw [isLeftRegular_iff_nonsingular, isRightRegular_iff_nonsingular]
omit [DecidableEq n] [Fintype n] in
/-- https://mathoverflow.net/questions/511862/transpose-symmetry-of-injectivity-of-linear-maps-over-semirings
asks whether this is still true without `IsCancelAdd R`. -/
theorem linearIndependent_col_iff_row [Finite n] :
LinearIndependent R A.col ↔ LinearIndependent R A.row := by
have := Fintype.ofFinite
classical rw [linearIndependent_col_iff, linearIndependent_row_iff]
end Matrix
open Matrix
/-- A nontrivial commutative semiring satisfies the strong rank condition. -/
instance (priority := 100) CommSemiring.strongRankCondition_of_nontrivial [Nontrivial R] :
StrongRankCondition R where
le_of_fin_injective {n m} f hf := by
let g : (Fin m → R) →ₗ[R] (Fin n → R) := .pi fun i ↦ if h : i < m then .proj ⟨i, h⟩ else 0
by_contra! hnm
have hg : Function.Injective g := fun x y eq ↦ funext fun i ↦ by
simpa [g] using congr($eq ⟨i, i.prop.trans hnm⟩)
let A := (g ∘ₗ f).toMatrix'
have hA : A.Nonsingular := .of_linearIndependent_col <| mulVec_injective_iff.mp <| by
convert hg.comp hf; ext; simp [A, g]
have : A.row ⟨m, hnm⟩ = 0 := by ext; simp [A, g]
exact not_subsingleton R
⟨by simpa [Nonsingular, IsDetpBalanced, detp_eq_of_row_eq_zero _ this] using hA⟩
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet am 2026-11-24)
¤
*© Formatika GbR, Deutschland
|
|
2026-11-24
|