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