cd1eaa9bb6c88d627f7adb25ce71099d07d0bfc2
[coq-categories.git] / src / Subcategories_ch7_1.v
1 (****************************************************************************)
2 (* Chapter 7.1: Subcategories                                               *)
3 (****************************************************************************)
4
5 Generalizable All Variables.
6 Require Import Notations.
7 Require Import Categories_ch1_3.
8 Require Import Functors_ch1_4.
9 Require Import Isomorphisms_ch1_5.
10 Require Import OppositeCategories_ch1_6_2.
11 Require Import NaturalTransformations_ch7_4.
12 Require Import NaturalIsomorphisms_ch7_5.
13
14 (*
15  * See the README for an explanation of why there is "WideSubcategory"
16  * and "FullSubcategory" but no "Subcategory"
17  *)
18
19 (* a full subcategory requires nothing more than a predicate on objects *)
20 Class FullSubcategory `(C:Category)(Pobj:C->Type) := { }.
21
22 (* the category construction for full subcategories is simpler: *)
23 Instance FullSubCategoriesAreCategories `(fsc:@FullSubcategory Ob Hom C Pobj)
24   : Category (sigT Pobj) (fun dom ran => (projT1 dom)~~{C}~~>(projT1 ran)) :=
25 { id   := fun t         => id (projT1 t)
26 ; eqv  := fun a b f g   => eqv _ _ f g
27 ; comp := fun a b c f g => f >>> g
28 }.
29   intros; apply Build_Equivalence. unfold Reflexive.
30      intros; reflexivity.
31      unfold Symmetric; intros; simpl; symmetry; auto.
32      unfold Transitive; intros; simpl. transitivity y; auto.
33   intros; unfold Proper. unfold respectful. intros. simpl. apply comp_respects. auto. auto.
34   intros; simpl. apply left_identity.
35   intros; simpl. apply right_identity.
36   intros; simpl. apply associativity.
37   Defined.
38 Coercion FullSubCategoriesAreCategories : FullSubcategory >-> Category.
39
40 (* every category is a subcategory of itself *)
41 (*
42 Instance IdentitySubCategory `(C:Category Ob Hom) : SubCategory C (fun _ => True) (fun _ _ _ _ _ => True).
43   intros; apply Build_SubCategory.
44   intros; auto.
45   intros; auto.
46   Defined.
47 (* the inclusion operation from a subcategory to its host is a functor *)
48 Instance InclusionFunctor `(C:Category Ob Hom)`(SP:@SubCategory _ _ C Pobj Pmor)
49   : Functor SP C (fun x => projT1 x) :=
50   { fmor := fun dom ran f => projT1 f }.
51   intros. unfold eqv in H. simpl in H. auto.
52   intros. simpl. reflexivity.
53   intros. simpl. reflexivity.
54   Defined.
55 *)
56
57
58 (* a wide subcategory includes all objects, so it requires nothing more than a predicate on each hom-set *)
59 Class WideSubcategory `(C:Category Ob Hom)(Pmor:forall a b:Ob, (a~>b) ->Type) : Type :=
60 { wsc_id_included    : forall (a:Ob), Pmor a a (id a)
61 ; wsc_comp_included  : forall (a b c:Ob) f g, (Pmor a b f) -> (Pmor b c g) -> (Pmor a c (f>>>g))
62 }.
63
64 (* the category construction for full subcategories is simpler: *)
65 Instance WideSubCategoriesAreCategories `{C:Category(Ob:=Ob)}{Pmor}(wsc:WideSubcategory C Pmor)
66   : Category Ob (fun x y => sigT (Pmor x y)) :=
67   { id   := fun t         => existT _ (id t) (@wsc_id_included _ _ _ _ wsc t)
68   ; eqv  := fun a b f g   => eqv _ _ (projT1 f) (projT1 g)
69   ; comp := fun a b c f g => existT (Pmor a c) (projT1 f >>> projT1 g)
70                                     (@wsc_comp_included _ _ _ _ wsc _ _ _ _ _ (projT2 f) (projT2 g))
71   }.
72   intros; apply Build_Equivalence. unfold Reflexive.
73      intros; reflexivity.
74      unfold Symmetric; intros; simpl; symmetry; auto.
75      unfold Transitive; intros; simpl. transitivity (projT1 y); auto.
76   intros; unfold Proper. unfold respectful. intros. simpl. apply comp_respects. auto. auto.
77   intros; simpl. apply left_identity.
78   intros; simpl. apply right_identity.
79   intros; simpl. apply associativity.
80   Defined.
81 Coercion WideSubCategoriesAreCategories : WideSubcategory >-> Category.
82
83 (* the full image of a functor is a full subcategory *)
84 Section FullImage.
85
86   Context `(F:Functor(c1:=C)(c2:=D)).
87
88   Instance FullImage : Category C (fun x y => (F x)~~{D}~~>(F y)) :=
89   { id    := fun t         => id (F t)
90   ; eqv   := fun x y   f g => eqv(Category:=D)  _ _ f g
91   ; comp  := fun x y z f g => comp(Category:=D) _ _ _ f g
92   }.
93   intros; apply Build_Equivalence. unfold Reflexive.
94      intros; reflexivity.
95      unfold Symmetric; intros; simpl; symmetry; auto.
96      unfold Transitive; intros; simpl. transitivity y; auto.
97   intros; unfold Proper. unfold respectful. intros. simpl. apply comp_respects. auto. auto.
98   intros; simpl. apply left_identity.
99   intros; simpl. apply right_identity.
100   intros; simpl. apply associativity.
101   Defined.
102
103   Instance FullImage_InclusionFunctor : Functor FullImage D (fun x => F x) :=
104     { fmor := fun x y f => f }.
105     intros; auto.
106     intros; simpl; reflexivity.
107     intros; simpl; reflexivity.
108     Defined.
109
110   Instance RestrictToImage : Functor C FullImage (fun x => x) :=
111     { fmor := fun a b f => F \ f }.
112     intros; simpl; apply fmor_respects; auto.
113     intros; simpl; apply fmor_preserves_id; auto.
114     intros; simpl; apply fmor_preserves_comp; auto.
115     Defined.
116
117   Lemma RestrictToImage_splits : F ~~~~ (RestrictToImage >>>> FullImage_InclusionFunctor).
118     unfold EqualFunctors; simpl; intros; apply heq_morphisms_intro.
119     apply fmor_respects.
120     auto.
121     Defined.
122
123 End FullImage.
124
125 (* any functor may be restricted to a subcategory of its domain *)
126 Section RestrictDomain.
127
128   Context `{C:Category}.
129   Context `{D:Category}.
130   Context `(F:!Functor C D fobj).
131   Context  {Pmor}(S:WideSubcategory C Pmor).
132
133   Instance RestrictDomain : Functor S D fobj :=
134     { fmor  := fun a b f => F \ (projT1 f) }.
135     intros; destruct f; destruct f'; simpl in *.
136       apply fmor_respects; auto.
137     intros. simpl. apply fmor_preserves_id.
138     intros; simpl; destruct f; destruct g; simpl in *.
139       apply fmor_preserves_comp.
140     Defined.
141
142 End RestrictDomain.
143
144 (*
145 Instance func_opSubcat `(c1:Category)`(c2:Category)`(SP:@SubCategory _ _ c2 Pobj Pmor)
146   {fobj}(F:Functor c1⁽ºᑭ⁾ SP fobj) : Functor c1 SP⁽ºᑭ⁾ fobj :=
147   { fmor                := fun a b f => fmor F f }.
148   intros. apply (@fmor_respects _ _ _ _ _ _ _ F _ _ f f' H).
149   intros. apply (@fmor_preserves_id _ _ _ _ _ _ _ F a).
150   intros. apply (@fmor_preserves_comp _ _ _ _ _ _ _ F _ _ g _ f).
151   Defined.
152 *)
153
154 (*
155 (* if a functor's range falls within a subcategory, then it is already a functor into that subcategory *)
156 Section FunctorWithRangeInSubCategory.
157   Context `(Cat1:Category O1 Hom1).
158   Context `(Cat2:Category O2 Hom2).
159   Context (Pobj:Cat2 -> Type).
160   Context (Pmor:forall a b:Cat2, (Pobj a) -> (Pobj b) -> (a~~{Cat2}~~>b) -> Type).
161   Context (SP:SubCategory Cat2 Pobj Pmor).
162   Context (Fobj:Cat1->Cat2).
163   Section Forward.
164     Context (F:Functor Cat1 Cat2 Fobj).
165     Context (pobj:forall a, Pobj (F a)).
166     Context (pmor:forall a b f, Pmor (F a) (F b) (pobj a) (pobj b) (F \ f)).
167     Definition FunctorWithRangeInSubCategory_fobj (X:Cat1) : SP :=
168       existT Pobj (Fobj X) (pobj X).
169     Definition FunctorWithRangeInSubCategory_fmor (dom ran:Cat1)(X:dom~>ran) : (@hom _ _ SP
170       (FunctorWithRangeInSubCategory_fobj dom) (FunctorWithRangeInSubCategory_fobj ran)).
171       intros.
172       exists (F \ X).
173       apply (pmor dom ran X).
174       Defined.
175     Definition FunctorWithRangeInSubCategory : Functor Cat1 SP FunctorWithRangeInSubCategory_fobj.
176       apply Build_Functor with (fmor:=FunctorWithRangeInSubCategory_fmor);
177         intros;
178         unfold FunctorWithRangeInSubCategory_fmor;
179         simpl.
180       setoid_rewrite H; auto.
181       apply (fmor_preserves_id F).
182       apply (fmor_preserves_comp F).
183       Defined.
184   End Forward.
185   Section Opposite.
186     Context (F:Functor Cat1 Cat2⁽ºᑭ⁾ Fobj).
187     Context (pobj:forall a, Pobj (F a)).
188     Context (pmor:forall a b f, Pmor (F b) (F a) (pobj b) (pobj a) (F \ f)).
189     Definition FunctorWithRangeInSubCategoryOp_fobj (X:Cat1) : SP :=
190       existT Pobj (Fobj X) (pobj X).
191     Definition FunctorWithRangeInSubCategoryOp_fmor (dom ran:Cat1)(X:dom~>ran) :
192       (FunctorWithRangeInSubCategoryOp_fobj dom)~~{SP⁽ºᑭ⁾}~~>(FunctorWithRangeInSubCategoryOp_fobj ran).
193       intros.
194       exists (F \ X).
195       apply (pmor dom ran X).
196       Defined.
197     (*
198     Definition FunctorWithRangeInSubCategoryOp : Functor Cat1 SP⁽ºᑭ⁾ FunctorWithRangeInSubCategoryOp_fobj.
199       apply Build_Functor with (fmor:=FunctorWithRangeInSubCategoryOp_fmor);
200         intros;
201         unfold FunctorWithRangeInSubCategoryOp_fmor;
202         simpl.
203       apply (fmor_respects(Functor:=F)); auto.
204       apply (fmor_preserves_id(Functor:=F)).
205       unfold eqv; simpl.
206       set (@fmor_preserves_comp _ _ _ _ _ _ _ F _ _ f _ g) as qq.
207       setoid_rewrite <- qq.
208       apply reflexivity.
209       Defined.
210       *)
211   End Opposite.
212 End FunctorWithRangeInSubCategory.
213 *)
214
215
216 (* Definition 7.1: faithful functors *)
217 Definition FaithfulFunctor `(F:Functor(c1:=C1)(c2:=C2)(fobj:=Fobj)) :=
218   forall (a b:C1), forall (f f':a~>b), (fmor _ f)~~(fmor _ f') -> f~~f'.
219
220 (* Definition 7.1: full functors *)
221 Class FullFunctor `(F:Functor(c1:=C1)(c2:=C2)(fobj:=Fobj)) :=
222   { ff_invert         : forall {a b}(f:(Fobj a)~~{C2}~~>(Fobj b)) , { f' : a~~{C1}~~>b & (F \ f') ~~ f }
223   ; ff_respects       : forall {a b}, Proper (eqv (Fobj a) (Fobj b) ==> eqv a b) (fun x => projT1 (@ff_invert a b x))
224   }.
225   Coercion ff_invert : FullFunctor >-> Funclass.
226
227 (* Definition 7.1: (essentially) surjective on objects *)
228 Definition EssentiallySurjectiveOnObjects `(F:Functor(c1:=C1)(c2:=C2)(fobj:=Fobj)) :=
229   forall o2:C2, { o1:C1 & (F o1) ≅ o2 }.
230
231 (* Definition 7.1: (essentially) injective on objects *)
232 (* TODO *)
233
234 Class ConservativeFunctor `(F:Functor(c1:=C1)(c2:=C2)(fobj:=Fobj)) :=
235   { cf_reflect_iso  : forall (a b:C1),  (F a) ≅ (F b) -> a ≅ b
236   ; cf_reflect_iso1 : forall a b (i:(F a) ≅ (F b)), F \ #(cf_reflect_iso a b i) ~~ #i
237   ; cf_reflect_iso2 : forall a b (i:(F a) ≅ (F b)), F \ #(cf_reflect_iso a b i)⁻¹ ~~ #i⁻¹
238   }.
239
240 (* "monic up to natural iso" *)
241 Definition WeaklyMonic
242     `{C:Category}
243     `{D:Category}
244      {Fobj}
245      (F:@Functor _ _ C _ _ D Fobj) := forall
246      Eob EHom (E:@Category Eob EHom)
247     `{G :@Functor _ _ E _ _ C Gobj'}
248     `{H :@Functor _ _ E _ _ C Hobj'},
249     G >>>> F ≃ H >>>> F
250     -> G ≃ H.
251
252 Section FullFaithfulFunctor_section.
253   Context `(F:Functor(c1:=C1)(c2:=C2)(fobj:=Fobj)).
254   Context  (F_full:FullFunctor F).
255   Context  (F_faithful:FaithfulFunctor F).
256
257   Lemma ff_functor_section_id_preserved : forall a:C1, projT1 (F_full _ _ (id (F a))) ~~ id a.
258     intros.
259     set (F_full a a (id (F a))) as qq.
260     destruct qq.
261     simpl.
262     apply F_faithful.
263     setoid_rewrite fmor_preserves_id.
264     auto.
265     Qed.
266
267   Definition ff_functor_section_fmor {a b:FullImage F} (f:a~~{FullImage F}~~>b) : a~~{C1}~~>b.
268     set (@ff_invert _ _ _ _ _ _ _ _ F_full _ _ f) as f'.
269     destruct f'.
270     apply x.
271     Defined.
272
273   Lemma ff_functor_section_respectful {a2 b2 c2 : C1}
274     (x0 : Fobj b2 ~~{ C2 }~~> Fobj c2)
275     (x  : Fobj a2 ~~{ C2 }~~> Fobj b2) :
276     (let (x1, _) := F_full a2 b2 x in x1) >>>
277     (let (x1, _) := F_full b2 c2 x0 in x1) ~~
278     (let (x1, _) := F_full a2 c2 (x >>> x0) in x1).
279     set (F_full _ _ x) as x_full.
280     set (F_full _ _ x0) as x0_full.
281     set (F_full _ _ (x >>> x0)) as x_x0_full.
282     destruct x_full.
283     destruct x0_full.
284     destruct x_x0_full.
285     apply F_faithful.
286     setoid_rewrite e1.
287     setoid_rewrite <- (fmor_preserves_comp F).
288     setoid_rewrite e.
289     setoid_rewrite e0.
290     reflexivity.
291     Qed.
292
293   Instance ff_functor_section_functor : Functor (FullImage F) C1 (fun x => x) :=
294     { fmor := fun a b f => ff_functor_section_fmor f }.
295     intros.
296       unfold ff_functor_section_fmor; simpl.
297       destruct (F_full a b f).
298       destruct (F_full a b f').
299       apply F_faithful.
300       setoid_rewrite e0.
301       setoid_rewrite e.
302       auto.
303     intros; simpl; subst.
304       apply ff_functor_section_id_preserved.
305     intros; simpl in *.
306       apply ff_functor_section_respectful.
307       Defined.
308 (*
309   Lemma ff_functor_section_splits_helper (a2 b2:C1)(f:existT (fun d : C2, {c : C1 & Fobj c = d}) (Fobj a2)
310         (existT (fun c : C1, Fobj c = Fobj a2) a2 (eq_refl _)) ~~{ 
311       FullImage F
312       }~~> existT (fun d : C2, {c : C1 & Fobj c = d}) 
313              (Fobj b2) (existT (fun c : C1, Fobj c = Fobj b2) b2 (eq_refl _)))
314      : F \ (let (x1, _) := F_full a2 b2 f in x1) ~~ f.
315     simpl.
316     set (F_full a2 b2 f) as qq.
317     destruct qq.
318     apply e.
319     Qed.
320 *)
321   Lemma ff_functor_section_splits : (ff_functor_section_functor >>>> RestrictToImage F) ~~~~ functor_id _.
322     unfold EqualFunctors; intros; simpl.
323     unfold ff_functor_section_fmor; simpl.
324     destruct (F_full a b f).
325     idtac.
326     apply (@heq_morphisms_intro _ _ (FullImage F) a b).
327     unfold eqv; simpl.
328     setoid_rewrite e.
329     apply H.
330     Qed.
331
332   Lemma ff_functor_section_splits_niso : (ff_functor_section_functor >>>> RestrictToImage F) ≃ functor_id _.
333     intros; simpl.
334     exists iso_id; intros.
335     symmetry.
336     unfold functor_comp; simpl.
337     setoid_rewrite left_identity.
338     setoid_rewrite right_identity.
339     unfold ff_functor_section_fmor.
340     destruct (F_full A B f).
341     auto.
342     Qed.
343
344   Lemma ff_functor_section_splits_niso' : (RestrictToImage F >>>> ff_functor_section_functor) ≃ functor_id _.
345     intros; simpl.
346     exists iso_id; intros.
347     symmetry.
348     unfold functor_comp; simpl.
349     setoid_rewrite left_identity.
350     setoid_rewrite right_identity.
351     unfold ff_functor_section_fmor.
352     destruct (F_full A B (F \ f)).
353     apply F_faithful.
354     auto.
355     Qed.
356
357   Context (CF:ConservativeFunctor F).
358
359   Lemma if_fullimage `{C0:Category}{Aobj}{Bobj}{A:Functor C0 C1 Aobj}{B:Functor C0 C1 Bobj} :
360     A >>>> F ≃ B >>>> F ->
361     A >>>> RestrictToImage F ≃ B >>>> RestrictToImage F.
362     intro H.
363     destruct H.
364     unfold IsomorphicFunctors.
365     set (fun A  => functors_preserve_isos (RestrictToImage F) (cf_reflect_iso _ _ (x A))).
366     exists i.
367     intros.
368     unfold RestrictToImage.
369     unfold functor_comp.
370     simpl.
371     unfold functor_comp in H.
372     simpl in H.
373     rewrite (cf_reflect_iso1(ConservativeFunctor:=CF) _ _ (x A0)).
374     rewrite (cf_reflect_iso1(ConservativeFunctor:=CF) _ _ (x B0)).
375     apply H.
376     Qed.
377
378   Lemma ffc_functor_weakly_monic : ConservativeFunctor F -> WeaklyMonic F.
379     intro H.
380     unfold WeaklyMonic; intros.
381     apply (if_comp(F2:=G>>>>functor_id _)).
382     apply if_inv.
383     apply if_right_identity.
384     apply if_inv.
385     apply (if_comp(F2:=H0>>>>functor_id _)).
386     apply if_inv.
387     apply if_right_identity.
388     eapply if_inv.
389     apply (if_comp(F2:=G>>>>(RestrictToImage F >>>> ff_functor_section_functor))).
390     apply (if_respects G G (functor_id C1) (RestrictToImage F >>>> ff_functor_section_functor)).
391     apply if_id.
392     apply if_inv.
393     apply ff_functor_section_splits_niso'.
394     apply if_inv.
395     apply (if_comp(F2:=H0>>>>(RestrictToImage F >>>> ff_functor_section_functor))).
396     apply (if_respects H0 H0 (functor_id C1) (RestrictToImage F >>>> ff_functor_section_functor)).
397     apply if_id.
398     apply if_inv.
399     apply ff_functor_section_splits_niso'.
400     assert
401       ((H0 >>>> (RestrictToImage F >>>> ff_functor_section_functor))
402         ≃ ((H0 >>>> RestrictToImage F) >>>> ff_functor_section_functor)).
403     apply if_inv.
404     apply (if_associativity H0 (RestrictToImage F) ff_functor_section_functor).
405     apply (if_comp H2).
406     clear H2.
407     apply if_inv.
408     assert
409       ((G >>>> (RestrictToImage F >>>> ff_functor_section_functor))
410         ≃ ((G >>>> RestrictToImage F) >>>> ff_functor_section_functor)).
411     apply if_inv.
412     apply (if_associativity G (RestrictToImage F) ff_functor_section_functor).
413     apply (if_comp H2).
414     clear H2.
415     apply (if_respects (G >>>> RestrictToImage F) (H0 >>>> RestrictToImage F)
416       ff_functor_section_functor ff_functor_section_functor).
417     apply if_fullimage.
418     apply H1.
419     simpl.
420     exists (ni_id _).
421     intros.
422     simpl.
423     setoid_rewrite left_identity.
424     setoid_rewrite right_identity.
425     reflexivity.
426     Qed.
427
428 End FullFaithfulFunctor_section.