]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/lambdadelta/basic_2/grammar/lenv_append.ma
aa2e587d80cc08e1a959b1bef6577de34ef07fb0
[helm.git] / matita / matita / contribs / lambdadelta / basic_2 / grammar / lenv_append.ma
1 (**************************************************************************)
2 (*       ___                                                              *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||         The HELM team.                                      *)
8 (*      ||A||         http://helm.cs.unibo.it                             *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU General Public License Version 2                  *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 include "ground_2/notation/functions/append_2.ma".
16 include "basic_2/notation/functions/snbind2_3.ma".
17 include "basic_2/notation/functions/snabbr_2.ma".
18 include "basic_2/notation/functions/snabst_2.ma".
19 include "basic_2/grammar/lenv_length.ma".
20
21 (* LOCAL ENVIRONMENTS *******************************************************)
22
23 let rec append L K on K ≝ match K with
24 [ LAtom       ⇒ L
25 | LPair K I V ⇒ (append L K). ⓑ{I} V
26 ].
27
28 interpretation "append (local environment)" 'Append L1 L2 = (append L1 L2).
29
30 interpretation "local environment tail binding construction (binary)"
31    'SnBind2 I T L = (append (LPair LAtom I T) L).
32
33 interpretation "tail abbreviation (local environment)"
34    'SnAbbr T L = (append (LPair LAtom Abbr T) L).
35
36 interpretation "tail abstraction (local environment)"
37    'SnAbst L T = (append (LPair LAtom Abst T) L).
38
39 definition d_appendable_sn: predicate (lenv→relation term) ≝ λR.
40                             ∀K,T1,T2. R K T1 T2 → ∀L. R (L @@ K) T1 T2.
41
42 (* Basic properties *********************************************************)
43
44 lemma append_atom: ∀L. L @@ ⋆ = L.
45 // qed.
46
47 lemma append_pair: ∀I,L,K,V. L @@ (K.ⓑ{I}V) = (L @@ K).ⓑ{I}V.
48 // qed.
49
50 lemma append_atom_sn: ∀L. ⋆ @@ L = L.
51 #L elim L -L //
52 #L #I #V >append_pair //
53 qed.
54
55 lemma append_assoc: associative … append.
56 #L1 #L2 #L3 elim L3 -L3 //
57 qed.
58
59 lemma append_length: ∀L1,L2. |L1 @@ L2| = |L1| + |L2|.
60 #L1 #L2 elim L2 -L2 //
61 #L2 #I #V2 >append_pair >length_pair >length_pair //
62 qed.
63
64 lemma ltail_length: ∀I,L,V. |ⓑ{I}V.L| = ⫯|L|.
65 #I #L #V >append_length //
66 qed.
67
68 (* Basic_1: was just: chead_ctail *)
69 lemma lpair_ltail: ∀L,I,V. ∃∃J,K,W. L.ⓑ{I}V = ⓑ{J}W.K & |L| = |K|.
70 #L elim L -L /2 width=5 by ex2_3_intro/
71 #L #Z #X #IHL #I #V elim (IHL Z X) -IHL
72 #J #K #W #H #_ >H -H >ltail_length
73 @(ex2_3_intro … J (K.ⓑ{I}V) W) /2 width=1 by length_pair/
74 qed-.
75
76 (* Basic inversion lemmas ***************************************************)
77
78 lemma append_inj_sn: ∀K1,K2,L1,L2. L1 @@ K1 = L2 @@ K2 → |K1| = |K2| →
79                      L1 = L2 ∧ K1 = K2.
80 #K1 elim K1 -K1
81 [ * /2 width=1 by conj/
82   #K2 #I2 #V2 #L1 #L2 #_ >length_atom >length_pair
83   #H destruct
84 | #K1 #I1 #V1 #IH *
85   [ #L1 #L2 #_ >length_atom >length_pair
86     #H destruct
87   | #K2 #I2 #V2 #L1 #L2 #H1 #H2
88     elim (destruct_lpair_lpair_aux … H1) -H1 #H1 #H3 #H4 destruct (**) (* destruct lemma needed *)
89     elim (IH … H1) -IH -H1 /2 width=1 by conj/
90   ]
91 ]
92 qed-.
93
94 (* Note: lemma 750 *)
95 lemma append_inj_dx: ∀K1,K2,L1,L2. L1 @@ K1 = L2 @@ K2 → |L1| = |L2| →
96                      L1 = L2 ∧ K1 = K2.
97 #K1 elim K1 -K1
98 [ * /2 width=1 by conj/
99   #K2 #I2 #V2 #L1 #L2 >append_atom >append_pair #H destruct
100   >length_pair >append_length >plus_n_Sm
101   #H elim (plus_xSy_x_false … H)
102 | #K1 #I1 #V1 #IH *
103   [ #L1 #L2 >append_pair >append_atom #H destruct
104     >length_pair >append_length >plus_n_Sm #H
105     lapply (discr_plus_x_xy … H) -H #H destruct
106   | #K2 #I2 #V2 #L1 #L2 >append_pair >append_pair #H1 #H2
107     elim (destruct_lpair_lpair_aux … H1) -H1 #H1 #H3 #H4 destruct (**) (* destruct lemma needed *)
108     elim (IH … H1) -IH -H1 /2 width=1 by conj/
109   ]
110 ]
111 qed-.
112
113 lemma append_inv_refl_dx: ∀L,K. L @@ K = L → K = ⋆.
114 #L #K #H elim (append_inj_dx … (⋆) … H) //
115 qed-.
116
117 lemma append_inv_pair_dx: ∀I,L,K,V. L @@ K = L.ⓑ{I}V → K = ⋆.ⓑ{I}V.
118 #I #L #K #V #H elim (append_inj_dx … (⋆.ⓑ{I}V) … H) //
119 qed-.
120
121 lemma length_inv_pos_dx_ltail: ∀L,l. |L| = ⫯l →
122                                ∃∃I,K,V. |K| = l & L = ⓑ{I}V.K.
123 #Y #l #H elim (length_inv_succ_dx … H) -H #I #L #V #Hl #HLK destruct
124 elim (lpair_ltail L I V) /2 width=5 by ex2_3_intro/
125 qed-.
126
127 lemma length_inv_pos_sn_ltail: ∀L,l. ⫯l = |L| →
128                                ∃∃I,K,V. l = |K| & L = ⓑ{I}V.K.
129 #Y #l #H elim (length_inv_succ_sn … H) -H #I #L #V #Hl #HLK destruct
130 elim (lpair_ltail L I V) /2 width=5 by ex2_3_intro/
131 qed-.
132
133 (* Basic eliminators ********************************************************)
134
135 (* Basic_1: was: c_tail_ind *)
136 lemma lenv_ind_alt: ∀R:predicate lenv.
137                     R (⋆) → (∀I,L,T. R L → R (ⓑ{I}T.L)) →
138                     ∀L. R L.
139 #R #IH1 #IH2 #L @(f_ind … length … L) -L #x #IHx * // -IH1
140 #L #I #V #H destruct elim (lpair_ltail L I V) /4 width=1 by/
141 qed-.