1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| The HELM team. *)
8 (* ||A|| http://helm.cs.unibo.it *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU General Public License Version 2 *)
13 (**************************************************************************)
15 include "datatypes/subsets.ma".
17 record binary_relation (A,B: setoid) : Type ≝
18 { satisfy:> binary_morphism1 A B CPROP }.
20 notation < "hvbox (x \nbsp \natur term 90 r \nbsp y)" with precedence 45 for @{'satisfy $r $x $y}.
21 notation > "hvbox (x \natur term 90 r y)" with precedence 45 for @{'satisfy $r $x $y}.
22 interpretation "relation applied" 'satisfy r x y = (fun1 ___ (satisfy __ r) x y).
24 definition binary_relation_setoid: setoid → setoid → setoid1.
27 [ apply (binary_relation A B)
29 [ apply (λA,B.λr,r': binary_relation A B. ∀x,y. r x y ↔ r' x y)
30 | simplify; intros 3; split; intro; assumption
31 | simplify; intros 5; split; intro;
32 [ apply (fi ?? (H ??)) | apply (if ?? (H ??))] assumption
33 | simplify; intros 7; split; intro;
34 [ apply (if ?? (H1 ??)) | apply (fi ?? (H ??)) ]
35 [ apply (if ?? (H ??)) | apply (fi ?? (H1 ??)) ]
39 definition composition:
41 binary_morphism1 (binary_relation_setoid A B) (binary_relation_setoid B C) (binary_relation_setoid A C).
47 [ apply (λs1:A.λs3:C.∃s2:B. s1 ♮R12 s2 ∧ s2 ♮R23 s3);
49 split; intro; cases H2 (w H3); clear H2; exists; [1,3: apply w ]
50 [ apply (. (H‡#)‡(#‡H1)); assumption
51 | apply (. ((H \sup -1)‡#)‡(#‡(H1 \sup -1))); assumption]]
52 | intros 8; split; intro H2; simplify in H2 ⊢ %;
53 cases H2 (w H3); clear H2; exists [1,3: apply w] cases H3 (H2 H4); clear H3;
54 [ lapply (if ?? (H x w) H2) | lapply (fi ?? (H x w) H2) ]
55 [ lapply (if ?? (H1 w y) H4)| lapply (fi ?? (H1 w y) H4) ]
56 exists; try assumption;
60 definition REL: category1.
63 | intros (T T1); apply (binary_relation_setoid T T1)
64 | intros; constructor 1;
65 constructor 1; unfold setoid1_of_setoid; simplify;
66 [ intros; apply (c = c1)
67 | intros; split; intro;
68 [ apply (trans ????? (H \sup -1));
69 apply (trans ????? H2);
71 | apply (trans ????? H);
72 apply (trans ????? H2);
77 cases f (w H); clear f; cases H; clear H;
78 [cases f (w1 H); clear f | cases f1 (w1 H); clear f1]
80 exists; try assumption;
81 split; try assumption;
82 exists; try assumption;
84 |6,7: intros 5; unfold composition; simplify; split; intro;
85 unfold setoid1_of_setoid in x y; simplify in x y;
86 [1,3: cases H (w H1); clear H; cases H1; clear H1; unfold;
87 [ apply (. (H \sup -1 : eq1 ? w x)‡#); assumption
88 | apply (. #‡(H : eq1 ? w y)); assumption]
89 |2,4: exists; try assumption; split; first [apply refl | assumption]]]
92 definition full_subset: ∀s:REL. Ω \sup s.
93 apply (λs.{x | True});
94 intros; simplify; split; intro; assumption.
99 definition setoid1_of_REL: REL → setoid ≝ λS. S.
101 coercion setoid1_of_REL.
103 definition comprehension: ∀b:REL. (b ⇒ CPROP) → Ω \sup b.
104 apply (λb:REL. λP: b ⇒ CPROP. {x | x ∈ b ∧ P x});
105 intros; simplify; apply (.= (H‡#)‡(†H)); apply refl1.
108 interpretation "subset comprehension" 'comprehension s p =
109 (comprehension s (mk_unary_morphism __ p _)).
111 definition ext: ∀X,S:REL. binary_morphism1 (arrows1 ? X S) S (Ω \sup X).
112 apply (λX,S.mk_binary_morphism1 ??? (λr:arrows1 ? X S.λf:S.{x ∈ X | x ♮r f}) ?);
113 [ intros; simplify; apply (.= (H‡#)); apply refl1
114 | intros; simplify; split; intros; simplify; intros; cases f; split; try assumption;
115 [ apply (. (#‡H1)); whd in H; apply (if ?? (H ??)); assumption
116 | apply (. (#‡H1\sup -1)); whd in H; apply (fi ?? (H ??));assumption]]
119 definition extS: ∀X,S:REL. ∀r: arrows1 ? X S. Ω \sup S ⇒ Ω \sup X.
120 (* ∃ is not yet a morphism apply (λX,S,r,F.{x ∈ X | ∃a. a ∈ F ∧ x ♮r a});*)
121 intros (X S r); constructor 1;
122 [ intro F; constructor 1; constructor 1;
123 [ apply (λx. x ∈ X ∧ ∃a:S. a ∈ F ∧ x ♮r a);
124 | intros; split; intro; cases f (H1 H2); clear f; split;
125 [ apply (. (H‡#)); assumption
126 |3: apply (. (H\sup -1‡#)); assumption
127 |2,4: cases H2 (w H3); exists; [1,3: apply w]
128 [ apply (. (#‡(H‡#))); assumption
129 | apply (. (#‡(H \sup -1‡#))); assumption]]]
130 | intros; split; simplify; intros; cases f; cases H1; split;
132 |2,4: exists; [1,3: apply w]
133 [ apply (. (#‡H)‡#); assumption
134 | apply (. (#‡H\sup -1)‡#); assumption]]]
137 lemma equalset_extS_id_X_X: ∀o:REL.∀X.extS ?? (id1 ? o) X = X.
139 unfold extS; simplify;
141 [ intros 2; change with (a ∈ X);
145 change in f2 with (eq1 ? a w);
146 apply (. (f2\sup -1‡#));
148 | intros 2; change in f with (a ∈ X);
151 | exists; [ apply a ]
154 | change with (a = a); apply refl]]]
157 lemma extS_com: ∀o1,o2,o3,c1,c2,S. extS o1 o3 (c2 ∘ c1) S = extS o1 o2 c1 (extS o2 o3 c2 S).
158 intros; unfold extS; simplify; split; intros; simplify; intros;
159 [ cases f (H1 H2); cases H2 (w H3); clear f H2; split; [assumption]
160 cases H3 (H4 H5); cases H5 (w1 H6); clear H3 H5; cases H6 (H7 H8); clear H6;
161 exists; [apply w1] split [2: assumption] constructor 1; [assumption]
162 exists; [apply w] split; assumption
163 | cases f (H1 H2); cases H2 (w H3); clear f H2; split; [assumption]
164 cases H3 (H4 H5); cases H4 (w1 H6); clear H3 H4; cases H6 (w2 H7); clear H6;
165 cases H7; clear H7; exists; [apply w2] split; [assumption] exists [apply w] split;
169 (* the same as ⋄ for a basic pair *)
170 definition image: ∀U,V:REL. binary_morphism1 (arrows1 ? U V) (Ω \sup U) (Ω \sup V).
171 intros; constructor 1;
172 [ apply (λr: arrows1 ? U V.λS: Ω \sup U. {y | ∃x:U. x ♮r y ∧ x ∈ S});
173 intros; simplify; split; intro; cases H1; exists [1,3: apply w]
174 [ apply (. (#‡H)‡#); assumption
175 | apply (. (#‡H \sup -1)‡#); assumption]
176 | intros; split; simplify; intros; cases H2; exists [1,3: apply w]
177 [ apply (. #‡(#‡H1)); cases x; split; try assumption;
178 apply (if ?? (H ??)); assumption
179 | apply (. #‡(#‡H1 \sup -1)); cases x; split; try assumption;
180 apply (if ?? (H \sup -1 ??)); assumption]]
183 (* the same as □ for a basic pair *)
184 definition minus_star_image: ∀U,V:REL. binary_morphism1 (arrows1 ? U V) (Ω \sup U) (Ω \sup V).
185 intros; constructor 1;
186 [ apply (λr: arrows1 ? U V.λS: Ω \sup U. {y | ∀x:U. x ♮r y → x ∈ S});
187 intros; simplify; split; intros; apply H1;
188 [ apply (. #‡H \sup -1); assumption
189 | apply (. #‡H); assumption]
190 | intros; split; simplify; intros; [ apply (. #‡H1); | apply (. #‡H1 \sup -1)]
191 apply H2; [ apply (if ?? (H \sup -1 ??)); | apply (if ?? (H ??)) ] assumption]
194 (* minus_image is the same as ext *)
196 theorem image_id: ∀o,U. image o o (id1 REL o) U = U.
197 intros; unfold image; simplify; split; simplify; intros;
198 [ change with (a ∈ U);
199 cases H; cases x; change in f with (eq1 ? w a); apply (. f‡#); assumption
200 | change in f with (a ∈ U);
201 exists; [apply a] split; [ change with (a = a); apply refl | assumption]]
204 theorem minus_star_image_id: ∀o,U. minus_star_image o o (id1 REL o) U = U.
205 intros; unfold minus_star_image; simplify; split; simplify; intros;
206 [ change with (a ∈ U); apply H; change with (a=a); apply refl
207 | change in f1 with (eq1 ? x a); apply (. f1 \sup -1‡#); apply f]
210 theorem image_comp: ∀A,B,C,r,s,X. image A C (r ∘ s) X = image B C r (image A B s X).
211 intros; unfold image; simplify; split; simplify; intros; cases H; clear H; cases x;
212 clear x; [ cases f; clear f; | cases f1; clear f1 ]
213 exists; try assumption; cases x; clear x; split; try assumption;
214 exists; try assumption; split; assumption.
217 theorem minus_star_image_comp:
219 minus_star_image A C (r ∘ s) X = minus_star_image B C r (minus_star_image A B s X).
220 intros; unfold minus_star_image; simplify; split; simplify; intros; whd; intros;
221 [ apply H; exists; try assumption; split; assumption
222 | change with (x ∈ X); cases f; cases x1; apply H; assumption]
230 ∀x. ext ?? (b∘a) x = extS ?? a (ext ?? b x).
232 unfold ext; unfold extS; simplify; split; intro; simplify; intros;
233 cases f; clear f; split; try assumption;
234 [ cases f2; clear f2; cases x1; clear x1; exists; [apply w] split;
235 [1: split] assumption;
236 | cases H; clear H; cases x1; clear x1; exists [apply w]; split;
237 [2: cases f] assumption]
240 theorem extS_singleton:
241 ∀o1,o2.∀a:arrows1 ? o1 o2.∀x.extS o1 o2 a (singleton o2 x) = ext o1 o2 a x.
242 intros; unfold extS; unfold ext; unfold singleton; simplify;
243 split; intros 2; simplify; cases f; split; try assumption;
244 [ cases H; cases x1; change in f2 with (eq1 ? x w); apply (. #‡f2 \sup -1);
246 | exists; try assumption; split; try assumption; change with (x = x); apply refl]