forked from leanprover-community/mathlib4
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathColimits.lean
More file actions
185 lines (145 loc) · 6.82 KB
/
Copy pathColimits.lean
File metadata and controls
185 lines (145 loc) · 6.82 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
/-
Copyright (c) 2019 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Joël Riou
-/
module
public import Mathlib.Algebra.Category.ModuleCat.Basic
public import Mathlib.Algebra.Category.Grp.Colimits
public import Mathlib.CategoryTheory.ConcreteCategory.Elementwise
public import Mathlib.LinearAlgebra.DFinsupp
/-!
# The category of R-modules has all colimits.
From the existence of colimits in `AddCommGrpCat`, we deduce the existence of colimits
in `ModuleCat R`. This way, we get for free that the functor
`forget₂ (ModuleCat R) AddCommGrpCat` commutes with colimits.
Note that finite colimits can already be obtained from the instance `Abelian (Module R)`.
TODO:
In fact, in `ModuleCat R` there is a much nicer model of colimits as quotients
of finitely supported functions, and we really should implement this as well.
-/
@[expose] public section
universe w' w u v
open CategoryTheory Category Limits
variable {R : Type w} [Ring R]
namespace ModuleCat
variable {J : Type u} [Category.{v} J] (F : J ⥤ ModuleCat.{w'} R)
namespace HasColimit
variable [HasColimit (F ⋙ forget₂ _ AddCommGrpCat)]
set_option backward.defeqAttrib.useBackward true in
set_option backward.isDefEq.respectTransparency false in
/-- The induced scalar multiplication on
`colimit (F ⋙ forget₂ _ AddCommGrpCat)`. -/
@[simps]
noncomputable def coconePointSMul :
R →+* End (colimit (F ⋙ forget₂ _ AddCommGrpCat)) where
toFun r := colimMap
{ app := fun j => (F.obj j).smul r
naturality := fun _ _ _ => smul_naturality _ _ }
map_zero' := colimit.hom_ext (by simp +instances)
map_one' := colimit.hom_ext (by simp +instances)
map_add' r s := colimit.hom_ext (fun j => by
simp +instances only [Functor.comp_obj, forget₂_obj, map_add, ι_colimMap]
rw [Preadditive.add_comp, Preadditive.comp_add]
simp only [ι_colimMap, Functor.comp_obj, forget₂_obj])
map_mul' r s := colimit.hom_ext (fun j => by simp +instances)
set_option backward.isDefEq.respectTransparency false in
/-- The cocone for `F` constructed from the colimit of
`(F ⋙ forget₂ (ModuleCat R) AddCommGrpCat)`. -/
@[simps]
noncomputable def colimitCocone : Cocone F where
pt := mkOfSMul (coconePointSMul F)
ι :=
{ app := fun j => homMk (colimit.ι (F ⋙ forget₂ _ AddCommGrpCat) j) (fun r => by
dsimp
-- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644
erw [mkOfSMul_smul]
simp)
naturality := fun i j f => by
apply (forget₂ _ AddCommGrpCat).map_injective
simp only [Functor.map_comp, forget₂_map_homMk]
dsimp
erw [colimit.w (F ⋙ forget₂ _ AddCommGrpCat), comp_id] }
set_option backward.defeqAttrib.useBackward true in
set_option backward.isDefEq.respectTransparency false in
/-- The cocone for `F` constructed from the colimit of
`(F ⋙ forget₂ (ModuleCat R) AddCommGrpCat)` is a colimit cocone. -/
noncomputable def isColimitColimitCocone : IsColimit (colimitCocone F) where
desc s := homMk (colimit.desc _ ((forget₂ _ AddCommGrpCat).mapCocone s)) (fun r => by
apply colimit.hom_ext
intro j
dsimp
rw [colimit.ι_desc_assoc]
-- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644
erw [mkOfSMul_smul]
dsimp
simp only [ι_colimMap_assoc, Functor.comp_obj, forget₂_obj, colimit.ι_desc,
Functor.mapCocone_pt, Functor.mapCocone_ι_app, forget₂_map]
exact smul_naturality (s.ι.app j) r)
fac s j := by
apply (forget₂ _ AddCommGrpCat).map_injective
exact colimit.ι_desc ((forget₂ _ AddCommGrpCat).mapCocone s) j
uniq s m hm := by
apply (forget₂ _ AddCommGrpCat).map_injective
apply colimit.hom_ext
intro j
erw [colimit.ι_desc ((forget₂ _ AddCommGrpCat).mapCocone s) j]
dsimp
rw [← hm]
rfl
instance : HasColimit F := ⟨_, isColimitColimitCocone F⟩
noncomputable instance : PreservesColimit F (forget₂ _ AddCommGrpCat) :=
preservesColimit_of_preserves_colimit_cocone (isColimitColimitCocone F) (colimit.isColimit _)
noncomputable instance reflectsColimit :
ReflectsColimit F (forget₂ (ModuleCat.{w'} R) AddCommGrpCat) :=
reflectsColimit_of_reflectsIsomorphisms _ _
end HasColimit
variable (J R)
instance hasColimitsOfShape [HasColimitsOfShape J AddCommGrpCat.{w'}] :
HasColimitsOfShape J (ModuleCat.{w'} R) where
noncomputable instance reflectsColimitsOfShape [HasColimitsOfShape J AddCommGrpCat.{w'}] :
ReflectsColimitsOfShape J (forget₂ (ModuleCat.{w'} R) AddCommGrpCat) where
instance hasColimitsOfSize [HasColimitsOfSize.{v, u} AddCommGrpCat.{w'}] :
HasColimitsOfSize.{v, u} (ModuleCat.{w'} R) where
noncomputable instance forget₂PreservesColimitsOfShape
[HasColimitsOfShape J AddCommGrpCat.{w'}] :
PreservesColimitsOfShape J (forget₂ (ModuleCat.{w'} R) AddCommGrpCat) where
noncomputable instance forget₂PreservesColimitsOfSize
[HasColimitsOfSize.{u, v} AddCommGrpCat.{w'}] :
PreservesColimitsOfSize.{u, v} (forget₂ (ModuleCat.{w'} R) AddCommGrpCat) where
noncomputable instance
[HasColimitsOfSize.{u, v} AddCommGrpMax.{w, w'}] :
PreservesColimitsOfSize.{u, v} (forget₂ (ModuleCat.{max w w'} R) AddCommGrpCat) where
instance : HasFiniteColimits (ModuleCat.{w'} R) := inferInstance
-- Sanity checks, just to make sure typeclass search can find the instances we want.
example (R : Type u) [Ring R] : HasColimits (ModuleCat.{max v u} R) :=
inferInstance
example (R : Type u) [Ring R] : HasColimits (ModuleCat.{max u v} R) :=
inferInstance
example (R : Type u) [Ring R] : HasColimits (ModuleCat.{u} R) :=
inferInstance
example (R : Type u) [Ring R] : HasCoequalizers (ModuleCat.{u} R) := by
infer_instance
-- for some reason, this instance is not found automatically later on
instance : HasCoequalizers (ModuleCat.{v} R) where
noncomputable example (R : Type u) [Ring R] :
PreservesColimits (forget₂ (ModuleCat.{u} R) AddCommGrpCat) := inferInstance
section
variable (R : Type w) [CommRing R] (M ι : Type u) [AddCommGroup M] [Module R M]
/-- The coproduct cone induced by the concrete coproduct. -/
noncomputable
def finsuppCocone : Cofan fun _ : ι ↦ ModuleCat.of R M :=
Cofan.mk (ModuleCat.of R (ι →₀ M)) fun i ↦
ModuleCat.ofHom (Finsupp.lsingle i (R := R) (M := ModuleCat.of R M))
set_option backward.defeqAttrib.useBackward true in
set_option backward.isDefEq.respectTransparency false in
/-- The concrete coproduct cone is colimiting. -/
noncomputable
def finsuppCoconeIsColimit : IsColimit (finsuppCocone R M ι) where
desc s := ModuleCat.ofHom <| Finsupp.lsum R (N := s.pt) (fun i ↦ (s.ι.app ⟨i⟩).hom)
fac := by aesop (add simp finsuppCocone)
uniq s f h := by
ext : 1
exact Finsupp.lhom_ext' fun i ↦ LinearMap.ext fun x ↦ by simpa using! congr($(h ⟨i⟩) (x : M))
end
end ModuleCat