| 1 |
Require Import TestSuite.admit. |
| 2 |
Set Implicit Arguments. |
| 3 |
Generalizable All Variables. |
| 4 |
Set Asymmetric Patterns. |
| 5 |
Set Universe Polymorphism. |
| 6 |
|
| 7 |
Delimit Scope object_scope with object. |
| 8 |
Delimit Scope morphism_scope with morphism. |
| 9 |
Delimit Scope category_scope with category. |
| 10 |
Delimit Scope functor_scope with functor. |
| 11 |
|
| 12 |
Local Open Scope category_scope. |
| 13 |
|
| 14 |
Record SpecializedCategory (obj : Type) := |
| 15 |
{ |
| 16 |
Object :> _ := obj; |
| 17 |
Morphism : obj -> obj -> Type; |
| 18 |
|
| 19 |
Compose : forall s d d', Morphism d d' -> Morphism s d -> Morphism s d' |
| 20 |
}. |
| 21 |
|
| 22 |
Bind Scope category_scope with SpecializedCategory. |
| 23 |
Bind Scope object_scope with Object. |
| 24 |
Bind Scope morphism_scope with Morphism. |
| 25 |
|
| 26 |
Arguments Object {obj%_type} C%_category / : rename. |
| 27 |
Arguments Morphism {obj%_type} !C%_category s d : rename. (* , simpl nomatch. *) |
| 28 |
Arguments Compose {obj%_type} [!C%_category s%_object d%_object d'%_object] m1%_morphism m2%_morphism : rename. |
| 29 |
|
| 30 |
Record Category := { |
| 31 |
CObject : Type; |
| 32 |
|
| 33 |
UnderlyingCategory :> @SpecializedCategory CObject |
| 34 |
}. |
| 35 |
|
| 36 |
Definition GeneralizeCategory `(C : @SpecializedCategory obj) : Category. |
| 37 |
refine {| CObject := C.(Object) |}; auto. (* Changing this [auto] to [assumption] removes the universe inconsistency. *) |
| 38 |
Defined. |
| 39 |
|
| 40 |
Coercion GeneralizeCategory : SpecializedCategory >-> Category. |
| 41 |
|
| 42 |
Record SpecializedFunctor |
| 43 |
`(C : @SpecializedCategory objC) |
| 44 |
`(D : @SpecializedCategory objD) |
| 45 |
:= { |
| 46 |
ObjectOf :> objC -> objD; |
| 47 |
MorphismOf : forall s d, C.(Morphism) s d -> D.(Morphism) (ObjectOf s) (ObjectOf d) |
| 48 |
}. |
| 49 |
|
| 50 |
Section Functor. |
| 51 |
Context (C D : Category). |
| 52 |
|
| 53 |
Definition Functor := SpecializedFunctor C D. |
| 54 |
End Functor. |
| 55 |
|
| 56 |
Bind Scope functor_scope with SpecializedFunctor. |
| 57 |
Bind Scope functor_scope with Functor. |
| 58 |
|
| 59 |
Arguments SpecializedFunctor {objC} C {objD} D. |
| 60 |
Arguments Functor C D. |
| 61 |
Arguments ObjectOf {objC%_type C%_category objD%_type D%_category} F%_functor c%_object : rename, simpl nomatch. |
| 62 |
Arguments MorphismOf {objC%_type} [C%_category] {objD%_type} [D%_category] F%_functor [s%_object d%_object] m%_morphism : rename, simpl nomatch. |
| 63 |
|
| 64 |
Section FunctorComposition. |
| 65 |
Context `(B : @SpecializedCategory objB). |
| 66 |
Context `(C : @SpecializedCategory objC). |
| 67 |
Context `(D : @SpecializedCategory objD). |
| 68 |
Context `(E : @SpecializedCategory objE). |
| 69 |
|
| 70 |
Definition ComposeFunctors (G : SpecializedFunctor D E) (F : SpecializedFunctor C D) : SpecializedFunctor C E |
| 71 |
:= Build_SpecializedFunctor C E |
| 72 |
(fun c => G (F c)) |
| 73 |
(fun _ _ m => G.(MorphismOf) (F.(MorphismOf) m)). |
| 74 |
End FunctorComposition. |
| 75 |
|
| 76 |
Record SpecializedNaturalTransformation |
| 77 |
`{C : @SpecializedCategory objC} |
| 78 |
`{D : @SpecializedCategory objD} |
| 79 |
(F G : SpecializedFunctor C D) |
| 80 |
:= { |
| 81 |
ComponentsOf :> forall c, D.(Morphism) (F c) (G c) |
| 82 |
}. |
| 83 |
|
| 84 |
Definition ProductCategory |
| 85 |
`(C : @SpecializedCategory objC) |
| 86 |
`(D : @SpecializedCategory objD) |
| 87 |
: @SpecializedCategory (objC * objD)%type |
| 88 |
:= @Build_SpecializedCategory _ |
| 89 |
(fun s d => (C.(Morphism) (fst s) (fst d) * D.(Morphism) (snd s) (snd d))%type) |
| 90 |
(fun s d d' m2 m1 => (Compose (fst m2) (fst m1), Compose (snd m2) (snd m1))). |
| 91 |
|
| 92 |
Infix "*" := ProductCategory : category_scope. |
| 93 |
|
| 94 |
Section ProductCategoryFunctors. |
| 95 |
Context `{C : @SpecializedCategory objC}. |
| 96 |
Context `{D : @SpecializedCategory objD}. |
| 97 |
|
| 98 |
Definition fst_Functor : SpecializedFunctor (C * D) C |
| 99 |
:= Build_SpecializedFunctor (C * D) C |
| 100 |
(@fst _ _) |
| 101 |
(fun _ _ => @fst _ _). |
| 102 |
|
| 103 |
Definition snd_Functor : SpecializedFunctor (C * D) D |
| 104 |
:= Build_SpecializedFunctor (C * D) D |
| 105 |
(@snd _ _) |
| 106 |
(fun _ _ => @snd _ _). |
| 107 |
End ProductCategoryFunctors. |
| 108 |
|
| 109 |
|
| 110 |
Definition OppositeCategory `(C : @SpecializedCategory objC) : @SpecializedCategory objC := |
| 111 |
@Build_SpecializedCategory objC |
| 112 |
(fun s d => Morphism C d s) |
| 113 |
(fun _ _ _ m1 m2 => Compose m2 m1). |
| 114 |
|
| 115 |
Section OppositeFunctor. |
| 116 |
Context `(C : @SpecializedCategory objC). |
| 117 |
Context `(D : @SpecializedCategory objD). |
| 118 |
Variable F : SpecializedFunctor C D. |
| 119 |
Let COp := OppositeCategory C. |
| 120 |
Let DOp := OppositeCategory D. |
| 121 |
|
| 122 |
Definition OppositeFunctor : SpecializedFunctor COp DOp |
| 123 |
:= Build_SpecializedFunctor COp DOp |
| 124 |
(fun c : COp => F c : DOp) |
| 125 |
(fun (s d : COp) (m : C.(Morphism) d s) => MorphismOf F (s := d) (d := s) m). |
| 126 |
End OppositeFunctor. |
| 127 |
|
| 128 |
Section FunctorProduct. |
| 129 |
Context `(C : @SpecializedCategory objC). |
| 130 |
Context `(D : @SpecializedCategory objD). |
| 131 |
Context `(D' : @SpecializedCategory objD'). |
| 132 |
|
| 133 |
Definition FunctorProduct (F : Functor C D) (F' : Functor C D') : SpecializedFunctor C (D * D'). |
| 134 |
match goal with |
| 135 |
| [ |- SpecializedFunctor ?C0 ?D0 ] => |
| 136 |
refine (Build_SpecializedFunctor |
| 137 |
C0 D0 |
| 138 |
(fun c => (F c, F' c)) |
| 139 |
(fun s d m => (MorphismOf F m, MorphismOf F' m))) |
| 140 |
end. |
| 141 |
Defined. |
| 142 |
End FunctorProduct. |
| 143 |
|
| 144 |
Section FunctorProduct'. |
| 145 |
Context `(C : @SpecializedCategory objC). |
| 146 |
Context `(D : @SpecializedCategory objD). |
| 147 |
Context `(C' : @SpecializedCategory objC'). |
| 148 |
Context `(D' : @SpecializedCategory objD'). |
| 149 |
Variable F : Functor C D. |
| 150 |
Variable F' : Functor C' D'. |
| 151 |
|
| 152 |
Definition FunctorProduct' : SpecializedFunctor (C * C') (D * D') |
| 153 |
:= FunctorProduct (ComposeFunctors F fst_Functor) (ComposeFunctors F' snd_Functor). |
| 154 |
End FunctorProduct'. |
| 155 |
|
| 156 |
(** XXX TODO(jgross): Change this to [FunctorProduct]. *) |
| 157 |
Infix "*" := FunctorProduct' : functor_scope. |
| 158 |
|
| 159 |
Definition TypeCat : @SpecializedCategory Type := |
| 160 |
(@Build_SpecializedCategory Type |
| 161 |
(fun s d => s -> d) |
| 162 |
(fun _ _ _ f g => (fun x => f (g x)))). |
| 163 |
|
| 164 |
Section HomFunctor. |
| 165 |
Context `(C : @SpecializedCategory objC). |
| 166 |
Let COp := OppositeCategory C. |
| 167 |
|
| 168 |
Definition CovariantHomFunctor (A : COp) : SpecializedFunctor C TypeCat |
| 169 |
:= Build_SpecializedFunctor C TypeCat |
| 170 |
(fun X : C => C.(Morphism) A X : TypeCat) |
| 171 |
(fun X Y f => (fun g : C.(Morphism) A X => Compose f g)). |
| 172 |
|
| 173 |
Definition hom_functor_object_of (c'c : COp * C) := C.(Morphism) (fst c'c) (snd c'c) : TypeCat. |
| 174 |
|
| 175 |
Definition hom_functor_morphism_of (s's : (COp * C)%type) (d'd : (COp * C)%type) (hf : (COp * C).(Morphism) s's d'd) : |
| 176 |
TypeCat.(Morphism) (hom_functor_object_of s's) (hom_functor_object_of d'd). |
| 177 |
unfold hom_functor_object_of in *. |
| 178 |
destruct s's as [ s' s ], d'd as [ d' d ]. |
| 179 |
destruct hf as [ h f ]. |
| 180 |
intro g. |
| 181 |
exact (Compose f (Compose g h)). |
| 182 |
Defined. |
| 183 |
|
| 184 |
Definition HomFunctor : SpecializedFunctor (COp * C) TypeCat |
| 185 |
:= Build_SpecializedFunctor (COp * C) TypeCat |
| 186 |
(fun c'c : COp * C => C.(Morphism) (fst c'c) (snd c'c) : TypeCat) |
| 187 |
(fun X Y (hf : (COp * C).(Morphism) X Y) => hom_functor_morphism_of hf). |
| 188 |
End HomFunctor. |
| 189 |
|
| 190 |
Section FullFaithful. |
| 191 |
Context `(C : @SpecializedCategory objC). |
| 192 |
Context `(D : @SpecializedCategory objD). |
| 193 |
Variable F : SpecializedFunctor C D. |
| 194 |
Let COp := OppositeCategory C. |
| 195 |
Let DOp := OppositeCategory D. |
| 196 |
Let FOp := OppositeFunctor F. |
| 197 |
|
| 198 |
Definition InducedHomNaturalTransformation : |
| 199 |
SpecializedNaturalTransformation (HomFunctor C) (ComposeFunctors (HomFunctor D) (FOp * F)) |
| 200 |
:= (Build_SpecializedNaturalTransformation (HomFunctor C) (ComposeFunctors (HomFunctor D) (FOp * F)) |
| 201 |
(fun sd : (COp * C) => |
| 202 |
MorphismOf F (s := _) (d := _))). |
| 203 |
End FullFaithful. |
| 204 |
|
| 205 |
Definition FunctorCategory |
| 206 |
`(C : @SpecializedCategory objC) |
| 207 |
`(D : @SpecializedCategory objD) |
| 208 |
: @SpecializedCategory (SpecializedFunctor C D). |
| 209 |
refine (@Build_SpecializedCategory _ |
| 210 |
(SpecializedNaturalTransformation (C := C) (D := D)) |
| 211 |
_); |
| 212 |
admit. |
| 213 |
Defined. |
| 214 |
|
| 215 |
Notation "C ^ D" := (FunctorCategory D C) : category_scope. |
| 216 |
|
| 217 |
Section Yoneda. |
| 218 |
Context `(C : @SpecializedCategory objC). |
| 219 |
Let COp := OppositeCategory C. |
| 220 |
|
| 221 |
Section Yoneda. |
| 222 |
Let Yoneda_NT s d (f : COp.(Morphism) s d) : SpecializedNaturalTransformation (CovariantHomFunctor C s) (CovariantHomFunctor C d) |
| 223 |
:= Build_SpecializedNaturalTransformation |
| 224 |
(CovariantHomFunctor C s) |
| 225 |
(CovariantHomFunctor C d) |
| 226 |
(fun c : C => (fun m : C.(Morphism) _ _ => Compose m f)). |
| 227 |
|
| 228 |
Definition Yoneda : SpecializedFunctor COp (TypeCat ^ C) |
| 229 |
:= Build_SpecializedFunctor COp (TypeCat ^ C) |
| 230 |
(fun c : COp => CovariantHomFunctor C c : TypeCat ^ C) |
| 231 |
(fun s d (f : Morphism COp s d) => Yoneda_NT s d f). |
| 232 |
End Yoneda. |
| 233 |
End Yoneda. |
| 234 |
|
| 235 |
Section FullyFaithful. |
| 236 |
Context `(C : @SpecializedCategory objC). |
| 237 |
|
| 238 |
Set Printing Universes. |
| 239 |
Check InducedHomNaturalTransformation (Yoneda C). |
| 240 |
(* Error: Universe inconsistency (cannot enforce Top.865 = Top.851 because |
| 241 |
Top.851 < Top.869 <= Top.864 <= Top.865). *) |
| 242 |
End FullyFaithful. |