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 (*CSC: the URI must disappear: there is a bug now *)
26 interpretation "natural 'less or equal to'" 'leq x y = (cic:/matita/library_autobatch/nat/orders/le.ind#xpointer(1/1) x y).
27 (*CSC: the URI must disappear: there is a bug now *)
28 interpretation "natural 'neither less nor equal to'" 'nleq x y =
29 (cic:/matita/logic/connectives/Not.con
30 (cic:/matita/library_autobatch/nat/orders/le.ind#xpointer(1/1) x y)).
32 definition lt: nat \to nat \to Prop \def
33 \lambda n,m:nat.(S n) \leq m.
35 (*CSC: the URI must disappear: there is a bug now *)
36 interpretation "natural 'less than'" 'lt x y = (cic:/matita/library_autobatch/nat/orders/lt.con x y).
37 (*CSC: the URI must disappear: there is a bug now *)
38 interpretation "natural 'not less than'" 'nless x y =
39 (cic:/matita/logic/connectives/Not.con (cic:/matita/library_autobatch/nat/orders/lt.con x y)).
41 definition ge: nat \to nat \to Prop \def
42 \lambda n,m:nat.m \leq n.
44 (*CSC: the URI must disappear: there is a bug now *)
45 interpretation "natural 'greater or equal to'" 'geq x y = (cic:/matita/library_autobatch/nat/orders/ge.con x y).
47 definition gt: nat \to nat \to Prop \def
50 (*CSC: the URI must disappear: there is a bug now *)
51 interpretation "natural 'greater than'" 'gt x y = (cic:/matita/library_autobatch/nat/orders/gt.con x y).
52 (*CSC: the URI must disappear: there is a bug now *)
53 interpretation "natural 'not greater than'" 'ngtr x y =
54 (cic:/matita/logic/connectives/Not.con (cic:/matita/library_autobatch/nat/orders/gt.con x y)).
56 theorem transitive_le : transitive nat le.
66 theorem trans_le: \forall n,m,p:nat. n \leq m \to m \leq p \to n \leq p
69 theorem transitive_lt: transitive nat lt.
74 (*apply le_S;assumption.*)
78 theorem trans_lt: \forall n,m,p:nat. lt n m \to lt m p \to lt n p
81 theorem le_S_S: \forall n,m:nat. n \leq m \to S n \leq S m.
90 theorem le_O_n : \forall n:nat. O \leq n.
99 theorem le_n_Sn : \forall n:nat. n \leq S n.
105 theorem le_pred_n : \forall n:nat. pred n \leq n.
115 theorem le_S_S_to_le : \forall n,m:nat. S n \leq S m \to n \leq m.
117 change with (pred (S n) \leq pred (S m)).
120 | apply (trans_le ? (pred n1))
127 theorem leS_to_not_zero : \forall n,m:nat. S n \leq m \to not_zero m.
130 [ (*qui autobatch non chiude il goal*)
132 | (*qui autobatch non chiude il goal*)
138 theorem not_le_Sn_O: \forall n:nat. S n \nleq O.
143 (*qui autobatch NON chiude il goal*)
144 apply (leS_to_not_zero ? ? H).
147 theorem not_le_Sn_n: \forall n:nat. S n \nleq n.
154 (*cut (S n1 \leq n1).
157 | apply le_S_S_to_le.
164 theorem le_to_or_lt_eq : \forall n,m:nat.
165 n \leq m \to n < m \lor n = m.
180 theorem lt_to_not_eq : \forall n,m:nat. n<m \to n \neq m.
183 cut ((le (S n) m) \to False)
193 theorem lt_to_le : \forall n,m:nat. n<m \to n \leq m.
206 theorem lt_S_to_le : \forall n,m:nat. n < S m \to n \leq m.
214 theorem not_le_to_lt: \forall n,m:nat. n \nleq m \to m<n.
216 apply (nat_elim2 (\lambda n,m.n \nleq m \to m<n))
218 apply (absurd (O \leq n1));autobatch
240 theorem lt_to_not_le: \forall n,m:nat. n<m \to m \nleq n.
245 (*[ apply (not_le_Sn_n n H1)
252 theorem not_lt_to_le: \forall n,m:nat. Not (lt n m) \to le m n.
257 (*qui autobatch non chiude il goal*)
261 theorem le_to_not_lt: \forall n,m:nat. le n m \to Not (lt m n).
272 theorem le_n_O_to_eq : \forall n:nat. n \leq O \to O=n.
276 | apply False_ind.autobatch
282 theorem le_n_O_elim: \forall n:nat.n \leq O \to \forall P: nat \to Prop.
288 apply (not_le_Sn_O ? H1)
292 theorem le_n_Sm_elim : \forall n,m:nat.n \leq S m \to
293 \forall P:Prop. (S n \leq S m \to P) \to (n=S m \to P) \to P.
305 lemma le_to_le_to_eq: \forall n,m. n \le m \to m \le n \to n = m.
309 (*apply le_n_O_to_eq.
318 [ apply le_S_S_to_le.assumption
319 | apply le_S_S_to_le.assumption
324 (* lt and le trans *)
325 theorem lt_O_S : \forall n:nat. O < S n.
332 theorem lt_to_le_to_lt: \forall n,m,p:nat. lt n m \to le m p \to lt n p.
342 theorem le_to_lt_to_lt: \forall n,m,p:nat. le n m \to lt m p \to lt n p.
353 theorem lt_S_to_lt: \forall n,m. S n < m \to n < m.
355 (*apply (trans_lt ? (S n))
361 theorem ltn_to_ltO: \forall n,m:nat. lt n m \to lt O m.
363 apply (le_to_lt_to_lt O n)
369 theorem lt_O_n_elim: \forall n:nat. lt O n \to
370 \forall P:nat\to Prop. (\forall m:nat.P (S m)) \to P n.
374 exact (not_le_Sn_O O H)
379 (* other abstract properties *)
380 theorem antisymmetric_le : antisymmetric nat le.
381 unfold antisymmetric.
384 apply (nat_elim2 (\lambda n,m.(n \leq m \to m \leq n \to n=m)))
390 apply (not_le_Sn_O ? H)
394 apply le_S_S_to_le;assumption
399 * autobatch chiude il goal prima della tattica intros 2, tuttavia non chiude gli ultimi
400 * 2 rami aperti dalla tattica apply (nat_elim2 (\lambda n,m.(n \leq m \to m \leq n \to n=m))).
401 * evidentemente autobatch sfrutta una dimostrazione diversa rispetto a quella proposta
405 theorem antisym_le: \forall n,m:nat. n \leq m \to m \leq n \to n=m
406 \def antisymmetric_le.
408 theorem decidable_le: \forall n,m:nat. decidable (n \leq m).
410 apply (nat_elim2 (\lambda n,m.decidable (n \leq m)))
412 unfold decidable.autobatch
419 exact (not_le_Sn_O n1)*)
439 theorem decidable_lt: \forall n,m:nat. decidable (n < m).
441 (*qui autobatch non chiude il goal*)
442 exact (decidable_le (S n) m).
445 (* well founded induction principles *)
447 theorem nat_elim1 : \forall n:nat.\forall P:nat \to Prop.
448 (\forall m.(\forall p. (p \lt m) \to P p) \to P m) \to P n.
450 cut (\forall q:nat. q \le n \to P q)
455 [ apply (le_n_O_elim q H1).
459 apply (not_le_Sn_O p H2)
467 | apply (lt_to_le_to_lt p q (S n1) H3 H2).
473 (* some properties of functions *)
475 definition increasing \def \lambda f:nat \to nat.
476 \forall n:nat. f n < f (S n).
478 theorem increasing_to_monotonic: \forall f:nat \to nat.
479 increasing f \to monotonic nat lt f.
487 | apply (trans_le ? (f n1))
489 | apply (trans_le ? (S (f n1)))
497 theorem le_n_fn: \forall f:nat \to nat. (increasing f)
498 \to \forall n:nat. n \le (f n).
502 | apply (trans_le ? (S (f n1)))
506 unfold increasing in H.
513 theorem increasing_to_le: \forall f:nat \to nat. (increasing f)
514 \to \forall m:nat. \exists i. m \le (f i).
517 [ apply (ex_intro ? ? O).
520 apply (ex_intro ? ? (S a)).
521 apply (trans_le ? (S (f a)))
525 unfold increasing in H.
532 theorem increasing_to_le2: \forall f:nat \to nat. (increasing f)
533 \to \forall m:nat. (f O) \le m \to
534 \exists i. (f i) \le m \land m <(f (S i)).
538 (*apply (ex_intro ? ? O).
545 cut ((S n1) < (f (S a)) \lor (S n1) = (f (S a)))
547 [ apply (ex_intro ? ? a).
554 | apply (ex_intro ? ? (S a)).
564 (*apply le_to_or_lt_eq.