]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/library/dama/ordered_set.ma
Preparing for 0.5.9 release.
[helm.git] / helm / software / matita / library / dama / ordered_set.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/constructors.ma".
16 include "logic/cprop_connectives.ma".
17
18
19 (* TEMPLATES
20 notation "''" non associative with precedence 90 for @{'}.
21 notation "''" non associative with precedence 90 for @{'}.
22
23 interpretation "" ' = ( (os_l ?)).
24 interpretation "" ' = ( (os_r ?)).
25 *)
26
27 (* Definition 2.1 *)
28 record half_ordered_set: Type ≝ {
29   hos_carr:> Type;
30   wloss: ∀A,B:Type. (A → A → B) → A → A → B;
31   wloss_prop: (∀T,R,P,x,y.P x y = wloss T R P x y) ∨ (∀T,R,P,x,y.P y x = wloss T R P x y); 
32   hos_excess_: hos_carr → hos_carr → CProp;
33   hos_coreflexive: coreflexive ? (wloss ?? hos_excess_);
34   hos_cotransitive: cotransitive ? (wloss ?? hos_excess_)
35 }.
36
37 definition hos_excess ≝ λO:half_ordered_set.wloss O ?? (hos_excess_ O). 
38
39 definition dual_hos : half_ordered_set → half_ordered_set.
40 intro; constructor 1;
41 [ apply (hos_carr h);
42 | apply (λT,R,f,x,y.wloss h T R f y x); 
43 | intros; cases (wloss_prop h);[right|left]intros;apply H; 
44 | apply (hos_excess_ h);
45 | apply (hos_coreflexive h);
46 | intros 4 (x y z H); simplify in H ⊢ %; cases (hos_cotransitive h y x z H);
47   [right|left] assumption;]
48 qed.
49
50 record ordered_set : Type ≝ {
51   os_l : half_ordered_set
52 }.
53
54 definition os_r : ordered_set → half_ordered_set.
55 intro o; apply (dual_hos (os_l o)); qed.
56
57 lemma half2full : half_ordered_set → ordered_set.
58 intro hos;
59 constructor 1; apply hos;  
60 qed.
61
62 definition Type_of_ordered_set : ordered_set → Type.
63 intro o; apply (hos_carr (os_l o)); qed.
64
65 definition Type_of_ordered_set_dual : ordered_set → Type.
66 intro o; apply (hos_carr (os_r o)); qed.
67
68 coercion Type_of_ordered_set_dual.
69 coercion Type_of_ordered_set.
70
71 notation "a ≰≰ b" non associative with precedence 45 for @{'nleq_low $a $b}.
72 interpretation "Ordered half set excess" 'nleq_low a b = (hos_excess ? a b).
73
74 interpretation "Ordered set excess (dual)" 'ngeq a b = (hos_excess (os_r ?) a b).
75 interpretation "Ordered set excess" 'nleq a b = (hos_excess (os_l ?) a b).
76
77 notation "'exc_coreflexive'" non associative with precedence 90 for @{'exc_coreflexive}.
78 notation "'cxe_coreflexive'" non associative with precedence 90 for @{'cxe_coreflexive}.
79
80 interpretation "exc_coreflexive" 'exc_coreflexive = ((hos_coreflexive (os_l ?))).
81 interpretation "cxe_coreflexive" 'cxe_coreflexive = ((hos_coreflexive (os_r ?))).
82
83 notation "'exc_cotransitive'" non associative with precedence 90 for @{'exc_cotransitive}.
84 notation "'cxe_cotransitive'" non associative with precedence 90 for @{'cxe_cotransitive}.
85
86 interpretation "exc_cotransitive" 'exc_cotransitive = ((hos_cotransitive (os_l ?))).
87 interpretation "cxe_cotransitive" 'cxe_cotransitive = ((hos_cotransitive (os_r ?))).
88
89 (* Definition 2.2 (3) *)
90 definition le ≝ λE:half_ordered_set.λa,b:E. ¬ (a ≰≰ b).
91
92 notation "hvbox(a break ≤≤ b)" non associative with precedence 45 for @{ 'leq_low $a $b }.
93 interpretation "Half ordered set greater or equal than" 'leq_low a b = ((le ? a b)).
94
95 interpretation "Ordered set greater or equal than" 'geq a b = ((le (os_r ?) a b)).
96 interpretation "Ordered set less or equal than" 'leq a b = ((le (os_l ?) a b)).
97
98 lemma hle_reflexive: ∀E.reflexive ? (le E).
99 unfold reflexive; intros 3; apply (hos_coreflexive ? x H);
100 qed.
101
102 notation "'le_reflexive'" non associative with precedence 90 for @{'le_reflexive}.
103 notation "'ge_reflexive'" non associative with precedence 90 for @{'ge_reflexive}.
104
105 interpretation "le reflexive" 'le_reflexive = (hle_reflexive (os_l ?)).
106 interpretation "ge reflexive" 'ge_reflexive = (hle_reflexive (os_r ?)).
107
108 (* DUALITY TESTS 
109 lemma test_le_ge_convertible :∀o:ordered_set.∀x,y:o. x ≤ y → y ≥ x.
110 intros; assumption; qed.
111
112 lemma test_ge_reflexive :∀o:ordered_set.∀x:o. x ≥ x.
113 intros; apply ge_reflexive. qed.
114
115 lemma test_le_reflexive :∀o:ordered_set.∀x:o. x ≤ x.
116 intros; apply le_reflexive. qed.
117 *)
118
119 lemma hle_transitive: ∀E.transitive ? (le E).
120 unfold transitive; intros 7 (E x y z H1 H2 H3); cases (hos_cotransitive E x z y H3) (H4 H4);
121 [cases (H1 H4)|cases (H2 H4)]
122 qed.
123
124 notation "'le_transitive'" non associative with precedence 90 for @{'le_transitive}.
125 notation "'ge_transitive'" non associative with precedence 90 for @{'ge_transitive}.
126
127 interpretation "le transitive" 'le_transitive = (hle_transitive (os_l ?)).
128 interpretation "ge transitive" 'ge_transitive = (hle_transitive (os_r ?)).
129
130 (* Lemma 2.3 *)
131 lemma exc_hle_variance: 
132   ∀O:half_ordered_set.∀a,b,a',b':O.a ≰≰ b → a ≤≤ a' → b' ≤≤ b → a' ≰≰ b'. 
133 intros (O a b a1 b1 Eab Laa1 Lb1b);
134 cases (hos_cotransitive ? a b a1 Eab) (H H); [cases (Laa1 H)]
135 cases (hos_cotransitive ? ?? b1 H) (H1 H1); [assumption]
136 cases (Lb1b H1);
137 qed.
138
139 notation "'exc_le_variance'" non associative with precedence 90 for @{'exc_le_variance}.
140 notation "'exc_ge_variance'" non associative with precedence 90 for @{'exc_ge_variance}.
141
142 interpretation "exc_le_variance" 'exc_le_variance = (exc_hle_variance (os_l ?)).
143 interpretation "exc_ge_variance" 'exc_ge_variance = (exc_hle_variance (os_r ?)).
144
145 definition square_exc ≝
146  λO:half_ordered_set.λx,y:O×O.\fst x ≰≰ \fst y ∨ \snd x ≰≰ \snd y.
147
148 lemma square_half_ordered_set: half_ordered_set → half_ordered_set.
149 intro O;
150 apply (mk_half_ordered_set (O × O));
151 [1: apply (wloss O);
152 |2: intros; cases (wloss_prop O); [left|right] intros; apply H;
153 |3: apply (square_exc O); 
154 |4: intro x; cases (wloss_prop O); rewrite < (H  ?? (square_exc O) x x); clear H;
155     cases x; clear x; unfold square_exc; intro H; cases H; clear H; simplify in H1;
156     [1,3: apply (hos_coreflexive O h H1);
157     |*: apply (hos_coreflexive O h1 H1);]
158 |5: intros 3 (x0 y0 z0); cases (wloss_prop O);
159     do 3 rewrite < (H  ?? (square_exc O)); clear H; cases x0; cases y0; cases z0; clear x0 y0 z0;
160     simplify; intro H; cases H; clear H;
161     [1: cases (hos_cotransitive ? h h2 h4 H1); [left;left|right;left] assumption;
162     |2: cases (hos_cotransitive ? h1 h3 h5 H1); [left;right|right;right] assumption;
163     |3: cases (hos_cotransitive ? h2 h h4 H1); [right;left|left;left] assumption;
164     |4: cases (hos_cotransitive ? h3 h1 h5 H1); [right;right|left;right] assumption;]]
165 qed.
166
167 lemma square_ordered_set: ordered_set → ordered_set.
168 intro O; constructor 1; apply (square_half_ordered_set (os_l O));
169 qed.
170
171 notation "s 2 \atop \nleq" non associative with precedence 90
172   for @{ 'square_os $s }.
173 notation > "s 'squareO'" non associative with precedence 90
174   for @{ 'squareO $s }.
175 interpretation "ordered set square" 'squareO s = (square_ordered_set s). 
176 interpretation "ordered set square" 'square_os s = (square_ordered_set s).
177
178 definition os_subset ≝ λO:ordered_set.λP,Q:O→Prop.∀x:O.P x → Q x.
179
180 interpretation "ordered set subset" 'subseteq a b = (os_subset ? a b). 
181