Skip to content

Commit b1caad9

Browse files
committed
refactor: colimits in ModuleCat (#6925)
This PR refactors the construction of colimits of modules in order to prove that the forgetful functor to abelian groups preserves colimits.
1 parent 25953fd commit b1caad9

File tree

7 files changed

+294
-387
lines changed

7 files changed

+294
-387
lines changed

Mathlib/Algebra/Category/AlgebraCat/Limits.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,12 @@ instance forget₂RingPreservesLimits : PreservesLimits (forget₂ (AlgebraCat R
159159
/-- The forgetful functor from R-algebras to R-modules preserves all limits.
160160
-/
161161
instance forget₂ModulePreservesLimitsOfSize : PreservesLimitsOfSize.{v, v}
162-
(forget₂ (AlgebraCatMax.{v, w} R) (ModuleCat.ModuleCatMax.{v, w} R)) where
162+
(forget₂ (AlgebraCatMax.{v, w} R) (ModuleCatMax.{v, w} R)) where
163163
preservesLimitsOfShape :=
164164
{ preservesLimit :=
165165
preservesLimitOfPreservesLimitCone (limitConeIsLimit _)
166166
(ModuleCat.HasLimits.limitConeIsLimit
167-
(_ ⋙ forget₂ (AlgebraCatMax.{v, w} R) (ModuleCat.ModuleCatMax.{v, w} R))) }
167+
(_ ⋙ forget₂ (AlgebraCatMax.{v, w} R) (ModuleCatMax.{v, w} R))) }
168168
#align Algebra.forget₂_Module_preserves_limits_of_size AlgebraCat.forget₂ModulePreservesLimitsOfSize
169169

170170
instance forget₂ModulePreservesLimits :

Mathlib/Algebra/Category/GroupCat/Basic.lean

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,3 +512,23 @@ set_option linter.uppercaseLean3 false in
512512
#align CommGroup.forget_reflects_isos CommGroupCat.forget_reflects_isos
513513
set_option linter.uppercaseLean3 false in
514514
#align AddCommGroup.forget_reflects_isos AddCommGroupCat.forget_reflects_isos
515+
516+
-- note: in the following definitions, there is a problem with `@[to_additive]`
517+
-- as the `Category` instance is not found on the additive variant
518+
-- this variant is then renamed with a `Aux` suffix
519+
520+
/-- An alias for `GroupCat.{max u v}`, to deal around unification issues. -/
521+
@[to_additive (attr := nolint checkUnivs) GroupCatMaxAux
522+
"An alias for `AddGroupCat.{max u v}`, to deal around unification issues."]
523+
abbrev GroupCatMax.{u1, u2} := GroupCat.{max u1 u2}
524+
/-- An alias for `AddGroupCat.{max u v}`, to deal around unification issues. -/
525+
@[nolint checkUnivs]
526+
abbrev AddGroupCatMax.{u1, u2} := AddGroupCat.{max u1 u2}
527+
528+
/-- An alias for `CommGroupCat.{max u v}`, to deal around unification issues. -/
529+
@[to_additive (attr := nolint checkUnivs) AddCommGroupCatMaxAux
530+
"An alias for `AddCommGroupCat.{max u v}`, to deal around unification issues."]
531+
abbrev CommGroupCatMax.{u1, u2} := CommGroupCat.{max u1 u2}
532+
/-- An alias for `AddCommGroupCat.{max u v}`, to deal around unification issues. -/
533+
@[nolint checkUnivs]
534+
abbrev AddCommGroupCatMax.{u1, u2} := AddCommGroupCat.{max u1 u2}

Mathlib/Algebra/Category/GroupCat/Colimits.lean

Lines changed: 58 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Authors: Scott Morrison
66
import Mathlib.Algebra.Category.GroupCat.Preadditive
77
import Mathlib.GroupTheory.QuotientGroup
88
import Mathlib.CategoryTheory.Limits.Shapes.Kernels
9+
import Mathlib.CategoryTheory.Limits.Shapes.FiniteLimits
910
import Mathlib.CategoryTheory.ConcreteCategory.Elementwise
1011

1112
#align_import algebra.category.Group.colimits from "leanprover-community/mathlib"@"70fd9563a21e7b963887c9360bd29b2393e6225a"
@@ -25,16 +26,18 @@ of finitely supported functions, and we really should implement this as well (or
2526
-- porting note: `AddCommGroup` in all the names
2627
set_option linter.uppercaseLean3 false
2728

28-
universe u v
29+
universe w u v
2930

30-
open CategoryTheory
31-
32-
open CategoryTheory.Limits
31+
open CategoryTheory Limits
3332

3433
-- [ROBOT VOICE]:
3534
-- You should pretend for now that this file was automatically generated.
3635
-- It follows the same template as colimits in Mon.
37-
namespace AddCommGroupCat.Colimits
36+
namespace AddCommGroupCat
37+
38+
variable {J : Type u} [Category.{v} J] (F : J ⥤ AddCommGroupCat.{max u v w})
39+
40+
namespace Colimits
3841

3942
/-!
4043
We build the colimit of a diagram in `AddCommGroupCat` by constructing the
@@ -43,9 +46,6 @@ then taking the quotient by the abelian group laws within each abelian group,
4346
and the identifications given by the morphisms in the diagram.
4447
-/
4548

46-
47-
variable {J : Type v} [SmallCategory J] (F : J ⥤ AddCommGroupCat.{v})
48-
4949
/-- An inductive type representing all group expressions (without relations)
5050
on a collection of types indexed by the objects of `J`.
5151
-/
@@ -58,7 +58,7 @@ inductive Prequotient
5858
| add : Prequotient → Prequotient → Prequotient
5959
#align AddCommGroup.colimits.prequotient AddCommGroupCat.Colimits.Prequotient
6060

61-
instance : Inhabited (Prequotient F) :=
61+
instance : Inhabited (Prequotient.{w} F) :=
6262
⟨Prequotient.zero⟩
6363

6464
open Prequotient
@@ -67,7 +67,7 @@ open Prequotient
6767
because of the abelian group laws, or
6868
because one element is mapped to another by a morphism in the diagram.
6969
-/
70-
inductive Relation : Prequotient F → Prequotient F → Prop
70+
inductive Relation : Prequotient.{w} F → Prequotient.{w} F → Prop
7171
-- Make it an equivalence relation:
7272
| refl : ∀ x, Relation x x
7373
| symm : ∀ (x y) (_ : Relation x y), Relation y x
@@ -95,7 +95,7 @@ inductive Relation : Prequotient F → Prequotient F → Prop
9595
/--
9696
The setoid corresponding to group expressions modulo abelian group relations and identifications.
9797
-/
98-
def colimitSetoid : Setoid (Prequotient F) where
98+
def colimitSetoid : Setoid (Prequotient.{w} F) where
9999
r := Relation F
100100
iseqv := ⟨Relation.refl, fun r => Relation.symm _ _ r, fun r => Relation.trans _ _ _ r⟩
101101
#align AddCommGroup.colimits.colimit_setoid AddCommGroupCat.Colimits.colimitSetoid
@@ -104,11 +104,11 @@ attribute [instance] colimitSetoid
104104

105105
/-- The underlying type of the colimit of a diagram in `AddCommGroupCat`.
106106
-/
107-
def ColimitType : Type v :=
108-
Quotient (colimitSetoid F)
107+
def ColimitType : Type max u v w :=
108+
Quotient (colimitSetoid.{w} F)
109109
#align AddCommGroup.colimits.colimit_type AddCommGroupCat.Colimits.ColimitType
110110

111-
instance : AddCommGroup (ColimitType F) where
111+
instance : AddCommGroup (ColimitType.{w} F) where
112112
zero := Quotient.mk _ zero
113113
neg := Quotient.map neg Relation.neg_1
114114
add := Quotient.map₂ add <| fun x x' rx y y' ry =>
@@ -120,79 +120,79 @@ instance : AddCommGroup (ColimitType F) where
120120
add_assoc := Quotient.ind <| fun _ => Quotient.ind₂ <| fun _ _ =>
121121
Quotient.sound <| Relation.add_assoc _ _ _
122122

123-
instance ColimitTypeInhabited : Inhabited (ColimitType.{v} F) := ⟨0
123+
instance ColimitTypeInhabited : Inhabited (ColimitType.{w} F) := ⟨0
124124

125125
@[simp]
126-
theorem quot_zero : Quot.mk Setoid.r zero = (0 : ColimitType F) :=
126+
theorem quot_zero : Quot.mk Setoid.r zero = (0 : ColimitType.{w} F) :=
127127
rfl
128128
#align AddCommGroup.colimits.quot_zero AddCommGroupCat.Colimits.quot_zero
129129

130130
@[simp]
131131
theorem quot_neg (x) : Quot.mk Setoid.r (neg x) =
132132
-- Porting note : force Lean to treat `ColimitType F` no as `Quot _`
133-
Neg.neg (α := ColimitType.{v} F) (Quot.mk Setoid.r x : ColimitType.{v} F) :=
133+
Neg.neg (α := ColimitType.{w} F) (Quot.mk Setoid.r x : ColimitType.{w} F) :=
134134
rfl
135135
#align AddCommGroup.colimits.quot_neg AddCommGroupCat.Colimits.quot_neg
136136

137137
@[simp]
138138
theorem quot_add (x y) :
139139
Quot.mk Setoid.r (add x y) =
140140
-- Porting note : force Lean to treat `ColimitType F` no as `Quot _`
141-
Add.add (α := ColimitType.{v} F) (Quot.mk Setoid.r x) (Quot.mk Setoid.r y) :=
141+
Add.add (α := ColimitType.{w} F) (Quot.mk Setoid.r x) (Quot.mk Setoid.r y) :=
142142
rfl
143143
#align AddCommGroup.colimits.quot_add AddCommGroupCat.Colimits.quot_add
144144

145145
/-- The bundled abelian group giving the colimit of a diagram. -/
146146
def colimit : AddCommGroupCat :=
147-
AddCommGroupCat.of (ColimitType F)
147+
AddCommGroupCat.of (ColimitType.{w} F)
148148
#align AddCommGroup.colimits.colimit AddCommGroupCat.Colimits.colimit
149149

150150
/-- The function from a given abelian group in the diagram to the colimit abelian group. -/
151-
def coconeFun (j : J) (x : F.obj j) : ColimitType F :=
151+
def coconeFun (j : J) (x : F.obj j) : ColimitType.{w} F :=
152152
Quot.mk _ (Prequotient.of j x)
153153
#align AddCommGroup.colimits.cocone_fun AddCommGroupCat.Colimits.coconeFun
154154

155155
/-- The group homomorphism from a given abelian group in the diagram to the colimit abelian
156156
group. -/
157-
def coconeMorphism (j : J) : F.obj j ⟶ colimit F where
157+
def coconeMorphism (j : J) : F.obj j ⟶ colimit.{w} F where
158158
toFun := coconeFun F j
159159
map_zero' := by apply Quot.sound; apply Relation.zero
160160
map_add' := by intros; apply Quot.sound; apply Relation.add
161161
#align AddCommGroup.colimits.cocone_morphism AddCommGroupCat.Colimits.coconeMorphism
162162

163163
@[simp]
164164
theorem cocone_naturality {j j' : J} (f : j ⟶ j') :
165-
F.map f ≫ coconeMorphism F j' = coconeMorphism F j := by
165+
F.map f ≫ coconeMorphism.{w} F j' = coconeMorphism F j := by
166166
ext
167167
apply Quot.sound
168168
apply Relation.map
169169
#align AddCommGroup.colimits.cocone_naturality AddCommGroupCat.Colimits.cocone_naturality
170170

171171
@[simp]
172172
theorem cocone_naturality_components (j j' : J) (f : j ⟶ j') (x : F.obj j) :
173-
(coconeMorphism F j') (F.map f x) = (coconeMorphism F j) x := by
173+
(coconeMorphism.{w} F j') (F.map f x) = (coconeMorphism F j) x := by
174174
rw [← cocone_naturality F f]
175175
rfl
176176
#align AddCommGroup.colimits.cocone_naturality_components AddCommGroupCat.Colimits.cocone_naturality_components
177177

178178
/-- The cocone over the proposed colimit abelian group. -/
179179
def colimitCocone : Cocone F where
180-
pt := colimit F
180+
pt := colimit.{w} F
181181
ι := { app := coconeMorphism F }
182182
#align AddCommGroup.colimits.colimit_cocone AddCommGroupCat.Colimits.colimitCocone
183183

184184
/-- The function from the free abelian group on the diagram to the cone point of any other
185185
cocone. -/
186186
@[simp]
187-
def descFunLift (s : Cocone F) : Prequotient F → s.pt
187+
def descFunLift (s : Cocone F) : Prequotient.{w} F → s.pt
188188
| Prequotient.of j x => (s.ι.app j) x
189189
| zero => 0
190190
| neg x => -descFunLift s x
191191
| add x y => descFunLift s x + descFunLift s y
192192
#align AddCommGroup.colimits.desc_fun_lift AddCommGroupCat.Colimits.descFunLift
193193

194194
/-- The function from the colimit abelian group to the cone point of any other cocone. -/
195-
def descFun (s : Cocone F) : ColimitType F → s.pt := by
195+
def descFun (s : Cocone F) : ColimitType.{w} F → s.pt := by
196196
fapply Quot.lift
197197
· exact descFunLift F s
198198
· intro x y r
@@ -216,15 +216,15 @@ def descFun (s : Cocone F) : ColimitType F → s.pt := by
216216
#align AddCommGroup.colimits.desc_fun AddCommGroupCat.Colimits.descFun
217217

218218
/-- The group homomorphism from the colimit abelian group to the cone point of any other cocone. -/
219-
def descMorphism (s : Cocone F) : colimit.{v} F ⟶ s.pt where
219+
def descMorphism (s : Cocone F) : colimit.{w} F ⟶ s.pt where
220220
toFun := descFun F s
221221
map_zero' := rfl
222222
-- Porting note : in `mathlib3`, nothing needs to be done after `induction`
223223
map_add' x y := Quot.induction_on₂ x y fun _ _ => by dsimp [(· + ·)]; rw [←quot_add F]; rfl
224224
#align AddCommGroup.colimits.desc_morphism AddCommGroupCat.Colimits.descMorphism
225225

226226
/-- Evidence that the proposed colimit is the colimit. -/
227-
def colimitCoconeIsColimit : IsColimit (colimitCocone.{v} F) where
227+
def colimitCoconeIsColimit : IsColimit (colimitCocone.{w} F) where
228228
desc s := descMorphism F s
229229
uniq s m w := FunLike.ext _ _ <| fun x => Quot.inductionOn x fun x => by
230230
change (m : ColimitType F →+ s.pt) _ = (descMorphism F s : ColimitType F →+ s.pt) _
@@ -241,15 +241,37 @@ def colimitCoconeIsColimit : IsColimit (colimitCocone.{v} F) where
241241
erw [m.map_add, (descMorphism F s).map_add, ihx, ihy]
242242
#align AddCommGroup.colimits.colimit_cocone_is_colimit AddCommGroupCat.Colimits.colimitCoconeIsColimit
243243

244-
instance hasColimits_addCommGroupCat : HasColimits AddCommGroupCat
245-
where has_colimits_of_shape {_ _} :=
246-
{ has_colimit := fun F =>
247-
HasColimit.mk
248-
{ cocone := colimitCocone F
249-
isColimit := colimitCoconeIsColimit F } }
250-
#align AddCommGroup.colimits.has_colimits_AddCommGroup AddCommGroupCat.Colimits.hasColimits_addCommGroupCat
244+
end Colimits
245+
246+
lemma hasColimit : HasColimit F := ⟨_, Colimits.colimitCoconeIsColimit.{w} F⟩
247+
248+
variable (J)
251249

252-
end AddCommGroupCat.Colimits
250+
lemma hasColimitsOfShape : HasColimitsOfShape J AddCommGroupCat.{max u v w} where
251+
has_colimit F := hasColimit.{w} F
252+
253+
lemma hasColimitsOfSize : HasColimitsOfSize.{v, u} AddCommGroupCat.{max u v w} :=
254+
fun _ => hasColimitsOfShape.{w} _⟩
255+
256+
instance hasColimits : HasColimits AddCommGroupCat.{w} := hasColimitsOfSize.{w}
257+
#align AddCommGroup.colimits.has_colimits_AddCommGroup AddCommGroupCat.hasColimits
258+
259+
instance : HasColimitsOfSize.{v, v} (AddCommGroupCatMax.{u, v}) := hasColimitsOfSize.{u}
260+
instance : HasColimitsOfSize.{u, u} (AddCommGroupCatMax.{u, v}) := hasColimitsOfSize.{v}
261+
instance : HasColimitsOfSize.{u, v} (AddCommGroupCatMax.{u, v}) := hasColimitsOfSize.{u}
262+
instance : HasColimitsOfSize.{v, u} (AddCommGroupCatMax.{u, v}) := hasColimitsOfSize.{u}
263+
instance : HasColimitsOfSize.{0, 0} (AddCommGroupCat.{u}) := hasColimitsOfSize.{u, 0, 0}
264+
265+
example : HasColimits AddCommGroupCatMax.{v, u} :=
266+
inferInstance
267+
268+
example : HasColimits AddCommGroupCatMax.{u, v} :=
269+
inferInstance
270+
271+
example : HasColimits AddCommGroupCat.{u} :=
272+
inferInstance
273+
274+
end AddCommGroupCat
253275

254276
namespace AddCommGroupCat
255277

Mathlib/Algebra/Category/GroupCat/Limits.lean

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,6 @@ noncomputable section
2929

3030
variable {J : Type v} [SmallCategory J]
3131

32-
-- Porting note: typemax hack to fix universe complaints
33-
/-- An alias for `GroupCat.{max u v}`, to deal around unification issues. -/
34-
@[to_additive (attr := nolint checkUnivs)
35-
"An alias for `AddGroupCat.{max u v}`, to deal around unification issues."]
36-
abbrev GroupCatMax.{u1, u2} := GroupCat.{max u1 u2}
37-
38-
3932
namespace GroupCat
4033

4134
@[to_additive]
@@ -218,12 +211,6 @@ set_option linter.uppercaseLean3 false in
218211

219212
end GroupCat
220213

221-
-- Porting note: typemax hack to fix universe complaints
222-
/-- An alias for `CommGroupCat.{max u v}`, to deal around unification issues. -/
223-
@[to_additive (attr := nolint checkUnivs)
224-
"An alias for `AddCommGroupCat.{max u v}`, to deal around unification issues."]
225-
abbrev CommGroupCatMax.{u1, u2} := CommGroupCat.{max u1 u2}
226-
227214
namespace CommGroupCat
228215

229216
@[to_additive]

0 commit comments

Comments
 (0)