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/library_autobatch/nat/orders".
17 include "auto/nat/nat.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 interpretation "natural 'less or equal to'" 'leq x y = (le x y).
26 interpretation "natural 'neither less nor equal to'" 'nleq x y = (Not (le x y)).
28 definition lt: nat \to nat \to Prop \def
29 \lambda n,m:nat.(S n) \leq m.
31 interpretation "natural 'less than'" 'lt x y = (lt x y).
32 interpretation "natural 'not less than'" 'nless x y = (Not (lt x y)).
34 definition ge: nat \to nat \to Prop \def
35 \lambda n,m:nat.m \leq n.
37 interpretation "natural 'greater or equal to'" 'geq x y = (ge x y).
39 definition gt: nat \to nat \to Prop \def
42 interpretation "natural 'greater than'" 'gt x y = (gt x y).
43 interpretation "natural 'not greater than'" 'ngtr x y = (Not (gt x y)).
45 theorem transitive_le : transitive nat le.
55 theorem trans_le: \forall n,m,p:nat. n \leq m \to m \leq p \to n \leq p
58 theorem transitive_lt: transitive nat lt.
63 (*apply le_S;assumption.*)
67 theorem trans_lt: \forall n,m,p:nat. lt n m \to lt m p \to lt n p
70 theorem le_S_S: \forall n,m:nat. n \leq m \to S n \leq S m.
79 theorem le_O_n : \forall n:nat. O \leq n.
88 theorem le_n_Sn : \forall n:nat. n \leq S n.
94 theorem le_pred_n : \forall n:nat. pred n \leq n.
104 theorem le_S_S_to_le : \forall n,m:nat. S n \leq S m \to n \leq m.
106 change with (pred (S n) \leq pred (S m)).
109 | apply (trans_le ? (pred n1))
116 theorem leS_to_not_zero : \forall n,m:nat. S n \leq m \to not_zero m.
119 [ (*qui autobatch non chiude il goal*)
121 | (*qui autobatch non chiude il goal*)
127 theorem not_le_Sn_O: \forall n:nat. S n \nleq O.
132 (*qui autobatch NON chiude il goal*)
133 apply (leS_to_not_zero ? ? H).
136 theorem not_le_Sn_n: \forall n:nat. S n \nleq n.
143 (*cut (S n1 \leq n1).
146 | apply le_S_S_to_le.
153 theorem le_to_or_lt_eq : \forall n,m:nat.
154 n \leq m \to n < m \lor n = m.
169 theorem lt_to_not_eq : \forall n,m:nat. n<m \to n \neq m.
172 cut ((le (S n) m) \to False)
182 theorem lt_to_le : \forall n,m:nat. n<m \to n \leq m.
195 theorem lt_S_to_le : \forall n,m:nat. n < S m \to n \leq m.
203 theorem not_le_to_lt: \forall n,m:nat. n \nleq m \to m<n.
205 apply (nat_elim2 (\lambda n,m.n \nleq m \to m<n))
207 apply (absurd (O \leq n1));autobatch
229 theorem lt_to_not_le: \forall n,m:nat. n<m \to m \nleq n.
234 (*[ apply (not_le_Sn_n n H1)
241 theorem not_lt_to_le: \forall n,m:nat. Not (lt n m) \to le m n.
246 (*qui autobatch non chiude il goal*)
250 theorem le_to_not_lt: \forall n,m:nat. le n m \to Not (lt m n).
261 theorem le_n_O_to_eq : \forall n:nat. n \leq O \to O=n.
265 | apply False_ind.autobatch
271 theorem le_n_O_elim: \forall n:nat.n \leq O \to \forall P: nat \to Prop.
277 apply (not_le_Sn_O ? H1)
281 theorem le_n_Sm_elim : \forall n,m:nat.n \leq S m \to
282 \forall P:Prop. (S n \leq S m \to P) \to (n=S m \to P) \to P.
294 lemma le_to_le_to_eq: \forall n,m. n \le m \to m \le n \to n = m.
298 (*apply le_n_O_to_eq.
307 [ apply le_S_S_to_le.assumption
308 | apply le_S_S_to_le.assumption
313 (* lt and le trans *)
314 theorem lt_O_S : \forall n:nat. O < S n.
321 theorem lt_to_le_to_lt: \forall n,m,p:nat. lt n m \to le m p \to lt n p.
331 theorem le_to_lt_to_lt: \forall n,m,p:nat. le n m \to lt m p \to lt n p.
342 theorem lt_S_to_lt: \forall n,m. S n < m \to n < m.
344 (*apply (trans_lt ? (S n))
350 theorem ltn_to_ltO: \forall n,m:nat. lt n m \to lt O m.
352 apply (le_to_lt_to_lt O n)
358 theorem lt_O_n_elim: \forall n:nat. lt O n \to
359 \forall P:nat\to Prop. (\forall m:nat.P (S m)) \to P n.
363 exact (not_le_Sn_O O H)
368 (* other abstract properties *)
369 theorem antisymmetric_le : antisymmetric nat le.
370 unfold antisymmetric.
373 apply (nat_elim2 (\lambda n,m.(n \leq m \to m \leq n \to n=m)))
379 apply (not_le_Sn_O ? H)
383 apply le_S_S_to_le;assumption
388 * autobatch chiude il goal prima della tattica intros 2, tuttavia non chiude gli ultimi
389 * 2 rami aperti dalla tattica apply (nat_elim2 (\lambda n,m.(n \leq m \to m \leq n \to n=m))).
390 * evidentemente autobatch sfrutta una dimostrazione diversa rispetto a quella proposta
394 theorem antisym_le: \forall n,m:nat. n \leq m \to m \leq n \to n=m
395 \def antisymmetric_le.
397 theorem decidable_le: \forall n,m:nat. decidable (n \leq m).
399 apply (nat_elim2 (\lambda n,m.decidable (n \leq m)))
401 unfold decidable.autobatch
408 exact (not_le_Sn_O n1)*)
428 theorem decidable_lt: \forall n,m:nat. decidable (n < m).
430 (*qui autobatch non chiude il goal*)
431 exact (decidable_le (S n) m).
434 (* well founded induction principles *)
436 theorem nat_elim1 : \forall n:nat.\forall P:nat \to Prop.
437 (\forall m.(\forall p. (p \lt m) \to P p) \to P m) \to P n.
439 cut (\forall q:nat. q \le n \to P q)
444 [ apply (le_n_O_elim q H1).
448 apply (not_le_Sn_O p H2)
456 | apply (lt_to_le_to_lt p q (S n1) H3 H2).
462 (* some properties of functions *)
464 definition increasing \def \lambda f:nat \to nat.
465 \forall n:nat. f n < f (S n).
467 theorem increasing_to_monotonic: \forall f:nat \to nat.
468 increasing f \to monotonic nat lt f.
476 | apply (trans_le ? (f n1))
478 | apply (trans_le ? (S (f n1)))
486 theorem le_n_fn: \forall f:nat \to nat. (increasing f)
487 \to \forall n:nat. n \le (f n).
491 | apply (trans_le ? (S (f n1)))
495 unfold increasing in H.
502 theorem increasing_to_le: \forall f:nat \to nat. (increasing f)
503 \to \forall m:nat. \exists i. m \le (f i).
506 [ apply (ex_intro ? ? O).
509 apply (ex_intro ? ? (S a)).
510 apply (trans_le ? (S (f a)))
514 unfold increasing in H.
521 theorem increasing_to_le2: \forall f:nat \to nat. (increasing f)
522 \to \forall m:nat. (f O) \le m \to
523 \exists i. (f i) \le m \land m <(f (S i)).
527 (*apply (ex_intro ? ? O).
534 cut ((S n1) < (f (S a)) \lor (S n1) = (f (S a)))
536 [ apply (ex_intro ? ? a).
543 | apply (ex_intro ? ? (S a)).
553 (*apply le_to_or_lt_eq.