1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| The HELM team. *)
8 (* ||A|| http://helm.cs.unibo.it *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU General Public License Version 2 *)
13 (**************************************************************************)
15 include "ground/generated/insert_eq_1.ma".
16 include "ground/arith/nat_succ.ma".
18 (* ORDER FOR NON-NEGATIVE INTEGERS ******************************************)
21 inductive nle (m:nat): predicate nat ≝
23 | nle_succ_dx: ∀n. nle m n → nle m (↑n)
27 "less equal (non-negative integers)"
30 (* Basic constructions ******************************************************)
33 lemma nle_succ_dx_refl (m): m ≤ ↑m.
34 /2 width=1 by nle_refl, nle_succ_dx/ qed.
37 lemma nle_zero_sx (m): 𝟎 ≤ m.
38 #m @(nat_ind_succ … m) -m /2 width=1 by nle_succ_dx/
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/
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/
55 (* Basic destructions *******************************************************)
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/
61 (* Basic inversions *********************************************************)
64 lemma nle_inv_succ_bi (m) (n): ↑m ≤ ↑n → m ≤ n.
65 #m #n @(insert_eq_1 … (↑n))
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/
74 lemma nle_inv_zero_dx (m): m ≤ 𝟎 → 𝟎 = m.
75 #m @(insert_eq_1 … (𝟎))
78 | #y #_ #H elim (eq_inv_zero_nsucc … H)
82 (* Advanced inversions ******************************************************)
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-.
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/
95 (*** le_to_le_to_eq *)
96 theorem nle_antisym (m) (n): m ≤ n → n ≤ m → m = n.
99 lapply (nle_des_succ_sn … Hn) #H
100 lapply (IH H) -IH -H #H destruct
101 elim (nle_inv_succ_sn_refl … Hn)
104 (* Advanced eliminations ****************************************************)
107 lemma nle_ind_alt (Q: relation2 nat nat):
109 (∀m,n. m ≤ n → Q 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/
117 (* Advanced constructions ***************************************************)
119 (*** transitive_le *)
120 theorem nle_trans: Transitive … nle.
121 #m #n #H elim H -n /3 width=1 by nle_des_succ_sn/
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/