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