]> matita.cs.unibo.it Git - helm.git/blob - categories.ma
6dac9b044bb537175b1f4dc33708356563836fbc
[helm.git] / categories.ma
1 (**************************************************************************)
2 (*       ___                                                              *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||         The HELM team.                                      *)
8 (*      ||A||         http://helm.cs.unibo.it                             *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU General Public License Version 2                  *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 include "logic/cprop_connectives.ma".
16
17 definition Type0 := Type.
18 definition Type1 := Type.
19 definition Type2 := Type.
20 definition Type0_lt_Type1 := (Type0 : Type1).
21 definition Type1_lt_Type2 := (Type1 : Type2).
22
23 record equivalence_relation (A:Type) : Type ≝
24  { eq_rel:2> A → A → CProp;
25    refl: reflexive ? eq_rel;
26    sym: symmetric ? eq_rel;
27    trans: transitive ? eq_rel
28  }.
29
30 record setoid : Type1 ≝
31  { carr:> Type;
32    eq: equivalence_relation carr
33  }.
34
35 definition reflexive1 ≝ λA:Type.λR:A→A→CProp.∀x:A.R x x.
36 definition symmetric1 ≝ λC:Type.λlt:C→C→CProp. ∀x,y:C.lt x y → lt y x.
37 definition transitive1 ≝ λA:Type.λR:A→A→CProp.∀x,y,z:A.R x y → R y z → R x z.
38
39 record equivalence_relation1 (A:Type) : Type2 ≝
40  { eq_rel1:2> A → A → CProp;
41    refl1: reflexive1 ? eq_rel1;
42    sym1: symmetric1 ? eq_rel1;
43    trans1: transitive1 ? eq_rel1
44  }.
45
46 record setoid1: Type ≝
47  { carr1:> Type;
48    eq1: equivalence_relation1 carr1
49  }.
50
51 definition setoid1_of_setoid: setoid → setoid1.
52  intro;
53  constructor 1;
54   [ apply (carr s)
55   | constructor 1;
56     [ apply (eq_rel s);
57       apply (eq s)
58     | apply (refl s)
59     | apply (sym s)
60     | apply (trans s)]]
61 qed.
62
63 coercion setoid1_of_setoid.
64
65 (*
66 definition Leibniz: Type → setoid.
67  intro;
68  constructor 1;
69   [ apply T
70   | constructor 1;
71      [ apply (λx,y:T.cic:/matita/logic/equality/eq.ind#xpointer(1/1) ? x y)
72      | alias id "refl_eq" = "cic:/matita/logic/equality/eq.ind#xpointer(1/1/1)".
73        apply refl_eq
74      | alias id "sym_eq" = "cic:/matita/logic/equality/sym_eq.con".
75        apply sym_eq
76      | alias id "trans_eq" = "cic:/matita/logic/equality/trans_eq.con".
77        apply trans_eq ]]
78 qed.
79
80 coercion Leibniz.
81 *)
82
83 interpretation "setoid1 eq" 'eq x y = (eq_rel1 _ (eq1 _) x y).
84 interpretation "setoid eq" 'eq x y = (eq_rel _ (eq _) x y).
85 interpretation "setoid1 symmetry" 'invert r = (sym1 ____ r).
86 interpretation "setoid symmetry" 'invert r = (sym ____ r).
87 notation ".= r" with precedence 50 for @{'trans $r}.
88 interpretation "trans1" 'trans r = (trans1 _____ r).
89 interpretation "trans" 'trans r = (trans _____ r).
90
91 (*
92 record unary_morphism0 (A,B: setoid) : Type0 ≝
93  { fun_0:1> A → B;
94    prop_0: ∀a,a'. eq ? a a' → eq ? (fun_0 a) (fun_0 a')
95  }.
96 *)
97
98 record unary_morphism (A,B: setoid1) : Type0 ≝
99  { fun_1:1> A → B;
100    prop_1: ∀a,a'. eq1 ? a a' → eq1 ? (fun_1 a) (fun_1 a')
101  }.
102
103 record binary_morphism (A,B,C:setoid) : Type0 ≝
104  { fun:2> A → B → C;
105    prop: ∀a,a',b,b'. eq ? a a' → eq ? b b' → eq ? (fun a b) (fun a' b')
106  }.
107
108 record binary_morphism1 (A,B,C:setoid1) : Type0 ≝
109  { fun1:2> A → B → C;
110    prop1: ∀a,a',b,b'. eq1 ? a a' → eq1 ? b b' → eq1 ? (fun1 a b) (fun1 a' b')
111  }.
112
113 notation "hbox(a break ⇒ b)" right associative with precedence 20 for @{ 'Imply $a $b }.
114 interpretation "unary morphism" 'Imply a b = (unary_morphism a b).
115
116 notation "† c" with precedence 90 for @{'prop1 $c }.
117 notation "l ‡ r" with precedence 90 for @{'prop $l $r }.
118 notation "#" with precedence 90 for @{'refl}.
119 interpretation "prop_1" 'prop1 c = (prop_1 _____ c).
120 (* interpretation "prop_0" 'prop1 c = (prop_0 _____ c). *)
121 interpretation "prop1" 'prop l r = (prop1 ________ l r).
122 interpretation "prop" 'prop l r = (prop ________ l r).
123 interpretation "refl1" 'refl = (refl1 ___).
124 interpretation "refl" 'refl = (refl ___).
125
126 definition CPROP: setoid1.
127  constructor 1;
128   [ apply CProp
129   | constructor 1;
130      [ apply Iff
131      | intros 1; split; intro; assumption
132      | intros 3; cases H; split; assumption
133      | intros 5; cases H; cases H1; split; intro;
134         [ apply (H4 (H2 H6)) | apply (H3 (H5 H6))]]]
135 qed.
136
137 definition if': ∀A,B:CPROP. A = B → A → B.
138  intros; apply (if ?? H); assumption.
139 qed.
140
141 notation ". r" with precedence 50 for @{'if $r}.
142 interpretation "if" 'if r = (if' __ r).
143
144 definition and_morphism: binary_morphism1 CPROP CPROP CPROP.
145  constructor 1;
146   [ apply And
147   | intros; split; intro; cases H2; split;
148      [ apply (if ?? H a1)
149      | apply (if ?? H1 b1)
150      | apply (fi ?? H a1)
151      | apply (fi ?? H1 b1)]]
152 qed.
153
154 interpretation "and_morphism" 'and a b = (fun1 ___ and_morphism a b).
155
156 definition or_morphism: binary_morphism1 CPROP CPROP CPROP.
157  constructor 1;
158   [ apply Or
159   | intros; split; intro; cases H2; [1,3:left |2,4: right]
160      [ apply (if ?? H a1)
161      | apply (fi ?? H a1)
162      | apply (if ?? H1 b1)
163      | apply (fi ?? H1 b1)]]
164 qed.
165
166 interpretation "or_morphism" 'or a b = (fun1 ___ or_morphism a b).
167
168 definition if_morphism: binary_morphism1 CPROP CPROP CPROP.
169  constructor 1;
170   [ apply (λA,B. A → B)
171   | intros; split; intros;
172      [ apply (if ?? H1); apply H2; apply (fi ?? H); assumption
173      | apply (fi ?? H1); apply H2; apply (if ?? H); assumption]]
174 qed.
175
176 (*
177 definition eq_morphism: ∀S:setoid. binary_morphism S S CPROP.
178  intro;
179  constructor 1;
180   [ apply (eq_rel ? (eq S))
181   | intros; split; intro;
182      [ apply (.= H \sup -1);
183        apply (.= H2);
184        assumption
185      | apply (.= H);
186        apply (.= H2);
187        apply (H1 \sup -1)]]
188 qed.
189 *)
190
191 record category : Type1 ≝
192  { objs:> Type;
193    arrows: objs → objs → setoid;
194    id: ∀o:objs. arrows o o;
195    comp: ∀o1,o2,o3. binary_morphism (arrows o1 o2) (arrows o2 o3) (arrows o1 o3);
196    comp_assoc: ∀o1,o2,o3,o4. ∀a12,a23,a34.
197     comp o1 o3 o4 (comp o1 o2 o3 a12 a23) a34 = comp o1 o2 o4 a12 (comp o2 o3 o4 a23 a34);
198    id_neutral_left: ∀o1,o2. ∀a: arrows o1 o2. comp ??? (id o1) a = a;
199    id_neutral_right: ∀o1,o2. ∀a: arrows o1 o2. comp ??? a (id o2) = a
200  }.
201
202 record category1 : Type2 ≝
203  { objs1:> Type;
204    arrows1: objs1 → objs1 → setoid1;
205    id1: ∀o:objs1. arrows1 o o;
206    comp1: ∀o1,o2,o3. binary_morphism1 (arrows1 o1 o2) (arrows1 o2 o3) (arrows1 o1 o3);
207    comp_assoc1: ∀o1,o2,o3,o4. ∀a12,a23,a34.
208     comp1 o1 o3 o4 (comp1 o1 o2 o3 a12 a23) a34 = comp1 o1 o2 o4 a12 (comp1 o2 o3 o4 a23 a34);
209    id_neutral_right1: ∀o1,o2. ∀a: arrows1 o1 o2. comp1 ??? (id1 o1) a = a;
210    id_neutral_left1: ∀o1,o2. ∀a: arrows1 o1 o2. comp1 ??? a (id1 o2) = a
211  }.
212
213 notation "'ASSOC'" with precedence 90 for @{'assoc}.
214 notation "'ASSOC1'" with precedence 90 for @{'assoc1}.
215
216 interpretation "category1 composition" 'compose x y = (fun1 ___ (comp1 ____) y x).
217 interpretation "category1 assoc" 'assoc1 = (comp_assoc1 ________).
218 interpretation "category composition" 'compose x y = (fun ___ (comp ____) y x).
219 interpretation "category assoc" 'assoc = (comp_assoc ________).