forked from leanprover-community/mathlib4
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBasic.lean
More file actions
365 lines (290 loc) · 11.2 KB
/
Copy pathBasic.lean
File metadata and controls
365 lines (290 loc) · 11.2 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon, Kim Morrison
-/
module
public import Mathlib.CategoryTheory.EqToHom
public import Mathlib.CategoryTheory.NatIso
public import Mathlib.CategoryTheory.Products.Basic
/-!
# Categories of indexed families of objects.
We define the pointwise category structure on indexed families of objects in a category
(and also the dependent generalization).
-/
@[expose] public section
namespace CategoryTheory
open Functor
universe w₀ w₁ w₂ v₁ v₂ v₃ u₁ u₂ u₃
variable {I : Type w₀} {J : Type w₁} (C : I → Type u₁) [∀ i, Category.{v₁} (C i)]
/-- `pi C` gives the Cartesian product of an indexed family of categories.
-/
instance pi : Category.{max w₀ v₁} (∀ i, C i) where
Hom X Y := ∀ i, X i ⟶ Y i
id X i := 𝟙 (X i)
comp f g i := f i ≫ g i
namespace Pi
@[simp]
theorem id_apply (X : ∀ i, C i) (i) : (𝟙 X : ∀ i, X i ⟶ X i) i = 𝟙 (X i) :=
rfl
@[simp]
theorem comp_apply {X Y Z : ∀ i, C i} (f : X ⟶ Y) (g : Y ⟶ Z) (i) :
(f ≫ g : ∀ i, X i ⟶ Z i) i = f i ≫ g i :=
rfl
@[ext]
lemma ext {X Y : ∀ i, C i} {f g : X ⟶ Y} (w : ∀ i, f i = g i) : f = g :=
funext (w ·)
/--
The evaluation functor at `i : I`, sending an `I`-indexed family of objects to the object over `i`.
-/
@[simps]
def eval (i : I) : (∀ i, C i) ⥤ C i where
obj f := f i
map α := α i
section
variable {J : Type w₁}
instance (f : J → I) : (j : J) → Category ((C ∘ f) j) :=
inferInstanceAs <| (j : J) → Category (C (f j))
/-- Pull back an `I`-indexed family of objects to a `J`-indexed family, along a function `J → I`.
-/
@[simps]
def comap (h : J → I) : (∀ i, C i) ⥤ (∀ j, C (h j)) where
obj f i := f (h i)
map α i := α (h i)
variable (I)
set_option backward.isDefEq.respectTransparency false in
/-- The natural isomorphism between
pulling back a grading along the identity function,
and the identity functor. -/
@[simps]
def comapId : comap C (id : I → I) ≅ 𝟭 (∀ i, C i) where
hom := { app := fun X => 𝟙 X }
inv := { app := fun X => 𝟙 X }
example (g : J → I) : (j : J) → Category (C (g j)) := by infer_instance
variable {I}
variable {K : Type w₂}
set_option backward.isDefEq.respectTransparency false in
/-- The natural isomorphism comparing between
pulling back along two successive functions, and
pulling back along their composition
-/
@[simps!]
def comapComp (f : K → J) (g : J → I) : comap C g ⋙ comap (C ∘ g) f ≅ comap C (g ∘ f) where
hom :=
{ app := fun X b => 𝟙 (X (g (f b)))
naturality := fun X Y f' => by simp only [comap, Function.comp]; funext; simp }
inv :=
{ app := fun X b => 𝟙 (X (g (f b)))
naturality := fun X Y f' => by simp only [comap, Function.comp]; funext; simp }
set_option backward.isDefEq.respectTransparency false in
/-- The natural isomorphism between pulling back then evaluating, and just evaluating. -/
@[simps!]
def comapEvalIsoEval (h : J → I) (j : J) : comap C h ⋙ eval (C ∘ h) j ≅ eval C (h j) :=
NatIso.ofComponents (fun _ => Iso.refl _) (by simp)
end
section
variable {J : Type w₀} {D : J → Type u₁} [∀ j, Category.{v₁} (D j)]
instance sumElimCategory : ∀ s : I ⊕ J, Category.{v₁} (Sum.elim C D s)
| Sum.inl i => inferInstanceAs <| Category (C i)
| Sum.inr j => inferInstanceAs <| Category (D j)
set_option backward.isDefEq.respectTransparency false in
/-- The bifunctor combining an `I`-indexed family of objects with a `J`-indexed family of objects
to obtain an `I ⊕ J`-indexed family of objects.
-/
@[simps]
def sum : (∀ i, C i) ⥤ (∀ j, D j) ⥤ ∀ s : I ⊕ J, Sum.elim C D s where
obj X :=
{ obj := fun Y s =>
match s with
| .inl i => X i
| .inr j => Y j
map := fun {_} {_} f s =>
match s with
| .inl i => 𝟙 (X i)
| .inr j => f j }
map {X} {X'} f :=
{ app := fun Y s =>
match s with
| .inl i => f i
| .inr j => 𝟙 (Y j) }
end
variable {C}
/-- A family of isomorphisms gives rise to an isomorphism of families. -/
@[simps]
def isoMk {X Y : ∀ i, C i} (iso : ∀ i, X i ≅ Y i) :
X ≅ Y where
hom := fun i => (iso i).hom
inv := fun i => (iso i).inv
/-- An isomorphism between `I`-indexed objects gives an isomorphism between each
pair of corresponding components. -/
@[simps]
def isoApp {X Y : ∀ i, C i} (f : X ≅ Y) (i : I) : X i ≅ Y i :=
⟨f.hom i, f.inv i,
by rw [← comp_apply, Iso.hom_inv_id, id_apply], by rw [← comp_apply, Iso.inv_hom_id, id_apply]⟩
@[simp]
theorem isoApp_refl (X : ∀ i, C i) (i : I) : isoApp (Iso.refl X) i = Iso.refl (X i) :=
rfl
@[simp]
theorem isoApp_symm {X Y : ∀ i, C i} (f : X ≅ Y) (i : I) : isoApp f.symm i = (isoApp f i).symm :=
rfl
@[simp]
theorem isoApp_trans {X Y Z : ∀ i, C i} (f : X ≅ Y) (g : Y ≅ Z) (i : I) :
isoApp (f ≪≫ g) i = isoApp f i ≪≫ isoApp g i :=
rfl
end Pi
namespace Functor
variable {C}
variable {D : I → Type u₂} [∀ i, Category.{v₂} (D i)] {A : Type u₃} [Category.{v₃} A]
/-- Assemble an `I`-indexed family of functors into a functor between the pi types.
-/
@[simps]
def pi (F : ∀ i, C i ⥤ D i) : (∀ i, C i) ⥤ ∀ i, D i where
obj f i := (F i).obj (f i)
map α i := (F i).map (α i)
/-- Similar to `pi`, but all functors come from the same category `A`
-/
@[simps]
def pi' (f : ∀ i, A ⥤ C i) : A ⥤ ∀ i, C i where
obj a i := (f i).obj a
map h i := (f i).map h
/-- The projections of `Functor.pi' F` are isomorphic to the functors of the family `F` -/
@[simps!]
def pi'CompEval {A : Type*} [Category* A] (F : ∀ i, A ⥤ C i) (i : I) :
pi' F ⋙ Pi.eval C i ≅ F i :=
Iso.refl _
section EqToHom
@[simp]
theorem eqToHom_proj {x x' : ∀ i, C i} (h : x = x') (i : I) :
(eqToHom h : x ⟶ x') i = eqToHom (funext_iff.mp h i) := by
subst h
rfl
end EqToHom
-- One could add some natural isomorphisms showing
-- how `Functor.pi` commutes with `Pi.eval` and `Pi.comap`.
@[simp]
theorem pi'_eval (f : ∀ i, A ⥤ C i) (i : I) : pi' f ⋙ Pi.eval C i = f i :=
rfl
/-- Two functors to a product category are equal iff they agree on every coordinate. -/
theorem pi_ext (f f' : A ⥤ ∀ i, C i) (h : ∀ i, f ⋙ (Pi.eval C i) = f' ⋙ (Pi.eval C i)) :
f = f' := by
apply Functor.ext; rotate_left
· intro X
ext i
specialize h i
have := congr_obj h X
simpa
· intro X Y g
funext i
specialize h i
have := congr_hom h g
simpa
end Functor
namespace NatTrans
variable {C}
variable {D : I → Type u₂} [∀ i, Category.{v₂} (D i)]
variable {F G : ∀ i, C i ⥤ D i}
/-- Assemble an `I`-indexed family of natural transformations into a single natural transformation.
-/
@[simps!]
def pi (α : ∀ i, F i ⟶ G i) : Functor.pi F ⟶ Functor.pi G where
app f i := (α i).app (f i)
/-- Assemble an `I`-indexed family of natural transformations into a single natural transformation.
-/
@[simps]
def pi' {E : Type*} [Category* E] {F G : E ⥤ ∀ i, C i}
(τ : ∀ i, F ⋙ Pi.eval C i ⟶ G ⋙ Pi.eval C i) : F ⟶ G where
app := fun X i => (τ i).app X
naturality _ _ f := by
ext i
exact (τ i).naturality f
end NatTrans
namespace NatIso
variable {C}
variable {D : I → Type u₂} [∀ i, Category.{v₂} (D i)]
variable {F G : ∀ i, C i ⥤ D i}
/-- Assemble an `I`-indexed family of natural isomorphisms into a single natural isomorphism.
-/
@[simps]
def pi (e : ∀ i, F i ≅ G i) : Functor.pi F ≅ Functor.pi G where
hom := NatTrans.pi (fun i => (e i).hom)
inv := NatTrans.pi (fun i => (e i).inv)
set_option backward.isDefEq.respectTransparency false in
/-- Assemble an `I`-indexed family of natural isomorphisms into a single natural isomorphism.
-/
@[simps]
def pi' {E : Type*} [Category* E] {F G : E ⥤ ∀ i, C i}
(e : ∀ i, F ⋙ Pi.eval C i ≅ G ⋙ Pi.eval C i) : F ≅ G where
hom := NatTrans.pi' (fun i => (e i).hom)
inv := NatTrans.pi' (fun i => (e i).inv)
end NatIso
variable {C}
lemma isIso_pi_iff {X Y : ∀ i, C i} (f : X ⟶ Y) :
IsIso f ↔ ∀ i, IsIso (f i) := by
constructor
· intro _ i
exact (Pi.isoApp (asIso f) i).isIso_hom
· intro
exact ⟨fun i => inv (f i), by cat_disch, by cat_disch⟩
variable (C)
/-- For a family of categories `C i` indexed by `I`, an equality `i = j` in `I` induces
an equivalence `C i ≌ C j`. -/
def Pi.eqToEquivalence {i j : I} (h : i = j) : C i ≌ C j := by subst h; rfl
/-- When `i = j`, projections `Pi.eval C i` and `Pi.eval C j` are related by the equivalence
`Pi.eqToEquivalence C h : C i ≌ C j`. -/
@[simps!]
def Pi.evalCompEqToEquivalenceFunctor {i j : I} (h : i = j) :
Pi.eval C i ⋙ (Pi.eqToEquivalence C h).functor ≅
Pi.eval C j :=
eqToIso (by subst h; rfl)
/-- The equivalences given by `Pi.eqToEquivalence` are compatible with reindexing. -/
@[simps!]
def Pi.eqToEquivalenceFunctorIso (f : J → I) {i' j' : J} (h : i' = j') :
(Pi.eqToEquivalence C (congr_arg f h)).functor ≅
(Pi.eqToEquivalence (fun i' => C (f i')) h).functor :=
eqToIso (by subst h; rfl)
attribute [local simp] eqToHom_map
/-- Reindexing a family of categories gives equivalent `Pi` categories. -/
@[simps]
noncomputable def Pi.equivalenceOfEquiv (e : J ≃ I) :
(∀ j, C (e j)) ≌ (∀ i, C i) where
functor := pi' (fun i => Pi.eval _ (e.symm i) ⋙
(Pi.eqToEquivalence C (by simp)).functor)
inverse := Functor.pi' (fun i' => Pi.eval _ (e i'))
unitIso := NatIso.pi' (fun i' => leftUnitor _ ≪≫
(Pi.evalCompEqToEquivalenceFunctor (fun j => C (e j)) (e.symm_apply_apply i')).symm ≪≫
isoWhiskerLeft _ ((Pi.eqToEquivalenceFunctorIso C e (e.symm_apply_apply i')).symm) ≪≫
(pi'CompEval _ _).symm ≪≫ isoWhiskerLeft _ (pi'CompEval _ _).symm ≪≫
(associator _ _ _).symm)
counitIso := NatIso.pi' (fun i => (associator _ _ _).symm ≪≫
isoWhiskerRight (pi'CompEval _ _) _ ≪≫
Pi.evalCompEqToEquivalenceFunctor C (e.apply_symm_apply i) ≪≫
(leftUnitor _).symm)
/-- A product of categories indexed by `Option J` identifies to a binary product. -/
@[simps]
def Pi.optionEquivalence (C' : Option J → Type u₁) [∀ i, Category.{v₁} (C' i)] :
(∀ i, C' i) ≌ C' none × (∀ (j : J), C' (some j)) where
functor := Functor.prod' (Pi.eval C' none)
(Functor.pi' (fun i => (Pi.eval _ (some i))))
inverse := Functor.pi' (fun i => match i with
| none => Prod.fst _ _
| some i => Prod.snd _ _ ⋙ (Pi.eval _ i))
unitIso := NatIso.pi' (fun i => match i with
| none => Iso.refl _
| some _ => Iso.refl _)
counitIso := by exact Iso.refl _
namespace Equivalence
variable {C}
variable {D : I → Type u₂} [∀ i, Category.{v₂} (D i)]
/-- Assemble an `I`-indexed family of equivalences of categories
into a single equivalence. -/
@[simps]
def pi (E : ∀ i, C i ≌ D i) : (∀ i, C i) ≌ (∀ i, D i) where
functor := Functor.pi (fun i => (E i).functor)
inverse := Functor.pi (fun i => (E i).inverse)
unitIso := NatIso.pi (fun i => (E i).unitIso)
counitIso := NatIso.pi (fun i => (E i).counitIso)
instance (F : ∀ i, C i ⥤ D i) [∀ i, (F i).IsEquivalence] :
(Functor.pi F).IsEquivalence :=
(pi (fun i => (F i).asEquivalence)).isEquivalence_functor
end Equivalence
end CategoryTheory