]> matita.cs.unibo.it Git - helm.git/blob - helm/matita/library/nat/orders.ma
Committing all the recent development of Andrea after the merge between his
[helm.git] / helm / matita / library / nat / orders.ma
1 (**************************************************************************)
2 (*       ___                                                                *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||       A.Asperti, C.Sacerdoti Coen,                          *)
8 (*      ||A||       E.Tassi, S.Zacchiroli                                 *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU Lesser General Public License Version 2.1         *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 set "baseuri" "cic:/matita/nat/orders".
16
17 include "nat/plus.ma".
18 include "higher_order_defs/ordering.ma".
19
20 (* definitions *)
21 inductive le (n:nat) : nat \to Prop \def
22   | le_n : le n n
23   | le_S : \forall m:nat. le n m \to le n (S m).
24
25 (*CSC: the URI must disappear: there is a bug now *)
26 interpretation "natural 'less or equal to'" 'leq x y = (cic:/matita/nat/orders/le.ind#xpointer(1/1) x y).
27
28 definition lt: nat \to nat \to Prop \def
29 \lambda n,m:nat.(S n) \leq m.
30
31 (*CSC: the URI must disappear: there is a bug now *)
32 interpretation "natural 'less than'" 'lt x y = (cic:/matita/nat/orders/lt.con x y).
33
34 definition ge: nat \to nat \to Prop \def
35 \lambda n,m:nat.m \leq n.
36
37 (*CSC: the URI must disappear: there is a bug now *)
38 interpretation "natural 'greater or equal to'" 'geq x y = (cic:/matita/nat/orders/ge.con x y).
39
40 definition gt: nat \to nat \to Prop \def
41 \lambda n,m:nat.m<n.
42
43 (*CSC: the URI must disappear: there is a bug now *)
44 interpretation "natural 'greater than'" 'gt x y = (cic:/matita/nat/orders/gt.con x y).
45
46 theorem transitive_le : transitive nat le.
47 simplify.intros.elim H1.
48 assumption.
49 apply le_S.assumption.
50 qed.
51
52 theorem trans_le: \forall n,m,p:nat. n \leq m \to m \leq p \to n \leq p
53 \def transitive_le.
54
55 theorem transitive_lt: transitive nat lt.
56 simplify.intros.elim H1.
57 apply le_S. assumption.
58 apply le_S.assumption.
59 qed.
60
61 theorem trans_lt: \forall n,m,p:nat. lt n m \to lt m p \to lt n p
62 \def transitive_lt.
63
64 theorem le_S_S: \forall n,m:nat. n \leq m \to S n \leq S m.
65 intros.elim H.
66 apply le_n.
67 apply le_S.assumption.
68 qed.
69
70 theorem le_O_n : \forall n:nat. O \leq n.
71 intros.elim n.
72 apply le_n.apply 
73 le_S. assumption.
74 qed.
75
76 theorem le_n_Sn : \forall n:nat. n \leq S n.
77 intros. apply le_S.apply le_n.
78 qed.
79
80 theorem le_pred_n : \forall n:nat. pred n \leq n.
81 intros.elim n.
82 simplify.apply le_n.
83 simplify.apply le_n_Sn.
84 qed.
85
86 theorem le_S_S_to_le : \forall n,m:nat. S n \leq S m \to n \leq m.
87 intros.change with pred (S n) \leq pred (S m).
88 elim H.apply le_n.apply trans_le ? (pred n1).assumption.
89 apply le_pred_n.
90 qed.
91
92 theorem leS_to_not_zero : \forall n,m:nat. S n \leq m \to not_zero m.
93 intros.elim H.exact I.exact I.
94 qed.
95
96 (* not le *)
97 theorem not_le_Sn_O: \forall n:nat. \lnot (S n \leq O).
98 intros.simplify.intros.apply leS_to_not_zero ? ? H.
99 qed.
100
101 theorem not_le_Sn_n: \forall n:nat. \lnot (S n \leq n).
102 intros.elim n.apply not_le_Sn_O.simplify.intros.cut S n1 \leq n1.
103 apply H.assumption.
104 apply le_S_S_to_le.assumption.
105 qed.
106
107 (* not eq *)
108 theorem lt_to_not_eq : \forall n,m:nat. n<m \to \lnot (n=m).
109 simplify.intros.cut (le (S n) m) \to False.
110 apply Hcut.assumption.rewrite < H1.
111 apply not_le_Sn_n.
112 qed.
113
114 (* le vs. lt *)
115 theorem lt_to_le : \forall n,m:nat. n<m \to n \leq m.
116 simplify.intros.elim H.
117 apply le_S. apply le_n.
118 apply le_S. assumption.
119 qed.
120
121 theorem lt_S_to_le : \forall n,m:nat. n < S m \to n \leq m.
122 simplify.intros.
123 apply le_S_S_to_le.assumption.
124 qed.
125
126 theorem not_le_to_lt: \forall n,m:nat. \lnot (n \leq m) \to m<n.
127 intros 2.
128 apply nat_elim2 (\lambda n,m.\lnot (n \leq m) \to m<n).
129 intros.apply absurd (O \leq n1).apply le_O_n.assumption.
130 simplify.intros.apply le_S_S.apply le_O_n.
131 simplify.intros.apply le_S_S.apply H.intros.apply H1.apply le_S_S.
132 assumption.
133 qed.
134
135 theorem lt_to_not_le: \forall n,m:nat. n<m \to \lnot (m \leq n).
136 simplify.intros 3.elim H.
137 apply not_le_Sn_n n H1.
138 apply H2.apply lt_to_le. apply H3.
139 qed.
140
141 theorem not_lt_to_le: \forall n,m:nat. Not (lt n m) \to le m n.
142 simplify.intros.
143 apply lt_S_to_le.
144 apply not_le_to_lt.exact H.
145 qed.
146
147 theorem le_to_not_lt: \forall n,m:nat. le n m \to Not (lt m n).
148 intros.
149 change with Not (le (S m) n).
150 apply lt_to_not_le.simplify.
151 apply le_S_S.assumption.
152 qed.
153
154 (* le elimination *)
155 theorem le_n_O_to_eq : \forall n:nat. n \leq O \to O=n.
156 intro.elim n.reflexivity.
157 apply False_ind.
158 (* non si applica not_le_Sn_O *)
159 apply  (not_le_Sn_O ? H1).
160 qed.
161
162 theorem le_n_O_elim: \forall n:nat.n \leq O \to \forall P: nat \to Prop.
163 P O \to P n.
164 intro.elim n.
165 assumption.
166 apply False_ind.
167 apply  (not_le_Sn_O ? H1).
168 qed.
169
170 theorem le_n_Sm_elim : \forall n,m:nat.n \leq S m \to 
171 \forall P:Prop. (S n \leq S m \to P) \to (n=S m \to P) \to P.
172 intros 4.elim H.
173 apply H2.reflexivity.
174 apply H3. apply le_S_S. assumption.
175 qed.
176
177 (* lt and le trans *)
178 theorem lt_to_le_to_lt: \forall n,m,p:nat. lt n m \to le m p \to lt n p.
179 intros.elim H1.
180 assumption.simplify.apply le_S.assumption.
181 qed.
182
183 theorem le_to_lt_to_lt: \forall n,m,p:nat. le n m \to lt m p \to lt n p.
184 intros 4.elim H.
185 assumption.apply H2.simplify.
186 apply lt_to_le.assumption.
187 qed.
188
189 theorem ltn_to_ltO: \forall n,m:nat. lt n m \to lt O m.
190 intros.apply le_to_lt_to_lt O n.
191 apply le_O_n.assumption.
192 qed.
193
194 theorem lt_O_n_elim: \forall n:nat. lt O n \to 
195 \forall P:nat\to Prop. (\forall m:nat.P (S m)) \to P n.
196 intro.elim n.apply False_ind.exact not_le_Sn_O O H.
197 apply H2.
198 qed.
199
200 (* other abstract properties *)
201 theorem antisymmetric_le : antisymmetric nat le.
202 simplify.intros 2.
203 apply nat_elim2 (\lambda n,m.(n \leq m \to m \leq n \to n=m)).
204 intros.apply le_n_O_to_eq.assumption.
205 intros.apply False_ind.apply not_le_Sn_O ? H.
206 intros.apply eq_f.apply H.
207 apply le_S_S_to_le.assumption.
208 apply le_S_S_to_le.assumption.
209 qed.
210
211 theorem antisym_le: \forall n,m:nat. n \leq m \to m \leq n \to n=m
212 \def antisymmetric_le.
213
214 theorem decidable_le: \forall n,m:nat. decidable (n \leq m).
215 intros.
216 apply nat_elim2 (\lambda n,m.decidable (n \leq m)).
217 intros.simplify.left.apply le_O_n.
218 intros.simplify.right.exact not_le_Sn_O n1.
219 intros 2.simplify.intro.elim H.
220 left.apply le_S_S.assumption.
221 right.intro.apply H1.apply le_S_S_to_le.assumption.
222 qed.
223
224 theorem decidable_lt: \forall n,m:nat. decidable (n < m).
225 intros.exact decidable_le (S n) m.
226 qed.