1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| A.Asperti, C.Sacerdoti Coen, *)
8 (* ||A|| E.Tassi, S.Zacchiroli *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU Lesser General Public License Version 2.1 *)
13 (**************************************************************************)
15 set "baseuri" "cic:/matita/nat/orders".
17 include "nat/plus.ma".
18 include "higher_order_defs/ordering.ma".
21 inductive le (n:nat) : nat \to Prop \def
23 | le_S : \forall m:nat. le n m \to le n (S m).
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).
28 definition lt: nat \to nat \to Prop \def
29 \lambda n,m:nat.(S n) \leq m.
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).
34 definition ge: nat \to nat \to Prop \def
35 \lambda n,m:nat.m \leq n.
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).
40 definition gt: nat \to nat \to Prop \def
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).
46 theorem transitive_le : transitive nat le.
47 simplify.intros.elim H1.
49 apply le_S.assumption.
52 theorem trans_le: \forall n,m,p:nat. n \leq m \to m \leq p \to n \leq p
55 theorem transitive_lt: transitive nat lt.
56 simplify.intros.elim H1.
57 apply le_S. assumption.
58 apply le_S.assumption.
61 theorem trans_lt: \forall n,m,p:nat. lt n m \to lt m p \to lt n p
64 theorem le_S_S: \forall n,m:nat. n \leq m \to S n \leq S m.
67 apply le_S.assumption.
70 theorem le_O_n : \forall n:nat. O \leq n.
76 theorem le_n_Sn : \forall n:nat. n \leq S n.
77 intros. apply le_S.apply le_n.
80 theorem le_pred_n : \forall n:nat. pred n \leq n.
83 simplify.apply le_n_Sn.
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.
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.
97 theorem not_le_Sn_O: \forall n:nat. \lnot (S n \leq O).
98 intros.simplify.intros.apply leS_to_not_zero ? ? H.
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.
104 apply le_S_S_to_le.assumption.
108 theorem le_to_or_lt_eq : \forall n,m:nat.
109 n \leq m \to n < m \lor n = m.
112 left.simplify.apply le_S_S.assumption.
116 theorem lt_to_not_eq : \forall n,m:nat. n<m \to \lnot (n=m).
117 simplify.intros.cut (le (S n) m) \to False.
118 apply Hcut.assumption.rewrite < H1.
123 theorem lt_to_le : \forall n,m:nat. n<m \to n \leq m.
124 simplify.intros.elim H.
125 apply le_S. apply le_n.
126 apply le_S. assumption.
129 theorem lt_S_to_le : \forall n,m:nat. n < S m \to n \leq m.
131 apply le_S_S_to_le.assumption.
134 theorem not_le_to_lt: \forall n,m:nat. \lnot (n \leq m) \to m<n.
136 apply nat_elim2 (\lambda n,m.\lnot (n \leq m) \to m<n).
137 intros.apply absurd (O \leq n1).apply le_O_n.assumption.
138 simplify.intros.apply le_S_S.apply le_O_n.
139 simplify.intros.apply le_S_S.apply H.intros.apply H1.apply le_S_S.
143 theorem lt_to_not_le: \forall n,m:nat. n<m \to \lnot (m \leq n).
144 simplify.intros 3.elim H.
145 apply not_le_Sn_n n H1.
146 apply H2.apply lt_to_le. apply H3.
149 theorem not_lt_to_le: \forall n,m:nat. Not (lt n m) \to le m n.
152 apply not_le_to_lt.exact H.
155 theorem le_to_not_lt: \forall n,m:nat. le n m \to Not (lt m n).
157 change with Not (le (S m) n).
158 apply lt_to_not_le.simplify.
159 apply le_S_S.assumption.
163 theorem le_n_O_to_eq : \forall n:nat. n \leq O \to O=n.
164 intro.elim n.reflexivity.
166 (* non si applica not_le_Sn_O *)
167 apply (not_le_Sn_O ? H1).
170 theorem le_n_O_elim: \forall n:nat.n \leq O \to \forall P: nat \to Prop.
175 apply (not_le_Sn_O ? H1).
178 theorem le_n_Sm_elim : \forall n,m:nat.n \leq S m \to
179 \forall P:Prop. (S n \leq S m \to P) \to (n=S m \to P) \to P.
181 apply H2.reflexivity.
182 apply H3. apply le_S_S. assumption.
185 (* lt and le trans *)
186 theorem lt_to_le_to_lt: \forall n,m,p:nat. lt n m \to le m p \to lt n p.
188 assumption.simplify.apply le_S.assumption.
191 theorem le_to_lt_to_lt: \forall n,m,p:nat. le n m \to lt m p \to lt n p.
193 assumption.apply H2.simplify.
194 apply lt_to_le.assumption.
197 theorem ltn_to_ltO: \forall n,m:nat. lt n m \to lt O m.
198 intros.apply le_to_lt_to_lt O n.
199 apply le_O_n.assumption.
202 theorem lt_O_n_elim: \forall n:nat. lt O n \to
203 \forall P:nat\to Prop. (\forall m:nat.P (S m)) \to P n.
204 intro.elim n.apply False_ind.exact not_le_Sn_O O H.
208 (* other abstract properties *)
209 theorem antisymmetric_le : antisymmetric nat le.
211 apply nat_elim2 (\lambda n,m.(n \leq m \to m \leq n \to n=m)).
212 intros.apply le_n_O_to_eq.assumption.
213 intros.apply False_ind.apply not_le_Sn_O ? H.
214 intros.apply eq_f.apply H.
215 apply le_S_S_to_le.assumption.
216 apply le_S_S_to_le.assumption.
219 theorem antisym_le: \forall n,m:nat. n \leq m \to m \leq n \to n=m
220 \def antisymmetric_le.
222 theorem decidable_le: \forall n,m:nat. decidable (n \leq m).
224 apply nat_elim2 (\lambda n,m.decidable (n \leq m)).
225 intros.simplify.left.apply le_O_n.
226 intros.simplify.right.exact not_le_Sn_O n1.
227 intros 2.simplify.intro.elim H.
228 left.apply le_S_S.assumption.
229 right.intro.apply H1.apply le_S_S_to_le.assumption.
232 theorem decidable_lt: \forall n,m:nat. decidable (n < m).
233 intros.exact decidable_le (S n) m.
236 (* well founded induction principles *)
238 theorem nat_elim1 : \forall n:nat.\forall P:nat \to Prop.
239 (\forall m.(\forall p. (p \lt m) \to P p) \to P m) \to P n.
240 intros.cut \forall q:nat. q \le n \to P q.
241 apply Hcut n.apply le_n.
242 elim n.apply le_n_O_elim q H1.
244 intros.apply False_ind.apply not_le_Sn_O p H2.
245 apply H.intros.apply H1.
247 apply lt_S_to_le.assumption.
248 apply lt_to_le_to_lt p q (S n1) H3 H2.
251 (* some properties of functions *)
253 definition increasing \def \lambda f:nat \to nat.
254 \forall n:nat. f n < f (S n).
256 theorem increasing_to_monotonic: \forall f:nat \to nat.
257 increasing f \to monotonic nat lt f.
258 simplify.intros.elim H1.apply H.
259 apply trans_le ? (f n1).
260 assumption.apply trans_le ? (S (f n1)).
265 theorem le_n_fn: \forall f:nat \to nat. (increasing f)
266 \to \forall n:nat. n \le (f n).
269 apply trans_le ? (S (f n1)).
270 apply le_S_S.apply H1.
271 simplify in H. apply H.
274 theorem increasing_to_le: \forall f:nat \to nat. (increasing f)
275 \to \forall m:nat. ex nat (\lambda i. m \le (f i)).
277 apply ex_intro ? ? O.apply le_O_n.
279 apply ex_intro ? ? (S a).
280 apply trans_le ? (S (f a)).
281 apply le_S_S.assumption.
286 theorem increasing_to_le2: \forall f:nat \to nat. (increasing f)
287 \to \forall m:nat. (f O) \le m \to
288 ex nat (\lambda i. (f i) \le m \land m <(f (S i))).
290 apply ex_intro ? ? O.
291 split.apply le_n.apply H.
293 cut (S n1) < (f (S a)) \lor (S n1) = (f (S a)).
295 apply ex_intro ? ? a.
296 split.apply le_S. assumption.assumption.
297 apply ex_intro ? ? (S a).
298 split.rewrite < H7.apply le_n.
301 apply le_to_or_lt_eq.apply H6.