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