]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/library/formal_topology/relations.ma
72e12aa9dc500009518aebf7fb7038f629821771
[helm.git] / helm / software / matita / library / formal_topology / relations.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 "datatypes/subsets.ma".
16
17 record binary_relation (A,B: setoid) : Type ≝
18  { satisfy:> binary_morphism1 A B CPROP }.
19
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).
23
24 definition binary_relation_setoid: setoid → setoid → setoid1.
25  intros (A B);
26  constructor 1;
27   [ apply (binary_relation A B)
28   | constructor 1;
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 ??)) ]
36        assumption]]
37 qed.
38
39 definition composition:
40  ∀A,B,C.
41   binary_morphism1 (binary_relation_setoid A B) (binary_relation_setoid B C) (binary_relation_setoid A C).
42  intros;
43  constructor 1;
44   [ intros (R12 R23);
45     constructor 1;
46     constructor 1;
47      [ apply (λs1:A.λs3:C.∃s2:B. s1 ♮R12 s2 ∧ s2 ♮R23 s3);
48      | intros;
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;
57     split; assumption]
58 qed.
59
60 definition REL: category1.
61  constructor 1;
62   [ apply setoid
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);
70           apply H1
71         | apply (trans ????? H);
72           apply (trans ????? H2);
73           apply (H1 \sup -1)]]
74   | apply composition
75   | intros 9;
76     split; intro;
77     cases f (w H); clear f; cases H; clear H;
78     [cases f (w1 H); clear f | cases f1 (w1 H); clear f1]
79     cases H; clear H;
80     exists; try assumption;
81     split; try assumption;
82     exists; try assumption;
83     split; 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]]]
90 qed.
91
92 definition full_subset: ∀s:REL. Ω \sup s.
93  apply (λs.{x | True});
94  intros; simplify; split; intro; assumption.
95 qed.
96
97 coercion full_subset.
98
99 definition setoid1_of_REL: REL → setoid ≝ λS. S.
100
101 coercion setoid1_of_REL.
102
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.
106 qed.
107
108 interpretation "subset comprehension" 'comprehension s p =
109  (comprehension s (mk_unary_morphism __ p _)).
110
111 definition ext: ∀X,S:REL. ∀r: arrows1 ? X S. S ⇒ Ω \sup X.
112  apply (λX,S,r.mk_unary_morphism ?? (λf.{x ∈ X | x ♮r f}) ?);
113   [ intros; simplify; apply (.= (H‡#)); apply refl1
114   | intros; simplify; split; intros; simplify; intros;
115      [ apply (. #‡(#‡H)); assumption
116      | apply (. #‡(#‡H\sup -1)); assumption]]
117 qed.
118
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;
131      [1,3: assumption
132      |2,4: exists; [1,3: apply w]
133       [ apply (. (#‡H)‡#); assumption
134       | apply (. (#‡H\sup -1)‡#); assumption]]]
135 qed.
136
137 lemma equalset_extS_id_X_X: ∀o:REL.∀X.extS ?? (id1 ? o) X = X.
138  intros;
139  unfold extS; simplify;
140  split; simplify;
141   [ intros 2; change with (a ∈ X);
142     cases f; clear f;
143     cases H; clear H;
144     cases x; clear x;
145     change in f2 with (eq1 ? a w);
146     apply (. (f2\sup -1‡#));
147     assumption
148   | intros 2; change in f with (a ∈ X);
149     split;
150      [ whd; exact I 
151      | exists; [ apply a ]
152        split;
153         [ assumption
154         | change with (a = a); apply refl]]]
155 qed.
156
157 lemma extS_com: ∀o1,o2,o3,c1,c2,S. extS o1 o3 (c1 ∘ c2) 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;
166     assumption]
167 qed.
168