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 "basic_2/syntax/lenv_length.ma".
16 include "basic_2/syntax/append.ma".
18 (* APPEND FOR LOCAL ENVIRONMENTS ********************************************)
20 (* Properties with length for local environments ****************************)
22 lemma append_length: ∀L1,L2. |L1 @@ L2| = |L1| + |L2|.
23 #L1 #L2 elim L2 -L2 //
24 #L2 #I >append_bind >length_bind >length_bind //
27 lemma ltail_length: ∀I,L. |ⓘ{I}.L| = ⫯|L|.
28 #I #L >append_length //
31 (* Advanced inversion lemmas on length for local environments ***************)
33 (* Basic_2A1: was: length_inv_pos_dx_ltail *)
34 lemma length_inv_succ_dx_ltail: ∀L,n. |L| = ⫯n →
35 ∃∃I,K. |K| = n & L = ⓘ{I}.K.
36 #Y #n #H elim (length_inv_succ_dx … H) -H #I #L #Hn #HLK destruct
37 elim (lenv_case_tail … L) [2: * #K #J ]
38 #H destruct /2 width=4 by ex2_2_intro/
41 (* Basic_2A1: was: length_inv_pos_sn_ltail *)
42 lemma length_inv_succ_sn_ltail: ∀L,n. ⫯n = |L| →
43 ∃∃I,K. n = |K| & L = ⓘ{I}.K.
44 #Y #n #H elim (length_inv_succ_sn … H) -H #I #L #Hn #HLK destruct
45 elim (lenv_case_tail … L) [2: * #K #J ]
46 #H destruct /2 width=4 by ex2_2_intro/
49 (* Inversion lemmas with length for local environments **********************)
51 (* Basic_2A1: was: append_inj_sn *)
52 lemma append_inj_length_sn: ∀K1,K2,L1,L2. L1 @@ K1 = L2 @@ K2 → |K1| = |K2| →
55 [ * /2 width=1 by conj/
56 #K2 #I2 #L1 #L2 #_ >length_atom >length_bind
59 [ #L1 #L2 #_ >length_atom >length_bind
61 | #K2 #I2 #L1 #L2 #H1 >length_bind >length_bind #H2
62 elim (destruct_lbind_lbind_aux … H1) -H1 #H1 #H3 destruct (**) (* destruct lemma needed *)
63 elim (IH … H1) -IH -H1 /3 width=4 by conj/
69 (* Basic_2A1: was: append_inj_dx *)
70 lemma append_inj_length_dx: ∀K1,K2,L1,L2. L1 @@ K1 = L2 @@ K2 → |L1| = |L2| →
73 [ * /2 width=1 by conj/
74 #K2 #I2 #L1 #L2 >append_atom >append_bind #H destruct
75 >length_bind >append_length >plus_n_Sm
76 #H elim (plus_xSy_x_false … H)
78 [ #L1 #L2 >append_bind >append_atom #H destruct
79 >length_bind >append_length >plus_n_Sm #H
80 lapply (discr_plus_x_xy … H) -H #H destruct
81 | #K2 #I2 #L1 #L2 >append_bind >append_bind #H1 #H2
82 elim (destruct_lbind_lbind_aux … H1) -H1 #H1 #H3 destruct (**) (* destruct lemma needed *)
83 elim (IH … H1) -IH -H1 /2 width=1 by conj/
88 (* Advanced inversion lemmas ************************************************)
90 lemma append_inj_dx: ∀L,K1,K2. L@@K1 = L@@K2 → K1 = K2.
91 #L #K1 #K2 #H elim (append_inj_length_dx … H) -H //
94 lemma append_inv_refl_dx: ∀L,K. L@@K = L → K = ⋆.
95 #L #K #H elim (append_inj_dx … (⋆) … H) //
98 lemma append_inv_pair_dx: ∀I,L,K,V. L@@K = L.ⓑ{I}V → K = ⋆.ⓑ{I}V.
99 #I #L #K #V #H elim (append_inj_dx … (⋆.ⓑ{I}V) … H) //
102 (* Basic eliminators ********************************************************)
104 (* Basic_1: was: c_tail_ind *)
105 (* Basic_2A1: was: lenv_ind_alt *)
106 lemma lenv_ind_tail: ∀R:predicate lenv.
107 R (⋆) → (∀I,L. R L → R (ⓘ{I}.L)) → ∀L. R L.
108 #R #IH1 #IH2 #L @(f_ind … length … L) -L #x #IHx * //
109 #L #I -IH1 #H destruct
110 elim (lenv_case_tail … L) [2: * #K #J ]
111 #H destruct /3 width=1 by/