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/insert_eq/insert_eq_0.ma".
16 include "ground/arith/nat_succ.ma".
18 (* ORDER FOR NON-NEGATIVE INTEGERS ******************************************)
22 inductive nle (m:nat): predicate nat ≝
24 | nle_succ_dx: ∀n. nle m n → nle m (↑n)
28 "less equal (non-negative integers)"
31 (* Basic constructions ******************************************************)
34 lemma nle_succ_dx_refl (m): m ≤ ↑m.
35 /2 width=1 by nle_refl, nle_succ_dx/ qed.
38 lemma nle_zero_sx (m): 𝟎 ≤ m.
39 #m @(nat_ind_succ … m) -m /2 width=1 by nle_succ_dx/
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/
48 lemma nle_ge_dis (m) (n): ∨∨ m ≤ n | n ≤ m.
49 #m #n @(nat_ind_succ_2 … m n) -m -n
50 [ /2 width=1 by or_introl/
51 | /2 width=1 by or_intror/
52 | #m #n * /3 width=2 by nle_succ_bi, or_introl, or_intror/
56 (* Basic inversions *********************************************************)
58 lemma nle_inv_succ_sn (m) (n): ↑m ≤ n → m ≤ n.
59 #m #n #H elim H -n /2 width=1 by nle_succ_dx/
63 lemma nle_inv_succ_bi (m) (n): ↑m ≤ ↑n → m ≤ n.
64 #m #n @(insert_eq_0 … (↑n))
66 [ #H <(eq_inv_nsucc_bi … H) -m //
67 | #y #Hy #H >(eq_inv_nsucc_bi … H) -n /2 width=1 by nle_inv_succ_sn/
72 lemma nle_inv_zero_dx (m): m ≤ 𝟎 → 𝟎 = m.
73 #m @(insert_eq_0 … (𝟎))
76 | #y #_ #H elim (eq_inv_nzero_succ … H)
80 (* Advanced inversions ******************************************************)
82 lemma nle_inv_succ_zero (m): ↑m ≤ 𝟎 → ⊥.
83 /3 width=2 by nle_inv_zero_dx, eq_inv_nzero_succ/ qed-.
85 lemma nle_inv_succ_sn_refl (m): ↑m ≤ m → ⊥.
86 #m @(nat_ind_succ … m) -m [| #m #IH ] #H
87 [ /3 width=2 by nle_inv_zero_dx, eq_inv_nzero_succ/
88 | /3 width=1 by nle_inv_succ_bi/
92 (*** le_to_le_to_eq *)
93 theorem nle_antisym (m) (n): m ≤ n → n ≤ m → m = n.
96 lapply (nle_inv_succ_sn … Hn) #H
97 lapply (IH H) -IH -H #H destruct
98 elim (nle_inv_succ_sn_refl … Hn)
101 (* Advanced eliminations ****************************************************)
104 lemma nle_ind_alt (Q: relation2 nat nat):
106 (∀m,n. m ≤ n → Q m n → Q (↑m) (↑n)) →
108 #Q #IH1 #IH2 #m #n @(nat_ind_succ_2 … m n) -m -n //
109 [ #m #H elim (nle_inv_succ_zero … H)
110 | /4 width=1 by nle_inv_succ_bi/
114 (* Advanced constructions ***************************************************)
116 (*** transitive_le *)
117 theorem nle_trans: Transitive … nle.
118 #m #n #H elim H -n /3 width=1 by nle_inv_succ_sn/
122 lemma nle_dec (m) (n): Decidable … (m ≤ n).
123 #m #n elim (nle_ge_dis m n) [ /2 width=1 by or_introl/ ]
124 #Hnm elim (eq_nat_dec m n) [ #H destruct /2 width=1 by nle_refl, or_introl/ ]
125 /4 width=1 by nle_antisym, or_intror/