]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/lambdadelta/basic_2/relocation/cpy.ma
06e4a43c915e9973489d64664acc4c79a5cff239
[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 "ground_2/ynat/ynat_max.ma".
16 include "basic_2/notation/relations/psubst_6.ma".
17 include "basic_2/grammar/genv.ma".
18 include "basic_2/grammar/cl_shift.ma".
19 include "basic_2/relocation/ldrop_append.ma".
20 include "basic_2/relocation/lsuby.ma".
21
22 (* CONTEXT-SENSITIVE EXTENDED ORDINARY SUBSTITUTION FOR TERMS ***************)
23
24 (* activate genv *)
25 inductive cpy: ynat → ynat → 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 ≤ yinj i → i < d+e →
28              ⇩[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) e G (L.ⓑ{I}V1) 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 ordinary substritution (term)"
38    'PSubst G L T1 d e T2 = (cpy d e G L T1 T2).
39
40 (* Basic properties *********************************************************)
41
42 lemma lsuby_cpy_trans: ∀G,d,e. lsub_trans … (cpy d e G) (lsuby d e).
43 #G #d #e #L1 #T1 #T2 #H elim H -G -L1 -T1 -T2 -d -e
44 [ //
45 | #I #G #L1 #K1 #V #W #i #d #e #Hdi #Hide #HLK1 #HVW #L2 #HL12
46   elim (lsuby_fwd_ldrop2_be … HL12 … HLK1) -HL12 -HLK1 /2 width=5 by cpy_subst/
47 | /4 width=1 by lsuby_succ, cpy_bind/
48 | /3 width=1 by cpy_flat/
49 ]
50 qed-.
51
52 lemma cpy_refl: ∀G,T,L,d,e. ⦃G, L⦄ ⊢ T ▶[d, e] T.
53 #G #T elim T -T // * /2 width=1 by cpy_bind, cpy_flat/
54 qed.
55
56 (* Basic_1: was: subst1_ex *)
57 lemma cpy_full: ∀I,G,K,V,T1,L,d. ⇩[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   /4 width=5 by cpy_subst, ylt_inj, 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}W1) (d+1)) -IHU1
71     /3 width=9 by cpy_bind, ldrop_drop, 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 [ /3 width=5 by cpy_subst, ylt_yle_trans, yle_trans/
83 | /4 width=3 by cpy_bind, ylt_yle_trans, yle_succ/
84 | /3 width=1 by cpy_flat/
85 ]
86 qed-.
87
88 lemma cpy_weak_top: ∀G,L,T1,T2,d,e.
89                     ⦃G, L⦄ ⊢ T1 ▶[d, e] T2 → ⦃G, L⦄ ⊢ T1 ▶[d, |L| - d] T2.
90 #G #L #T1 #T2 #d #e #H elim H -G -L -T1 -T2 -d -e //
91 [ #I #G #L #K #V #W #i #d #e #Hdi #_ #HLK #HVW
92   lapply (ldrop_fwd_length_lt2 … HLK)
93   /4 width=5 by cpy_subst, ylt_yle_trans, ylt_inj/
94 | #a #I #G #L #V1 #V2 normalize in match (|L.ⓑ{I}V2|); (**) (* |?| does not work *)
95   /2 width=1 by cpy_bind/
96 | /2 width=1 by cpy_flat/
97 ]
98 qed-.
99
100 lemma cpy_weak_full: ∀G,L,T1,T2,d,e.
101                      ⦃G, L⦄ ⊢ T1 ▶[d, e] T2 → ⦃G, L⦄ ⊢ T1 ▶[0, |L|] T2.
102 #G #L #T1 #T2 #d #e #HT12
103 lapply (cpy_weak … HT12 0 (d + e) ? ?) -HT12
104 /2 width=2 by cpy_weak_top/
105 qed-.
106
107 lemma cpy_up: ∀G,L,U1,U2,dt,et. ⦃G, L⦄ ⊢ U1 ▶[dt, et] U2 →
108               ∀T1,d,e. ⇧[d, e] T1 ≡ U1 →
109               d ≤ dt → d + e ≤ dt + et →
110               ∃∃T2. ⦃G, L⦄ ⊢ U1 ▶[d+e, dt+et-(d+e)] U2 & ⇧[d, e] T2 ≡ U2.
111 #G #L #U1 #U2 #dt #et #H elim H -G -L -U1 -U2 -dt -et
112 [ * #i #G #L #dt #et #T1 #d #e #H #_
113   [ lapply (lift_inv_sort2 … H) -H #H destruct /2 width=3 by ex2_intro/
114   | elim (lift_inv_lref2 … H) -H * #Hid #H destruct /3 width=3 by lift_lref_ge_minus, lift_lref_lt, ex2_intro/
115   | lapply (lift_inv_gref2 … H) -H #H destruct /2 width=3 by ex2_intro/
116   ]
117 | #I #G #L #K #V #W #i #dt #et #Hdti #Hidet #HLK #HVW #T1 #d #e #H #Hddt #Hdedet
118   elim (lift_inv_lref2 … H) -H * #Hid #H destruct [ -V -Hidet -Hdedet | -Hdti -Hddt ]
119   [ elim (ylt_yle_false … Hddt) -Hddt /3 width=3 by yle_ylt_trans, ylt_inj/
120   | elim (le_inv_plus_l … Hid) #Hdie #Hei
121     elim (lift_split … HVW d (i-e+1) ? ? ?) [2,3,4: /2 width=1 by le_S_S, le_S/ ] -Hdie
122     #T2 #_ >plus_minus // <minus_minus /2 width=1 by le_S/ <minus_n_n <plus_n_O #H -Hei
123     @(ex2_intro … H) -H @(cpy_subst … HLK HVW) /2 width=1 by yle_inj/ >ymax_pre_sn_comm // (**) (* explicit constructor *)
124   ]
125 | #a #I #G #L #W1 #W2 #U1 #U2 #dt #et #_ #_ #IHW12 #IHU12 #X #d #e #H #Hddt #Hdedet
126   elim (lift_inv_bind2 … H) -H #V1 #T1 #HVW1 #HTU1 #H destruct
127   elim (IHW12 … HVW1) -V1 -IHW12 //
128   elim (IHU12 … HTU1) -T1 -IHU12 /2 width=1 by yle_succ/
129   <yplus_inj >yplus_SO2 >yplus_succ1 >yplus_succ1
130   /3 width=2 by cpy_bind, lift_bind, ex2_intro/
131 | #I #G #L #W1 #W2 #U1 #U2 #dt #et #_ #_ #IHW12 #IHU12 #X #d #e #H #Hddt #Hdedet
132   elim (lift_inv_flat2 … H) -H #V1 #T1 #HVW1 #HTU1 #H destruct
133   elim (IHW12 … HVW1) -V1 -IHW12 // elim (IHU12 … HTU1) -T1 -IHU12
134   /3 width=2 by cpy_flat, lift_flat, ex2_intro/
135 ]
136 qed-.
137
138 lemma cpy_split_up: ∀G,L,T1,T2,d,e. ⦃G, L⦄ ⊢ T1 ▶[d, e] T2 → ∀i. i ≤ d + e →
139                     ∃∃T. ⦃G, L⦄ ⊢ T1 ▶[d, i-d] T & ⦃G, L⦄ ⊢ T ▶[i, d+e-i] T2.
140 #G #L #T1 #T2 #d #e #H elim H -G -L -T1 -T2 -d -e
141 [ /2 width=3 by ex2_intro/
142 | #I #G #L #K #V #W #i #d #e #Hdi #Hide #HLK #HVW #j #Hjde
143   elim (ylt_split i j) [ -Hide -Hjde | -Hdi ]
144   /4 width=9 by cpy_subst, ylt_yle_trans, ex2_intro/
145 | #a #I #G #L #V1 #V2 #T1 #T2 #d #e #_ #_ #IHV12 #IHT12 #i #Hide
146   elim (IHV12 i) -IHV12 // #V
147   elim (IHT12 (i+1)) -IHT12 /2 width=1 by yle_succ/ -Hide
148   >yplus_SO2 >yplus_succ1 #T #HT1 #HT2
149   lapply (lsuby_cpy_trans … HT2 (L.ⓑ{I}V) ?) -HT2
150   /3 width=5 by lsuby_succ, ex2_intro, cpy_bind/
151 | #I #G #L #V1 #V2 #T1 #T2 #d #e #_ #_ #IHV12 #IHT12 #i #Hide
152   elim (IHV12 i) -IHV12 // elim (IHT12 i) -IHT12 // -Hide
153   /3 width=5 by ex2_intro, cpy_flat/
154 ]
155 qed-.
156
157 lemma cpy_split_down: ∀G,L,T1,T2,d,e. ⦃G, L⦄ ⊢ T1 ▶[d, e] T2 → ∀i. i ≤ d + e →
158                       ∃∃T. ⦃G, L⦄ ⊢ T1 ▶[i, d+e-i] T & ⦃G, L⦄ ⊢ T ▶[d, i-d] T2.
159 #G #L #T1 #T2 #d #e #H elim H -G -L -T1 -T2 -d -e
160 [ /2 width=3 by ex2_intro/
161 | #I #G #L #K #V #W #i #d #e #Hdi #Hide #HLK #HVW #j #Hjde
162   elim (ylt_split i j) [ -Hide -Hjde | -Hdi ]
163   /4 width=9 by cpy_subst, ylt_yle_trans, ex2_intro/
164 | #a #I #G #L #V1 #V2 #T1 #T2 #d #e #_ #_ #IHV12 #IHT12 #i #Hide
165   elim (IHV12 i) -IHV12 // #V
166   elim (IHT12 (i+1)) -IHT12 /2 width=1 by yle_succ/ -Hide
167   >yplus_SO2 >yplus_succ1 #T #HT1 #HT2
168   lapply (lsuby_cpy_trans … HT2 (L.ⓑ{I}V) ?) -HT2
169   /3 width=5 by lsuby_succ, ex2_intro, cpy_bind/
170 | #I #G #L #V1 #V2 #T1 #T2 #d #e #_ #_ #IHV12 #IHT12 #i #Hide
171   elim (IHV12 i) -IHV12 // elim (IHT12 i) -IHT12 // -Hide
172   /3 width=5 by ex2_intro, cpy_flat/
173 ]
174 qed-.
175
176 lemma cpy_append: ∀G,d,e. l_appendable_sn … (cpy d e G).
177 #G #d #e #K #T1 #T2 #H elim H -G -K -T1 -T2 -d -e
178 /2 width=1 by cpy_atom, cpy_bind, cpy_flat/
179 #I #G #K #K0 #V #W #i #d #e #Hdi #Hide #HK0 #HVW #L
180 lapply (ldrop_fwd_length_lt2 … HK0) #H
181 @(cpy_subst I … (L@@K0) … HVW) // (**) (* /4/ does not work *)
182 @(ldrop_O1_append_sn_le … HK0) /2 width=2 by lt_to_le/
183 qed-.
184
185 (* Basic inversion lemmas ***************************************************)
186
187 fact cpy_inv_atom1_aux: ∀G,L,T1,T2,d,e. ⦃G, L⦄ ⊢ T1 ▶[d, e] T2 → ∀J. T1 = ⓪{J} →
188                         T2 = ⓪{J} ∨
189                         ∃∃I,K,V,i. d ≤ yinj i & i < d + e &
190                                    ⇩[i] L ≡ K.ⓑ{I}V &
191                                    ⇧[O, i+1] V ≡ T2 &
192                                    J = LRef i.
193 #G #L #T1 #T2 #d #e * -G -L -T1 -T2 -d -e
194 [ #I #G #L #d #e #J #H destruct /2 width=1 by or_introl/
195 | #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/
196 | #a #I #G #L #V1 #V2 #T1 #T2 #d #e #_ #_ #J #H destruct
197 | #I #G #L #V1 #V2 #T1 #T2 #d #e #_ #_ #J #H destruct
198 ]
199 qed-.
200
201 lemma cpy_inv_atom1: ∀I,G,L,T2,d,e. ⦃G, L⦄ ⊢ ⓪{I} ▶[d, e] T2 →
202                      T2 = ⓪{I} ∨
203                      ∃∃J,K,V,i. d ≤ yinj i & i < d + e &
204                                 ⇩[i] L ≡ K.ⓑ{J}V &
205                                 ⇧[O, i+1] V ≡ T2 &
206                                 I = LRef i.
207 /2 width=4 by cpy_inv_atom1_aux/ qed-.
208
209 (* Basic_1: was: subst1_gen_sort *)
210 lemma cpy_inv_sort1: ∀G,L,T2,k,d,e. ⦃G, L⦄ ⊢ ⋆k ▶[d, e] T2 → T2 = ⋆k.
211 #G #L #T2 #k #d #e #H
212 elim (cpy_inv_atom1 … H) -H //
213 * #I #K #V #i #_ #_ #_ #_ #H destruct
214 qed-.
215
216 (* Basic_1: was: subst1_gen_lref *)
217 lemma cpy_inv_lref1: ∀G,L,T2,i,d,e. ⦃G, L⦄ ⊢ #i ▶[d, e] T2 →
218                      T2 = #i ∨
219                      ∃∃I,K,V. d ≤ i & i < d + e &
220                               ⇩[i] L ≡ K.ⓑ{I}V &
221                               ⇧[O, i+1] V ≡ T2.
222 #G #L #T2 #i #d #e #H
223 elim (cpy_inv_atom1 … H) -H /2 width=1 by or_introl/
224 * #I #K #V #j #Hdj #Hjde #HLK #HVT2 #H destruct /3 width=5 by ex4_3_intro, or_intror/
225 qed-.
226
227 lemma cpy_inv_gref1: ∀G,L,T2,p,d,e. ⦃G, L⦄ ⊢ §p ▶[d, e] T2 → T2 = §p.
228 #G #L #T2 #p #d #e #H
229 elim (cpy_inv_atom1 … H) -H //
230 * #I #K #V #i #_ #_ #_ #_ #H destruct
231 qed-.
232
233 fact cpy_inv_bind1_aux: ∀G,L,U1,U2,d,e. ⦃G, L⦄ ⊢ U1 ▶[d, e] U2 →
234                         ∀a,I,V1,T1. U1 = ⓑ{a,I}V1.T1 →
235                         ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ▶[d, e] V2 &
236                                  ⦃G, L. ⓑ{I}V1⦄ ⊢ T1 ▶[⫯d, e] T2 &
237                                  U2 = ⓑ{a,I}V2.T2.
238 #G #L #U1 #U2 #d #e * -G -L -U1 -U2 -d -e
239 [ #I #G #L #d #e #b #J #W1 #U1 #H destruct
240 | #I #G #L #K #V #W #i #d #e #_ #_ #_ #_ #b #J #W1 #U1 #H destruct
241 | #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/
242 | #I #G #L #V1 #V2 #T1 #T2 #d #e #_ #_ #b #J #W1 #U1 #H destruct
243 ]
244 qed-.
245
246 lemma cpy_inv_bind1: ∀a,I,G,L,V1,T1,U2,d,e. ⦃G, L⦄ ⊢ ⓑ{a,I} V1. T1 ▶[d, e] U2 →
247                      ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ▶[d, e] V2 &
248                               ⦃G, L.ⓑ{I}V1⦄ ⊢ T1 ▶[⫯d, e] T2 &
249                               U2 = ⓑ{a,I}V2.T2.
250 /2 width=3 by cpy_inv_bind1_aux/ qed-.
251
252 fact cpy_inv_flat1_aux: ∀G,L,U1,U2,d,e. ⦃G, L⦄ ⊢ U1 ▶[d, e] U2 →
253                         ∀I,V1,T1. U1 = ⓕ{I}V1.T1 →
254                         ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ▶[d, e] V2 &
255                                  ⦃G, L⦄ ⊢ T1 ▶[d, e] T2 &
256                                  U2 = ⓕ{I}V2.T2.
257 #G #L #U1 #U2 #d #e * -G -L -U1 -U2 -d -e
258 [ #I #G #L #d #e #J #W1 #U1 #H destruct
259 | #I #G #L #K #V #W #i #d #e #_ #_ #_ #_ #J #W1 #U1 #H destruct
260 | #a #I #G #L #V1 #V2 #T1 #T2 #d #e #_ #_ #J #W1 #U1 #H destruct
261 | #I #G #L #V1 #V2 #T1 #T2 #d #e #HV12 #HT12 #J #W1 #U1 #H destruct /2 width=5 by ex3_2_intro/
262 ]
263 qed-.
264
265 lemma cpy_inv_flat1: ∀I,G,L,V1,T1,U2,d,e. ⦃G, L⦄ ⊢ ⓕ{I} V1. T1 ▶[d, e] U2 →
266                      ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ▶[d, e] V2 &
267                               ⦃G, L⦄ ⊢ T1 ▶[d, e] T2 &
268                               U2 = ⓕ{I}V2.T2.
269 /2 width=3 by cpy_inv_flat1_aux/ qed-.
270
271
272 fact cpy_inv_refl_O2_aux: ∀G,L,T1,T2,d,e. ⦃G, L⦄ ⊢ T1 ▶[d, e] T2 → e = 0 → T1 = T2.
273 #G #L #T1 #T2 #d #e #H elim H -G -L -T1 -T2 -d -e
274 [ //
275 | #I #G #L #K #V #W #i #d #e #Hdi #Hide #_ #_ #H destruct
276   elim (ylt_yle_false … Hdi) -Hdi //
277 | /3 width=1 by eq_f2/
278 | /3 width=1 by eq_f2/
279 ]
280 qed-.
281
282 lemma cpy_inv_refl_O2: ∀G,L,T1,T2,d. ⦃G, L⦄ ⊢ T1 ▶[d, 0] T2 → T1 = T2.
283 /2 width=6 by cpy_inv_refl_O2_aux/ qed-.
284
285 (* Basic_1: was: subst1_gen_lift_eq *)
286 lemma cpy_inv_lift1_eq: ∀G,T1,U1,d,e. ⇧[d, e] T1 ≡ U1 →
287                         ∀L,U2. ⦃G, L⦄ ⊢ U1 ▶[d, e] U2 → U1 = U2.
288 #G #T1 #U1 #d #e #HTU1 #L #U2 #HU12 elim (cpy_up … HU12 … HTU1) -HU12 -HTU1
289 /2 width=4 by cpy_inv_refl_O2/
290 qed-.
291
292 (* Basic forward lemmas *****************************************************)
293
294 lemma cpy_fwd_tw: ∀G,L,T1,T2,d,e. ⦃G, L⦄ ⊢ T1 ▶[d, e] T2 → ♯{T1} ≤ ♯{T2}.
295 #G #L #T1 #T2 #d #e #H elim H -G -L -T1 -T2 -d -e normalize
296 /3 width=1 by monotonic_le_plus_l, le_plus/
297 qed-.
298
299 lemma cpy_fwd_shift1: ∀G,L1,L,T1,T,d,e. ⦃G, L⦄ ⊢ L1 @@ T1 ▶[d, e] T →
300                       ∃∃L2,T2. |L1| = |L2| & T = L2 @@ T2.
301 #G #L1 @(lenv_ind_dx … L1) -L1 normalize
302 [ #L #T1 #T #d #e #HT1
303   @(ex2_2_intro … (⋆)) // (**) (* explicit constructor *)
304 | #I #L1 #V1 #IH #L #T1 #X #d #e
305   >shift_append_assoc normalize #H
306   elim (cpy_inv_bind1 … H) -H
307   #V0 #T0 #_ #HT10 #H destruct
308   elim (IH … HT10) -IH -HT10 #L2 #T2 #HL12 #H destruct
309   >append_length >HL12 -HL12
310   @(ex2_2_intro … (⋆.ⓑ{I}V0@@L2) T2) [ >append_length ] (**) (* explicit constructor *)
311   /2 width=3 by trans_eq/
312 ]
313 qed-.
314
315 (* Basic_1: removed theorems 25:
316             subst0_gen_sort subst0_gen_lref subst0_gen_head subst0_gen_lift_lt
317             subst0_gen_lift_false subst0_gen_lift_ge subst0_refl subst0_trans
318             subst0_lift_lt subst0_lift_ge subst0_lift_ge_S subst0_lift_ge_s
319             subst0_subst0 subst0_subst0_back subst0_weight_le subst0_weight_lt
320             subst0_confluence_neq subst0_confluence_eq subst0_tlt_head
321             subst0_confluence_lift subst0_tlt
322             subst1_head subst1_gen_head subst1_lift_S subst1_confluence_lift
323 *)