| 1 |
Axiom proof_admitted : False. |
| 2 |
Tactic Notation "admit" := abstract case proof_admitted. |
| 3 |
Require Corelib.Program.Basics Corelib.Program.Tactics. |
| 4 |
Export Corelib.Program.Basics Corelib.Program.Tactics. |
| 5 |
Set Primitive Projections. |
| 6 |
Set Universe Polymorphism. |
| 7 |
|
| 8 |
Close Scope nat_scope. |
| 9 |
Require Setoid. |
| 10 |
Require Export Corelib.Classes.CMorphisms. |
| 11 |
|
| 12 |
Notation "∀ x .. y , P" := (forall x, .. (forall y, P) ..) |
| 13 |
(at level 200, x binder, y binder, right associativity). |
| 14 |
|
| 15 |
Class Setoid A := { |
| 16 |
equiv : crelation A; |
| 17 |
setoid_equiv :: Equivalence equiv |
| 18 |
}. |
| 19 |
|
| 20 |
Notation "f ≈ g" := (equiv f g) (at level 79). |
| 21 |
|
| 22 |
Ltac cat := |
| 23 |
intros; |
| 24 |
autorewrite with categories; |
| 25 |
auto with category_laws; |
| 26 |
try reflexivity. |
| 27 |
|
| 28 |
#[export] Hint Extern 4 (equiv ?A ?A) => reflexivity : category_laws. |
| 29 |
|
| 30 |
Ltac proper := repeat intro; simpl; try cat; intuition. |
| 31 |
|
| 32 |
Ltac cat_simpl := |
| 33 |
program_simpl; autounfold; |
| 34 |
try solve [ |
| 35 |
program_simpl; autounfold in *; |
| 36 |
simpl in *; intros; |
| 37 |
simpl in *; cat]; |
| 38 |
simpl in *. |
| 39 |
|
| 40 |
Global Obligation Tactic := cat_simpl. |
| 41 |
|
| 42 |
Reserved Infix "~>" (at level 90, right associativity). |
| 43 |
|
| 44 |
Class Category := { |
| 45 |
obj : Type; |
| 46 |
|
| 47 |
uhom := Type : Type; |
| 48 |
hom : obj -> obj -> uhom where "a ~> b" := (hom a b); |
| 49 |
homset :: ∀ X Y, Setoid (X ~> Y); |
| 50 |
|
| 51 |
id {x} : x ~> x; |
| 52 |
}. |
| 53 |
|
| 54 |
Delimit Scope category_scope with category. |
| 55 |
Delimit Scope object_scope with object. |
| 56 |
|
| 57 |
Notation "x ~> y" := (@hom _%category x%object y%object) |
| 58 |
(at level 90, right associativity) : homset_scope. |
| 59 |
Notation "x ~{ C }~> y" := (@hom C%category x%object y%object) |
| 60 |
(at level 90) : homset_scope. |
| 61 |
|
| 62 |
Notation "id[ x ]" := (@id _%category x%object) |
| 63 |
(at level 9, format "id[ x ]") : morphism_scope. |
| 64 |
|
| 65 |
Coercion obj : Category >-> Sortclass. |
| 66 |
|
| 67 |
Open Scope homset_scope. |
| 68 |
Open Scope morphism_scope. |
| 69 |
|
| 70 |
Class Functor (C D : Category) := { |
| 71 |
fobj : C -> D; |
| 72 |
fmap {x y : C} (f : x ~> y) : fobj x ~> fobj y; |
| 73 |
|
| 74 |
fmap_respects :: ∀ x y, Proper (equiv ==> equiv) (@fmap x y); |
| 75 |
|
| 76 |
fmap_id {x : C} : fmap (@id C x) ≈ id; |
| 77 |
}. |
| 78 |
Delimit Scope functor_scope with functor. |
| 79 |
|
| 80 |
Coercion fobj : Functor >-> Funclass. |
| 81 |
|
| 82 |
Notation "fmap[ F ]" := (@fmap _ _ F%functor _ _) |
| 83 |
(at level 9, format "fmap[ F ]") : morphism_scope. |
| 84 |
|
| 85 |
#[export] Hint Rewrite @fmap_id : categories. |
| 86 |
|
| 87 |
Definition Product (C D : Category) : Category := {| |
| 88 |
obj := C * D; |
| 89 |
hom := fun x y => (fst x ~> fst y) * (snd x ~> snd y); |
| 90 |
homset := fun x y => |
| 91 |
let setoid_C := @homset C (fst x) (fst y) in |
| 92 |
let setoid_D := @homset D (snd x) (snd y) in |
| 93 |
{| equiv := fun f g => |
| 94 |
(@equiv _ setoid_C (fst f) (fst g) * |
| 95 |
@equiv _ setoid_D (snd f) (snd g)) |
| 96 |
; setoid_equiv := _ |
| 97 |
{| Equivalence_Reflexive := fun x => |
| 98 |
(@Equivalence_Reflexive _ _ (@setoid_equiv _ setoid_C) (fst x), |
| 99 |
@Equivalence_Reflexive _ _ (@setoid_equiv _ setoid_D) (snd x)) |
| 100 |
; Equivalence_Symmetric := fun x y f => |
| 101 |
(@Equivalence_Symmetric |
| 102 |
_ _ (@setoid_equiv _ setoid_C) (fst x) (fst y) (fst f), |
| 103 |
@Equivalence_Symmetric |
| 104 |
_ _ (@setoid_equiv _ setoid_D) (snd x) (snd y) (snd f)) |
| 105 |
; Equivalence_Transitive := fun x y z f g => |
| 106 |
(@Equivalence_Transitive |
| 107 |
_ _ (@setoid_equiv _ setoid_C) (fst x) (fst y) (fst z) |
| 108 |
(fst f) (fst g), |
| 109 |
@Equivalence_Transitive |
| 110 |
_ _ (@setoid_equiv _ setoid_D) (snd x) (snd y) (snd z) |
| 111 |
(snd f) (snd g)) |} |}; |
| 112 |
id := fun _ => (id, id); |
| 113 |
|}. |
| 114 |
|
| 115 |
Section Bifunctor. |
| 116 |
|
| 117 |
Context {C : Category}. |
| 118 |
Context {D : Category}. |
| 119 |
Context {E : Category}. |
| 120 |
|
| 121 |
Definition bimap {F : Functor (Product C D) E} {x w : C} {y z : D} |
| 122 |
(f : x ~{C}~> w) (g : y ~{D}~> z) : |
| 123 |
F (x, y) ~{E}~> F (w, z) := @fmap (Product C D) E F (x, y) (w, z) (f, g). |
| 124 |
|
| 125 |
Global Program Instance bimap_respects {F : Functor (Product C D) E} {x w : C} {y z : D} : |
| 126 |
Proper (equiv ==> equiv ==> equiv) (@bimap F x w y z). |
| 127 |
Next Obligation. |
| 128 |
admit. |
| 129 |
Defined. |
| 130 |
|
| 131 |
Lemma bimap_id_id {F : Functor (Product C D) E} {x y} : |
| 132 |
bimap (id[x]) (id[y]) ≈ id. |
| 133 |
admit. |
| 134 |
Defined. |
| 135 |
|
| 136 |
End Bifunctor. |
| 137 |
|
| 138 |
Notation "bimap[ F ]" := (@bimap _ _ _ F%functor _ _ _ _) |
| 139 |
(at level 9, format "bimap[ F ]") : morphism_scope. |
| 140 |
|
| 141 |
#[export] Hint Rewrite @bimap_id_id : categories. |
| 142 |
|
| 143 |
Reserved Infix "⨂" (at level 30, right associativity). |
| 144 |
|
| 145 |
Class Monoidal {C : Category} := { |
| 146 |
tensor : Functor (Product C C) C where "x ⨂ y" := (tensor (x, y)); |
| 147 |
}. |
| 148 |
|
| 149 |
Notation "x ⨂ y" := (@tensor _ _ (x%object, y%object)) |
| 150 |
(at level 30, right associativity) : object_scope. |
| 151 |
Notation "f ⨂ g" := (bimap[@tensor _ _] f g) |
| 152 |
(at level 30, right associativity) : morphism_scope. |
| 153 |
|
| 154 |
#[export] Program Instance PP |
| 155 |
{C : Category} {D : Category} `{@Monoidal D} |
| 156 |
{F : Functor C D} {G : Functor C D} : Functor C D := { |
| 157 |
fobj := fun x => (F x ⨂ G x)%object; |
| 158 |
fmap := fun _ _ f => fmap[F] f ⨂ fmap[G] f |
| 159 |
}. |
| 160 |
Next Obligation. |
| 161 |
proper. |
| 162 |
rewrite X. (* was anomaly undefined universe *) |
| 163 |
reflexivity. |
| 164 |
Qed. |