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

Commit 92e9d64

Browse files
kim-emdigama0
authored andcommitted
feat(category_theory): restating functor.map and nat_trans.app (#268)
1 parent e955897 commit 92e9d64

File tree

6 files changed

+72
-40
lines changed

6 files changed

+72
-40
lines changed

category_theory/functor.lean

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ Defines a functor between categories.
99
by the underlying function on objects, the name is capitalised.)
1010
1111
Introduces notations
12-
`C ↝ D` for the type of all functors from `C` to `D`. (I would like a better arrow here, unfortunately ⇒ (`\functor`) is taken by core.)
12+
`C ↝ D` for the type of all functors from `C` to `D`.
13+
(I would like a better arrow here, unfortunately ⇒ (`\functor`) is taken by core.)
1314
`F X` (a coercion) for a functor `F` acting on an object `X`.
1415
-/
1516

@@ -22,20 +23,20 @@ universes u₁ v₁ u₂ v₂ u₃ v₃
2223
/--
2324
`functor C D` represents a functor between categories `C` and `D`.
2425
25-
To apply a functor `F` to an object use `F X`, and to a morphism use `F.map f`.
26+
To apply a functor `F` to an object use `F X` (which uses a coercion), and to a morphism use `F.map f`.
2627
2728
The axiom `map_id_lemma` expresses preservation of identities, and
2829
`map_comp_lemma` expresses functoriality.
30+
31+
Implementation note: when constructing a `functor`, you need to define the
32+
`map'` field (which does not know about the coercion).
33+
When using a `functor`, use the `map` field (which makes use of the coercion).
2934
-/
3035
structure functor (C : Type u₁) [category.{u₁ v₁} C] (D : Type u₂) [category.{u₂ v₂} D] : Type (max u₁ v₁ u₂ v₂) :=
3136
(obj : C → D)
32-
(map : Π {X Y : C}, (X ⟶ Y) → ((obj X) ⟶ (obj Y)))
33-
(map_id : ∀ (X : C), map (𝟙 X) = 𝟙 (obj X) . obviously)
34-
(map_comp : ∀ {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z), map (f ≫ g) = (map f) ≫ (map g) . obviously)
35-
36-
restate_axiom functor.map_id
37-
restate_axiom functor.map_comp
38-
attribute [simp,ematch] functor.map_id_lemma functor.map_comp_lemma
37+
(map' : Π {X Y : C}, (X ⟶ Y) → ((obj X) ⟶ (obj Y)))
38+
(map_id : ∀ (X : C), map' (𝟙 X) = 𝟙 (obj X) . obviously)
39+
(map_comp : ∀ {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z), map' (f ≫ g) = (map' f) ≫ (map' g) . obviously)
3940

4041
infixr ` ↝ `:70 := functor -- type as \lea --
4142

@@ -49,7 +50,20 @@ instance : has_coe_to_fun (C ↝ D) :=
4950
{ F := λ F, C → D,
5051
coe := λ F, F.obj }
5152

52-
@[simp] lemma coe_def (F : C ↝ D) (X : C) : F X = F.obj X := rfl
53+
def map (F : C ↝ D) {X Y : C} (f : X ⟶ Y) : (F X) ⟶ (F Y) := F.map' f
54+
55+
@[simp,ematch] lemma map_id_lemma (F : C ↝ D) (X : C) : F.map (𝟙 X) = 𝟙 (F X) :=
56+
begin unfold functor.map, erw F.map_id, refl end
57+
@[simp,ematch] lemma map_comp_lemma (F : C ↝ D) {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) :
58+
F.map (f ≫ g) = F.map f ≫ F.map g :=
59+
begin unfold functor.map, erw F.map_comp end
60+
61+
-- We do not define a refl lemma unfolding the coercion.
62+
-- However we do provide lemmas for the coercion applied to an explicit structure.
63+
@[simp] lemma mk_obj (o : C → D) (m mi mc) (X : C) :
64+
({ functor . obj := o, map' := m, map_id := mi, map_comp := mc } : C ↝ D) X = o X := rfl
65+
@[simp] lemma mk_map (o : C → D) (m mi mc) {X Y : C} (f : X ⟶ Y) :
66+
functor.map { functor . obj := o, map' := m, map_id := mi, map_comp := mc } f = m f := rfl
5367
end
5468

5569
section
@@ -59,7 +73,7 @@ include 𝒞
5973
/-- `functor.id C` is the identity functor on a category `C`. -/
6074
protected def id : C ↝ C :=
6175
{ obj := λ X, X,
62-
map := λ _ _ f, f,
76+
map' := λ _ _ f, f,
6377
map_id := begin /- `obviously'` says: -/ intros, refl end,
6478
map_comp := begin /- `obviously'` says: -/ intros, refl end }
6579

@@ -70,22 +84,25 @@ variable {C}
7084
end
7185

7286
section
73-
variables {C : Type u₁} [𝒞 : category.{u₁ v₁} C] {D : Type u₂} [𝒟 : category.{u₂ v₂} D] {E : Type u₃} [ℰ : category.{u₃ v₃} E]
87+
variables {C : Type u₁} [𝒞 : category.{u₁ v₁} C]
88+
{D : Type u₂} [𝒟 : category.{u₂ v₂} D]
89+
{E : Type u₃} [ℰ : category.{u₃ v₃} E]
7490
include 𝒞 𝒟 ℰ
7591

7692
/--
7793
`F ⋙ G` is the composition of a functor `F` and a functor `G` (`F` first, then `G`).
7894
-/
7995
def comp (F : C ↝ D) (G : D ↝ E) : C ↝ E :=
80-
{ obj := λ X, G.obj (F.obj X),
81-
map := λ _ _ f, G.map (F.map f),
96+
{ obj := λ X, G (F X),
97+
map' := λ _ _ f, G.map (F.map f),
8298
map_id := begin /- `obviously'` says: -/ intros, simp end,
8399
map_comp := begin /- `obviously'` says: -/ intros, simp end }
84100

85101
infixr ` ⋙ `:80 := comp
86102

87103
@[simp] lemma comp_obj (F : C ↝ D) (G : D ↝ E) (X : C) : (F ⋙ G) X = G (F X) := rfl
88-
@[simp] lemma comp_map (F : C ↝ D) (G : D ↝ E) (X Y : C) (f : X ⟶ Y) : (F ⋙ G).map f = G.map (F.map f) := rfl
104+
@[simp] lemma comp_map (F : C ↝ D) (G : D ↝ E) (X Y : C) (f : X ⟶ Y) :
105+
(F ⋙ G).map f = G.map (F.map f) := rfl
89106
end
90107

91108
end functor

category_theory/functor_category.lean

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ open nat_trans
1616
Notice that if `C` and `D` are both small categories at the same universe level, this is another small category at that level.
1717
However if `C` and `D` are both large categories at the same universe level, this is a small category at the next higher level.
1818
-/
19-
instance functor.category (C : Type u₁) [category.{u₁ v₁} C] (D : Type u₂) [category.{u₂ v₂} D] : category.{(max u₁ v₁ u₂ v₂) (max u₁ v₂)} (C ↝ D) :=
19+
instance functor.category (C : Type u₁) [category.{u₁ v₁} C] (D : Type u₂) [category.{u₂ v₂} D] :
20+
category.{(max u₁ v₁ u₂ v₂) (max u₁ v₂)} (C ↝ D) :=
2021
{ hom := λ F G, F ⟹ G,
2122
id := λ F, nat_trans.id F,
2223
comp := λ _ _ _ α β, α ⊟ β,
@@ -31,18 +32,24 @@ variables {C : Type u₁} [𝒞 : category.{u₁ v₁} C] {D : Type u₂} [𝒟
3132
include 𝒞 𝒟
3233

3334
@[simp, ematch] lemma id_app (F : C ↝ D) (X : C) : (𝟙 F : F ⟹ F) X = 𝟙 (F X) := rfl
34-
@[simp, ematch] lemma comp_app {F G H : C ↝ D} (α : F ⟶ G) (β : G ⟶ H) (X : C) : ((α ≫ β) : F ⟹ H) X = (α : F ⟹ G) X ≫ (β : G ⟹ H) X := rfl
35+
@[simp, ematch] lemma comp_app {F G H : C ↝ D} (α : F ⟶ G) (β : G ⟶ H) (X : C) :
36+
((α ≫ β) : F ⟹ H) X = (α : F ⟹ G) X ≫ (β : G ⟹ H) X := rfl
3537
end
3638

3739
namespace nat_trans
38-
-- This section gives two lemmas about natural transformations between functors into functor categories, spelling them out in components.
40+
-- This section gives two lemmas about natural transformations between functors into functor categories,
41+
-- spelling them out in components.
3942

40-
variables {C : Type u₁} [𝒞 : category.{u₁ v₁} C] {D : Type u₂} [𝒟 : category.{u₂ v₂} D] {E : Type u₃} [ℰ : category.{u₃ v₃} E]
43+
variables {C : Type u₁} [𝒞 : category.{u₁ v₁} C]
44+
{D : Type u₂} [𝒟 : category.{u₂ v₂} D]
45+
{E : Type u₃} [ℰ : category.{u₃ v₃} E]
4146
include 𝒞 𝒟 ℰ
4247

43-
@[ematch] lemma app_naturality {F G : C ↝ (D ↝ E)} (T : F ⟹ G) (X : C) {Y Z : D} (f : Y ⟶ Z) : ((F X).map f) ≫ ((T X) Z) = ((T X) Y) ≫ ((G X).map f) := (T X).naturality f
48+
@[ematch] lemma app_naturality {F G : C ↝ (D ↝ E)} (T : F ⟹ G) (X : C) {Y Z : D} (f : Y ⟶ Z) :
49+
((F X).map f) ≫ ((T X) Z) = ((T X) Y) ≫ ((G X).map f) := (T X).naturality f
4450

45-
@[ematch] lemma naturality_app {F G : C ↝ (D ↝ E)} (T : F ⟹ G) (Z : D) {X Y : C} (f : X ⟶ Y) : ((F.map f) Z) ≫ ((T Y) Z) = ((T X) Z) ≫ ((G.map f) Z) := congr_fun (congr_arg app (T.naturality f)) Z
51+
@[ematch] lemma naturality_app {F G : C ↝ (D ↝ E)} (T : F ⟹ G) (Z : D) {X Y : C} (f : X ⟶ Y) :
52+
((F.map f) Z) ≫ ((T Y) Z) = ((T X) Z) ≫ ((G.map f) Z) := congr_fun (congr_arg app (T.naturality f)) Z
4653

4754
end nat_trans
4855

category_theory/natural_transformation.lean

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ structure nat_trans (F G : C ↝ D) : Type (max u₁ v₂) :=
3333
(app : Π X : C, (F X) ⟶ (G X))
3434
(naturality : ∀ {X Y : C} (f : X ⟶ Y), (F.map f) ≫ (app Y) = (app X) ≫ (G.map f) . obviously)
3535

36-
restate_axiom nat_trans.naturality
37-
attribute [ematch] nat_trans.naturality_lemma
38-
3936
infixr ` ⟹ `:50 := nat_trans -- type as \==> or ⟹
4037

4138
namespace nat_trans
@@ -44,12 +41,20 @@ instance {F G : C ↝ D} : has_coe_to_fun (F ⟹ G) :=
4441
{ F := λ α, Π X : C, (F X) ⟶ (G X),
4542
coe := λ α, α.app }
4643

47-
@[simp] lemma coe_def {F G : C ↝ D} (α : F ⟹ G) (X : C) : α X = α.app X := rfl
44+
@[simp] lemma mk_app {F G : C ↝ D} (app : Π X : C, (F X) ⟶ (G X)) (naturality) (X : C) :
45+
{ nat_trans . app := app, naturality := naturality } X = app X := rfl
46+
47+
@[ematch] lemma naturality_lemma {F G : C ↝ D} (α : F ⟹ G) {X Y : C} (f : X ⟶ Y) :
48+
(F.map f) ≫ (α Y) = (α X) ≫ (G.map f) :=
49+
begin
50+
/- `obviously'` says: -/
51+
erw nat_trans.naturality, refl
52+
end
4853

4954
/-- `nat_trans.id F` is the identity natural transformation on a functor `F`. -/
5055
protected def id (F : C ↝ D) : F ⟹ F :=
5156
{ app := λ X, 𝟙 (F X),
52-
naturality := begin /- `obviously'` says: -/ intros, dsimp, simp end }
57+
naturality := begin /- `obviously'` says: -/ intros, simp end }
5358

5459
@[simp] lemma id_app (F : C ↝ D) (X : C) : (nat_trans.id F) X = 𝟙 (F X) := rfl
5560

@@ -76,7 +81,8 @@ def vcomp (α : F ⟹ G) (β : G ⟹ H) : F ⟹ H :=
7681
notation α `⊟` β:80 := vcomp α β
7782

7883
@[simp] lemma vcomp_app (α : F ⟹ G) (β : G ⟹ H) (X : C) : (α ⊟ β) X = (α X) ≫ (β X) := rfl
79-
@[ematch] lemma vcomp_assoc (α : F ⟹ G) (β : G ⟹ H) (γ : H ⟹ I) : (α ⊟ β) ⊟ γ = (α ⊟ (β ⊟ γ)) := begin ext, intros, dsimp, rw [assoc] end
84+
@[ematch] lemma vcomp_assoc (α : F ⟹ G) (β : G ⟹ H) (γ : H ⟹ I) : (α ⊟ β) ⊟ γ = (α ⊟ (β ⊟ γ)) :=
85+
begin ext, intros, dsimp, rw [assoc] end
8086
end
8187

8288
variables {E : Type u₃} [ℰ : category.{u₃ v₃} E]
@@ -97,11 +103,13 @@ def hcomp {F G : C ↝ D} {H I : D ↝ E} (α : F ⟹ G) (β : H ⟹ I) : (F ⋙
97103

98104
notation α `◫` β:80 := hcomp α β
99105

100-
@[simp] lemma hcomp_app {F G : C ↝ D} {H I : D ↝ E} (α : F ⟹ G) (β : H ⟹ I) (X : C) : (α ◫ β) X = (β (F X)) ≫ (I.map (α X)) := rfl
106+
@[simp] lemma hcomp_app {F G : C ↝ D} {H I : D ↝ E} (α : F ⟹ G) (β : H ⟹ I) (X : C) :
107+
(α ◫ β) X = (β (F X)) ≫ (I.map (α X)) := rfl
101108

102109
-- Note that we don't yet prove a `hcomp_assoc` lemma here: even stating it is painful, because we need to use associativity of functor composition
103110

104-
@[ematch] lemma exchange {F G H : C ↝ D} {I J K : D ↝ E} (α : F ⟹ G) (β : G ⟹ H) (γ : I ⟹ J) (δ : J ⟹ K) : ((α ⊟ β) ◫ (γ ⊟ δ)) = ((α ◫ γ) ⊟ (β ◫ δ)) :=
111+
@[ematch] lemma exchange {F G H : C ↝ D} {I J K : D ↝ E} (α : F ⟹ G) (β : G ⟹ H) (γ : I ⟹ J) (δ : J ⟹ K) :
112+
((α ⊟ β) ◫ (γ ⊟ δ)) = ((α ◫ γ) ⊟ (β ◫ δ)) :=
105113
begin
106114
-- `obviously'` says:
107115
ext,

category_theory/opposites.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ include 𝒟
3333

3434
protected definition op (F : C ↝ D) : (Cᵒᵖ) ↝ (Dᵒᵖ) :=
3535
{ obj := λ X, F X,
36-
map := λ X Y f, F.map f,
37-
map_id := begin /- `obviously'` says: -/ intros, erw [map_id], refl, end,
38-
map_comp := begin /- `obviously'` says: -/ intros, erw [map_comp], refl end }
36+
map' := λ X Y f, F.map f,
37+
map_id := begin /- `obviously'` says: -/ intros, erw [map_id_lemma], refl, end,
38+
map_comp := begin /- `obviously'` says: -/ intros, erw [map_comp_lemma], refl end }
3939

4040
@[simp] lemma opposite_obj (F : C ↝ D) (X : C) : (F.op) X = F X := rfl
4141
@[simp] lemma opposite_map (F : C ↝ D) {X Y : C} (f : X ⟶ Y) : (F.op).map f = F.map f := rfl
@@ -46,7 +46,7 @@ variable (C)
4646
/-- `functor.hom` is the hom-pairing, sending (X,Y) to X → Y, contravariant in X and covariant in Y. -/
4747
definition hom : (Cᵒᵖ × C) ↝ (Type v₁) :=
4848
{ obj := λ p, @category.hom C _ p.1 p.2,
49-
map := λ X Y f, λ h, f.1 ≫ h ≫ f.2,
49+
map' := λ X Y f, λ h, f.1 ≫ h ≫ f.2,
5050
map_id := begin /- `obviously'` says: -/ intros, ext, intros, cases X, dsimp at *, simp, erw [category.id_comp_lemma] end,
5151
map_comp := begin /- `obviously'` says: -/ intros, ext, intros, cases f, cases g, cases X, cases Y, cases Z, dsimp at *, simp, erw [category.assoc] end }
5252

category_theory/products.lean

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,28 @@ namespace prod
4343
/-- `inl C Z` is the functor `X ↦ (X, Z)`. -/
4444
def inl (C : Type u₁) [category.{u₁ v₁} C] {D : Type u₁} [category.{u₁ v₁} D] (Z : D) : C ↝ (C × D) :=
4545
{ obj := λ X, (X, Z),
46-
map := λ X Y f, (f, 𝟙 Z),
46+
map' := λ X Y f, (f, 𝟙 Z),
4747
map_id := begin /- `obviously'` says: -/ intros, refl end,
4848
map_comp := begin /- `obviously'` says: -/ intros, dsimp, simp end }
4949

5050
/-- `inr D Z` is the functor `X ↦ (Z, X)`. -/
5151
def inr {C : Type u₁} [category.{u₁ v₁} C] (D : Type u₁) [category.{u₁ v₁} D] (Z : C) : D ↝ (C × D) :=
5252
{ obj := λ X, (Z, X),
53-
map := λ X Y f, (𝟙 Z, f),
53+
map' := λ X Y f, (𝟙 Z, f),
5454
map_id := begin /- `obviously'` says: -/ intros, refl end,
5555
map_comp := begin /- `obviously'` says: -/ intros, dsimp, simp end }
5656

5757
/-- `fst` is the functor `(X, Y) ↦ X`. -/
5858
def fst (C : Type u₁) [category.{u₁ v₁} C] (Z : C) (D : Type u₁) [category.{u₁ v₁} D] : (C × D) ↝ C :=
5959
{ obj := λ X, X.1,
60-
map := λ X Y f, f.1,
60+
map' := λ X Y f, f.1,
6161
map_id := begin /- `obviously'` says: -/ intros, refl end,
6262
map_comp := begin /- `obviously'` says: -/ intros, refl end }
6363

6464
/-- `snd` is the functor `(X, Y) ↦ Y`. -/
6565
def snd (C : Type u₁) [category.{u₁ v₁} C] (Z : C) (D : Type u₁) [category.{u₁ v₁} D] : (C × D) ↝ D :=
6666
{ obj := λ X, X.2,
67-
map := λ X Y f, f.2,
67+
map' := λ X Y f, f.2,
6868
map_id := begin /- `obviously'` says: -/ intros, refl end,
6969
map_comp := begin /- `obviously'` says: -/ intros, refl end }
7070

@@ -76,8 +76,8 @@ include 𝒜 ℬ 𝒞 𝒟
7676
namespace functor
7777
/-- The cartesian product of two functors. -/
7878
def prod (F : A ↝ B) (G : C ↝ D) : (A × C) ↝ (B × D) :=
79-
{ obj := λ X, (F X.1, G X.2),
80-
map := λ _ _ f, (F.map f.1, G.map f.2),
79+
{ obj := λ X, (F X.1, G X.2),
80+
map' := λ _ _ f, (F.map f.1, G.map f.2),
8181
map_id := begin /- `obviously'` says: -/ intros, cases X, dsimp, rw map_id_lemma, rw map_id_lemma end,
8282
map_comp := begin /- `obviously'` says: -/ intros, cases Z, cases Y, cases X, cases f, cases g, dsimp at *, rw map_comp_lemma, rw map_comp_lemma end }
8383

category_theory/types.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ end functor_to_types
4444

4545
definition ulift : (Type u) ↝ (Type (max u v)) :=
4646
{ obj := λ X, ulift.{v} X,
47-
map := λ X Y f, λ x : ulift.{v} X, ulift.up (f x.down),
47+
map' := λ X Y f, λ x : ulift.{v} X, ulift.up (f x.down),
4848
map_id := begin /- `obviously'` says: -/ intros, ext, refl end,
4949
map_comp := begin /- `obviously'` says: -/ intros, refl end }
5050

0 commit comments

Comments
 (0)