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 ≝
25 | nle_succ_dx: ∀n. nle m n → nle m (↑n)
29 "less equal (non-negative integers)"
32 (* Basic constructions ******************************************************)
35 lemma nle_succ_dx_refl (m): m ≤ ↑m.
36 /2 width=1 by nle_refl, nle_succ_dx/ qed.
39 lemma nle_zero_sx (m): 𝟎 ≤ m.
40 #m @(nat_ind_succ … m) -m /2 width=1 by nle_succ_dx/
44 lemma nle_succ_bi (m) (n): m ≤ n → ↑m ≤ ↑n.
45 #m #n #H elim H -n /2 width=1 by nle_refl, nle_succ_dx/
49 lemma nat_split_le_ge (m) (n): ∨∨ m ≤ n | n ≤ m.
50 #m #n @(nat_ind_2_succ … m n) -m -n
51 [ /2 width=1 by or_introl/
52 | /2 width=1 by or_intror/
53 | #m #n * /3 width=2 by nle_succ_bi, or_introl, or_intror/
57 (* Basic destructions *******************************************************)
59 lemma nle_des_succ_sn (m) (n): ↑m ≤ n → m ≤ n.
60 #m #n #H elim H -n /2 width=1 by nle_succ_dx/
63 (* Basic inversions *********************************************************)
66 lemma nle_inv_succ_bi (m) (n): ↑m ≤ ↑n → m ≤ n.
67 #m #n @(insert_eq_1 … (↑n))
69 [ #H >(eq_inv_nsucc_bi … H) -n //
70 | #o #Ho #H >(eq_inv_nsucc_bi … H) -n
71 /2 width=1 by nle_des_succ_sn/
76 lemma nle_inv_zero_dx (m): m ≤ 𝟎 → 𝟎 = m.
77 #m @(insert_eq_1 … (𝟎))
80 | #y #_ #H elim (eq_inv_zero_nsucc … H)
84 (* Advanced inversions ******************************************************)
86 (*** le_plus_xSy_O_false *)
87 lemma nle_inv_succ_zero (m): ↑m ≤ 𝟎 → ⊥.
88 /3 width=2 by nle_inv_zero_dx, eq_inv_zero_nsucc/ qed-.
90 lemma nle_inv_succ_sn_refl (m): ↑m ≤ m → ⊥.
91 #m @(nat_ind_succ … m) -m [| #m #IH ] #H
92 [ /2 width=2 by nle_inv_succ_zero/
93 | /3 width=1 by nle_inv_succ_bi/
97 (*** le_to_le_to_eq *)
98 theorem nle_antisym (m) (n): m ≤ n → n ≤ m → m = n.
101 lapply (nle_des_succ_sn … Hn) #H
102 lapply (IH H) -IH -H #H destruct
103 elim (nle_inv_succ_sn_refl … Hn)
106 (* Advanced eliminations ****************************************************)
109 lemma nle_ind_alt (Q: relation2 nat nat):
111 (∀m,n. m ≤ n → Q m n → Q (↑m) (↑n)) →
113 #Q #IH1 #IH2 #m #n @(nat_ind_2_succ … m n) -m -n //
114 [ #m #_ #H elim (nle_inv_succ_zero … H)
115 | /4 width=1 by nle_inv_succ_bi/
119 (* Advanced constructions ***************************************************)
121 (*** transitive_le *)
122 theorem nle_trans: Transitive … nle.
123 #m #n #H elim H -n /3 width=1 by nle_des_succ_sn/
126 (*** decidable_le le_dec *)
127 lemma nle_dec (m) (n): Decidable … (m ≤ n).
128 #m #n elim (nat_split_le_ge m n) [ /2 width=1 by or_introl/ ]
129 #Hnm elim (eq_nat_dec m n) [ #H destruct /2 width=1 by nle_refl, or_introl/ ]
130 /4 width=1 by nle_antisym, or_intror/