forked from leanprover-community/mathlib4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasic.lean
More file actions
334 lines (258 loc) · 12 KB
/
Basic.lean
File metadata and controls
334 lines (258 loc) · 12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Alexander Bentkamp
-/
module
public import Mathlib.LinearAlgebra.Basis.Defs
public import Mathlib.LinearAlgebra.LinearIndependent.Basic
public import Mathlib.LinearAlgebra.Span.Basic
/-!
# Basic results on bases
The main goal of this file is to show the equivalence between bases and families of vectors that are
linearly independent and whose span is the whole space.
There are also various lemmas on bases on specific spaces (such as empty or singletons).
## Main results
* `Basis.linearIndependent`: the basis vectors are linear independent.
* `Basis.span_eq`: the basis vectors span the whole space.
* `Basis.mk`: construct a basis out of `v : ι → M` such that `LinearIndependent v` and
`span (range v) = ⊤`.
-/
@[expose] public section
assert_not_exists Ordinal
noncomputable section
universe u
open Function Set Submodule Finsupp
variable {ι : Type*} {ι' : Type*} {R : Type*} {R₂ : Type*} {M : Type*} {M' : Type*}
namespace Module.Basis
variable [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid M'] [Module R M']
(b : Basis ι R M)
section Properties
theorem repr_range : LinearMap.range (b.repr : M →ₗ[R] ι →₀ R) = Finsupp.supported R R univ := by
rw [LinearEquiv.range, Finsupp.supported_univ]
theorem mem_span_repr_support (m : M) : m ∈ span R (b '' (b.repr m).support) :=
(Finsupp.mem_span_image_iff_linearCombination _).2
⟨b.repr m, by simp [Finsupp.mem_supported_support]⟩
theorem repr_support_subset_of_mem_span (s : Set ι) {m : M}
(hm : m ∈ span R (b '' s)) : ↑(b.repr m).support ⊆ s := by
rcases (Finsupp.mem_span_image_iff_linearCombination _).1 hm with ⟨l, hl, rfl⟩
rwa [repr_linearCombination, ← Finsupp.mem_supported R l]
theorem mem_span_image {m : M} {s : Set ι} : m ∈ span R (b '' s) ↔ ↑(b.repr m).support ⊆ s :=
⟨repr_support_subset_of_mem_span _ _, fun h ↦
span_mono (Set.image_mono h) (mem_span_repr_support b _)⟩
@[simp]
theorem self_mem_span_image [Nontrivial R] {i : ι} {s : Set ι} :
b i ∈ span R (b '' s) ↔ i ∈ s := by
simp [mem_span_image, Finsupp.support_single_ne_zero]
protected theorem mem_span (x : M) : x ∈ span R (range b) :=
span_mono (image_subset_range _ _) (mem_span_repr_support b x)
@[simp]
protected theorem span_eq : span R (range b) = ⊤ :=
eq_top_iff.mpr fun x _ => b.mem_span x
theorem _root_.Submodule.eq_top_iff_forall_basis_mem {p : Submodule R M} :
p = ⊤ ↔ ∀ i, b i ∈ p := by
refine ⟨fun h ↦ by simp [h], fun h ↦ ?_⟩
replace h : range b ⊆ p := by rintro - ⟨i, rfl⟩; exact h i
simpa using span_mono (R := R) h
theorem index_nonempty (b : Basis ι R M) [Nontrivial M] : Nonempty ι := by
obtain ⟨x, y, ne⟩ : ∃ x y : M, x ≠ y := Nontrivial.exists_pair_ne
obtain ⟨i, _⟩ := not_forall.mp (mt b.ext_elem_iff.2 ne)
exact ⟨i⟩
protected theorem linearIndependent : LinearIndependent R b :=
fun x y hxy => by
rw [← b.repr_linearCombination x, hxy, b.repr_linearCombination y]
protected lemma linearIndepOn (s : Set ι) : LinearIndepOn R b s :=
b.linearIndependent.linearIndepOn s
protected theorem ne_zero [Nontrivial R] (i) : b i ≠ 0 :=
b.linearIndependent.ne_zero i
theorem injective_constr_of_linearIndependent
[Semiring R₂] [Module R₂ M'] [SMulCommClass R R₂ M'] {v : ι → M'}
(hv : LinearIndependent R v) : Injective (b.constr R₂ v) :=
fun _ _ hab ↦ b.repr.injective <| hv.finsuppLinearCombination_injective <| by
simpa [constr_def] using hab
end Properties
variable {v : ι → M} {x y : M}
section Mk
variable (hli : LinearIndependent R v) (hsp : ⊤ ≤ span R (range v))
/-- A linear independent family of vectors spanning the whole module is a basis. -/
protected noncomputable def mk : Basis ι R M :=
.ofRepr
{ hli.repr.comp (LinearMap.id.codRestrict _ fun _ => hsp Submodule.mem_top) with
invFun := Finsupp.linearCombination _ v
left_inv := fun x => hli.linearCombination_repr ⟨x, _⟩
right_inv := fun _ => hli.repr_eq rfl }
@[simp]
theorem mk_repr : (Basis.mk hli hsp).repr x = hli.repr ⟨x, hsp Submodule.mem_top⟩ :=
rfl
theorem mk_apply (i : ι) : Basis.mk hli hsp i = v i :=
show Finsupp.linearCombination _ v _ = v i by simp
@[simp]
theorem coe_mk : ⇑(Basis.mk hli hsp) = v :=
funext (mk_apply _ _)
end Mk
section Coord
@[simp]
theorem linearIndependent_coord {R : Type*} [CommSemiring R] [Module R M] (b : Basis ι R M) :
LinearIndependent R b.coord := by
classical
refine linearIndependent_iff'ₛ.mpr fun s l₁ l₂ h j hj ↦ ?_
simpa [hj, Finsupp.single_apply] using congr($h (b j))
variable (hli : LinearIndependent R v) (hsp : ⊤ ≤ span R (range v))
variable {hli hsp}
/-- Given a basis, the `i`th element of the dual basis evaluates to 1 on the `i`th element of the
basis. -/
theorem mk_coord_apply_eq (i : ι) : (Basis.mk hli hsp).coord i (v i) = 1 :=
show hli.repr ⟨v i, Submodule.subset_span (mem_range_self i)⟩ i = 1 by simp [hli.repr_eq_single i]
/-- Given a basis, the `i`th element of the dual basis evaluates to 0 on the `j`th element of the
basis if `j ≠ i`. -/
theorem mk_coord_apply_ne {i j : ι} (h : j ≠ i) : (Basis.mk hli hsp).coord i (v j) = 0 :=
show hli.repr ⟨v j, Submodule.subset_span (mem_range_self j)⟩ i = 0 by
simp [hli.repr_eq_single j, h]
/-- Given a basis, the `i`th element of the dual basis evaluates to the Kronecker delta on the
`j`th element of the basis. -/
theorem mk_coord_apply [DecidableEq ι] {i j : ι} :
(Basis.mk hli hsp).coord i (v j) = if j = i then 1 else 0 := by
rcases eq_or_ne j i with h | h
· simp only [h, if_true, mk_coord_apply_eq i]
· simp only [h, if_false, mk_coord_apply_ne h]
end Coord
section Span
variable (hli : LinearIndependent R v)
/-- A linear independent family of vectors is a basis for their span. -/
protected noncomputable def span : Basis ι R (span R (range v)) :=
Basis.mk (linearIndependent_span hli) <| by
intro x _
have : ∀ i, v i ∈ span R (range v) := fun i ↦ subset_span (Set.mem_range_self _)
have h₁ : (((↑) : span R (range v) → M) '' range fun i => ⟨v i, this i⟩) = range v := by
simp only [← Set.range_comp]
rfl
have h₂ : map (Submodule.subtype (span R (range v))) (span R (range fun i => ⟨v i, this i⟩)) =
span R (range v) := by
rw [← span_image, Submodule.coe_subtype, h₁]
have h₃ : (x : M) ∈ map (Submodule.subtype (span R (range v)))
(span R (Set.range fun i => Subtype.mk (v i) (this i))) := by
rw [h₂]
apply Subtype.mem x
rcases mem_map.1 h₃ with ⟨y, hy₁, hy₂⟩
have h_x_eq_y : x = y := by
rw [Subtype.ext_iff, ← hy₂]
simp
rwa [h_x_eq_y]
@[simp]
protected theorem span_apply (i : ι) :
Basis.span hli i = ⟨v i, Submodule.subset_span <| mem_range_self _⟩ := by
ext
exact congr_arg ((↑) : span R (range v) → M) <| Basis.mk_apply _ _ _
protected theorem coe_span_apply (i : ι) : (Basis.span hli i : M) = v i := by simp
@[simp]
protected theorem span_repr_eq_single (i : ι)
(hi : v i ∈ span R (range v) := subset_span <| mem_range_self i) :
(Basis.span hli).repr ⟨v i, hi⟩ = single i 1 := by
rw [← LinearEquiv.eq_symm_apply]
simp [Basis.span]
lemma span_neg {R M : Type*} [Ring R] [AddCommGroup M] [Module R M]
{v : ι → M} (hli : LinearIndependent R v)
(h : span R (range v) = span R (range (-v)) := by simp [← neg_range']) :
Basis.span hli.neg = ((Basis.span hli).map <| (LinearEquiv.neg _).trans (.ofEq _ _ h)) := by
ext; simp
end Span
/-- Any basis is a maximal linear independent set.
-/
theorem maximal [Nontrivial R] (b : Basis ι R M) : b.linearIndependent.Maximal := fun w hi h => by
-- If `w` is strictly bigger than `range b`,
apply le_antisymm h
-- then choose some `x ∈ w \ range b`,
intro x p
by_contra q
-- and write it in terms of the basis.
have e := b.linearCombination_repr x
-- This then expresses `x` as a linear combination
-- of elements of `w` which are in the range of `b`,
let u : ι ↪ w :=
⟨fun i => ⟨b i, h ⟨i, rfl⟩⟩, fun i i' r =>
b.injective (by simpa only [Subtype.mk_eq_mk] using r)⟩
simp_rw [Finsupp.linearCombination_apply] at e
change ((b.repr x).sum fun (i : ι) (a : R) ↦ a • (u i : M)) = ((⟨x, p⟩ : w) : M) at e
rw [← Finsupp.sum_embDomain (f := u) (g := fun x r ↦ r • (x : M)),
← Finsupp.linearCombination_apply] at e
-- Now we can contradict the linear independence of `hi`
refine hi.linearCombination_ne_of_notMem_support _ ?_ e
simp only [Finset.mem_map, Finsupp.support_embDomain]
rintro ⟨j, -, W⟩
simp only [u, Embedding.coeFn_mk, Subtype.mk_eq_mk] at W
apply q ⟨j, W⟩
instance uniqueBasis [Subsingleton R] : Unique (Basis ι R M) :=
⟨⟨⟨default⟩⟩, fun ⟨b⟩ => by rw [Subsingleton.elim b]⟩
variable (b : Basis ι R M)
section Singleton
/-- `Basis.singleton ι R` is the basis sending the unique element of `ι` to `1 : R`. -/
protected def singleton (ι R : Type*) [Unique ι] [Semiring R] : Basis ι R R :=
ofRepr
{ toFun := fun x => Finsupp.single default x
invFun := fun f => f default
left_inv := fun x => by simp
right_inv := fun f => Finsupp.unique_ext (by simp)
map_add' := fun x y => by simp
map_smul' := fun c x => by simp }
@[simp]
theorem singleton_apply (ι R : Type*) [Unique ι] [Semiring R] (i) : Basis.singleton ι R i = 1 :=
apply_eq_iff.mpr (by simp [Basis.singleton])
@[simp]
theorem singleton_repr (ι R : Type*) [Unique ι] [Semiring R] (x i) :
(Basis.singleton ι R).repr x i = x := by simp [Basis.singleton, Unique.eq_default i]
@[simp]
theorem coe_singleton {ι R : Type*} [Unique ι] [Semiring R] :
⇑(Basis.singleton ι R) = 1 := by
ext; simp
end Singleton
section Empty
variable (M)
/-- If `M` is a subsingleton and `ι` is empty, this is the unique `ι`-indexed basis for `M`. -/
protected def empty [Subsingleton M] [IsEmpty ι] : Basis ι R M :=
ofRepr 0
instance emptyUnique [Subsingleton M] [IsEmpty ι] : Unique (Basis ι R M) where
default := Basis.empty M
uniq := fun _ => congr_arg ofRepr <| Subsingleton.elim _ _
end Empty
section Module.IsTorsionFree
-- Can't be an instance because the basis can't be inferred.
protected lemma isTorsionFree (b : Basis ι R M) :
Module.IsTorsionFree R M := b.repr.injective.moduleIsTorsionFree _ (by simp)
protected theorem smul_eq_zero [IsDomain R] (b : Basis ι R M) {c : R} {x : M} :
c • x = 0 ↔ c = 0 ∨ x = 0 := by have := b.isTorsionFree; exact smul_eq_zero
end Module.IsTorsionFree
section Singleton
theorem basis_singleton_iff {R M : Type*} [Ring R] [IsDomain R] [AddCommGroup M] [Module R M]
[IsTorsionFree R M] (ι : Type*) [Unique ι] :
Nonempty (Basis ι R M) ↔ ∃ x ≠ 0, ∀ y : M, ∃ r : R, r • x = y := by
constructor
· rintro ⟨b⟩
refine ⟨b default, b.linearIndependent.ne_zero _, ?_⟩
simpa [span_singleton_eq_top_iff, Set.range_unique] using b.span_eq
· rintro ⟨x, nz, w⟩
refine ⟨ofRepr <| LinearEquiv.symm
{ toFun := fun f => f default • x
invFun := fun y => Finsupp.single default (w y).choose
left_inv := fun f => Finsupp.unique_ext ?_
right_inv := fun y => ?_
map_add' := fun y z => ?_
map_smul' := fun c y => ?_ }⟩
· simp [Finsupp.add_apply, add_smul]
· simp only [Finsupp.coe_smul, Pi.smul_apply, RingHom.id_apply]
rw [← smul_assoc]
· refine smul_left_injective _ nz ?_
simp only [Finsupp.single_eq_same]
exact (w (f default • x)).choose_spec
· simp only [Finsupp.single_eq_same]
exact (w y).choose_spec
end Singleton
end Basis
open Fintype in
lemma card_fintype [Semiring R] [AddCommMonoid M] [Module R M] [Fintype ι] (b : Basis ι R M)
[Fintype R] [Fintype M] :
card M = card R ^ card ι := by
classical
calc
card M = card (ι → R) := card_congr b.equivFun.toEquiv
_ = card R ^ card ι := by simp
end Module