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 (**************************************************************************)
17 include "higher_order_defs/relations.ma".
18 include "nat/plus.ma".
19 include "constructive_higher_order_relations.ma".
20 include "constructive_connectives.ma".
22 record excess_base : Type ≝ {
24 exc_excess: exc_carr → exc_carr → Type;
25 exc_coreflexive: coreflexive ? exc_excess;
26 exc_cotransitive: cotransitive ? exc_excess
29 interpretation "Excess base excess" 'nleq a b = (exc_excess _ a b).
31 (* E(#,≰) → E(#,sym(≰)) *)
32 lemma make_dual_exc: excess_base → excess_base.
34 apply (mk_excess_base (exc_carr E));
35 [ apply (λx,y:E.y≰x);|apply exc_coreflexive;
36 | unfold cotransitive; simplify; intros (x y z H);
37 cases (exc_cotransitive E ??z H);[right|left]assumption]
40 record excess_dual : Type ≝ {
41 exc_dual_base:> excess_base;
42 exc_dual_dual_ : excess_base;
43 exc_with: exc_dual_dual_ = make_dual_exc exc_dual_base
46 lemma mk_excess_dual_smart: excess_base → excess_dual.
47 intro; apply mk_excess_dual; [apply e| apply (make_dual_exc e)|reflexivity]
50 definition exc_dual_dual: excess_dual → excess_base.
51 intro E; apply (make_dual_exc E);
54 coercion cic:/matita/excess/exc_dual_dual.con.
56 record apartness : Type ≝ {
58 ap_apart: ap_carr → ap_carr → Type;
59 ap_coreflexive: coreflexive ? ap_apart;
60 ap_symmetric: symmetric ? ap_apart;
61 ap_cotransitive: cotransitive ? ap_apart
64 notation "hvbox(a break # b)" non associative with precedence 50 for @{ 'apart $a $b}.
65 interpretation "apartness" 'apart x y = (ap_apart _ x y).
67 definition apartness_of_excess_base: excess_base → apartness.
68 intros (E); apply (mk_apartness E (λa,b:E. a ≰ b ∨ b ≰ a));
69 [1: unfold; cases E; simplify; clear E; intros (x); unfold;
70 intros (H1); apply (H x); cases H1; assumption;
71 |2: unfold; intros(x y H); cases H; clear H; [right|left] assumption;
72 |3: intros (E); unfold; cases E (T f _ cTf); simplify; intros (x y z Axy);
73 cases Axy (H H); lapply (cTf ? ? z H) as H1; cases H1; clear Axy H1;
74 [left; left|right; left|right; right|left; right] assumption]
77 record excess_ : Type ≝ {
78 exc_exc:> excess_dual;
80 exc_with1: ap_carr exc_ap_ = exc_carr exc_exc
83 definition exc_ap: excess_ → apartness.
84 intro E; apply (mk_apartness E); unfold Type_OF_excess_;
85 cases (exc_with1 E); simplify;
86 [apply (ap_apart (exc_ap_ E));
87 |apply ap_coreflexive;|apply ap_symmetric;|apply ap_cotransitive]
90 coercion cic:/matita/excess/exc_ap.con.
92 interpretation "Excess excess_" 'nleq a b =
93 (exc_excess (excess_base_OF_excess_1 _) a b).
95 record excess : Type ≝ {
96 excess_carr:> excess_;
97 ap2exc: ∀y,x:excess_carr. y # x → y ≰ x ∨ x ≰ y;
98 exc2ap: ∀y,x:excess_carr.y ≰ x ∨ x ≰ y → y # x
101 interpretation "Excess excess" 'nleq a b =
102 (exc_excess (excess_base_OF_excess1 _) a b).
104 interpretation "Excess (dual) excess" 'ngeq a b =
105 (exc_excess (excess_base_OF_excess _) a b).
107 definition strong_ext ≝ λA:apartness.λop:A→A.∀x,y. op x # op y → x # y.
109 definition le ≝ λE:excess_base.λa,b:E. ¬ (a ≰ b).
111 interpretation "Excess less or equal than" 'leq a b =
112 (le (excess_base_OF_excess1 _) a b).
114 interpretation "Excess less or equal than" 'geq a b =
115 (le (excess_base_OF_excess _) a b).
117 lemma le_reflexive: ∀E.reflexive ? (le E).
118 unfold reflexive; intros 3 (E x H); apply (exc_coreflexive ?? H);
121 lemma le_transitive: ∀E.transitive ? (le E).
122 unfold transitive; intros 7 (E x y z H1 H2 H3); cases (exc_cotransitive ??? y H3) (H4 H4);
123 [cases (H1 H4)|cases (H2 H4)]
126 definition eq ≝ λA:apartness.λa,b:A. ¬ (a # b).
128 notation "hvbox(a break ≈ b)" non associative with precedence 50 for @{ 'napart $a $b}.
129 interpretation "Apartness alikeness" 'napart a b = (eq _ a b).
130 interpretation "Excess alikeness" 'napart a b = (eq (excess_base_OF_excess1 _) a b).
131 interpretation "Excess (dual) alikeness" 'napart a b = (eq (excess_base_OF_excess _) a b).
133 lemma eq_reflexive:∀E:apartness. reflexive ? (eq E).
134 intros (E); unfold; intros (x); apply ap_coreflexive;
137 lemma eq_sym_:∀E:apartness.symmetric ? (eq E).
138 unfold symmetric; intros 5 (E x y H H1); cases (H (ap_symmetric ??? H1));
141 lemma eq_sym:∀E:apartness.∀x,y:E.x ≈ y → y ≈ x ≝ eq_sym_.
144 coercion cic:/matita/excess/eq_sym.con.
146 lemma eq_trans_: ∀E:apartness.transitive ? (eq E).
147 (* bug. intros k deve fare whd quanto basta *)
148 intros 6 (E x y z Exy Eyz); intro Axy; cases (ap_cotransitive ???y Axy);
149 [apply Exy|apply Eyz] assumption.
152 lemma eq_trans:∀E:apartness.∀x,z,y:E.x ≈ y → y ≈ z → x ≈ z ≝
153 λE,x,y,z.eq_trans_ E x z y.
155 notation > "'Eq'≈" non associative with precedence 50 for @{'eqrewrite}.
156 interpretation "eq_rew" 'eqrewrite = (eq_trans _ _ _).
158 alias id "antisymmetric" = "cic:/matita/constructive_higher_order_relations/antisymmetric.con".
159 lemma le_antisymmetric:
160 ∀E:excess.antisymmetric ? (le (excess_base_OF_excess1 E)) (eq E).
161 intros 5 (E x y Lxy Lyx); intro H;
162 cases (ap2exc ??? H); [apply Lxy;|apply Lyx] assumption;
165 definition lt ≝ λE:excess.λa,b:E. a ≤ b ∧ a # b.
167 interpretation "ordered sets less than" 'lt a b = (lt _ a b).
169 lemma lt_coreflexive: ∀E.coreflexive ? (lt E).
170 intros 2 (E x); intro H; cases H (_ ABS);
171 apply (ap_coreflexive ? x ABS);
174 lemma lt_transitive: ∀E.transitive ? (lt E).
175 intros (E); unfold; intros (x y z H1 H2); cases H1 (Lxy Axy); cases H2 (Lyz Ayz);
176 split; [apply (le_transitive ???? Lxy Lyz)] clear H1 H2;
177 elim (ap2exc ??? Axy) (H1 H1); elim (ap2exc ??? Ayz) (H2 H2); [1:cases (Lxy H1)|3:cases (Lyz H2)]
178 clear Axy Ayz;lapply (exc_cotransitive (exc_dual_base E)) as c; unfold cotransitive in c;
179 lapply (exc_coreflexive (exc_dual_base E)) as r; unfold coreflexive in r;
180 [1: lapply (c ?? y H1) as H3; elim H3 (H4 H4); [cases (Lxy H4)|cases (r ? H4)]
181 |2: lapply (c ?? x H2) as H3; elim H3 (H4 H4); [apply exc2ap; right; assumption|cases (Lxy H4)]]
184 theorem lt_to_excess: ∀E:excess.∀a,b:E. (a < b) → (b ≰ a).
185 intros (E a b Lab); elim Lab (LEab Aab);
186 elim (ap2exc ??? Aab) (H H); [cases (LEab H)] fold normalize (b ≰ a); assumption; (* BUG *)
189 lemma le_rewl: ∀E:excess.∀z,y,x:E. x ≈ y → x ≤ z → y ≤ z.
190 intros (E z y x Exy Lxz); apply (le_transitive ???? ? Lxz);
191 intro Xyz; apply Exy; apply exc2ap; right; assumption;
194 lemma le_rewr: ∀E:excess.∀z,y,x:E. x ≈ y → z ≤ x → z ≤ y.
195 intros (E z y x Exy Lxz); apply (le_transitive ???? Lxz);
196 intro Xyz; apply Exy; apply exc2ap; left; assumption;
199 notation > "'Le'≪" non associative with precedence 50 for @{'lerewritel}.
200 interpretation "le_rewl" 'lerewritel = (le_rewl _ _ _).
201 notation > "'Le'≫" non associative with precedence 50 for @{'lerewriter}.
202 interpretation "le_rewr" 'lerewriter = (le_rewr _ _ _).
204 lemma ap_rewl: ∀A:apartness.∀x,z,y:A. x ≈ y → y # z → x # z.
205 intros (A x z y Exy Ayz); cases (ap_cotransitive ???x Ayz); [2:assumption]
206 cases (Exy (ap_symmetric ??? a));
209 lemma ap_rewr: ∀A:apartness.∀x,z,y:A. x ≈ y → z # y → z # x.
210 intros (A x z y Exy Azy); apply ap_symmetric; apply (ap_rewl ???? Exy);
211 apply ap_symmetric; assumption;
214 notation > "'Ap'≪" non associative with precedence 50 for @{'aprewritel}.
215 interpretation "ap_rewl" 'aprewritel = (ap_rewl _ _ _).
216 notation > "'Ap'≫" non associative with precedence 50 for @{'aprewriter}.
217 interpretation "ap_rewr" 'aprewriter = (ap_rewr _ _ _).
219 alias symbol "napart" = "Apartness alikeness".
220 lemma exc_rewl: ∀A:excess.∀x,z,y:A. x ≈ y → y ≰ z → x ≰ z.
221 intros (A x z y Exy Ayz); elim (exc_cotransitive ???x Ayz); [2:assumption]
222 cases Exy; apply exc2ap; right; assumption;
225 lemma exc_rewr: ∀A:excess.∀x,z,y:A. x ≈ y → z ≰ y → z ≰ x.
226 intros (A x z y Exy Azy); elim (exc_cotransitive ???x Azy); [assumption]
227 elim (Exy); apply exc2ap; left; assumption;
230 notation > "'Ex'≪" non associative with precedence 50 for @{'excessrewritel}.
231 interpretation "exc_rewl" 'excessrewritel = (exc_rewl _ _ _).
232 notation > "'Ex'≫" non associative with precedence 50 for @{'excessrewriter}.
233 interpretation "exc_rewr" 'excessrewriter = (exc_rewr _ _ _).
235 lemma lt_rewr: ∀A:excess.∀x,z,y:A. x ≈ y → z < y → z < x.
236 intros (A x y z E H); split; elim H;
237 [apply (Le≫ ? (eq_sym ??? E));|apply (Ap≫ ? E)] assumption;
240 lemma lt_rewl: ∀A:excess.∀x,z,y:A. x ≈ y → y < z → x < z.
241 intros (A x y z E H); split; elim H;
242 [apply (Le≪ ? (eq_sym ??? E));| apply (Ap≪ ? E);] assumption;
245 notation > "'Lt'≪" non associative with precedence 50 for @{'ltrewritel}.
246 interpretation "lt_rewl" 'ltrewritel = (lt_rewl _ _ _).
247 notation > "'Lt'≫" non associative with precedence 50 for @{'ltrewriter}.
248 interpretation "lt_rewr" 'ltrewriter = (lt_rewr _ _ _).
250 lemma lt_le_transitive: ∀A:excess.∀x,y,z:A.x < y → y ≤ z → x < z.
251 intros (A x y z LT LE); cases LT (LEx APx); split; [apply (le_transitive ???? LEx LE)]
252 apply exc2ap; cases (ap2exc ??? APx) (EXx EXx); [cases (LEx EXx)]
253 cases (exc_cotransitive ??? z EXx) (EXz EXz); [cases (LE EXz)]
257 lemma le_lt_transitive: ∀A:excess.∀x,y,z:A.x ≤ y → y < z → x < z.
258 intros (A x y z LE LT); cases LT (LEx APx); split; [apply (le_transitive ???? LE LEx)]
259 elim (ap2exc ??? APx) (EXx EXx); [cases (LEx EXx)]
260 elim (exc_cotransitive ??? x EXx) (EXz EXz); [apply exc2ap; right; assumption]
261 cases LE; assumption;
264 lemma le_le_eq: ∀E:excess.∀a,b:E. a ≤ b → b ≤ a → a ≈ b.
265 intros (E x y L1 L2); intro H; cases (ap2exc ??? H); [apply L1|apply L2] assumption;
268 lemma eq_le_le: ∀E:excess.∀a,b:E. a ≈ b → a ≤ b ∧ b ≤ a.
269 intros (E x y H); whd in H;
270 split; intro; apply H; apply exc2ap; [left|right] assumption.
273 lemma ap_le_to_lt: ∀E:excess.∀a,c:E.c # a → c ≤ a → c < a.
274 intros; split; assumption;
277 definition total_order_property : ∀E:excess. Type ≝
278 λE:excess. ∀a,b:E. a ≰ b → b < a.