Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 8fab107

Browse files
committed
refactor(algebra/module): split of type constructions and move quotient, subtype and linear_map to their own theories in algebra/linear_algebra
1 parent fccc5d3 commit 8fab107

File tree

8 files changed

+343
-237
lines changed

8 files changed

+343
-237
lines changed

algebra/group.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ attribute [to_additive neg_add] mul_inv
133133

134134
end pending_1857
135135

136-
universe variable u
137-
variable {α : Type u}
136+
universe u
137+
variables {α : Type u}
138138

139139
@[simp, to_additive add_left_inj]
140140
theorem mul_left_inj [left_cancel_semigroup α] {a b c : α} : a * b = a * c ↔ b = c :=

algebra/linear_algebra/basic.lean

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,46 @@ have l = 0,
208208
have l 0 = 1, from finsupp.single_eq_same,
209209
by rw [‹l = 0›] at this; simp * at *
210210

211+
lemma linear_independent_union {s t : set β}
212+
(hs : linear_independent s) (ht : linear_independent t) (hst : span s ∩ span t = {0}) :
213+
linear_independent (s ∪ t) :=
214+
(zero_ne_one_or_forall_eq_0 α).elim
215+
(assume ne l hl eq0,
216+
let ls := l.filter $ λb, b ∈ s, lt := l.filter $ λb, b ∈ t in
217+
have hls : ↑ls.support ⊆ s, by simp [ls, subset_def],
218+
have hlt : ↑lt.support ⊆ t, by simp [ls, subset_def],
219+
have lt.sum (λb a, a • b) ∈ span t,
220+
from is_submodule.sum $ assume b hb, is_submodule.smul _ $ subset_span $ hlt hb,
221+
have l = ls + lt,
222+
from
223+
have ∀b, b ∈ s → b ∉ t,
224+
from assume b hbs hbt,
225+
have b ∈ span s ∩ span t, from ⟨subset_span hbs, subset_span hbt⟩,
226+
have b = 0, by rw [hst] at this; simp * at *,
227+
zero_not_mem_of_linear_independent ne hs $ this ▸ hbs,
228+
have lt = l.filter (λb, b ∉ s),
229+
from finsupp.ext $ assume b, by by_cases b ∈ t; by_cases b ∈ s; simp * at *,
230+
by rw [this]; exact finsupp.filter_pos_add_filter_neg.symm,
231+
have ls.sum (λb a, a • b) + lt.sum (λb a, a • b) = l.sum (λb a, a • b),
232+
by rw [this, finsupp.sum_add_index]; simp [add_smul],
233+
have ls_eq_neg_lt : ls.sum (λb a, a • b) = - lt.sum (λb a, a • b),
234+
from eq_of_sub_eq_zero $ by simp [this, eq0],
235+
have ls_sum_eq : ls.sum (λb a, a • b) = 0,
236+
from
237+
have - lt.sum (λb a, a • b) ∈ span t,
238+
from is_submodule.neg $ is_submodule.sum $
239+
assume b hb, is_submodule.smul _ $ subset_span $ hlt hb,
240+
have ls.sum (λb a, a • b) ∈ span s ∩ span t,
241+
from ⟨is_submodule.sum $ assume b hb, is_submodule.smul _ $ subset_span $ hls hb,
242+
ls_eq_neg_lt.symm ▸ this⟩,
243+
by rw [hst] at this; simp * at *,
244+
have ls = 0, from hs _ (finsupp.support_subset_iff.mp hls) ls_sum_eq,
245+
have lt_sum_eq : lt.sum (λb a, a • b) = 0,
246+
from eq_of_neg_eq_neg $ by rw [←ls_eq_neg_lt, ls_sum_eq]; simp,
247+
have lt = 0, from ht _ (finsupp.support_subset_iff.mp hlt) lt_sum_eq,
248+
by simp [‹l = ls + lt›, ‹ls = 0›, ‹lt = 0›])
249+
(assume eq_0 l _ _, finsupp.ext $ assume b, eq_0 _)
250+
211251
lemma linear_independent_Union_of_directed {s : set (set β)} (hs : ∀a∈s, ∀b∈s, ∃c∈s, a ∪ b ⊆ c)
212252
(h : ∀a∈s, linear_independent a) : linear_independent (⋃₀s) :=
213253
assume l hl eq,
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/-
2+
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Johannes Hölzl, Kenny Lau
5+
6+
Type of linear functions
7+
-/
8+
import algebra.linear_algebra.basic
9+
10+
universes u v w
11+
variables {α : Type u} {β : Type v} {γ : Type w}
12+
13+
14+
def linear_map {α : Type u} (β : Type v) (γ : Type w) [ring α] [module α β] [module α γ] :=
15+
subtype (@is_linear_map α β γ _ _ _)
16+
17+
namespace linear_map
18+
variables [ring α] [module α β] [module α γ]
19+
variables {r : α} {A B C : linear_map β γ} {x y : β}
20+
include α
21+
22+
instance : has_coe_to_fun (linear_map β γ) := ⟨_, subtype.val⟩
23+
24+
theorem ext (h : ∀ x, A x = B x) : A = B := subtype.eq $ funext h
25+
26+
lemma is_linear_map_coe : is_linear_map A := A.property
27+
28+
@[simp] lemma map_add : A (x + y) = A x + A y := is_linear_map_coe.add x y
29+
@[simp] lemma map_smul : A (r • x) = r • A x := is_linear_map_coe.smul r x
30+
@[simp] lemma map_zero : A 0 = 0 := is_linear_map_coe.zero
31+
@[simp] lemma map_neg : A (-x) = -A x := is_linear_map_coe.neg _
32+
@[simp] lemma map_sub : A (x - y) = A x - A y := is_linear_map_coe.sub _ _
33+
34+
/- kernel -/
35+
36+
def ker (A : linear_map β γ) : set β := {y | A y = 0}
37+
38+
section ker
39+
40+
@[simp] lemma mem_ker : x ∈ A.ker ↔ A x = 0 := iff.rfl
41+
42+
theorem ker_of_map_eq_map (h : A x = A y) : x - y ∈ A.ker :=
43+
by rw [mem_ker, map_sub]; exact sub_eq_zero_of_eq h
44+
45+
theorem inj_of_trivial_ker (H : A.ker ⊆ {0}) (h : A x = A y) : x = y :=
46+
eq_of_sub_eq_zero $ set.eq_of_mem_singleton $ H $ ker_of_map_eq_map h
47+
48+
variables (α A)
49+
50+
instance ker.is_submodule : is_submodule A.ker :=
51+
{ zero_ := map_zero,
52+
add_ := λ x y HU HV, by rw mem_ker at *; simp [HU, HV, mem_ker],
53+
smul := λ r x HV, by rw mem_ker at *; simp [HV] }
54+
55+
theorem sub_ker (HU : x ∈ A.ker) (HV : y ∈ A.ker) : x - y ∈ A.ker :=
56+
is_submodule.sub HU HV
57+
58+
end ker
59+
60+
/- image -/
61+
62+
def im (A : linear_map β γ) : set γ := {x | ∃ y, A y = x}
63+
64+
@[simp] lemma mem_im {A : linear_map β γ} {z : γ} :
65+
z ∈ A.im ↔ ∃ y, A y = z := iff.rfl
66+
67+
instance im.is_submodule : is_submodule A.im :=
68+
{ zero_ := ⟨0, map_zero⟩,
69+
add_ := λ a b ⟨x, hx⟩ ⟨y, hy⟩, ⟨x + y, by simp [hx, hy]⟩,
70+
smul := λ r a ⟨x, hx⟩, ⟨r • x, by simp [hx]⟩ }
71+
72+
section add_comm_group
73+
74+
instance : has_add (linear_map β γ) := ⟨λhf hg, ⟨_, hf.2.map_add hg.2⟩⟩
75+
instance : has_zero (linear_map β γ) := ⟨⟨_, is_linear_map.map_zero⟩⟩
76+
instance : has_neg (linear_map β γ) := ⟨λhf, ⟨_, hf.2.map_neg⟩⟩
77+
78+
@[simp] lemma add_app : (A + B) x = A x + B x := rfl
79+
@[simp] lemma zero_app : (0 : linear_map β γ) x = 0 := rfl
80+
@[simp] lemma neg_app : (-A) x = -A x := rfl
81+
82+
instance : add_comm_group (linear_map β γ) :=
83+
by refine {add := (+), zero := 0, neg := has_neg.neg, ..}; { intros, apply ext, simp }
84+
85+
end add_comm_group
86+
87+
end linear_map
88+
89+
namespace linear_map
90+
variables [comm_ring α] [module α β] [module α γ]
91+
92+
instance : has_scalar α (linear_map β γ) := ⟨λr f, ⟨λb, r • f b, f.2.map_smul_right⟩⟩
93+
94+
@[simp] lemma smul_app {r : α} {x : β} {A : linear_map β γ} : (r • A) x = r • (A x) := rfl
95+
96+
variables (α β γ)
97+
98+
instance : module α (linear_map β γ) :=
99+
by refine {smul := (•), ..linear_map.add_comm_group, ..};
100+
{ intros, apply ext, simp [smul_add, add_smul, mul_smul] }
101+
102+
end linear_map
103+
104+
namespace module
105+
variables [ring α] [module α β]
106+
include α
107+
108+
instance : has_one (linear_map β β) := ⟨⟨id, is_linear_map.id⟩⟩
109+
instance : has_mul (linear_map β β) := ⟨λf g, ⟨_, is_linear_map.comp f.2 g.2⟩⟩
110+
111+
@[simp] lemma one_app (x : β) : (1 : linear_map β β) x = x := rfl
112+
@[simp] lemma mul_app (A B : linear_map β β) (x : β) : (A * B) x = A (B x) := rfl
113+
114+
variables (α β)
115+
116+
-- declaring this an instance breaks `real.lean` with reaching max. instance resolution depth
117+
def endomorphism_ring : ring (linear_map β β) :=
118+
by refine {mul := (*), one := 1, ..linear_map.add_comm_group, ..};
119+
{ intros, apply linear_map.ext, simp }
120+
121+
def general_linear_group :=
122+
@units (linear_map β β) (@ring.to_semiring _ (endomorphism_ring α β))
123+
124+
end module
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/-
2+
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Author: Johannes Hölzl
5+
6+
Quotient construction on modules
7+
-/
8+
9+
import algebra.linear_algebra.basic
10+
11+
namespace is_submodule
12+
13+
universes u v w
14+
variables {α : Type u} {β : Type v} {γ : Type w}
15+
variables [ring α] [module α β] [module α γ] (s : set β) [hs : is_submodule s]
16+
include α s hs
17+
18+
open function
19+
20+
def quotient_rel : setoid β :=
21+
⟨λb₁ b₂, b₁ - b₂ ∈ s,
22+
assume b, by simp [zero],
23+
assume b₁ b₂ hb,
24+
have - (b₁ - b₂) ∈ s, from is_submodule.neg hb,
25+
by simpa using this,
26+
assume b₁ b₂ b₃ hb₁₂ hb₂₃,
27+
have (b₁ - b₂) + (b₂ - b₃) ∈ s, from add hb₁₂ hb₂₃,
28+
by simpa using this
29+
30+
local attribute [instance] quotient_rel
31+
32+
def quotient : Type v := quotient (quotient_rel s)
33+
34+
local notation ` Q ` := quotient s
35+
36+
instance quotient.has_zero : has_zero Q := ⟨⟦ 0 ⟧⟩
37+
38+
instance quotient.has_add : has_add Q :=
39+
⟨λa b, quotient.lift_on₂ a b (λa b, ⟦a + b⟧) $
40+
assume a₁ a₂ b₁ b₂ (h₁ : a₁ - b₁ ∈ s) (h₂ : a₂ - b₂ ∈ s),
41+
quotient.sound $
42+
have (a₁ - b₁) + (a₂ - b₂) ∈ s, from add h₁ h₂,
43+
show (a₁ + a₂) - (b₁ + b₂) ∈ s, by simpa⟩
44+
45+
instance quotient.has_neg : has_neg Q :=
46+
⟨λa, quotient.lift_on a (λa, ⟦- a⟧) $ assume a b (h : a - b ∈ s),
47+
quotient.sound $
48+
have - (a - b) ∈ s, from neg h,
49+
show (-a) - (-b) ∈ s, by simpa⟩
50+
51+
instance quotient.has_scalar : has_scalar α Q :=
52+
⟨λa b, quotient.lift_on b (λb, ⟦a • b⟧) $ assume b₁ b₂ (h : b₁ - b₂ ∈ s),
53+
quotient.sound $
54+
have a • (b₁ - b₂) ∈ s, from is_submodule.smul a h,
55+
show a • b₁ - a • b₂ ∈ s, by simpa [smul_add]⟩
56+
57+
instance quotient.module : module α Q :=
58+
{ module .
59+
zero := 0,
60+
add := (+),
61+
neg := has_neg.neg,
62+
smul := (•),
63+
add_assoc := assume a b c, quotient.induction_on₃ a b c $ assume a b c, quotient.sound $
64+
by simp,
65+
add_comm := assume a b, quotient.induction_on₂ a b $ assume a b, quotient.sound $
66+
by simp,
67+
add_zero := assume a, quotient.induction_on a $ assume a, quotient.sound $
68+
by simp,
69+
zero_add := assume a, quotient.induction_on a $ assume a, quotient.sound $
70+
by simp,
71+
add_left_neg := assume a, quotient.induction_on a $ assume a, quotient.sound $
72+
by simp,
73+
one_smul := assume a, quotient.induction_on a $ assume a, quotient.sound $
74+
by simp,
75+
mul_smul := assume a b c, quotient.induction_on c $ assume c, quotient.sound $
76+
by simp [mul_smul],
77+
smul_add := assume a b c, quotient.induction_on₂ b c $ assume b c, quotient.sound $
78+
by simp [smul_add],
79+
add_smul := assume a b c, quotient.induction_on c $ assume c, quotient.sound $
80+
by simp [add_smul] }
81+
82+
instance quotient.inhabited : inhabited Q := ⟨0
83+
84+
lemma is_linear_map_quotient_mk : @is_linear_map _ _ Q _ _ _ (λb, ⟦b⟧ : β → Q) :=
85+
by refine {..}; intros; refl
86+
87+
def quotient.lift {f : β → γ} (hf : is_linear_map f) (h : ∀x∈s, f x = 0) (b : Q) : γ :=
88+
b.lift_on f $ assume a b (hab : a - b ∈ s),
89+
have f a - f b = 0, by rw [←hf.sub]; exact h _ hab,
90+
show f a = f b, from eq_of_sub_eq_zero this
91+
92+
lemma is_linear_map_quotient_lift {f : β → γ} {h : ∀x y, x - y ∈ s → f x = f y}
93+
(hf : is_linear_map f) : is_linear_map (λq:Q, quotient.lift_on q f h) :=
94+
⟨assume b₁ b₂, quotient.induction_on₂ b₁ b₂ $ assume b₁ b₂, hf.add b₁ b₂,
95+
assume a b, quotient.induction_on b $ assume b, hf.smul a b⟩
96+
97+
lemma quotient.injective_lift [is_submodule s] {f : β → γ} (hf : is_linear_map f)
98+
(hs : s = {x | f x = 0}) : injective (quotient.lift s hf $ le_of_eq hs) :=
99+
assume a b, quotient.induction_on₂ a b $ assume a b (h : f a = f b), quotient.sound $
100+
have f (a - b) = 0, by rw [hf.sub]; simp [h],
101+
show a - b ∈ s, from hs.symm ▸ this
102+
103+
end is_submodule
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/-
2+
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Johannes Hölzl, Kenny Lau
5+
6+
Subtype construction of sub modules.
7+
-/
8+
import algebra.linear_algebra.basic
9+
10+
universes u v w
11+
variables {α : Type u} {β : Type v} {γ : Type w}
12+
variables [ring α] [module α β] [module α γ] {p : set β} [is_submodule p]
13+
variables {r : α} {x y : {x : β // x ∈ p}}
14+
include α
15+
16+
open is_submodule
17+
18+
instance : has_add {x : β // x ∈ p} := ⟨λ ⟨x, px⟩ ⟨y, py⟩, ⟨x + y, add px py⟩⟩
19+
instance : has_zero {x : β // x ∈ p} := ⟨⟨0, zero⟩⟩
20+
instance : has_neg {x : β // x ∈ p} := ⟨λ ⟨x, hx⟩, ⟨-x, neg hx⟩⟩
21+
instance : has_scalar α {x : β // x ∈ p} := ⟨λ c ⟨x, hx⟩, ⟨c • x, smul c hx⟩⟩
22+
23+
@[simp] lemma add_val : (x + y).val = x.val + y.val := by cases x; cases y; refl
24+
@[simp] lemma zero_val : (0 : {x : β // x ∈ p}).val = 0 := rfl
25+
@[simp] lemma neg_val : (-x).val = -x.val := by cases x; refl
26+
@[simp] lemma smul_val : (r • x).val = r • x.val := by cases x; refl
27+
28+
instance : module α {x : β // x ∈ p} :=
29+
by refine {add := (+), zero := 0, neg := has_neg.neg, smul := (•), ..};
30+
{ intros, apply subtype.eq,
31+
simp [smul_add, add_smul, mul_smul] }
32+
33+
lemma sub_val : (x - y).val = x.val - y.val := by simp
34+
35+
lemma is_linear_map_subtype_val {f : γ → {x : β // x ∈ p}} (hf : is_linear_map f) :
36+
is_linear_map (λb, (f b).val) :=
37+
by refine {..}; simp [hf.add, hf.smul]
38+
39+
lemma is_linear_map_subtype_mk {f : γ → β} (hf : is_linear_map f) {h : ∀c, f c ∈ p} :
40+
is_linear_map (λc, ⟨f c, h c⟩ : γ → {x : β // x ∈ p}) :=
41+
by refine {..}; intros; apply subtype.eq; simp [hf.add, hf.smul]

0 commit comments

Comments
 (0)