]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/lambdadelta/ground/arith/nat_le.ma
73c14396423e316aea768fe307e290c4108abb85
[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/insert_eq/insert_eq_0.ma".
16 include "ground/arith/nat_succ.ma".
17
18 (* ORDER FOR NON-NEGATIVE INTEGERS ******************************************)
19
20 (*** le *)
21 (*** le_ind *)
22 inductive nle (m:nat): predicate nat ≝
23 | nle_refl   : nle m m
24 | nle_succ_dx: ∀n. nle m n → nle m (↑n)
25 .
26
27 interpretation
28   "less equal (non-negative integers)"
29   'leq m n = (nle m n).
30
31 (* Basic constructions ******************************************************)
32
33 (*** le_n_Sn *)
34 lemma nle_succ_dx_refl (m): m ≤ ↑m.
35 /2 width=1 by nle_refl, nle_succ_dx/ qed.
36
37 (*** le_O_n *)
38 lemma nle_zero_sx (m): 𝟎 ≤ m.
39 #m @(nat_ind … m) -m /2 width=1 by nle_succ_dx/
40 qed.
41
42 (*** le_S_S *)
43 lemma nle_succ_bi (m) (n): m ≤ n → ↑m ≤ ↑n.
44 #m #n #H elim H -n /2 width=1 by nle_refl, nle_succ_dx/
45 qed.
46
47 (*** le_or_ge *)
48 lemma nle_ge_e (m) (n): ∨∨ m ≤ n | n ≤ m.
49 #m @(nat_ind … m) -m [ /2 width=1 by or_introl/ ]
50 #m #IH #n @(nat_ind … n) -n [ /2 width=1 by or_intror/ ]
51 #n #_ elim (IH n) -IH /3 width=2 by nle_succ_bi, or_introl, or_intror/
52 qed-.
53
54 (* Basic inversions *********************************************************)
55
56 lemma nle_inv_succ_sn (m) (n): ↑m ≤ n → m ≤ n.
57 #m #n #H elim H -n /2 width=1 by nle_succ_dx/
58 qed-.
59
60 (*** le_S_S_to_le *)
61 lemma nle_inv_succ_bi (m) (n): ↑m ≤ ↑n → m ≤ n.
62 #m #n @(insert_eq_0 … (↑n))
63 #y * -y
64 [ #H <(eq_inv_nsucc_bi … H) -m //
65 | #y #Hy #H >(eq_inv_nsucc_bi … H) -n /2 width=1 by nle_inv_succ_sn/
66 ]
67 qed-.
68
69 (*** le_n_O_to_eq *)
70 lemma nle_inv_zero_dx (m): m ≤ 𝟎 → 𝟎 = m.
71 #m @(insert_eq_0 … (𝟎))
72 #y * -y
73 [ #H destruct //
74 | #y #_ #H elim (eq_inv_nzero_succ … H)
75 ]
76 qed-.
77
78 (* Advanced inversions ******************************************************)
79
80 lemma nle_inv_succ_zero (m): ↑m ≤ 𝟎 → ⊥.
81 /3 width=2 by nle_inv_zero_dx, eq_inv_nzero_succ/ qed-.
82
83 lemma nle_inv_succ_sn_refl (m): ↑m ≤ m → ⊥.
84 #m @(nat_ind … m) -m [| #m #IH ] #H
85 [ /3 width=2 by nle_inv_zero_dx, eq_inv_nzero_succ/
86 | /3 width=1 by nle_inv_succ_bi/
87 ]
88 qed-.
89
90 (*** le_to_le_to_eq *)
91 theorem nle_antisym (m) (n): m ≤ n → n ≤ m → m = n.
92 #m #n #H elim H -n //
93 #n #_ #IH #Hn
94 lapply (nle_inv_succ_sn … Hn) #H
95 lapply (IH H) -IH -H #H destruct
96 elim (nle_inv_succ_sn_refl … Hn)
97 qed-.
98
99 (* Advanced eliminations ****************************************************)
100
101 lemma nle_ind_alt (Q: relation2 nat nat):
102       (∀n. Q (𝟎) (n)) →
103       (∀m,n. m ≤ n → Q m n → Q (↑m) (↑n)) →
104       ∀m,n. m ≤ n → Q m n.
105 #Q #IH1 #IH2 #m #n @(nat_ind_2 … m n) -m -n //
106 [ #m #H elim (nle_inv_succ_zero … H)
107 | /4 width=1 by nle_inv_succ_bi/
108 ]
109 qed-.
110
111 (* Advanced constructions ***************************************************)
112
113 (*** transitive_le *)
114 theorem nle_trans: Transitive … nle.
115 #m #n #H elim H -n /3 width=1 by nle_inv_succ_sn/
116 qed-.
117
118 (*** decidable_le *)
119 lemma nle_dec (m) (n): Decidable … (m ≤ n).
120 #m #n elim (nle_ge_e m n) [ /2 width=1 by or_introl/ ]
121 #Hnm elim (eq_nat_dec m n) [ #H destruct /2 width=1 by nle_refl, or_introl/ ]
122 /4 width=1 by nle_antisym, or_intror/
123 qed-.