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_2/notation/functions/append_2.ma".
16 include "basic_2/grammar/lenv_length.ma".
18 (* LOCAL ENVIRONMENTS *******************************************************)
20 let rec append L K on K ≝ match K with
22 | LPair K I V ⇒ (append L K). ⓑ{I} V
25 interpretation "append (local environment)" 'Append L1 L2 = (append L1 L2).
27 definition l_appendable_sn: predicate (lenv→relation term) ≝ λR.
28 ∀K,T1,T2. R K T1 T2 → ∀L. R (L @@ K) T1 T2.
30 (* Basic properties *********************************************************)
32 lemma append_atom_sn: ∀L. ⋆ @@ L = L.
33 #L elim L -L normalize //
36 lemma append_assoc: associative … append.
37 #L1 #L2 #L3 elim L3 -L3 normalize //
40 lemma append_length: ∀L1,L2. |L1 @@ L2| = |L1| + |L2|.
41 #L1 #L2 elim L2 -L2 normalize //
44 (* Basic inversion lemmas ***************************************************)
46 lemma append_inj_sn: ∀K1,K2,L1,L2. L1 @@ K1 = L2 @@ K2 → |K1| = |K2| →
49 [ * normalize /2 width=1/
50 #K2 #I2 #V2 #L1 #L2 #_ <plus_n_Sm #H destruct
51 | #K1 #I1 #V1 #IH * normalize
52 [ #L1 #L2 #_ <plus_n_Sm #H destruct
53 | #K2 #I2 #V2 #L1 #L2 #H1 #H2
54 elim (destruct_lpair_lpair … H1) -H1 #H1 #H3 #H4 destruct (**) (* destruct lemma needed *)
55 elim (IH … H1) -IH -H1 // -H2 /2 width=1/
61 lemma append_inj_dx: ∀K1,K2,L1,L2. L1 @@ K1 = L2 @@ K2 → |L1| = |L2| →
64 [ * normalize /2 width=1/
65 #K2 #I2 #V2 #L1 #L2 #H1 #H2 destruct
66 normalize in H2; >append_length in H2; #H
67 elim (plus_xySz_x_false … H)
68 | #K1 #I1 #V1 #IH * normalize
69 [ #L1 #L2 #H1 #H2 destruct
70 normalize in H2; >append_length in H2; #H
71 elim (plus_xySz_x_false … (sym_eq … H))
72 | #K2 #I2 #V2 #L1 #L2 #H1 #H2
73 elim (destruct_lpair_lpair … H1) -H1 #H1 #H3 #H4 destruct (**) (* destruct lemma needed *)
74 elim (IH … H1) -IH -H1 // -H2 /2 width=1/
79 lemma append_inv_refl_dx: ∀L,K. L @@ K = L → K = ⋆.
81 elim (append_inj_dx … (⋆) … H) //
84 lemma append_inv_pair_dx: ∀I,L,K,V. L @@ K = L.ⓑ{I}V → K = ⋆.ⓑ{I}V.
86 elim (append_inj_dx … (⋆.ⓑ{I}V) … H) //
89 lemma length_inv_pos_dx_append: ∀d,L. |L| = d + 1 →
90 ∃∃I,K,V. |K| = d & L = ⋆.ⓑ{I}V @@ K.
91 #d @(nat_ind_plus … d) -d
93 elim (length_inv_pos_dx … H) -H #I #K #V #H
94 >(length_inv_zero_dx … H) -H #H destruct
95 @ex2_3_intro [4: /2 width=2/ |5: // |1,2,3: skip ] (**) (* /3/ does not work *)
97 elim (length_inv_pos_dx … H) -H #I #K #V #H
98 elim (IHd … H) -IHd -H #I0 #K0 #V0 #H1 #H2 #H3 destruct
99 @(ex2_3_intro … (K0.ⓑ{I}V)) //
103 (* Basic_eliminators ********************************************************)
105 fact lenv_ind_dx_aux: ∀R:predicate lenv. R (⋆) →
106 (∀I,L,V. R L → R (⋆.ⓑ{I}V @@ L)) →
108 #R #Hatom #Hpair #d @(nat_ind_plus … d) -d
109 [ #L #H >(length_inv_zero_dx … H) -H //
111 elim (length_inv_pos_dx_append … H) -H #I #K #V #H1 #H2 destruct /3 width=1/
115 lemma lenv_ind_dx: ∀R:predicate lenv. R (⋆) →
116 (∀I,L,V. R L → R (⋆.ⓑ{I}V @@ L)) →
118 /3 width=2 by lenv_ind_dx_aux/ qed-.
120 (* Advanced inversion lemmas ************************************************)
122 lemma length_inv_pos_sn_append: ∀d,L. 1 + d = |L| →
123 ∃∃I,K,V. d = |K| & L = ⋆. ⓑ{I}V @@ K.
124 #d >commutative_plus @(nat_ind_plus … d) -d
125 [ #L #H elim (length_inv_pos_sn … H) -H #I #K #V #H1 #H2 destruct
126 >(length_inv_zero_sn … H1) -K
127 @(ex2_3_intro … (⋆)) // (**) (* explicit constructor *)
128 | #d #IHd #L #H elim (length_inv_pos_sn … H) -H #I #K #V #H1 #H2 destruct
130 elim (IHd K) -IHd // #J #L #W #H1 #H2 destruct
131 @(ex2_3_intro … (L.ⓑ{I}V)) // (**) (* explicit constructor *)
132 >append_length /2 width=1/