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

Commit 4db82a4

Browse files
committed
refactor(category_theory/cones): golf and cleanup cones (#6756)
No mathematical content here, basically just golfing and tidying in preparation for future PRs.
1 parent 56e5aa7 commit 4db82a4

File tree

2 files changed

+49
-70
lines changed

2 files changed

+49
-70
lines changed

src/category_theory/limits/cones.lean

Lines changed: 47 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ import category_theory.discrete_category
88
import category_theory.yoneda
99
import category_theory.reflects_isomorphisms
1010

11-
universes v u u' -- morphism levels before object levels. See note [category_theory universes].
11+
universes v u₁ u₂ -- morphism levels before object levels. See note [category_theory universes].
1212

1313
open category_theory
1414

1515
variables {J : Type v} [small_category J]
16-
variables {C : Type u} [category.{v} C]
16+
variables {K : Type v} [small_category K]
17+
variables {C : Type u₁} [category.{v} C]
18+
variables {D : Type u₂} [category.{v} D]
1719

1820
open category_theory
1921
open category_theory.category
@@ -31,7 +33,7 @@ natural transformations from the constant functor with value `X` to `F`.
3133
An object representing this functor is a limit of `F`.
3234
-/
3335
@[simps]
34-
def cones : Cᵒᵖ ⥤ Type v := (const J).op ⋙ (yoneda.obj F)
36+
def cones : Cᵒᵖ ⥤ Type v := (const J).op ⋙ yoneda.obj F
3537

3638
/--
3739
`F.cocones` is the functor assigning to an object `X` the type of
@@ -79,14 +81,11 @@ structure cone (F : J ⥤ C) :=
7981

8082
instance inhabited_cone (F : discrete punit ⥤ C) : inhabited (cone F) :=
8183
⟨{ X := F.obj punit.star,
82-
π :=
83-
{ app := λ X, match X with
84-
| punit.star := 𝟙 _
85-
end } }⟩
84+
π := { app := λ ⟨⟩, 𝟙 _ } }⟩
8685

8786
@[simp, reassoc] lemma cone.w {F : J ⥤ C} (c : cone F) {j j' : J} (f : j ⟶ j') :
8887
c.π.app j ≫ F.map f = c.π.app j' :=
89-
by { rw ← (c.π.naturality f), apply id_comp }
88+
by { rw ← c.π.naturality f, apply id_comp }
9089

9190
/--
9291
A `c : cocone F` is
@@ -101,41 +100,36 @@ structure cocone (F : J ⥤ C) :=
101100

102101
instance inhabited_cocone (F : discrete punit ⥤ C) : inhabited (cocone F) :=
103102
⟨{ X := F.obj punit.star,
104-
ι :=
105-
{ app := λ X, match X with
106-
| punit.star := 𝟙 _
107-
end } }⟩
103+
ι := { app := λ ⟨⟩, 𝟙 _ } }⟩
108104

109105
@[simp, reassoc] lemma cocone.w {F : J ⥤ C} (c : cocone F) {j j' : J} (f : j ⟶ j') :
110106
F.map f ≫ c.ι.app j' = c.ι.app j :=
111-
by { rw (c.ι.naturality f), apply comp_id }
107+
by { rw c.ι.naturality f, apply comp_id }
112108

113109
variables {F : J ⥤ C}
114110

115111
namespace cone
116112

117113
/-- The isomorphism between a cone on `F` and an element of the functor `F.cones`. -/
114+
@[simps]
118115
def equiv (F : J ⥤ C) : cone F ≅ Σ X, F.cones.obj X :=
119116
{ hom := λ c, ⟨op c.X, c.π⟩,
120-
inv := λ c, { X := unop c.1, π := c.2 },
121-
hom_inv_id' := begin ext1, cases x, refl, end,
122-
inv_hom_id' := begin ext1, cases x, refl, end }
117+
inv := λ c, { X := c.1.unop, π := c.2 },
118+
hom_inv_id' := by { ext1, cases x, refl },
119+
inv_hom_id' := by { ext1, cases x, refl } }
123120

124121
/-- A map to the vertex of a cone naturally induces a cone by composition. -/
125-
@[simp] def extensions (c : cone F) : yoneda.obj c.X ⟶ F.cones :=
122+
@[simps] def extensions (c : cone F) :
123+
yoneda.obj c.X ⟶ F.cones :=
126124
{ app := λ X f, (const J).map f ≫ c.π }
127125

128126
/-- A map to the vertex of a cone induces a cone by composition. -/
129-
@[simp] def extend (c : cone F) {X : C} (f : X ⟶ c.X) : cone F :=
127+
@[simps] def extend (c : cone F) {X : C} (f : X ⟶ c.X) : cone F :=
130128
{ X := X,
131129
π := c.extensions.app (op X) f }
132130

133-
@[simp] lemma extend_π (c : cone F) {X : Cᵒᵖ} (f : unop X ⟶ c.X) :
134-
(extend c f).π = c.extensions.app X f :=
135-
rfl
136-
137131
/-- Whisker a cone by precomposition of a functor. -/
138-
@[simps] def whisker {K : Type v} [small_category K] (E : K ⥤ J) (c : cone F) : cone (E ⋙ F) :=
132+
@[simps] def whisker (E : K ⥤ J) (c : cone F) : cone (E ⋙ F) :=
139133
{ X := c.X,
140134
π := whisker_left E c.π }
141135

@@ -147,27 +141,23 @@ namespace cocone
147141
def equiv (F : J ⥤ C) : cocone F ≅ Σ X, F.cocones.obj X :=
148142
{ hom := λ c, ⟨c.X, c.ι⟩,
149143
inv := λ c, { X := c.1, ι := c.2 },
150-
hom_inv_id' := begin ext1, cases x, refl, end,
151-
inv_hom_id' := begin ext1, cases x, refl, end }
144+
hom_inv_id' := by { ext1, cases x, refl },
145+
inv_hom_id' := by { ext1, cases x, refl } }
152146

153147
/-- A map from the vertex of a cocone naturally induces a cocone by composition. -/
154-
@[simp] def extensions (c : cocone F) : coyoneda.obj (op c.X) ⟶ F.cocones :=
148+
@[simps] def extensions (c : cocone F) : coyoneda.obj (op c.X) ⟶ F.cocones :=
155149
{ app := λ X f, c.ι ≫ (const J).map f }
156150

157151
/-- A map from the vertex of a cocone induces a cocone by composition. -/
158-
@[simp] def extend (c : cocone F) {X : C} (f : c.X ⟶ X) : cocone F :=
152+
@[simps] def extend (c : cocone F) {X : C} (f : c.X ⟶ X) : cocone F :=
159153
{ X := X,
160154
ι := c.extensions.app X f }
161155

162-
@[simp] lemma extend_ι (c : cocone F) {X : C} (f : c.X ⟶ X) :
163-
(extend c f).ι = c.extensions.app X f :=
164-
rfl
165-
166156
/--
167157
Whisker a cocone by precomposition of a functor. See `whiskering` for a functorial
168158
version.
169159
-/
170-
@[simps] def whisker {K : Type v} [small_category K] (E : K ⥤ J) (c : cocone F) : cocone (E ⋙ F) :=
160+
@[simps] def whisker (E : K ⥤ J) (c : cocone F) : cocone (E ⋙ F) :=
171161
{ X := c.X,
172162
ι := whisker_left E c.ι }
173163

@@ -183,10 +173,10 @@ restate_axiom cone_morphism.w'
183173
attribute [simp, reassoc] cone_morphism.w
184174

185175
instance inhabited_cone_morphism (A : cone F) : inhabited (cone_morphism A A) :=
186-
⟨{ hom := 𝟙 _}⟩
176+
⟨{ hom := 𝟙 _ }⟩
187177

188178
/-- The category of cones on a given diagram. -/
189-
@[simps] instance cone.category : category.{v} (cone F) :=
179+
@[simps] instance cone.category : category (cone F) :=
190180
{ hom := λ A B, cone_morphism A B,
191181
comp := λ X Y Z f g, { hom := f.hom ≫ g.hom },
192182
id := λ B, { hom := 𝟙 B.X } }
@@ -214,16 +204,17 @@ Functorially postcompose a cone for `F` by a natural transformation `F ⟶ G` to
214204
-/
215205
@[simps] def postcompose {G : J ⥤ C} (α : F ⟶ G) : cone F ⥤ cone G :=
216206
{ obj := λ c, { X := c.X, π := c.π ≫ α },
217-
map := λ c₁ c₂ f, { hom := f.hom, w' :=
218-
by intro; erw ← category.assoc; simp [-category.assoc] } }
207+
map := λ c₁ c₂ f, { hom := f.hom } }
219208

220209
/-- Postcomposing a cone by the composite natural transformation `α ≫ β` is the same as
221210
postcomposing by `α` and then by `β`. -/
211+
@[simps]
222212
def postcompose_comp {G H : J ⥤ C} (α : F ⟶ G) (β : G ⟶ H) :
223213
postcompose (α ≫ β) ≅ postcompose α ⋙ postcompose β :=
224214
nat_iso.of_components (λ s, cones.ext (iso.refl _) (by tidy)) (by tidy)
225215

226216
/-- Postcomposing by the identity does not change the cone up to isomorphism. -/
217+
@[simps]
227218
def postcompose_id : postcompose (𝟙 F) ≅ 𝟭 (cone F) :=
228219
nat_iso.of_components (λ s, cones.ext (iso.refl _) (by tidy)) (by tidy)
229220

@@ -242,37 +233,32 @@ def postcompose_equivalence {G : J ⥤ C} (α : F ≅ G) : cone F ≌ cone G :=
242233
Whiskering on the left by `E : K ⥤ J` gives a functor from `cone F` to `cone (E ⋙ F)`.
243234
-/
244235
@[simps]
245-
def whiskering {K : Type v} [small_category K] (E : K ⥤ J) : cone F ⥤ cone (E ⋙ F) :=
236+
def whiskering (E : K ⥤ J) : cone F ⥤ cone (E ⋙ F) :=
246237
{ obj := λ c, c.whisker E,
247-
map := λ c c' f, { hom := f.hom, } }
238+
map := λ c c' f, { hom := f.hom } }
248239

249240
/--
250241
Whiskering by an equivalence gives an equivalence between categories of cones.
251242
-/
252243
@[simps]
253-
def whiskering_equivalence {K : Type v} [small_category K] (e : K ≌ J) :
244+
def whiskering_equivalence (e : K ≌ J) :
254245
cone F ≌ cone (e.functor ⋙ F) :=
255246
{ functor := whiskering e.functor,
256-
inverse := whiskering e.inverse ⋙
257-
postcompose ((functor.associator _ _ _).inv ≫ (whisker_right (e.counit_iso).hom F) ≫
258-
(functor.left_unitor F).hom),
247+
inverse := whiskering e.inverse ⋙ postcompose (e.inv_fun_id_assoc F).hom,
259248
unit_iso := nat_iso.of_components (λ s, cones.ext (iso.refl _) (by tidy)) (by tidy),
260249
counit_iso := nat_iso.of_components (λ s, cones.ext (iso.refl _)
261250
(begin
262251
intro k,
263-
have t := s.π.naturality (e.unit_inv.app k),
264-
dsimp at t,
265-
simp only [←e.counit_app_functor k, id_comp] at t,
266-
dsimp,
267-
simp [t],
252+
dsimp, -- See library note [dsimp, simp]
253+
simpa [e.counit_app_functor] using s.w (e.unit_inv.app k),
268254
end)) (by tidy), }
269255

270256
/--
271257
The categories of cones over `F` and `G` are equivalent if `F` and `G` are naturally isomorphic
272258
(possibly after changing the indexing category by an equivalence).
273259
-/
274-
@[simps functor_obj]
275-
def equivalence_of_reindexing {K : Type v} [small_category K] {G : K ⥤ C}
260+
@[simps functor inverse unit_iso counit_iso]
261+
def equivalence_of_reindexing {G : K ⥤ C}
276262
(e : K ≌ J) (α : e.functor ⋙ F ≅ G) : cone F ≌ cone G :=
277263
(whiskering_equivalence e).trans (postcompose_equivalence α)
278264

@@ -284,7 +270,7 @@ variable (F)
284270
def forget : cone F ⥤ C :=
285271
{ obj := λ t, t.X, map := λ s t f, f.hom }
286272

287-
variables {D : Type u'} [category.{v} D] (G : C ⥤ D)
273+
variables (G : C ⥤ D)
288274

289275
/-- A functor `G : C ⥤ D` sends cones over `F` to cones over `F ⋙ G` functorially. -/
290276
@[simps] def functoriality : cone F ⥤ cone (F ⋙ G) :=
@@ -293,7 +279,7 @@ variables {D : Type u'} [category.{v} D] (G : C ⥤ D)
293279
π := { app := λ j, G.map (A.π.app j), naturality' := by intros; erw ←G.map_comp; tidy } },
294280
map := λ X Y f,
295281
{ hom := G.map f.hom,
296-
w' := by intros; rw [←functor.map_comp, f.w] } }
282+
w' := λ j, by simp [-cone_morphism.w, ←f.w j] } }
297283

298284
instance functoriality_full [full G] [faithful G] : full (functoriality F G) :=
299285
{ preimage := λ X Y t,
@@ -348,7 +334,7 @@ instance inhabited_cocone_morphism (A : cocone F) : inhabited (cocone_morphism A
348334
restate_axiom cocone_morphism.w'
349335
attribute [simp, reassoc] cocone_morphism.w
350336

351-
@[simps] instance cocone.category : category.{v} (cocone F) :=
337+
@[simps] instance cocone.category : category (cocone F) :=
352338
{ hom := λ A B, cocone_morphism A B,
353339
comp := λ _ _ _ f g,
354340
{ hom := f.hom ≫ g.hom },
@@ -403,15 +389,15 @@ def precompose_equivalence {G : J ⥤ C} (α : G ≅ F) : cocone F ≌ cocone G
403389
Whiskering on the left by `E : K ⥤ J` gives a functor from `cocone F` to `cocone (E ⋙ F)`.
404390
-/
405391
@[simps]
406-
def whiskering {K : Type v} [small_category K] (E : K ⥤ J) : cocone F ⥤ cocone (E ⋙ F) :=
392+
def whiskering (E : K ⥤ J) : cocone F ⥤ cocone (E ⋙ F) :=
407393
{ obj := λ c, c.whisker E,
408394
map := λ c c' f, { hom := f.hom, } }
409395

410396
/--
411397
Whiskering by an equivalence gives an equivalence between categories of cones.
412398
-/
413399
@[simps]
414-
def whiskering_equivalence {K : Type v} [small_category K] (e : K ≌ J) :
400+
def whiskering_equivalence (e : K ≌ J) :
415401
cocone F ≌ cocone (e.functor ⋙ F) :=
416402
{ functor := whiskering e.functor,
417403
inverse := whiskering e.inverse ⋙
@@ -421,19 +407,16 @@ def whiskering_equivalence {K : Type v} [small_category K] (e : K ≌ J) :
421407
counit_iso := nat_iso.of_components (λ s, cocones.ext (iso.refl _)
422408
(begin
423409
intro k,
424-
have t := s.ι.naturality (e.unit.app k),
425-
dsimp at t,
426-
simp only [←e.counit_inv_app_functor k, comp_id] at t,
427410
dsimp,
428-
simp [t],
411+
simpa [e.counit_inv_app_functor k] using s.w (e.unit.app k),
429412
end)) (by tidy), }
430413

431414
/--
432415
The categories of cocones over `F` and `G` are equivalent if `F` and `G` are naturally isomorphic
433416
(possibly after changing the indexing category by an equivalence).
434417
-/
435418
@[simps functor_obj]
436-
def equivalence_of_reindexing {K : Type v} [small_category K] {G : K ⥤ C}
419+
def equivalence_of_reindexing {G : K ⥤ C}
437420
(e : K ≌ J) (α : e.functor ⋙ F ≅ G) : cocone F ≌ cocone G :=
438421
(whiskering_equivalence e).trans (precompose_equivalence α.symm)
439422

@@ -445,7 +428,7 @@ variable (F)
445428
def forget : cocone F ⥤ C :=
446429
{ obj := λ t, t.X, map := λ s t f, f.hom }
447430

448-
variables {D : Type u'} [category.{v} D] (G : C ⥤ D)
431+
variables (G : C ⥤ D)
449432

450433
/-- A functor `G : C ⥤ D` sends cocones over `F` to cocones over `F ⋙ G` functorially. -/
451434
@[simps] def functoriality : cocone F ⥤ cocone (F ⋙ G) :=
@@ -510,7 +493,6 @@ end limits
510493

511494
namespace functor
512495

513-
variables {D : Type u'} [category.{v} D]
514496
variables {F : J ⥤ C} {G : J ⥤ C} (H : C ⥤ D)
515497

516498
open category_theory.limits
@@ -636,8 +618,6 @@ def map_cocone_precompose_equivalence_functor {α : F ≅ G} {c} :
636618
(cocones.precompose_equivalence (iso_whisker_right α H : _)).functor.obj (H.map_cocone c) :=
637619
cocones.ext (iso.refl _) (by tidy)
638620

639-
variables {K : Type v} [small_category K]
640-
641621
/--
642622
`map_cone` commutes with `whisker`
643623
-/
@@ -682,16 +662,14 @@ variables {F : J ⥤ C}
682662
{ X := unop c.X,
683663
π :=
684664
{ app := λ j, (c.ι.app (op j)).unop,
685-
naturality' := λ j j' f, has_hom.hom.op_inj
686-
begin dsimp, simp only [comp_id], exact (c.w f.op).symm, end } }
665+
naturality' := λ j j' f, has_hom.hom.op_inj (c.ι.naturality f.op).symm } }
687666

688667
/-- Change a `cone F.op` into a `cocone F`. -/
689668
@[simps] def cone.unop (c : cone F.op) : cocone F :=
690669
{ X := unop c.X,
691670
ι :=
692671
{ app := λ j, (c.π.app (op j)).unop,
693-
naturality' := λ j j' f, has_hom.hom.op_inj
694-
begin dsimp, simp only [id_comp], exact (c.w f.op), end } }
672+
naturality' := λ j j' f, has_hom.hom.op_inj (c.π.naturality f.op).symm } }
695673

696674
variables (F)
697675

@@ -778,16 +756,17 @@ namespace category_theory.functor
778756
open category_theory.limits
779757

780758
variables {F : J ⥤ C}
781-
variables {D : Type u'} [category.{v} D]
782759

783760
section
784761
variables (G : C ⥤ D)
785762

786763
/-- The opposite cocone of the image of a cone is the image of the opposite cocone. -/
764+
@[simps {rhs_md := semireducible}]
787765
def map_cone_op (t : cone F) : (G.map_cone t).op ≅ (G.op.map_cocone t.op) :=
788766
cocones.ext (iso.refl _) (by tidy)
789767

790768
/-- The opposite cone of the image of a cocone is the image of the opposite cone. -/
769+
@[simps {rhs_md := semireducible}]
791770
def map_cocone_op {t : cocone F} : (G.map_cocone t).op ≅ (G.op.map_cone t.op) :=
792771
cones.ext (iso.refl _) (by tidy)
793772

src/category_theory/limits/is_limit.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ def of_nat_iso {X : C} (h : yoneda.obj X ≅ F.cones) :
449449
rw ←hom_of_cone_of_hom h m,
450450
congr,
451451
rw cone_of_hom_fac,
452-
dsimp, cases s, congr' with j, exact w j,
452+
dsimp [cone.extend], cases s, congr' with j, exact w j,
453453
end }
454454
end
455455

@@ -864,7 +864,7 @@ def of_nat_iso {X : C} (h : coyoneda.obj (op X) ≅ F.cocones) :
864864
rw ←hom_of_cocone_of_hom h m,
865865
congr,
866866
rw cocone_of_hom_fac,
867-
dsimp, cases s, congr' with j, exact w j,
867+
dsimp [cocone.extend], cases s, congr' with j, exact w j,
868868
end }
869869
end
870870

0 commit comments

Comments
 (0)