]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/lambdadelta/basic_2/relocation/cpy.ma
theory of extended iterated substitution begins ...
[helm.git] / matita / matita / contribs / lambdadelta / basic_2 / relocation / cpy.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 "basic_2/notation/relations/extpsubst_6.ma".
16 include "basic_2/grammar/genv.ma".
17 include "basic_2/grammar/cl_shift.ma".
18 include "basic_2/relocation/ldrop_append.ma".
19 include "basic_2/relocation/lsuby.ma".
20
21 (* CONTEXT-SENSITIVE EXTENDED PARALLEL SUBSTITUTION FOR TERMS ***************)
22
23 (* Note: this substitution is ordinary *)
24 (* activate genv *)
25 inductive cpy: nat → nat → relation4 genv lenv term term ≝
26 | cpy_atom : ∀I,G,L,d,e. cpy d e G L (⓪{I}) (⓪{I})
27 | cpy_subst: ∀I,G,L,K,V,W,i,d,e. d ≤ i → i < d + e →
28              ⇩[0, i] L ≡ K.ⓑ{I}V → ⇧[0, i + 1] V ≡ W → cpy d e G L (#i) W
29 | cpy_bind : ∀a,I,G,L,V1,V2,T1,T2,d,e.
30              cpy d e G L V1 V2 → cpy (d + 1) e G (L.ⓑ{I}V2) T1 T2 →
31              cpy d e G L (ⓑ{a,I}V1.T1) (ⓑ{a,I}V2.T2)
32 | cpy_flat : ∀I,G,L,V1,V2,T1,T2,d,e.
33              cpy d e G L V1 V2 → cpy d e G L T1 T2 →
34              cpy d e G L (ⓕ{I}V1.T1) (ⓕ{I}V2.T2)
35 .
36
37 interpretation "context-sensitive extended parallel substritution (term)"
38    'ExtPSubst G L T1 d e T2 = (cpy d e G L T1 T2).
39
40 (* Basic properties *********************************************************)
41
42 lemma lsuby_cpy_trans: ∀G,L1,T1,T2,d,e. ⦃G, L1⦄ ⊢ T1 ▶×[d, e] T2 →
43                        ∀L2. L2 ⊑×[d, e] L1 → ⦃G, L2⦄ ⊢ T1 ▶×[d, e] T2.
44 #G #d #e #L1 #T1 #T2 #H elim H -G -L1 -T1 -T2 -d -e
45 [ //
46 | #I #G #L1 #K1 #V #W #i #d #e #Hdi #Hide #HLK1 #HVW #L2 #HL12
47   elim (lsuby_fwd_ldrop2_be … HL12 … HLK1) -HL12 -HLK1 /2 width=5 by cpy_subst/
48 | /4 width=1 by lsuby_succ, cpy_bind/
49 | /3 width=1 by cpy_flat/
50 ]
51 qed-.
52
53 lemma cpy_refl: ∀G,T,L,d,e. ⦃G, L⦄ ⊢ T ▶×[d, e] T.
54 #G #T elim T -T // * /2 width=1 by cpy_bind, cpy_flat/
55 qed.
56
57 lemma cpy_full: ∀I,G,K,V,T1,L,d. ⇩[0, d] L ≡ K.ⓑ{I}V →
58                 ∃∃T2,T. ⦃G, L⦄ ⊢ T1 ▶×[d, 1] T2 & ⇧[d, 1] T ≡ T2.
59 #I #G #K #V #T1 elim T1 -T1
60 [ * #i #L #d #HLK
61   /2 width=4 by lift_sort, lift_gref, ex2_2_intro/
62   elim (lt_or_eq_or_gt i d) #Hid
63   /3 width=4 by lift_lref_ge_minus, lift_lref_lt, ex2_2_intro/
64   destruct
65   elim (lift_total V 0 (i+1)) #W #HVW
66   elim (lift_split … HVW i i)
67   /3 width=5 by cpy_subst, le_n, ex2_2_intro/
68 | * [ #a ] #J #W1 #U1 #IHW1 #IHU1 #L #d #HLK
69   elim (IHW1 … HLK) -IHW1 #W2 #W #HW12 #HW2
70   [ elim (IHU1 (L.ⓑ{J}W2) (d+1)) -IHU1
71     /3 width=9 by cpy_bind, ldrop_ldrop, lift_bind, ex2_2_intro/
72   | elim (IHU1 … HLK) -IHU1 -HLK
73     /3 width=8 by cpy_flat, lift_flat, ex2_2_intro/
74   ]
75 ]
76 qed-.
77
78 lemma cpy_weak: ∀G,L,T1,T2,d1,e1. ⦃G, L⦄ ⊢ T1 ▶×[d1, e1] T2 →
79                 ∀d2,e2. d2 ≤ d1 → d1 + e1 ≤ d2 + e2 →
80                 ⦃G, L⦄ ⊢ T1 ▶×[d2, e2] T2.
81 #G #L #T1 #T2 #d1 #e1 #H elim H -G -L -T1 -T2 -d1 -e1
82 [ //
83 | /3 width=5 by cpy_subst, transitive_le/
84 | /4 width=3 by cpy_bind, le_to_lt_to_lt, le_S_S/
85 | /3 width=1 by cpy_flat/
86 ]
87 qed-.
88
89 lemma cpy_weak_top: ∀G,L,T1,T2,d,e.
90                     ⦃G, L⦄ ⊢ T1 ▶×[d, e] T2 → ⦃G, L⦄ ⊢ T1 ▶×[d, |L| - d] T2.
91 #G #L #T1 #T2 #d #e #H elim H -G -L -T1 -T2 -d -e
92 [ //
93 | #I #G #L #K #V #W #i #d #e #Hdi #_ #HLK #HVW
94   lapply (ldrop_fwd_length_lt2 … HLK)
95   /3 width=5 by cpy_subst, lt_to_le_to_lt/
96 | normalize /2 width=1 by cpy_bind/
97 | /2 width=1 by cpy_flat/
98 ]
99 qed-.
100
101 lemma cpy_weak_full: ∀G,L,T1,T2,d,e.
102                      ⦃G, L⦄ ⊢ T1 ▶×[d, e] T2 → ⦃G, L⦄ ⊢ T1 ▶×[0, |L|] T2.
103 #G #L #T1 #T2 #d #e #HT12
104 lapply (cpy_weak … HT12 0 (d + e) ? ?) -HT12
105 /2 width=2 by cpy_weak_top/
106 qed-.
107
108 lemma cpy_split_up: ∀G,L,T1,T2,d,e. ⦃G, L⦄ ⊢ T1 ▶×[d, e] T2 → ∀i. d ≤ i → i ≤ d + e →
109                     ∃∃T. ⦃G, L⦄ ⊢ T1 ▶×[d, i - d] T & ⦃G, L⦄ ⊢ T ▶×[i, d + e - i] T2.
110 #G #L #T1 #T2 #d #e #H elim H -G -L -T1 -T2 -d -e
111 [ /2 width=3 by ex2_intro/
112 | #I #G #L #K #V #W #i #d #e #Hdi #Hide #HLK #HVW #j #Hdj #Hjde
113   elim (lt_or_ge i j) [ -Hide -Hjde | -Hdi -Hdj ]
114   [ >(plus_minus_m_m j d) in ⊢ (%→?);
115     /3 width=5 by cpy_subst, ex2_intro/
116   | #Hij lapply (plus_minus_m_m … Hjde) -Hjde
117     /3 width=9 by cpy_atom, cpy_subst, ex2_intro/
118   ]
119 | #a #I #G #L #V1 #V2 #T1 #T2 #d #e #_ #_ #IHV12 #IHT12 #i #Hdi #Hide
120   elim (IHV12 i) -IHV12 // #V #HV1 #HV2
121   elim (IHT12 (i + 1)) -IHT12 /2 width=1 by le_S_S/
122   -Hdi -Hide >arith_c1x #T #HT1 #HT2
123   lapply (lsuby_cpy_trans … HT1 (L.ⓑ{I} V) ?) -HT1 /3 width=5 by lsuby_succ, ex2_intro, cpy_bind/
124 | #I #G #L #V1 #V2 #T1 #T2 #d #e #_ #_ #IHV12 #IHT12 #i #Hdi #Hide
125   elim (IHV12 i) -IHV12 // elim (IHT12 i) -IHT12 //
126   -Hdi -Hide /3 width=5 by ex2_intro, cpy_flat/
127 ]
128 qed-.
129
130 lemma cpy_split_down: ∀G,L,T1,T2,d,e. ⦃G, L⦄ ⊢ T1 ▶×[d, e] T2 →
131                       ∀i. d ≤ i → i ≤ d + e →
132                       ∃∃T. ⦃G, L⦄ ⊢ T1 ▶×[i, d + e - i] T &
133                            ⦃G, L⦄ ⊢ T ▶×[d, i - d] T2.
134 #G #L #T1 #T2 #d #e #H elim H -G -L -T1 -T2 -d -e
135 [ /2 width=3 by ex2_intro/
136 | #I #G #L #K #V #W #i #d #e #Hdi #Hide #HLK #HVW #j #Hdj #Hjde
137   elim (lt_or_ge i j)
138   [ -Hide -Hjde >(plus_minus_m_m j d) in ⊢ (% → ?); // -Hdj /3 width=9 by ex2_intro, cpy_atom, cpy_subst/
139   | -Hdi -Hdj
140     >(plus_minus_m_m (d+e) j) in Hide; // -Hjde /3 width=5 by ex2_intro, cpy_subst/
141   ]
142 | #a #I #G #L #V1 #V2 #T1 #T2 #d #e #_ #_ #IHV12 #IHT12 #i #Hdi #Hide
143   elim (IHV12 i) -IHV12 // #V
144   elim (IHT12 (i + 1)) -IHT12 /2 width=1 by le_S_S/
145   -Hdi -Hide >arith_c1x #T #HT1 #HT2
146   lapply (lsuby_cpy_trans … HT1 (L. ⓑ{I} V) ?) -HT1 /3 width=5 by lsuby_succ, ex2_intro, cpy_bind/
147 | #I #G #L #V1 #V2 #T1 #T2 #d #e #_ #_ #IHV12 #IHT12 #i #Hdi #Hide
148   elim (IHV12 i) -IHV12 // elim (IHT12 i) -IHT12 //
149   -Hdi -Hide /3 width=5 by ex2_intro, cpy_flat/
150 ]
151 qed-.
152
153 lemma cpy_append: ∀G,K,T1,T2,d,e. ⦃G, K⦄ ⊢ T1 ▶×[d, e] T2 →
154                   ∀L. ⦃G, L @@ K⦄ ⊢ T1 ▶×[d, e] T2.
155 #G #K #T1 #T2 #d #e #H elim H -K -T1 -T2 -d -e
156 /2 width=1 by cpy_atom, cpy_bind, cpy_flat/
157 #I #G #K #K0 #V #W #i #d #e #Hdi #Hide #HK0 #HVW #L
158 lapply (ldrop_fwd_length_lt2 … HK0) #H
159 @(cpy_subst I … (L@@K0) … HVW) // (**) (* /4/ does not work *)
160 @(ldrop_O1_append_sn_le … HK0) /2 width=2 by lt_to_le/
161 qed-.
162
163 (* Basic inversion lemmas ***************************************************)
164
165 fact cpy_inv_atom1_aux: ∀G,L,T1,T2,d,e. ⦃G, L⦄ ⊢ T1 ▶×[d, e] T2 → ∀J. T1 = ⓪{J} →
166                         T2 = ⓪{J} ∨
167                         ∃∃I,K,V,i. d ≤ i & i < d + e &
168                                    ⇩[O, i] L ≡ K.ⓑ{I}V &
169                                    ⇧[O, i + 1] V ≡ T2 &
170                                    J = LRef i.
171 #G #L #T1 #T2 #d #e * -G -L -T1 -T2 -d -e
172 [ #I #G #L #d #e #J #H destruct /2 width=1 by or_introl/
173 | #I #G #L #K #V #T2 #i #d #e #Hdi #Hide #HLK #HVT2 #J #H destruct /3 width=9 by ex5_4_intro, or_intror/
174 | #a #I #G #L #V1 #V2 #T1 #T2 #d #e #_ #_ #J #H destruct
175 | #I #G #L #V1 #V2 #T1 #T2 #d #e #_ #_ #J #H destruct
176 ]
177 qed-.
178
179 lemma cpy_inv_atom1: ∀I,G,L,T2,d,e. ⦃G, L⦄ ⊢ ⓪{I} ▶×[d, e] T2 →
180                      T2 = ⓪{I} ∨
181                      ∃∃J,K,V,i. d ≤ i & i < d + e &
182                                 ⇩[O, i] L ≡ K.ⓑ{J}V &
183                                 ⇧[O, i + 1] V ≡ T2 &
184                                 I = LRef i.
185 /2 width=4 by cpy_inv_atom1_aux/ qed-.
186
187 lemma cpy_inv_sort1: ∀G,L,T2,k,d,e. ⦃G, L⦄ ⊢ ⋆k ▶×[d, e] T2 → T2 = ⋆k.
188 #G #L #T2 #k #d #e #H
189 elim (cpy_inv_atom1 … H) -H //
190 * #I #K #V #i #_ #_ #_ #_ #H destruct
191 qed-.
192
193 lemma cpy_inv_lref1: ∀G,L,T2,i,d,e. ⦃G, L⦄ ⊢ #i ▶×[d, e] T2 →
194                      T2 = #i ∨
195                      ∃∃I,K,V. d ≤ i & i < d + e &
196                               ⇩[O, i] L ≡ K.ⓑ{I}V &
197                               ⇧[O, i + 1] V ≡ T2.
198 #G #L #T2 #i #d #e #H
199 elim (cpy_inv_atom1 … H) -H /2 width=1 by or_introl/
200 * #I #K #V #j #Hdj #Hjde #HLK #HVT2 #H destruct /3 width=5 by ex4_3_intro, or_intror/
201 qed-.
202
203 lemma cpy_inv_gref1: ∀G,L,T2,p,d,e. ⦃G, L⦄ ⊢ §p ▶×[d, e] T2 → T2 = §p.
204 #G #L #T2 #p #d #e #H
205 elim (cpy_inv_atom1 … H) -H //
206 * #I #K #V #i #_ #_ #_ #_ #H destruct
207 qed-.
208
209 fact cpy_inv_bind1_aux: ∀G,L,U1,U2,d,e. ⦃G, L⦄ ⊢ U1 ▶×[d, e] U2 →
210                         ∀a,I,V1,T1. U1 = ⓑ{a,I}V1.T1 →
211                         ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ▶×[d, e] V2 &
212                                  ⦃G, L. ⓑ{I}V2⦄ ⊢ T1 ▶×[d + 1, e] T2 &
213                                  U2 = ⓑ{a,I}V2.T2.
214 #G #L #U1 #U2 #d #e * -G -L -U1 -U2 -d -e
215 [ #I #G #L #d #e #b #J #W1 #U1 #H destruct
216 | #I #G #L #K #V #W #i #d #e #_ #_ #_ #_ #b #J #W1 #U1 #H destruct
217 | #a #I #G #L #V1 #V2 #T1 #T2 #d #e #HV12 #HT12 #b #J #W1 #U1 #H destruct /2 width=5 by ex3_2_intro/
218 | #I #G #L #V1 #V2 #T1 #T2 #d #e #_ #_ #b #J #W1 #U1 #H destruct
219 ]
220 qed-.
221
222 lemma cpy_inv_bind1: ∀a,I,G,L,V1,T1,U2,d,e. ⦃G, L⦄ ⊢ ⓑ{a,I} V1. T1 ▶×[d, e] U2 →
223                      ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ▶×[d, e] V2 &
224                               ⦃G, L.ⓑ{I}V2⦄ ⊢ T1 ▶×[d + 1, e] T2 &
225                               U2 = ⓑ{a,I}V2.T2.
226 /2 width=3 by cpy_inv_bind1_aux/ qed-.
227
228 fact cpy_inv_flat1_aux: ∀G,L,U1,U2,d,e. ⦃G, L⦄ ⊢ U1 ▶×[d, e] U2 →
229                         ∀I,V1,T1. U1 = ⓕ{I}V1.T1 →
230                         ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ▶×[d, e] V2 &
231                                  ⦃G, L⦄ ⊢ T1 ▶×[d, e] T2 &
232                                  U2 = ⓕ{I}V2.T2.
233 #G #L #U1 #U2 #d #e * -G -L -U1 -U2 -d -e
234 [ #I #G #L #d #e #J #W1 #U1 #H destruct
235 | #I #G #L #K #V #W #i #d #e #_ #_ #_ #_ #J #W1 #U1 #H destruct
236 | #a #I #G #L #V1 #V2 #T1 #T2 #d #e #_ #_ #J #W1 #U1 #H destruct
237 | #I #G #L #V1 #V2 #T1 #T2 #d #e #HV12 #HT12 #J #W1 #U1 #H destruct /2 width=5 by ex3_2_intro/
238 ]
239 qed-.
240
241 lemma cpy_inv_flat1: ∀I,G,L,V1,T1,U2,d,e. ⦃G, L⦄ ⊢ ⓕ{I} V1. T1 ▶×[d, e] U2 →
242                      ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ▶×[d, e] V2 &
243                               ⦃G, L⦄ ⊢ T1 ▶×[d, e] T2 &
244                               U2 = ⓕ{I}V2.T2.
245 /2 width=3 by cpy_inv_flat1_aux/ qed-.
246
247
248 fact cpy_inv_refl_O2_aux: ∀G,L,T1,T2,d,e. ⦃G, L⦄ ⊢ T1 ▶×[d, e] T2 → e = 0 → T1 = T2.
249 #G #L #T1 #T2 #d #e #H elim H -G -L -T1 -T2 -d -e
250 [ //
251 | #I #G #L #K #V #W #i #d #e #Hdi #Hide #_ #_ #H destruct
252   lapply (le_to_lt_to_lt … Hdi … Hide) -Hdi -Hide <plus_n_O #Hdd
253   elim (lt_refl_false … Hdd)
254 | /3 width=1 by eq_f2/
255 | /3 width=1 by eq_f2/
256 ]
257 qed-.
258
259 lemma cpy_inv_refl_O2: ∀G,L,T1,T2,d. ⦃G, L⦄ ⊢ T1 ▶×[d, 0] T2 → T1 = T2.
260 /2 width=6 by cpy_inv_refl_O2_aux/ qed-.
261
262 (* Basic forward lemmas *****************************************************)
263
264 lemma cpy_fwd_tw: ∀G,L,T1,T2,d,e. ⦃G, L⦄ ⊢ T1 ▶×[d, e] T2 → ♯{T1} ≤ ♯{T2}.
265 #G #L #T1 #T2 #d #e #H elim H -G -L -T1 -T2 -d -e normalize
266 /3 width=1 by monotonic_le_plus_l, le_plus/
267 qed-.
268
269 lemma cpy_fwd_shift1: ∀G,L1,L,T1,T,d,e. ⦃G, L⦄ ⊢ L1 @@ T1 ▶×[d, e] T →
270                       ∃∃L2,T2. |L1| = |L2| & T = L2 @@ T2.
271 #G #L1 @(lenv_ind_dx … L1) -L1 normalize
272 [ #L #T1 #T #d #e #HT1
273   @(ex2_2_intro … (⋆)) // (**) (* explicit constructor *)
274 | #I #L1 #V1 #IH #L #T1 #X #d #e
275   >shift_append_assoc normalize #H
276   elim (cpy_inv_bind1 … H) -H
277   #V0 #T0 #_ #HT10 #H destruct
278   elim (IH … HT10) -IH -HT10 #L2 #T2 #HL12 #H destruct
279   >append_length >HL12 -HL12
280   @(ex2_2_intro … (⋆.ⓑ{I}V0@@L2) T2) [ >append_length ] (**) (* explicit constructor *)
281   /2 width=3 by trans_eq/ 
282 ]
283 qed-.