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