]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/lambdadelta/ground/arith/nat_le.ma
propagating the arithmetics library, partial commit
[helm.git] / matita / matita / contribs / lambdadelta / ground / arith / nat_le.ma
1 (**************************************************************************)
2 (*       ___                                                              *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||         The HELM team.                                      *)
8 (*      ||A||         http://helm.cs.unibo.it                             *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU General Public License Version 2                  *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 include "ground/generated/insert_eq_1.ma".
16 include "ground/arith/nat_succ.ma".
17
18 (* ORDER FOR NON-NEGATIVE INTEGERS ******************************************)
19
20 (*** le *)
21 inductive nle (m:nat): predicate nat ≝
22 | nle_refl   : nle m m
23 | nle_succ_dx: ∀n. nle m n → nle m (↑n)
24 .
25
26 interpretation
27   "less equal (non-negative integers)"
28   'leq m n = (nle m n).
29
30 (* Basic constructions ******************************************************)
31
32 (*** le_n_Sn *)
33 lemma nle_succ_dx_refl (m): m ≤ ↑m.
34 /2 width=1 by nle_refl, nle_succ_dx/ qed.
35
36 (*** le_O_n *)
37 lemma nle_zero_sx (m): 𝟎 ≤ m.
38 #m @(nat_ind_succ … m) -m /2 width=1 by nle_succ_dx/
39 qed.
40
41 (*** le_S_S *)
42 lemma nle_succ_bi (m) (n): m ≤ n → ↑m ≤ ↑n.
43 #m #n #H elim H -n /2 width=1 by nle_refl, nle_succ_dx/
44 qed.
45
46 (*** le_or_ge *)
47 lemma nat_split_le_ge (m) (n): ∨∨ m ≤ n | n ≤ m.
48 #m #n @(nat_ind_2_succ … m n) -m -n
49 [ /2 width=1 by or_introl/
50 | /2 width=1 by or_intror/
51 | #m #n * /3 width=2 by nle_succ_bi, or_introl, or_intror/
52 ]
53 qed-.
54
55 (* Basic destructions *******************************************************)
56
57 lemma nle_des_succ_sn (m) (n): ↑m ≤ n → m ≤ n.
58 #m #n #H elim H -n /2 width=1 by nle_succ_dx/
59 qed-.
60
61 (* Basic inversions *********************************************************)
62
63 (*** le_S_S_to_le *)
64 lemma nle_inv_succ_bi (m) (n): ↑m ≤ ↑n → m ≤ n.
65 #m #n @(insert_eq_1 … (↑n))
66 #x * -x
67 [ #H >(eq_inv_nsucc_bi … H) -n //
68 | #o #Ho #H >(eq_inv_nsucc_bi … H) -n
69   /2 width=1 by nle_des_succ_sn/ 
70 ]
71 qed-.
72
73 (*** le_n_O_to_eq *)
74 lemma nle_inv_zero_dx (m): m ≤ 𝟎 → 𝟎 = m.
75 #m @(insert_eq_1 … (𝟎))
76 #y * -y
77 [ #H destruct //
78 | #y #_ #H elim (eq_inv_zero_nsucc … H)
79 ]
80 qed-.
81
82 (* Advanced inversions ******************************************************)
83
84 (*** le_plus_xSy_O_false *)
85 lemma nle_inv_succ_zero (m): ↑m ≤ 𝟎 → ⊥.
86 /3 width=2 by nle_inv_zero_dx, eq_inv_zero_nsucc/ qed-.
87
88 lemma nle_inv_succ_sn_refl (m): ↑m ≤ m → ⊥.
89 #m @(nat_ind_succ … m) -m [| #m #IH ] #H
90 [ /2 width=2 by nle_inv_succ_zero/
91 | /3 width=1 by nle_inv_succ_bi/
92 ]
93 qed-.
94
95 (*** le_to_le_to_eq *)
96 theorem nle_antisym (m) (n): m ≤ n → n ≤ m → m = n.
97 #m #n #H elim H -n //
98 #n #_ #IH #Hn
99 lapply (nle_des_succ_sn … Hn) #H
100 lapply (IH H) -IH -H #H destruct
101 elim (nle_inv_succ_sn_refl … Hn)
102 qed-.
103
104 (* Advanced eliminations ****************************************************)
105
106 (*** le_elim *)
107 lemma nle_ind_alt (Q: relation2 nat nat):
108       (∀n. Q (𝟎) (n)) →
109       (∀m,n. m ≤ n → Q m n → Q (↑m) (↑n)) →
110       ∀m,n. m ≤ n → Q m n.
111 #Q #IH1 #IH2 #m #n @(nat_ind_2_succ … m n) -m -n //
112 [ #m #_ #H elim (nle_inv_succ_zero … H)
113 | /4 width=1 by nle_inv_succ_bi/
114 ]
115 qed-.
116
117 (* Advanced constructions ***************************************************)
118
119 (*** transitive_le *)
120 theorem nle_trans: Transitive … nle.
121 #m #n #H elim H -n /3 width=1 by nle_des_succ_sn/
122 qed-.
123
124 (*** decidable_le le_dec *)
125 lemma nle_dec (m) (n): Decidable … (m ≤ n).
126 #m #n elim (nat_split_le_ge m n) [ /2 width=1 by or_introl/ ]
127 #Hnm elim (eq_nat_dec m n) [ #H destruct /2 width=1 by nle_refl, or_introl/ ]
128 /4 width=1 by nle_antisym, or_intror/
129 qed-.