]> matita.cs.unibo.it Git - helm.git/blob - helm/matita/library/nat/orders.ma
Added a new contrib div_and_mod and few modifs here and there.
[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 definition lt: nat \to nat \to Prop \def
26 \lambda n,m:nat.le (S n) m.
27
28 definition ge: nat \to nat \to Prop \def
29 \lambda n,m:nat.le m n.
30
31 definition gt: nat \to nat \to Prop \def
32 \lambda n,m:nat.lt m n.
33
34 theorem transitive_le : transitive nat le.
35 simplify.intros.elim H1.
36 assumption.
37 apply le_S.assumption.
38 qed.
39
40 theorem trans_le: \forall n,m,p:nat. le n m \to le m p \to le n p
41 \def transitive_le.
42
43 theorem le_S_S: \forall n,m:nat. le n m \to le (S n) (S m).
44 intros.elim H.
45 apply le_n.
46 apply le_S.assumption.
47 qed.
48
49 theorem le_O_n : \forall n:nat. le O n.
50 intros.elim n.
51 apply le_n.apply 
52 le_S. assumption.
53 qed.
54
55 theorem le_n_Sn : \forall n:nat. le n (S n).
56 intros. apply le_S.apply le_n.
57 qed.
58
59 theorem le_pred_n : \forall n:nat. le (pred n) n.
60 intros.elim n.
61 simplify.apply le_n.
62 simplify.apply le_n_Sn.
63 qed.
64
65 theorem le_S_S_to_le : \forall n,m:nat. le (S n) (S m) \to le n m.
66 intros.change with le (pred (S n)) (pred (S m)).
67 elim H.apply le_n.apply trans_le ? (pred e2).assumption.
68 apply le_pred_n.
69 qed.
70
71 theorem leS_to_not_zero : \forall n,m:nat. (le (S n) m ) \to not_zero m.
72 intros.elim H.exact I.exact I.
73 qed.
74
75 (* not le *)
76 theorem not_le_Sn_O: \forall n:nat. Not (le (S n) O).
77 intros.simplify.intros.apply leS_to_not_zero ? ? H.
78 qed.
79
80 theorem not_le_Sn_n: \forall n:nat. Not (le (S n) n).
81 intros.elim n.apply not_le_Sn_O.simplify.intros.cut le (S e1) e1.
82 apply H.assumption.
83 apply le_S_S_to_le.assumption.
84 qed.
85
86 (* le vs. lt *)
87 theorem lt_to_le : \forall n,m:nat. lt n m \to le n m.
88 simplify.intros.elim H.
89 apply le_S. apply le_n.
90 apply le_S. assumption.
91 qed.
92
93 theorem not_le_to_lt: \forall n,m:nat. Not (le n m) \to lt m n.
94 intros 2.
95 apply nat_elim2 (\lambda n,m.Not (le n m) \to lt m n).
96 intros.apply absurd (le O n1).apply le_O_n.assumption.
97 simplify.intros.apply le_S_S.apply le_O_n.
98 simplify.intros.apply le_S_S.apply H.intros.apply H1.apply le_S_S.
99 assumption.
100 qed.
101
102 theorem lt_to_not_le: \forall n,m:nat. lt n m \to Not (le m n).
103 simplify.intros 3.elim H.
104 apply not_le_Sn_n n H1.
105 apply H2.apply lt_to_le. apply H3.
106 qed.
107
108 (* le elimination *)
109 theorem le_n_O_to_eq : \forall n:nat. (le n O) \to (eq nat O n).
110 intro.elim n.reflexivity.
111 apply False_ind.
112 (* non si applica not_le_Sn_O *)
113 apply  (not_le_Sn_O ? H1).
114 qed.
115
116 theorem le_n_O_elim: \forall n:nat.le n O \to \forall P: nat \to Prop.
117 P O \to P n.
118 intro.elim n.
119 assumption.
120 apply False_ind.
121 apply  (not_le_Sn_O ? H1).
122 qed.
123
124 theorem le_n_Sm_elim : \forall n,m:nat.le n (S m) \to 
125 \forall P:Prop. (le (S n) (S m) \to P) \to (eq nat n (S m) \to P) \to P.
126 intros 4.elim H.
127 apply H2.reflexivity.
128 apply H3. apply le_S_S. assumption.
129 qed.
130
131 (* other abstract properties *)
132 theorem antisymmetric_le : antisymmetric nat le.
133 simplify.intros 2.
134 apply nat_elim2 (\lambda n,m.((le n m) \to (le m n) \to eq nat n m)).
135 intros.apply le_n_O_to_eq.assumption.
136 intros.apply False_ind.apply not_le_Sn_O ? H.
137 intros.apply eq_f.apply H.
138 apply le_S_S_to_le.assumption.
139 apply le_S_S_to_le.assumption.
140 qed.
141
142 theorem antisym_le: \forall n,m:nat. le n m \to le m n \to eq nat n m
143 \def antisymmetric_le.
144
145 theorem decidable_le: \forall n,m:nat. decidable (le n m).
146 intros.
147 apply nat_elim2 (\lambda n,m.decidable (le n m)).
148 intros.simplify.left.apply le_O_n.
149 intros.simplify.right.exact not_le_Sn_O n1.
150 intros 2.simplify.intro.elim H.
151 left.apply le_S_S.assumption.
152 right.intro.apply H1.apply le_S_S_to_le.assumption.
153 qed.
154
155