]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/dama/excess.ma
826ae8c0bd721964f0520ddb854d48b3c75c9080
[helm.git] / helm / software / matita / dama / excess.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
16
17 include "higher_order_defs/relations.ma".
18 include "nat/plus.ma".
19 include "constructive_higher_order_relations.ma".
20 include "constructive_connectives.ma".
21
22 record excess_base : Type ≝ {
23   exc_carr:> Type;
24   exc_excess: exc_carr → exc_carr → Type;
25   exc_coreflexive: coreflexive ? exc_excess;
26   exc_cotransitive: cotransitive ? exc_excess 
27 }.
28
29 interpretation "excess" 'nleq a b = (cic:/matita/excess/exc_excess.con _ a b). 
30
31 record apartness : Type ≝ {
32   ap_carr:> Type;
33   ap_apart: ap_carr → ap_carr → Type;
34   ap_coreflexive: coreflexive ? ap_apart;
35   ap_symmetric: symmetric ? ap_apart;
36   ap_cotransitive: cotransitive ? ap_apart
37 }.
38
39 notation "hvbox(a break # b)" non associative with precedence 50 for @{ 'apart $a $b}.
40 interpretation "apartness" 'apart x y = (cic:/matita/excess/ap_apart.con _ x y).
41
42 definition apartness_of_excess_base: excess_base → apartness.
43 intros (E); apply (mk_apartness E (λa,b:E. a ≰ b ∨ b ≰ a));  
44 [1: unfold; cases E; simplify; clear E; intros (x); unfold;
45     intros (H1); apply (H x); cases H1; assumption;
46 |2: unfold; intros(x y H); cases H; clear H; [right|left] assumption;
47 |3: intros (E); unfold; cases E (T f _ cTf); simplify; intros (x y z Axy);
48     cases Axy (H H); lapply (cTf ? ? z H) as H1; cases H1; clear Axy H1;
49     [left; left|right; left|right; right|left; right] assumption]
50 qed.
51
52 record excess_ : Type ≝ {
53   exc_exc:> excess_base;
54   exc_ap_: apartness;
55   exc_with: ap_carr exc_ap_ = exc_carr exc_exc
56 }.
57
58 definition exc_ap: excess_ → apartness.
59 intro E; apply (mk_apartness E); unfold Type_OF_excess_; 
60 cases (exc_with E); simplify;
61 [apply (ap_apart (exc_ap_ E));
62 |apply ap_coreflexive;|apply ap_symmetric;|apply ap_cotransitive] 
63 qed.
64
65 coercion cic:/matita/excess/exc_ap.con.
66
67 record excess : Type ≝ {
68   excess_carr:> excess_;
69   ap2exc: ∀y,x:excess_carr. y # x → y ≰ x ∨ x ≰ y;
70   exc2ap: ∀y,x:excess_carr.y ≰ x ∨ x ≰ y →  y # x 
71 }.
72
73 definition strong_ext ≝ λA:apartness.λop:A→A.∀x,y. op x # op y → x # y.
74
75 definition le ≝ λE:excess.λa,b:E. ¬ (a ≰ b).
76
77 interpretation "ordered sets less or equal than" 'leq a b = 
78  (cic:/matita/excess/le.con _ a b).
79
80 lemma le_reflexive: ∀E.reflexive ? (le E).
81 unfold reflexive; intros 3 (E x H); apply (exc_coreflexive ?? H);
82 qed.
83
84 lemma le_transitive: ∀E.transitive ? (le E).
85 unfold transitive; intros 7 (E x y z H1 H2 H3); cases (exc_cotransitive ??? y H3) (H4 H4);
86 [cases (H1 H4)|cases (H2 H4)]
87 qed.
88
89 definition eq ≝ λA:apartness.λa,b:A. ¬ (a # b).
90
91 notation "hvbox(a break ≈ b)" non associative with precedence 50 for @{ 'napart $a $b}.    
92 interpretation "alikeness" 'napart a b =
93   (cic:/matita/excess/eq.con _ a b). 
94
95 lemma eq_reflexive:∀E. reflexive ? (eq E).
96 intros (E); unfold; intros (x); apply ap_coreflexive; 
97 qed.
98
99 lemma eq_sym_:∀E.symmetric ? (eq E).
100 unfold symmetric; intros 5 (E x y H H1); cases (H (ap_symmetric ??? H1)); 
101 qed.
102
103 lemma eq_sym:∀E:apartness.∀x,y:E.x ≈ y → y ≈ x ≝ eq_sym_.
104
105 (* SETOID REWRITE *)
106 coercion cic:/matita/excess/eq_sym.con.
107
108 lemma eq_trans_: ∀E.transitive ? (eq E).
109 (* bug. intros k deve fare whd quanto basta *)
110 intros 6 (E x y z Exy Eyz); intro Axy; cases (ap_cotransitive ???y Axy); 
111 [apply Exy|apply Eyz] assumption.
112 qed.
113
114 lemma eq_trans:∀E:apartness.∀x,z,y:E.x ≈ y → y ≈ z → x ≈ z ≝ 
115   λE,x,y,z.eq_trans_ E x z y.
116
117 notation > "'Eq'≈" non associative with precedence 50 for @{'eqrewrite}.
118 interpretation "eq_rew" 'eqrewrite = (cic:/matita/excess/eq_trans.con _ _ _).
119
120 alias id "antisymmetric" = "cic:/matita/constructive_higher_order_relations/antisymmetric.con".
121 lemma le_antisymmetric: ∀E.antisymmetric ? (le E) (eq ?).
122 intros 5 (E x y Lxy Lyx); intro H; 
123 cases (ap2exc ??? H); [apply Lxy;|apply Lyx] assumption;
124 qed.
125
126 definition lt ≝ λE:excess.λa,b:E. a ≤ b ∧ a # b.
127
128 interpretation "ordered sets less than" 'lt a b = (cic:/matita/excess/lt.con _ a b).
129
130 lemma lt_coreflexive: ∀E.coreflexive ? (lt E).
131 intros 2 (E x); intro H; cases H (_ ABS); 
132 apply (ap_coreflexive ? x ABS);
133 qed.
134  
135 lemma lt_transitive: ∀E.transitive ? (lt E).
136 intros (E); unfold; intros (x y z H1 H2); cases H1 (Lxy Axy); cases H2 (Lyz Ayz); 
137 split; [apply (le_transitive ???? Lxy Lyz)] clear H1 H2;
138 elim (ap2exc ??? Axy) (H1 H1); elim (ap2exc ??? Ayz) (H2 H2); [1:cases (Lxy H1)|3:cases (Lyz H2)]
139 clear Axy Ayz;lapply (exc_cotransitive E) as c; unfold cotransitive in c;
140 lapply (exc_coreflexive E) as r; unfold coreflexive in r;
141 [1: lapply (c ?? y H1) as H3; elim H3 (H4 H4); [cases (Lxy H4)|cases (r ? H4)]
142 |2: lapply (c ?? x H2) as H3; elim H3 (H4 H4); [apply exc2ap; right; assumption|cases (Lxy H4)]]
143 qed.
144
145 theorem lt_to_excess: ∀E:excess.∀a,b:E. (a < b) → (b ≰ a).
146 intros (E a b Lab); elim Lab (LEab Aab);
147 elim (ap2exc ??? Aab) (H H); [cases (LEab H)] fold normalize (b ≰ a); assumption; (* BUG *)  
148 qed.
149
150 lemma le_rewl: ∀E:excess.∀z,y,x:E. x ≈ y → x ≤ z → y ≤ z.
151 intros (E z y x Exy Lxz); apply (le_transitive ???? ? Lxz);
152 intro Xyz; apply Exy; apply exc2ap; right; assumption;
153 qed.
154
155 lemma le_rewr: ∀E:excess.∀z,y,x:E. x ≈ y → z ≤ x → z ≤ y.
156 intros (E z y x Exy Lxz); apply (le_transitive ???? Lxz);
157 intro Xyz; apply Exy; apply exc2ap; left; assumption;
158 qed.
159
160 notation > "'Le'≪" non associative with precedence 50 for @{'lerewritel}.
161 interpretation "le_rewl" 'lerewritel = (cic:/matita/excess/le_rewl.con _ _ _).
162 notation > "'Le'≫" non associative with precedence 50 for @{'lerewriter}.
163 interpretation "le_rewr" 'lerewriter = (cic:/matita/excess/le_rewr.con _ _ _).
164
165 lemma ap_rewl: ∀A:apartness.∀x,z,y:A. x ≈ y → y # z → x # z.
166 intros (A x z y Exy Ayz); cases (ap_cotransitive ???x Ayz); [2:assumption]
167 cases (Exy (ap_symmetric ??? a));
168 qed.
169   
170 lemma ap_rewr: ∀A:apartness.∀x,z,y:A. x ≈ y → z # y → z # x.
171 intros (A x z y Exy Azy); apply ap_symmetric; apply (ap_rewl ???? Exy);
172 apply ap_symmetric; assumption;
173 qed.
174
175 notation > "'Ap'≪" non associative with precedence 50 for @{'aprewritel}.
176 interpretation "ap_rewl" 'aprewritel = (cic:/matita/excess/ap_rewl.con _ _ _).
177 notation > "'Ap'≫" non associative with precedence 50 for @{'aprewriter}.
178 interpretation "ap_rewr" 'aprewriter = (cic:/matita/excess/ap_rewr.con _ _ _).
179
180 lemma exc_rewl: ∀A:excess.∀x,z,y:A. x ≈ y → y ≰ z → x ≰ z.
181 intros (A x z y Exy Ayz); elim (exc_cotransitive ???x Ayz); [2:assumption]
182 cases Exy; apply exc2ap; right; assumption;
183 qed.
184   
185 lemma exc_rewr: ∀A:excess.∀x,z,y:A. x ≈ y → z ≰ y → z ≰ x.
186 intros (A x z y Exy Azy); elim (exc_cotransitive ???x Azy); [assumption]
187 elim (Exy); apply exc2ap; left; assumption;
188 qed.
189
190 notation > "'Ex'≪" non associative with precedence 50 for @{'excessrewritel}.
191 interpretation "exc_rewl" 'excessrewritel = (cic:/matita/excess/exc_rewl.con _ _ _).
192 notation > "'Ex'≫" non associative with precedence 50 for @{'excessrewriter}.
193 interpretation "exc_rewr" 'excessrewriter = (cic:/matita/excess/exc_rewr.con _ _ _).
194
195 lemma lt_rewr: ∀A:excess.∀x,z,y:A. x ≈ y → z < y → z < x.
196 intros (A x y z E H); split; elim H; 
197 [apply (Le≫ ? (eq_sym ??? E));|apply (Ap≫ ? E)] assumption;
198 qed.
199
200 lemma lt_rewl: ∀A:excess.∀x,z,y:A. x ≈ y → y < z → x < z.
201 intros (A x y z E H); split; elim H; 
202 [apply (Le≪ ? (eq_sym ??? E));| apply (Ap≪ ? E);] assumption;
203 qed.
204
205 notation > "'Lt'≪" non associative with precedence 50 for @{'ltrewritel}.
206 interpretation "lt_rewl" 'ltrewritel = (cic:/matita/excess/lt_rewl.con _ _ _).
207 notation > "'Lt'≫" non associative with precedence 50 for @{'ltrewriter}.
208 interpretation "lt_rewr" 'ltrewriter = (cic:/matita/excess/lt_rewr.con _ _ _).
209
210 lemma lt_le_transitive: ∀A:excess.∀x,y,z:A.x < y → y ≤ z → x < z.
211 intros (A x y z LT LE); cases LT (LEx APx); split; [apply (le_transitive ???? LEx LE)]
212 apply exc2ap; cases (ap2exc ??? APx) (EXx EXx); [cases (LEx EXx)]
213 cases (exc_cotransitive ??? z EXx) (EXz EXz); [cases (LE EXz)]
214 right; assumption;
215 qed.
216
217 lemma le_lt_transitive: ∀A:excess.∀x,y,z:A.x ≤ y → y < z → x < z.
218 intros (A x y z LE LT); cases LT (LEx APx); split; [apply (le_transitive ???? LE LEx)]
219 elim (ap2exc ??? APx) (EXx EXx); [cases (LEx EXx)]
220 elim (exc_cotransitive ??? x EXx) (EXz EXz); [apply exc2ap; right; assumption]
221 cases LE; assumption;
222 qed.
223     
224 lemma le_le_eq: ∀E:excess.∀a,b:E. a ≤ b → b ≤ a → a ≈ b.
225 intros (E x y L1 L2); intro H; cases (ap2exc ??? H); [apply L1|apply L2] assumption;
226 qed.
227
228 lemma eq_le_le: ∀E:excess.∀a,b:E. a ≈ b → a ≤ b ∧ b ≤ a.
229 intros (E x y H); whd in H;
230 split; intro; apply H; apply exc2ap; [left|right] assumption.
231 qed.
232
233 lemma ap_le_to_lt: ∀E:excess.∀a,c:E.c # a → c ≤ a → c < a.
234 intros; split; assumption;
235 qed.
236
237 definition total_order_property : ∀E:excess. Type ≝ 
238   λE:excess. ∀a,b:E. a ≰ b → b < a.
239
240 (* E(#,≰) → E(#,sym(≰)) *)
241 lemma dual_exc: excess→ excess.
242 intro E; apply mk_excess;
243 [1: apply mk_excess_;
244   [1: apply (mk_excess_base (exc_carr (excess_carr E)));
245       [ apply (λx,y:E.y≰x);|apply exc_coreflexive;
246       | unfold cotransitive; simplify; intros (x y z H);
247         cases (exc_cotransitive E ??z H);[right|left]assumption]
248   |2: apply (exc_ap_ E);
249   |3: apply (exc_with E);]
250 |2: simplify; intros (y x H); fold simplify (y#x) in H;
251     apply ap2exc; apply ap_symmetric; apply H;
252 |3: simplify; intros; fold simplify (y#x); apply exc2ap; 
253     cases o; [right|left]assumption]
254 qed.