]> matita.cs.unibo.it Git - helm.git/blob - helm/matita/library/nat/orders.ma
A little bit more of notation 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 interpretation "natural 'less or equal to'" 'leq x y = (cic:/matita/nat/orders/le.ind#xpointer(1/1) x y).
26 alias symbol "leq" (instance 0) = "natural 'less or equal to'".
27
28 definition lt: nat \to nat \to Prop \def
29 \lambda n,m:nat.(S n) \leq m.
30
31 interpretation "natural 'less than'" 'lt x y = (cic:/matita/nat/orders/lt.con x y).
32
33 definition ge: nat \to nat \to Prop \def
34 \lambda n,m:nat.m \leq n.
35
36 interpretation "natural 'greater or equal to'" 'geq x y = (cic:/matita/nat/orders/ge.con x y).
37
38 definition gt: nat \to nat \to Prop \def
39 \lambda n,m:nat.m<n.
40
41 interpretation "natural 'greater than'" 'gt x y = (cic:/matita/nat/orders/gt.con x y).
42
43 theorem transitive_le : transitive nat le.
44 simplify.intros.elim H1.
45 assumption.
46 apply le_S.assumption.
47 qed.
48
49 theorem trans_le: \forall n,m,p:nat. n \leq m \to m \leq p \to n \leq p
50 \def transitive_le.
51
52 theorem le_S_S: \forall n,m:nat. n \leq m \to S n \leq S m.
53 intros.elim H.
54 apply le_n.
55 apply le_S.assumption.
56 qed.
57
58 theorem le_O_n : \forall n:nat. O \leq n.
59 intros.elim n.
60 apply le_n.apply 
61 le_S. assumption.
62 qed.
63
64 theorem le_n_Sn : \forall n:nat. n \leq S n.
65 intros. apply le_S.apply le_n.
66 qed.
67
68 theorem le_pred_n : \forall n:nat. pred n \leq n.
69 intros.elim n.
70 simplify.apply le_n.
71 simplify.apply le_n_Sn.
72 qed.
73
74 theorem le_S_S_to_le : \forall n,m:nat. S n \leq S m \to n \leq m.
75 intros.change with pred (S n) \leq pred (S m).
76 elim H.apply le_n.apply trans_le ? (pred n1).assumption.
77 apply le_pred_n.
78 qed.
79
80 theorem leS_to_not_zero : \forall n,m:nat. S n \leq m \to not_zero m.
81 intros.elim H.exact I.exact I.
82 qed.
83
84 (* not le *)
85 theorem not_le_Sn_O: \forall n:nat. \lnot (S n \leq O).
86 intros.simplify.intros.apply leS_to_not_zero ? ? H.
87 qed.
88
89 theorem not_le_Sn_n: \forall n:nat. \lnot (S n \leq n).
90 intros.elim n.apply not_le_Sn_O.simplify.intros.cut S n1 \leq n1.
91 apply H.assumption.
92 apply le_S_S_to_le.assumption.
93 qed.
94
95 (* ??? this needs not le *)
96 theorem S_pred: \forall n:nat.O<n \to n=S (pred n).
97 intro.elim n.apply False_ind.exact not_le_Sn_O O H.
98 apply eq_f.apply pred_Sn.
99 qed.
100
101 (* le vs. lt *)
102 theorem lt_to_le : \forall n,m:nat. n<m \to n \leq m.
103 simplify.intros.elim H.
104 apply le_S. apply le_n.
105 apply le_S. assumption.
106 qed.
107
108 theorem not_le_to_lt: \forall n,m:nat. \lnot (n \leq m) \to m<n.
109 intros 2.
110 apply nat_elim2 (\lambda n,m.\lnot (n \leq m) \to m<n).
111 intros.apply absurd (O \leq n1).apply le_O_n.assumption.
112 simplify.intros.apply le_S_S.apply le_O_n.
113 simplify.intros.apply le_S_S.apply H.intros.apply H1.apply le_S_S.
114 assumption.
115 qed.
116
117 theorem lt_to_not_le: \forall n,m:nat. n<m \to \lnot (m \leq n).
118 simplify.intros 3.elim H.
119 apply not_le_Sn_n n H1.
120 apply H2.apply lt_to_le. apply H3.
121 qed.
122
123 (* le elimination *)
124 theorem le_n_O_to_eq : \forall n:nat. n \leq O \to O=n.
125 intro.elim n.reflexivity.
126 apply False_ind.
127 (* non si applica not_le_Sn_O *)
128 apply  (not_le_Sn_O ? H1).
129 qed.
130
131 theorem le_n_O_elim: \forall n:nat.n \leq O \to \forall P: nat \to Prop.
132 P O \to P n.
133 intro.elim n.
134 assumption.
135 apply False_ind.
136 apply  (not_le_Sn_O ? H1).
137 qed.
138
139 theorem le_n_Sm_elim : \forall n,m:nat.n \leq S m \to 
140 \forall P:Prop. (S n \leq S m \to P) \to (n=S m \to P) \to P.
141 intros 4.elim H.
142 apply H2.reflexivity.
143 apply H3. apply le_S_S. assumption.
144 qed.
145
146 (* other abstract properties *)
147 theorem antisymmetric_le : antisymmetric nat le.
148 simplify.intros 2.
149 apply nat_elim2 (\lambda n,m.(n \leq m \to m \leq n \to n=m)).
150 intros.apply le_n_O_to_eq.assumption.
151 intros.apply False_ind.apply not_le_Sn_O ? H.
152 intros.apply eq_f.apply H.
153 apply le_S_S_to_le.assumption.
154 apply le_S_S_to_le.assumption.
155 qed.
156
157 theorem antisym_le: \forall n,m:nat. n \leq m \to m \leq n \to n=m
158 \def antisymmetric_le.
159
160 theorem decidable_le: \forall n,m:nat. decidable (n \leq m).
161 intros.
162 apply nat_elim2 (\lambda n,m.decidable (n \leq m)).
163 intros.simplify.left.apply le_O_n.
164 intros.simplify.right.exact not_le_Sn_O n1.
165 intros 2.simplify.intro.elim H.
166 left.apply le_S_S.assumption.
167 right.intro.apply H1.apply le_S_S_to_le.assumption.
168 qed.