| 1 |
Require Program.Basics Program.Tactics. |
| 2 |
Require Corelib.Classes.CMorphisms. |
| 3 |
Require Setoid. |
| 4 |
|
| 5 |
Export Program.Basics Program.Tactics. |
| 6 |
Delimit Scope category_theory_scope with category_theory. |
| 7 |
Open Scope category_theory_scope. |
| 8 |
Export Corelib.Classes.CMorphisms. |
| 9 |
|
| 10 |
Notation "∀ x .. y , P" := (forall x, .. (forall y, P) ..) |
| 11 |
(at level 200, x binder, y binder, right associativity) : |
| 12 |
category_theory_scope. |
| 13 |
|
| 14 |
Notation "x → y" := (x -> y) |
| 15 |
(at level 99, y at level 200, right associativity): category_theory_scope. |
| 16 |
|
| 17 |
Class Setoid A := { |
| 18 |
equiv : crelation A; |
| 19 |
setoid_equiv :: Equivalence equiv |
| 20 |
}. |
| 21 |
|
| 22 |
Notation "f ≈ g" := (equiv f g) (at level 79) : category_theory_scope. |
| 23 |
|
| 24 |
Reserved Infix "~>" (at level 90, right associativity). |
| 25 |
|
| 26 |
Class Category := { |
| 27 |
obj : Type; |
| 28 |
|
| 29 |
uhom := Type : Type; |
| 30 |
hom : obj -> obj -> uhom where "a ~> b" := (hom a b); |
| 31 |
homset :: ∀ X Y, Setoid (X ~> Y); |
| 32 |
|
| 33 |
id {x} : x ~> x; |
| 34 |
compose {x y z} (f: y ~> z) (g : x ~> y) : x ~> z |
| 35 |
where "f ∘ g" := (compose f g); |
| 36 |
|
| 37 |
compose_respects x y z :: |
| 38 |
Proper (equiv ==> equiv ==> equiv) (@compose x y z); |
| 39 |
|
| 40 |
dom {x y} (f: x ~> y) := x; |
| 41 |
cod {x y} (f: x ~> y) := y; |
| 42 |
|
| 43 |
id_left {x y} (f : x ~> y) : id ∘ f ≈ f; |
| 44 |
id_right {x y} (f : x ~> y) : f ∘ id ≈ f; |
| 45 |
|
| 46 |
comp_assoc {x y z w} (f : z ~> w) (g : y ~> z) (h : x ~> y) : |
| 47 |
f ∘ (g ∘ h) ≈ (f ∘ g) ∘ h; |
| 48 |
comp_assoc_sym {x y z w} (f : z ~> w) (g : y ~> z) (h : x ~> y) : |
| 49 |
(f ∘ g) ∘ h ≈ f ∘ (g ∘ h) |
| 50 |
}. |
| 51 |
|
| 52 |
Delimit Scope category_scope with category. |
| 53 |
Delimit Scope object_scope with object. |
| 54 |
Delimit Scope morphism_scope with morphism. |
| 55 |
|
| 56 |
Notation "x ~> y" := (@hom _%category x%object y%object) |
| 57 |
(at level 90, right associativity) : homset_scope. |
| 58 |
|
| 59 |
Notation "f ∘ g" := |
| 60 |
(@compose _%category _%object _%object _%object f%morphism g%morphism) |
| 61 |
: morphism_scope. |
| 62 |
|
| 63 |
Coercion obj : Category >-> Sortclass. |
| 64 |
|
| 65 |
Open Scope category_scope. |
| 66 |
Open Scope homset_scope. |
| 67 |
Open Scope morphism_scope. |
| 68 |
|
| 69 |
#[warning="context-outside-section"] Context {C : Category}. |
| 70 |
|
| 71 |
Class Isomorphism (x y : C) : Type := { |
| 72 |
to :: x ~> y; |
| 73 |
from : y ~> x; |
| 74 |
|
| 75 |
iso_to_from : to ∘ from ≈ id; |
| 76 |
iso_from_to : from ∘ to ≈ id |
| 77 |
}. |
| 78 |
|
| 79 |
Arguments to {x y} _. |
| 80 |
Arguments from {x y} _. |
| 81 |
Arguments iso_to_from {x y} _. |
| 82 |
Arguments iso_from_to {x y} _. |
| 83 |
|
| 84 |
Infix "≅" := Isomorphism (at level 91) : category_scope. |
| 85 |
|
| 86 |
Global Program Instance iso_id {x : C} : x ≅ x := { |
| 87 |
to := id; |
| 88 |
from := id |
| 89 |
}. |
| 90 |
Next Obligation. |
| 91 |
now rewrite id_left. |
| 92 |
Qed. |
| 93 |
Next Obligation. |
| 94 |
now rewrite id_left. |
| 95 |
Qed. |
| 96 |
|
| 97 |
Global Program Definition iso_sym {x y : C} `(f : x ≅ y) : y ≅ x := {| |
| 98 |
to := from f; |
| 99 |
from := to f; |
| 100 |
|
| 101 |
iso_to_from := iso_from_to f; |
| 102 |
iso_from_to := iso_to_from f |
| 103 |
|}. |
| 104 |
|
| 105 |
Global Program Definition iso_compose {x y z : C} `(f : y ≅ z) `(g : x ≅ y) : |
| 106 |
x ≅ z := {| |
| 107 |
to := to f ∘ to g; |
| 108 |
from := from g ∘ from f |
| 109 |
|}. |
| 110 |
Next Obligation. |
| 111 |
rewrite <- comp_assoc. |
| 112 |
rewrite (comp_assoc (to g)). |
| 113 |
rewrite iso_to_from. |
| 114 |
rewrite id_left. |
| 115 |
apply iso_to_from. |
| 116 |
Defined. |
| 117 |
Next Obligation. |
| 118 |
rewrite <- comp_assoc. |
| 119 |
rewrite (comp_assoc (from f)). |
| 120 |
rewrite iso_from_to. |
| 121 |
rewrite id_left. |
| 122 |
apply iso_from_to. |
| 123 |
Defined. |
| 124 |
|
| 125 |
Global Program Instance isomorphism_equivalence : Equivalence Isomorphism := { |
| 126 |
Equivalence_Reflexive := @iso_id; |
| 127 |
Equivalence_Symmetric := @iso_sym; |
| 128 |
Equivalence_Transitive := fun _ _ _ g f => iso_compose f g |
| 129 |
}. |
| 130 |
|
| 131 |
Lemma iso_compose' {x y z : C} `(f : y ≅ z) `(g : x ≅ y) : x ≅ z. |
| 132 |
Proof. |
| 133 |
rewrite g. |
| 134 |
Abort. |