]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/library/formal_topology/relations.ma
e9989d4f76cbdd5df81b9e76c1e311f54c098865
[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.