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