Skip to content

Commit 351c9de

Browse files
committed
Add section_1_4 and exercises.
1 parent 6a37d38 commit 351c9de

2 files changed

Lines changed: 131 additions & 15 deletions

File tree

CategoryTheoryInContextLean/Section_1_3.lean

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ class Functor (α β : Type*) [C : Category α] [D : Category β] where
2828

2929
def EndoFunctor (α : Type*) [Category α] := @Functor α α
3030

31+
def IdFunctor {α : Type*} [Category α] : Functor α α where
32+
F X := X
33+
homF f := f
34+
map_id _ := rfl
35+
map_comp _ _ := rfl
36+
3137
-- examples 1.3.2.i
3238
def PowerSetFunctor : Functor Type Type where
3339
F X := Set X
@@ -100,20 +106,20 @@ def g_set_right_action (α : Type*) [Group α] (β : Type*) :
100106
-- todo: corollary 1.3.10, we haven't defined ⁻¹ on isomorphisms yet
101107

102108
-- definition 1.3.11 / exercise 1.3.iv
103-
def Hom_c_? (α : Type*) [Category α] (c : α) : Functor α Type where
109+
def Hom_c_? {α : Type*} [Category α] (c : α) : Functor α Type where
104110
F Y := Hom c Y
105111
homF {Y Z : α} (f : Hom Y Z) (g : Hom c Y) := g ≫ f
106112
map_id Y := by sorry
107113
map_comp {Y Z W : α} (f : Hom Y Z) (g : Hom Z W) := by sorry
108114

109-
def Hom_?_c (α : Type*) [Category α] (c : α) : ContraFunctor α Type where
115+
def Hom_?_c {α : Type*} [Category α] (c : α) : ContraFunctor α Type where
110116
F X := Hom X c
111117
homF {X Y : α} (f: Hom X Y) (g : Hom Y c) := f ≫ g
112118
map_id X := by sorry
113119
map_comp {X Y Z : α} (f : Hom X Y) (g : Hom Y Z) := by sorry
114120

115121
-- definition 1.3.12
116-
instance CatProduct {α β : Type*} [C : Category α] [D : Category β] : Category (Prod α β) where
122+
instance CatProduct {α β : Type*} [C : Category α] [D : Category β] : Category (α × β) where
117123
Hom X Y := (C.Hom X.1 Y.1) × (D.Hom X.2 Y.2)
118124
id X := (id X.1, id X.2)
119125
comp f g := (f.1 ≫ g.1, f.2 ≫ g.2)
@@ -129,7 +135,7 @@ fixing an object in the other factor.
129135
this is not proved in the book, but it is easy to prove and useful
130136
-/
131137
def prod_functor_functorial_1 {α β γ : Type*} [C : Category α] [D : Category β]
132-
[Inhabited β] [E : Category γ] (F : Functor (Prod α β) γ) : Functor α γ where
138+
[Inhabited β] [E : Category γ] (F : Functor (α × β) γ) : Functor α γ where
133139
F := fun X => F.F (X, default)
134140
homF := fun {X Y} f => F.homF (f, id default)
135141
map_id X := by
@@ -141,7 +147,7 @@ def prod_functor_functorial_1 {α β γ : Type*} [C : Category α] [D : Category
141147
rw [id_comp]
142148

143149
def prod_functor_functorial_2 {α β γ : Type*} [C : Category α] [D : Category β]
144-
[Inhabited α] [E : Category γ] (F : Functor (Prod α β) γ) : Functor β γ where
150+
[Inhabited α] [E : Category γ] (F : Functor (α × β) γ) : Functor β γ where
145151
-- todo: find a clever way to prove using prod_functor_functorial_1
146152
F := fun Y => F.F (default, Y)
147153
homF := fun {Y Z} f => F.homF (id default, f)
@@ -154,7 +160,7 @@ def prod_functor_functorial_2 {α β γ : Type*} [C : Category α] [D : Category
154160
rw [comp_id]
155161

156162
-- definition 1.3.13
157-
def Hom_bifunctor (α : Type*) [C : Category α] : Functor (Prod (Opposite α) α) Type where
163+
def Hom_bifunctor (α : Type*) [C : Category α] : Functor (Opposite α × α) Type where
158164
-- without the C. qualification Lean picks up C.opp.Hom and hilarity ensues
159165
F X := C.Hom X.1 X.2
160166
homF {X Y} f g := f.1 ≫ g ≫ f.2
@@ -177,6 +183,13 @@ def Hom_bifunctor (α : Type*) [C : Category α] : Functor (Prod (Opposite α)
177183
def Cat.{u, v} : Type (max (u+1) (v+1)) :=
178184
Σ (α : Type u), Category.{u, v} α
179185

186+
def Functor.comp {α β γ : Type*} [C : Category α] [D : Category β] [E : Category γ]
187+
(F : Functor α β) (G : Functor β γ) : Functor α γ where
188+
F x := G.F (F.F x)
189+
homF f := G.homF (F.homF f)
190+
map_id X := by simp [F.map_id, G.map_id]
191+
map_comp f g := by simp [F.map_comp, G.map_comp]
192+
180193
universe u v
181194
instance : Category Cat.{u, v} where
182195
Hom C D := @Functor C.1 D.1 C.2 D.2
@@ -187,15 +200,10 @@ instance : Category Cat.{u, v} where
187200
map_id _ := rfl
188201
map_comp _ _ := rfl
189202
}
190-
comp {C D E} F G := letI := C.2; letI := D.2; letI := E.2; {
191-
F x := G.F (F.F x)
192-
homF f := G.homF (F.homF f)
193-
map_id X := by simp [F.map_id, G.map_id]
194-
map_comp f g := by simp [F.map_comp, G.map_comp]
195-
}
196-
id_comp := by simp
197-
comp_id := by simp
198-
assoc := by simp
203+
comp {C D E} F G := @Functor.comp C.1 D.1 E.1 C.2 D.2 E.2 F G
204+
id_comp := by dsimp [Functor.comp]; simp
205+
comp_id := by dsimp [Functor.comp]; simp
206+
assoc := by dsimp [Functor.comp]; simp
199207

200208
def Category.CatIsomorphism (C D : Cat) := Isomorphism C.1 D.1
201209
def Category.CatIsomorphic (C D : Cat) := Isomorphic C.1 D.1
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import CategoryTheoryInContextLean.Section_1_1
2+
import CategoryTheoryInContextLean.Section_1_2
3+
import CategoryTheoryInContextLean.Section_1_3
4+
5+
/-!
6+
# Category Theory in Context - Section 1.4
7+
8+
We introduce natural transformations.
9+
10+
We continue to use the custom definition of a category, functor, etc, from Chapter 1.
11+
-/
12+
13+
namespace CategoryInContext
14+
open Category
15+
16+
-- definition 1.4.1
17+
class NaturalTransformation {α β : Type*} [C : Category α] [D : Category β]
18+
(F G : Functor α β) where
19+
arrow : (X : α) → D.Hom (F.F X) (G.F X)
20+
naturality : ∀ {X Y : α} (f : C.Hom X Y),
21+
arrow X ≫ G.homF f = F.homF f ≫ arrow Y
22+
23+
def IsNatIso {α β : Type*} [C : Category α] [D : Category β]
24+
{F G : Functor α β} (η : NaturalTransformation F G) : Prop :=
25+
∀ (X : α), IsIso (η.arrow X)
26+
27+
-- example 1.4.3iii
28+
def NatTrans_Id_PowerSet : NaturalTransformation IdFunctor PowerSetFunctor where
29+
arrow X := fun x => ({x} : Set X)
30+
naturality {X Y} f := by
31+
funext x
32+
simp only [Category.comp, Function.comp_apply, IdFunctor, PowerSetFunctor]
33+
rw [Set.image]
34+
simp
35+
36+
-- todo: add more examples from 1.4.3
37+
-- todo: add examples 1.4.4-6
38+
39+
-- example 1.4.7
40+
def NatTrans_Hom_c_?_Hom_?_c {α : Type*} [C : Category α] (c d : α) (h : Hom c d) :
41+
NaturalTransformation (Hom_c_? d) (Hom_c_? c) where
42+
arrow X := fun f => h ≫ f
43+
naturality {X Y} f := by
44+
funext g
45+
simp only [Category.comp, Function.comp_apply, Hom_c_?]
46+
rw [assoc]
47+
48+
-- technically we haven't defined natural transformations for contravariant functors.
49+
-- def NatTrans_Hom_?_c_Hom_c_? {α : Type*} [C : Category α] (c d : α) (h : Hom c d) :
50+
-- NaturalTransformation (Hom_?_c d) (Hom_?_c c) where
51+
52+
-- todo: add example 1.4.8
53+
-- exercise 1.4.i
54+
noncomputable def NatIso_inverse {α β : Type*} [C : Category α] [D : Category β]
55+
{F G : Functor α β} (η : NaturalTransformation F G) (h : IsNatIso η) :
56+
NaturalTransformation G F where
57+
arrow X := by
58+
have := h X
59+
rw [iso_iff_isIso] at this
60+
choose f hf using this
61+
exact f.inv
62+
63+
naturality {X Y} f := by
64+
sorry
65+
66+
theorem NatIso_inverse_isNatIso {α β : Type*} [C : Category α] [D : Category β]
67+
{F G : Functor α β} (η : NaturalTransformation F G) (h : IsNatIso η) :
68+
IsNatIso (NatIso_inverse η h) := by sorry
69+
70+
-- todo: exercise 1.4.ii, iii - are "what" problems formalizable in Lean?
71+
72+
-- exercise 1.4.iv
73+
theorem NatTrans_Hom_c_?_Hom_?_c_distinct {α : Type*} [C : Category α] (c d : α)
74+
(h1 h2 : Hom c d) (h : h1 ≠ h2) :
75+
NatTrans_Hom_c_?_Hom_?_c c d h1 ≠ NatTrans_Hom_c_?_Hom_?_c c d h2 := by sorry
76+
77+
-- exercise 1.4.v
78+
-- Natural transformation from G ∘ π₂ to F ∘ π₁ for comma category (F ↓ G)
79+
def Comma_NatTrans {C D E : Type*} [CC : Category C] [CD : Category D] [CE : Category E]
80+
(F : Functor D C) (G : Functor E C) :
81+
let CommaType := Σ (d : D) (e : E), Category.Hom (F.F d) (G.F e)
82+
letI : Category CommaType := Comma_category F G
83+
NaturalTransformation
84+
(Functor.comp (Comma_category_cod F G) G)
85+
(Functor.comp (Comma_category_dom F G) F) where
86+
arrow X := sorry
87+
naturality {X Y} f := by sorry
88+
89+
-- exercise 1.4.vi
90+
class ExtraNatrualTransformation {α β γ δ : Type*} [Category α] [Category β] [Category γ]
91+
[Category δ] (F : Functor (α × β × Opposite β) δ) (G : Functor (α × γ × Opposite γ) δ) where
92+
93+
arrow : (a : α) → (b : β) → (c : γ) → Hom (F.F (a, b, b)) (G.F (a, c, c))
94+
95+
lhs_prop {a a': α} {b : β} {c: γ} (f: Hom a a') :
96+
(arrow a b c) ≫ G.homF (f, id c, id c) = F.homF (f, id b, id b) ≫ (arrow a' b c)
97+
98+
-- type cast needed to avoid a mysterious error
99+
mid_prop {a : α} {b b' : β} {c : γ} (g : Hom b b') :
100+
F.homF (id a, g, id b') ≫ (arrow a b' c) = F.homF ((id a, id b, g) :
101+
@Category.Hom (α × β × Opposite β) _ (a, b, b') (a, b, b)) ≫ (arrow a b c)
102+
103+
-- type cast needed to avoid a mysterious error
104+
rhs_prop {a : α} {b : β} {c c' : γ} (h : Hom c c') :
105+
arrow a b c ≫ G.homF (id a, h, id c) = arrow a b c' ≫ G.homF ((id a, id c', h) :
106+
@Category.Hom (α × γ × Opposite γ) _ (a, c', c') (a, c', c))
107+
108+
end CategoryInContext

0 commit comments

Comments
 (0)