]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/lambdadelta/basic_2/relocation/cpy.ma
- lsubr moved down one component
[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/relocation/ldrop_append.ma".
18 include "basic_2/relocation/lsuby.ma".
19
20 (* CONTEXT-SENSITIVE EXTENDED PARALLEL SUBSTITUTION FOR TERMS ***************)
21
22 (* activate genv *)
23 inductive cpy: nat → nat → 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 ≤ i → i < d + e →
26              ⇩[0, 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 + 1) e G (L.ⓑ{I} V2) 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 parallel substritution (term)"
36    'ExtPSubst 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.
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_fwd_ldrop2_bind … HL12 … HLK1) -HL12 -HLK1 /2 width=5 by cpy_subst/
45 | /4 width=1 by lsuby_pair, 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 lemma cpy_full: ∀I,G,K,V,T1,L,d. ⇩[0, d] L ≡ K.ⓑ{I}V →
55                 ∃∃T2,T. ⦃G, L⦄ ⊢ T1 ▶×[d, 1] T2 & ⇧[d, 1] T ≡ T2.
56 #I #G #K #V #T1 elim T1 -T1
57 [ * #i #L #d #HLK
58   /2 width=4 by lift_sort, lift_gref, ex2_2_intro/
59   elim (lt_or_eq_or_gt i d) #Hid
60   /3 width=4 by lift_lref_ge_minus, lift_lref_lt, ex2_2_intro/
61   destruct
62   elim (lift_total V 0 (i+1)) #W #HVW
63   elim (lift_split … HVW i i)
64   /3 width=5 by cpy_subst, le_n, ex2_2_intro/
65 | * [ #a ] #J #W1 #U1 #IHW1 #IHU1 #L #d #HLK
66   elim (IHW1 … HLK) -IHW1 #W2 #W #HW12 #HW2
67   [ elim (IHU1 (L.ⓑ{J}W2) (d+1)) -IHU1
68     /3 width=9 by cpy_bind, ldrop_ldrop, 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,d1,e1. ⦃G, L⦄ ⊢ T1 ▶×[d1, e1] T2 →
76                 ∀d2,e2. d2 ≤ d1 → d1 + e1 ≤ d2 + e2 →
77                 ⦃G, L⦄ ⊢ T1 ▶×[d2, e2] T2.
78 #G #L #T1 #T2 #d1 #e1 #H elim H -G -L -T1 -T2 -d1 -e1
79 [ //
80 | /3 width=5 by cpy_subst, transitive_le/
81 | /4 width=3 by cpy_bind, le_to_lt_to_lt, le_S_S/
82 | /3 width=1 by cpy_flat/
83 ]
84 qed-.
85
86 lemma cpy_weak_top: ∀G,L,T1,T2,d,e.
87                     ⦃G, L⦄ ⊢ T1 ▶×[d, e] T2 → ⦃G, L⦄ ⊢ T1 ▶×[d, |L| - d] T2.
88 #G #L #T1 #T2 #d #e #H elim H -G -L -T1 -T2 -d -e
89 [ //
90 | #I #G #L #K #V #W #i #d #e #Hdi #_ #HLK #HVW
91   lapply (ldrop_fwd_length_lt2 … HLK)
92   /3 width=5 by cpy_subst, lt_to_le_to_lt/
93 | normalize /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,d,e.
99                      ⦃G, L⦄ ⊢ T1 ▶×[d, e] T2 → ⦃G, L⦄ ⊢ T1 ▶×[0, |L|] T2.
100 #G #L #T1 #T2 #d #e #HT12
101 lapply (cpy_weak … HT12 0 (d + e) ? ?) -HT12
102 /2 width=2 by cpy_weak_top/
103 qed-.
104
105 lemma cpy_split_up: ∀G,L,T1,T2,d,e. ⦃G, L⦄ ⊢ T1 ▶×[d, e] T2 → ∀i. d ≤ i → i ≤ d + e →
106                     ∃∃T. ⦃G, L⦄ ⊢ T1 ▶×[d, i - d] T & ⦃G, L⦄ ⊢ T ▶×[i, d + e - i] T2.
107 #G #L #T1 #T2 #d #e #H elim H -G -L -T1 -T2 -d -e
108 [ /2 width=3 by ex2_intro/
109 | #I #G #L #K #V #W #i #d #e #Hdi #Hide #HLK #HVW #j #Hdj #Hjde
110   elim (lt_or_ge i j) [ -Hide -Hjde | -Hdi -Hdj ]
111   [ >(plus_minus_m_m j d) in ⊢ (%→?);
112     /3 width=5 by cpy_subst, ex2_intro/
113   | #Hij lapply (plus_minus_m_m … Hjde) -Hjde
114     /3 width=9 by cpy_atom, cpy_subst, ex2_intro/
115   ]
116 | #a #I #G #L #V1 #V2 #T1 #T2 #d #e #_ #_ #IHV12 #IHT12 #i #Hdi #Hide
117   elim (IHV12 i) -IHV12 // #V #HV1 #HV2
118   elim (IHT12 (i + 1)) -IHT12 /2 width=1 by le_S_S/
119   -Hdi -Hide >arith_c1x #T #HT1 #HT2
120   lapply (lsuby_cpy_trans … HT1 (L.ⓑ{I} V) ?) -HT1 /3 width=5 by cpy_bind, ex2_intro/
121 | #L #I #V1 #V2 #T1 #T2 #d #e #_ #_ #IHV12 #IHT12 #i #Hdi #Hide
122   elim (IHV12 i ? ?) -IHV12 // elim (IHT12 i ? ?) -IHT12 //
123   -Hdi -Hide /3 width=5/
124 ]
125 qed.
126
127 lemma cpy_split_down: ∀L,T1,T2,d,e. ⦃G, L⦄ ⊢ T1 ▶×[d, e] T2 →
128                       ∀i. d ≤ i → i ≤ d + e →
129                       ∃∃T. ⦃G, L⦄ ⊢ T1 ▶×[i, d + e - i] T &
130                            ⦃G, L⦄ ⊢ T ▶×[d, i - d] T2.
131 #L #T1 #T2 #d #e #H elim H -L -T1 -T2 -d -e
132 [ /2 width=3/
133 | #L #K #V #W #i #d #e #Hdi #Hide #HLK #HVW #j #Hdj #Hjde
134   elim (lt_or_ge i j)
135   [ -Hide -Hjde >(plus_minus_m_m j d) in⦄ ⊢ (% → ?); // -Hdj /3 width=8/
136   | -Hdi -Hdj
137     >(plus_minus_m_m (d+e) j) in Hide; // -Hjde /3 width=4/
138   ]
139 | #L #a #I #V1 #V2 #T1 #T2 #d #e #_ #_ #IHV12 #IHT12 #i #Hdi #Hide
140   elim (IHV12 i ? ?) -IHV12 // #V #HV1 #HV2
141   elim (IHT12 (i + 1) ? ?) -IHT12 /2 width=1/
142   -Hdi -Hide >arith_c1x #T #HT1 #HT2
143   lapply (cpy_lsubr_trans … HT1 (L. ⓑ{I} V) ?) -HT1 /3 width=5/
144 | #L #I #V1 #V2 #T1 #T2 #d #e #_ #_ #IHV12 #IHT12 #i #Hdi #Hide
145   elim (IHV12 i ? ?) -IHV12 // elim (IHT12 i ? ?) -IHT12 //
146   -Hdi -Hide /3 width=5/
147 ]
148 qed.
149
150 lemma cpy_append: ∀K,T1,T2,d,e. K⦄ ⊢ T1 ▶×[d, e] T2 →
151                   ∀L. L @@ K⦄ ⊢ T1 ▶×[d, e] T2.
152 #K #T1 #T2 #d #e #H elim H -K -T1 -T2 -d -e // /2 width=1/
153 #K #K0 #V #W #i #d #e #Hdi #Hide #HK0 #HVW #L
154 lapply (ldrop_fwd_ldrop2_length … HK0) #H
155 @(cpy_subst … (L@@K0) … HVW) // (**) (* /3/ does not work *)
156 @(ldrop_O1_append_sn_le … HK0) /2 width=2/
157 qed.
158
159 (* Basic inversion lemmas ***************************************************)
160
161 fact cpy_inv_atom1_aux: ∀L,T1,T2,d,e. ⦃G, L⦄ ⊢ T1 ▶×[d, e] T2 → ∀I. T1 = ⓪{I} →
162                         T2 = ⓪{I} ∨
163                         ∃∃K,V,i. d ≤ i & i < d + e &
164                                  ⇩[O, i] L ≡ K. ⓓV &
165                                  ⇧[O, i + 1] V ≡ T2 &
166                                  I = LRef i.
167 #L #T1 #T2 #d #e * -L -T1 -T2 -d -e
168 [ #L #I #d #e #J #H destruct /2 width=1/
169 | #L #K #V #T2 #i #d #e #Hdi #Hide #HLK #HVT2 #I #H destruct /3 width=8/
170 | #L #a #I #V1 #V2 #T1 #T2 #d #e #_ #_ #J #H destruct
171 | #L #I #V1 #V2 #T1 #T2 #d #e #_ #_ #J #H destruct
172 ]
173 qed.
174
175 lemma cpy_inv_atom1: ∀L,T2,I,d,e. ⦃G, L⦄ ⊢ ⓪{I} ▶×[d, e] T2 →
176                      T2 = ⓪{I} ∨
177                      ∃∃K,V,i. d ≤ i & i < d + e &
178                               ⇩[O, i] L ≡ K. ⓓV &
179                               ⇧[O, i + 1] V ≡ T2 &
180                               I = LRef i.
181 /2 width=3/ qed-.
182
183
184 (* Basic_1: was: subst1_gen_sort *)
185 lemma cpy_inv_sort1: ∀L,T2,k,d,e. ⦃G, L⦄ ⊢ ⋆k ▶×[d, e] T2 → T2 = ⋆k.
186 #L #T2 #k #d #e #H
187 elim (cpy_inv_atom1 … H) -H //
188 * #K #V #i #_ #_ #_ #_ #H destruct
189 qed-.
190
191 (* Basic_1: was: subst1_gen_lref *)
192 lemma cpy_inv_lref1: ∀L,T2,i,d,e. ⦃G, L⦄ ⊢ #i ▶×[d, e] T2 →
193                      T2 = #i ∨
194                      ∃∃K,V. d ≤ i & i < d + e &
195                             ⇩[O, i] L ≡ K. ⓓV &
196                             ⇧[O, i + 1] V ≡ T2.
197 #L #T2 #i #d #e #H
198 elim (cpy_inv_atom1 … H) -H /2 width=1/
199 * #K #V #j #Hdj #Hjde #HLK #HVT2 #H destruct /3 width=4/
200 qed-.
201
202 lemma cpy_inv_gref1: ∀L,T2,p,d,e. ⦃G, L⦄ ⊢ §p ▶×[d, e] T2 → T2 = §p.
203 #L #T2 #p #d #e #H
204 elim (cpy_inv_atom1 … H) -H //
205 * #K #V #i #_ #_ #_ #_ #H destruct
206 qed-.
207
208 fact cpy_inv_bind1_aux: ∀d,e,L,U1,U2. ⦃G, L⦄ ⊢ U1 ▶×[d, e] U2 →
209                         ∀a,I,V1,T1. U1 = ⓑ{a,I} V1. T1 →
210                         ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ▶×[d, e] V2 &
211                                  L. ⓑ{I} V2⦄ ⊢ T1 ▶×[d + 1, e] T2 &
212                                  U2 = ⓑ{a,I} V2. T2.
213 #d #e #L #U1 #U2 * -d -e -L -U1 -U2
214 [ #L #k #d #e #a #I #V1 #T1 #H destruct
215 | #L #K #V #W #i #d #e #_ #_ #_ #_ #a #I #V1 #T1 #H destruct
216 | #L #b #J #V1 #V2 #T1 #T2 #d #e #HV12 #HT12 #a #I #V #T #H destruct /2 width=5/
217 | #L #J #V1 #V2 #T1 #T2 #d #e #_ #_ #a #I #V #T #H destruct
218 ]
219 qed.
220
221 lemma cpy_inv_bind1: ∀d,e,L,a,I,V1,T1,U2. ⦃G, L⦄ ⊢ ⓑ{a,I} V1. T1 ▶×[d, e] U2 →
222                      ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ▶×[d, e] V2 &
223                               L. ⓑ{I} V2⦄ ⊢ T1 ▶×[d + 1, e] T2 &
224                               U2 = ⓑ{a,I} V2. T2.
225 /2 width=3/ qed-.
226
227 fact cpy_inv_flat1_aux: ∀d,e,L,U1,U2. ⦃G, L⦄ ⊢ U1 ▶×[d, e] U2 →
228                         ∀I,V1,T1. U1 = ⓕ{I} V1. T1 →
229                         ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ▶×[d, e] V2 & ⦃G, L⦄ ⊢ T1 ▶×[d, e] T2 &
230                                  U2 =  ⓕ{I} V2. T2.
231 #d #e #L #U1 #U2 * -d -e -L -U1 -U2
232 [ #L #k #d #e #I #V1 #T1 #H destruct
233 | #L #K #V #W #i #d #e #_ #_ #_ #_ #I #V1 #T1 #H destruct
234 | #L #a #J #V1 #V2 #T1 #T2 #d #e #_ #_ #I #V #T #H destruct
235 | #L #J #V1 #V2 #T1 #T2 #d #e #HV12 #HT12 #I #V #T #H destruct /2 width=5/
236 ]
237 qed.
238
239 lemma cpy_inv_flat1: ∀d,e,L,I,V1,T1,U2. ⦃G, L⦄ ⊢ ⓕ{I} V1. T1 ▶×[d, e] U2 →
240                      ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ▶×[d, e] V2 & ⦃G, L⦄ ⊢ T1 ▶×[d, e] T2 &
241                               U2 =  ⓕ{I} V2. T2.
242 /2 width=3/ qed-.
243
244 fact cpy_inv_refl_O2_aux: ∀L,T1,T2,d,e. ⦃G, L⦄ ⊢ T1 ▶×[d, e] T2 → e = 0 → T1 = T2.
245 #L #T1 #T2 #d #e #H elim H -L -T1 -T2 -d -e
246 [ //
247 | #L #K #V #W #i #d #e #Hdi #Hide #_ #_ #H destruct
248   lapply (le_to_lt_to_lt … Hdi … Hide) -Hdi -Hide <plus_n_O #Hdd
249   elim (lt_refl_false … Hdd)
250 | /3 width=1/
251 | /3 width=1/
252 ]
253 qed.
254
255 lemma cpy_inv_refl_O2: ∀L,T1,T2,d. ⦃G, L⦄ ⊢ T1 ▶×[d, 0] T2 → T1 = T2.
256 /2 width=6/ qed-.
257
258 (* Basic forward lemmas *****************************************************)
259
260 lemma cpy_fwd_tw: ∀L,T1,T2,d,e. ⦃G, L⦄ ⊢ T1 ▶×[d, e] T2 → ♯{T1} ≤ ♯{T2}.
261 #L #T1 #T2 #d #e #H elim H -L -T1 -T2 -d -e normalize
262 /3 by monotonic_le_plus_l, le_plus/ (**) (* just /3 width=1/ is too slow *)
263 qed-.
264
265 lemma cpy_fwd_shift1: ∀L1,L,T1,T,d,e. ⦃G, L⦄ ⊢ L1 @@ T1 ▶[d, e] T →
266                       ∃∃L2,T2. |L1| = |L2| & T = L2 @@ T2.
267 #L1 @(lenv_ind_dx … L1) -L1 normalize
268 [ #L #T1 #T #d #e #HT1
269   @(ex2_2_intro … (⋆)) // (**) (* explicit constructor *)
270 | #I #L1 #V1 #IH #L #T1 #X #d #e
271   >shift_append_assoc normalize #H
272   elim (cpy_inv_bind1 … H) -H
273   #V0 #T0 #_ #HT10 #H destruct
274   elim (IH … HT10) -IH -HT10 #L2 #T2 #HL12 #H destruct
275   >append_length >HL12 -HL12
276   @(ex2_2_intro … (⋆.ⓑ{I}V0@@L2) T2) [ >append_length ] // /2 width=3/ (**) (* explicit constructor *)
277 ]
278 qed-.
279
280 (* Basic_1: removed theorems 25:
281             subst0_gen_sort subst0_gen_lref subst0_gen_head subst0_gen_lift_lt
282             subst0_gen_lift_false subst0_gen_lift_ge subst0_refl subst0_trans
283             subst0_lift_lt subst0_lift_ge subst0_lift_ge_S subst0_lift_ge_s
284             subst0_subst0 subst0_subst0_back subst0_weight_le subst0_weight_lt
285             subst0_confluence_neq subst0_confluence_eq subst0_tlt_head
286             subst0_confluence_lift subst0_tlt
287             subst1_head subst1_gen_head subst1_lift_S subst1_confluence_lift
288 *)