Skip to content

Commit 1296581

Browse files
committed
chore(LinearAlgebra): golfs around linearIndependent_single (#24209)
also generalize to semirings
1 parent 5c0b9cf commit 1296581

File tree

2 files changed

+55
-95
lines changed

2 files changed

+55
-95
lines changed

Mathlib/LinearAlgebra/Finsupp/VectorSpace.lean

Lines changed: 47 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -22,68 +22,70 @@ open Set LinearMap Submodule
2222

2323
universe u v w
2424

25+
namespace DFinsupp
26+
27+
variable {ι : Type*} {R : Type*} {M : ι → Type*}
28+
variable [Semiring R] [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)]
29+
30+
/-- The direct sum of free modules is free.
31+
32+
Note that while this is stated for `DFinsupp` not `DirectSum`, the types are defeq. -/
33+
noncomputable def basis {η : ι → Type*} (b : ∀ i, Basis (η i) R (M i)) :
34+
Basis (Σ i, η i) R (Π₀ i, M i) :=
35+
.ofRepr
36+
((mapRange.linearEquiv fun i => (b i).repr).trans (sigmaFinsuppLequivDFinsupp R).symm)
37+
38+
variable (R M) in
39+
instance _root_.Module.Free.dfinsupp [∀ i : ι, Module.Free R (M i)] : Module.Free R (Π₀ i, M i) :=
40+
.of_basis <| DFinsupp.basis fun i => Module.Free.chooseBasis R (M i)
41+
42+
variable [DecidableEq ι] {φ : ι → Type*} (f : ∀ i, φ i → M i)
43+
44+
open Finsupp (linearCombination)
45+
46+
theorem linearIndependent_single (hf : ∀ i, LinearIndependent R (f i)) :
47+
LinearIndependent R fun ix : Σ i, φ i ↦ single ix.1 (f ix.1 ix.2) := by
48+
classical
49+
have : linearCombination R (fun ix : Σ i, φ i ↦ single ix.1 (f ix.1 ix.2)) =
50+
DFinsupp.mapRange.linearMap (fun i ↦ linearCombination R (f i)) ∘ₗ
51+
(sigmaFinsuppLequivDFinsupp R).toLinearMap := by ext; simp
52+
rw [LinearIndependent, this]
53+
exact ((DFinsupp.mapRange_injective _ fun _ ↦ map_zero _).mpr hf).comp (Equiv.injective _)
54+
55+
lemma linearIndependent_single_iff :
56+
LinearIndependent R (fun ix : Σ i, φ i ↦ single ix.1 (f ix.1 ix.2)) ↔
57+
∀ i, LinearIndependent R (f i) :=
58+
fun h i ↦ (h.comp _ sigma_mk_injective).of_comp (lsingle i), linearIndependent_single _⟩
59+
60+
end DFinsupp
61+
2562
namespace Finsupp
2663

2764
section Semiring
2865

2966
variable {R : Type*} {M : Type*} {ι : Type*}
3067
variable [Semiring R] [AddCommMonoid M] [Module R M]
3168

32-
theorem linearIndependent_single {φ : ι → Type*} (f : ∀ ι, φ ι → M)
69+
theorem linearIndependent_single {φ : ι → Type*} (f : ∀ i, φ i → M)
3370
(hf : ∀ i, LinearIndependent R (f i)) :
3471
LinearIndependent R fun ix : Σ i, φ i ↦ single ix.1 (f ix.1 ix.2) := by
3572
classical
36-
have : linearCombination R (fun ix : Σ i, φ i ↦ single ix.1 (f ix.1 ix.2)) =
37-
(finsuppLequivDFinsupp R).symm.toLinearMap ∘ₗ
38-
DFinsupp.mapRange.linearMap (fun i ↦ linearCombination R (f i)) ∘ₗ
39-
(sigmaFinsuppLequivDFinsupp R).toLinearMap := by ext; simp
40-
rw [LinearIndependent, this]
41-
exact (finsuppLequivDFinsupp R).symm.injective.comp <|
42-
((DFinsupp.mapRange_injective _ fun _ ↦ map_zero _).mpr hf).comp (Equiv.injective _)
73+
convert (DFinsupp.linearIndependent_single _ hf).map_injOn
74+
_ (finsuppLequivDFinsupp R).symm.injective.injOn
75+
simp
4376

44-
lemma linearIndependent_single_iff {φ : ι → Type*} {f : ∀ ι, φ ι → M} :
77+
lemma linearIndependent_single_iff {φ : ι → Type*} {f : ∀ i, φ i → M} :
4578
LinearIndependent R (fun ix : Σ i, φ i ↦ single ix.1 (f ix.1 ix.2)) ↔
46-
∀ i, LinearIndependent R (f i) := by
47-
refine ⟨fun h i => ?_, linearIndependent_single _⟩
48-
replace h := h.comp _ (sigma_mk_injective (i := i))
49-
exact .of_comp (Finsupp.lsingle i) h
79+
∀ i, LinearIndependent R (f i) :=
80+
fun h i ↦ (h.comp _ sigma_mk_injective).of_comp (lsingle i), linearIndependent_single _⟩
5081

5182
open LinearMap Submodule
5283

5384
open scoped Classical in
5485
/-- The basis on `ι →₀ M` with basis vectors `fun ⟨i, x⟩ ↦ single i (b i x)`. -/
55-
protected def basis {φ : ι → Type*} (b : ∀ i, Basis (φ i) R M) : Basis (Σi, φ i) R (ι →₀ M) :=
56-
Basis.ofRepr
57-
{ toFun := fun g =>
58-
{ toFun := fun ix => (b ix.1).repr (g ix.1) ix.2
59-
support := g.support.sigma fun i => ((b i).repr (g i)).support
60-
mem_support_toFun := fun ix => by
61-
simp only [Finset.mem_sigma, mem_support_iff, and_iff_right_iff_imp, Ne]
62-
intro b hg
63-
simp [hg] at b }
64-
invFun := fun g =>
65-
{ toFun := fun i => (b i).repr.symm (g.comapDomain _ sigma_mk_injective.injOn)
66-
support := g.support.image Sigma.fst
67-
mem_support_toFun := fun i => by
68-
rw [Ne, ← (b i).repr.injective.eq_iff, (b i).repr.apply_symm_apply,
69-
DFunLike.ext_iff]
70-
simp only [exists_prop, LinearEquiv.map_zero, comapDomain_apply, zero_apply,
71-
exists_and_right, mem_support_iff, exists_eq_right, Sigma.exists, Finset.mem_image,
72-
not_forall] }
73-
left_inv := fun g => by
74-
ext i
75-
rw [← (b i).repr.injective.eq_iff]
76-
ext x
77-
simp only [coe_mk, LinearEquiv.apply_symm_apply, comapDomain_apply]
78-
right_inv := fun g => by
79-
ext ⟨i, x⟩
80-
simp only [coe_mk, LinearEquiv.apply_symm_apply, comapDomain_apply]
81-
map_add' := fun g h => by
82-
ext ⟨i, x⟩
83-
simp only [coe_mk, add_apply, LinearEquiv.map_add]
84-
map_smul' := fun c h => by
85-
ext ⟨i, x⟩
86-
simp only [coe_mk, smul_apply, LinearEquiv.map_smul, RingHom.id_apply] }
86+
protected def basis {φ : ι → Type*} (b : ∀ i, Basis (φ i) R M) : Basis (Σ i, φ i) R (ι →₀ M) :=
87+
.ofRepr <| (finsuppLequivDFinsupp R).trans <|
88+
(DFinsupp.mapRange.linearEquiv fun i ↦ (b i).repr).trans (sigmaFinsuppLequivDFinsupp R).symm
8789

8890
@[simp]
8991
theorem basis_repr {φ : ι → Type*} (b : ∀ i, Basis (φ i) R M) (g : ι →₀ M) (ix) :
@@ -95,7 +97,6 @@ theorem coe_basis {φ : ι → Type*} (b : ∀ i, Basis (φ i) R M) :
9597
⇑(Finsupp.basis b) = fun ix : Σi, φ i => single ix.1 (b ix.1 ix.2) :=
9698
funext fun ⟨i, x⟩ =>
9799
Basis.apply_eq_iff.mpr <| by
98-
classical
99100
ext ⟨j, y⟩
100101
by_cases h : i = j
101102
· cases h
@@ -136,24 +137,6 @@ end Ring
136137

137138
end Finsupp
138139

139-
namespace DFinsupp
140-
variable {ι : Type*} {R : Type*} {M : ι → Type*}
141-
variable [Semiring R] [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)]
142-
143-
/-- The direct sum of free modules is free.
144-
145-
Note that while this is stated for `DFinsupp` not `DirectSum`, the types are defeq. -/
146-
noncomputable def basis {η : ι → Type*} (b : ∀ i, Basis (η i) R (M i)) :
147-
Basis (Σi, η i) R (Π₀ i, M i) :=
148-
.ofRepr
149-
((mapRange.linearEquiv fun i => (b i).repr).trans (sigmaFinsuppLequivDFinsupp R).symm)
150-
151-
variable (R M) in
152-
instance _root_.Module.Free.dfinsupp [∀ i : ι, Module.Free R (M i)] : Module.Free R (Π₀ i, M i) :=
153-
.of_basis <| DFinsupp.basis fun i => Module.Free.chooseBasis R (M i)
154-
155-
end DFinsupp
156-
157140
lemma Module.Free.trans {R S M : Type*} [CommSemiring R] [Semiring S] [Algebra R S]
158141
[AddCommMonoid M] [Module R M] [Module S M] [IsScalarTower R S M] [Module.Free S M]
159142
[Module.Free R S] : Module.Free R M :=

Mathlib/LinearAlgebra/StdBasis.lean

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Johannes Hölzl
55
-/
66
import Mathlib.Algebra.Algebra.Pi
7-
import Mathlib.LinearAlgebra.Finsupp.SumProd
7+
import Mathlib.LinearAlgebra.Finsupp.VectorSpace
88
import Mathlib.LinearAlgebra.FreeModule.Basic
99
import Mathlib.LinearAlgebra.LinearIndependent.Lemmas
1010

@@ -31,7 +31,6 @@ this is a basis over `Fin 3 → R`.
3131
3232
-/
3333

34-
3534
open Function Set Submodule
3635

3736
namespace Pi
@@ -46,38 +45,16 @@ section Module
4645

4746
variable {η : Type*} {ιs : η → Type*} {Ms : η → Type*}
4847

49-
theorem linearIndependent_single [Ring R] [∀ i, AddCommGroup (Ms i)] [∀ i, Module R (Ms i)]
48+
theorem linearIndependent_single [Semiring R] [∀ i, AddCommMonoid (Ms i)] [∀ i, Module R (Ms i)]
5049
[DecidableEq η] (v : ∀ j, ιs j → Ms j) (hs : ∀ i, LinearIndependent R (v i)) :
51-
LinearIndependent R fun ji : Σj, ιs j ↦ Pi.single ji.1 (v ji.1 ji.2) := by
52-
have hs' : ∀ j : η, LinearIndependent R fun i : ιs j => LinearMap.single R Ms j (v j i) := by
53-
intro j
54-
exact (hs j).map' _ (LinearMap.ker_single _ _ _)
55-
apply linearIndependent_iUnion_finite hs'
56-
intro j J _ hiJ
57-
have h₀ :
58-
∀ j, span R (range fun i : ιs j => LinearMap.single R Ms j (v j i)) ≤
59-
LinearMap.range (LinearMap.single R Ms j) := by
60-
intro j
61-
rw [span_le, LinearMap.range_coe]
62-
apply range_comp_subset_range
63-
have h₁ :
64-
span R (range fun i : ιs j => LinearMap.single R Ms j (v j i)) ≤
65-
⨆ i ∈ ({j} : Set _), LinearMap.range (LinearMap.single R Ms i) := by
66-
rw [@iSup_singleton _ _ _ fun i => LinearMap.range (LinearMap.single R (Ms) i)]
67-
apply h₀
68-
have h₂ :
69-
⨆ j ∈ J, span R (range fun i : ιs j => LinearMap.single R Ms j (v j i)) ≤
70-
⨆ j ∈ J, LinearMap.range (LinearMap.single R (fun j : η => Ms j) j) :=
71-
iSup₂_mono fun i _ => h₀ i
72-
have h₃ : Disjoint (fun i : η => i ∈ ({j} : Set _)) J := by
73-
convert Set.disjoint_singleton_left.2 hiJ using 0
74-
exact (disjoint_single_single _ _ _ _ h₃).mono h₁ h₂
75-
76-
theorem linearIndependent_single_one (ι R : Type*) [Ring R] [DecidableEq ι] :
50+
LinearIndependent R fun ji : Σ j, ιs j ↦ Pi.single ji.1 (v ji.1 ji.2) := by
51+
convert (DFinsupp.linearIndependent_single _ hs).map_injOn _ DFinsupp.injective_pi_lapply.injOn
52+
53+
theorem linearIndependent_single_one (ι R : Type*) [Semiring R] [DecidableEq ι] :
7754
LinearIndependent R (fun i : ι ↦ Pi.single i (1 : R)) := by
7855
rw [← linearIndependent_equiv (Equiv.sigmaPUnit ι)]
7956
exact Pi.linearIndependent_single (fun (_ : ι) (_ : Unit) ↦ (1 : R))
80-
<| by simp +contextual [Fintype.linearIndependent_iff]
57+
<| by simp +contextual [Fintype.linearIndependent_iffₛ]
8158

8259
lemma linearIndependent_single_of_ne_zero {ι R M : Type*} [Ring R] [AddCommGroup M] [Module R M]
8360
[NoZeroSMulDivisors R M] [DecidableEq ι] {v : ι → M} (hv : ∀ i, v i ≠ 0) :
@@ -105,7 +82,7 @@ given by `s j` on each component.
10582
For the standard basis over `R` on the finite-dimensional space `η → R` see `Pi.basisFun`.
10683
-/
10784
protected noncomputable def basis (s : ∀ j, Basis (ιs j) R (Ms j)) :
108-
Basis (Σj, ιs j) R (∀ j, Ms j) :=
85+
Basis (Σ j, ιs j) R (∀ j, Ms j) :=
10986
Basis.ofRepr
11087
((LinearEquiv.piCongrRight fun j => (s j).repr) ≪≫ₗ
11188
(Finsupp.sigmaFinsuppLEquivPiFinsupp R).symm)

0 commit comments

Comments
 (0)