1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| The HELM team. *)
8 (* ||A|| http://helm.cs.unibo.it *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU General Public License Version 2 *)
13 (**************************************************************************)
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".
21 (* CONTEXT-SENSITIVE EXTENDED PARALLEL SUBSTITUTION FOR TERMS ***************)
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)
36 interpretation "context-sensitive extended parallel substritution (term)"
37 'ExtPSubst G L T1 d e T2 = (cpy d e G L T1 T2).
39 (* Basic properties *********************************************************)
41 lemma lsuby_cpy_trans: ∀G,L1,T1,T2,d,e. ⦃G, L1⦄ ⊢ T1 ▶×[d, e] T2 →
42 ∀L2. L2 ⊑×[d, e] L1 → ⦃G, L2⦄ ⊢ T1 ▶×[d, e] T2.
43 #G #d #e #L1 #T1 #T2 #H elim H -G -L1 -T1 -T2 -d -e
45 | #I #G #L1 #K1 #V #W #i #d #e #Hdi #Hide #HLK1 #HVW #L2 #HL12
46 elim (lsuby_fwd_ldrop2_be … HL12 … HLK1) -HL12 -HLK1 /2 width=5 by cpy_subst/
47 | /4 width=1 by lsuby_succ, cpy_bind/
48 | /3 width=1 by cpy_flat/
52 lemma cpy_refl: ∀G,T,L,d,e. ⦃G, L⦄ ⊢ T ▶×[d, e] T.
53 #G #T elim T -T // * /2 width=1 by cpy_bind, cpy_flat/
56 lemma cpy_full: ∀I,G,K,V,T1,L,d. ⇩[0, d] L ≡ K.ⓑ{I}V →
57 ∃∃T2,T. ⦃G, L⦄ ⊢ T1 ▶×[d, 1] T2 & ⇧[d, 1] T ≡ T2.
58 #I #G #K #V #T1 elim T1 -T1
60 /2 width=4 by lift_sort, lift_gref, ex2_2_intro/
61 elim (lt_or_eq_or_gt i d) #Hid
62 /3 width=4 by lift_lref_ge_minus, lift_lref_lt, ex2_2_intro/
64 elim (lift_total V 0 (i+1)) #W #HVW
65 elim (lift_split … HVW i i)
66 /3 width=5 by cpy_subst, le_n, ex2_2_intro/
67 | * [ #a ] #J #W1 #U1 #IHW1 #IHU1 #L #d #HLK
68 elim (IHW1 … HLK) -IHW1 #W2 #W #HW12 #HW2
69 [ elim (IHU1 (L.ⓑ{J}W2) (d+1)) -IHU1
70 /3 width=9 by cpy_bind, ldrop_ldrop, lift_bind, ex2_2_intro/
71 | elim (IHU1 … HLK) -IHU1 -HLK
72 /3 width=8 by cpy_flat, lift_flat, ex2_2_intro/
77 lemma cpy_weak: ∀G,L,T1,T2,d1,e1. ⦃G, L⦄ ⊢ T1 ▶×[d1, e1] T2 →
78 ∀d2,e2. d2 ≤ d1 → d1 + e1 ≤ d2 + e2 →
79 ⦃G, L⦄ ⊢ T1 ▶×[d2, e2] T2.
80 #G #L #T1 #T2 #d1 #e1 #H elim H -G -L -T1 -T2 -d1 -e1
82 | /3 width=5 by cpy_subst, transitive_le/
83 | /4 width=3 by cpy_bind, le_to_lt_to_lt, le_S_S/
84 | /3 width=1 by cpy_flat/
88 lemma cpy_weak_top: ∀G,L,T1,T2,d,e.
89 ⦃G, L⦄ ⊢ T1 ▶×[d, e] T2 → ⦃G, L⦄ ⊢ T1 ▶×[d, |L| - d] T2.
90 #G #L #T1 #T2 #d #e #H elim H -G -L -T1 -T2 -d -e
92 | #I #G #L #K #V #W #i #d #e #Hdi #_ #HLK #HVW
93 lapply (ldrop_fwd_length_lt2 … HLK)
94 /3 width=5 by cpy_subst, lt_to_le_to_lt/
95 | normalize /2 width=1 by cpy_bind/
96 | /2 width=1 by cpy_flat/
100 lemma cpy_weak_full: ∀G,L,T1,T2,d,e.
101 ⦃G, L⦄ ⊢ T1 ▶×[d, e] T2 → ⦃G, L⦄ ⊢ T1 ▶×[0, |L|] T2.
102 #G #L #T1 #T2 #d #e #HT12
103 lapply (cpy_weak … HT12 0 (d + e) ? ?) -HT12
104 /2 width=2 by cpy_weak_top/
107 lemma cpy_split_up: ∀G,L,T1,T2,d,e. ⦃G, L⦄ ⊢ T1 ▶×[d, e] T2 → ∀i. d ≤ i → i ≤ d + e →
108 ∃∃T. ⦃G, L⦄ ⊢ T1 ▶×[d, i - d] T & ⦃G, L⦄ ⊢ T ▶×[i, d + e - i] T2.
109 #G #L #T1 #T2 #d #e #H elim H -G -L -T1 -T2 -d -e
110 [ /2 width=3 by ex2_intro/
111 | #I #G #L #K #V #W #i #d #e #Hdi #Hide #HLK #HVW #j #Hdj #Hjde
112 elim (lt_or_ge i j) [ -Hide -Hjde | -Hdi -Hdj ]
113 [ >(plus_minus_m_m j d) in ⊢ (%→?);
114 /3 width=5 by cpy_subst, ex2_intro/
115 | #Hij lapply (plus_minus_m_m … Hjde) -Hjde
116 /3 width=9 by cpy_atom, cpy_subst, ex2_intro/
118 | #a #I #G #L #V1 #V2 #T1 #T2 #d #e #_ #_ #IHV12 #IHT12 #i #Hdi #Hide
119 elim (IHV12 i) -IHV12 // #V #HV1 #HV2
120 elim (IHT12 (i + 1)) -IHT12 /2 width=1 by le_S_S/
121 -Hdi -Hide >arith_c1x #T #HT1 #HT2
122 lapply (lsuby_cpy_trans … HT1 (L.ⓑ{I} V) ?) -HT1 /3 width=5 by lsuby_succ, ex2_intro, cpy_bind/
123 | #I #G #L #V1 #V2 #T1 #T2 #d #e #_ #_ #IHV12 #IHT12 #i #Hdi #Hide
124 elim (IHV12 i) -IHV12 // elim (IHT12 i) -IHT12 //
125 -Hdi -Hide /3 width=5 by ex2_intro, cpy_flat/
129 lemma cpy_split_down: ∀G,L,T1,T2,d,e. ⦃G, L⦄ ⊢ T1 ▶×[d, e] T2 →
130 ∀i. d ≤ i → i ≤ d + e →
131 ∃∃T. ⦃G, L⦄ ⊢ T1 ▶×[i, d + e - i] T &
132 ⦃G, L⦄ ⊢ T ▶×[d, i - d] T2.
133 #G #L #T1 #T2 #d #e #H elim H -G -L -T1 -T2 -d -e
134 [ /2 width=3 by ex2_intro/
135 | #I #G #L #K #V #W #i #d #e #Hdi #Hide #HLK #HVW #j #Hdj #Hjde
137 [ -Hide -Hjde >(plus_minus_m_m j d) in ⊢ (% → ?); // -Hdj /3 width=9 by ex2_intro, cpy_atom, cpy_subst/
139 >(plus_minus_m_m (d+e) j) in Hide; // -Hjde /3 width=5 by ex2_intro, cpy_subst/
141 | #a #I #G #L #V1 #V2 #T1 #T2 #d #e #_ #_ #IHV12 #IHT12 #i #Hdi #Hide
142 elim (IHV12 i) -IHV12 // #V
143 elim (IHT12 (i + 1)) -IHT12 /2 width=1 by le_S_S/
144 -Hdi -Hide >arith_c1x #T #HT1 #HT2
145 lapply (lsuby_cpy_trans … HT1 (L. ⓑ{I} V) ?) -HT1 /3 width=5 by lsuby_succ, ex2_intro, cpy_bind/
146 | #I #G #L #V1 #V2 #T1 #T2 #d #e #_ #_ #IHV12 #IHT12 #i #Hdi #Hide
147 elim (IHV12 i) -IHV12 // elim (IHT12 i) -IHT12 //
148 -Hdi -Hide /3 width=5 by ex2_intro, cpy_flat/
152 lemma cpy_append: ∀G,K,T1,T2,d,e. ⦃G, K⦄ ⊢ T1 ▶×[d, e] T2 →
153 ∀L. ⦃G, L @@ K⦄ ⊢ T1 ▶×[d, e] T2.
154 #G #K #T1 #T2 #d #e #H elim H -K -T1 -T2 -d -e
155 /2 width=1 by cpy_atom, cpy_bind, cpy_flat/
156 #I #G #K #K0 #V #W #i #d #e #Hdi #Hide #HK0 #HVW #L
157 lapply (ldrop_fwd_length_lt2 … HK0) #H
158 @(cpy_subst I … (L@@K0) … HVW) // (**) (* /4/ does not work *)
159 @(ldrop_O1_append_sn_le … HK0) /2 width=2 by lt_to_le/
162 (* Basic inversion lemmas ***************************************************)
164 fact cpy_inv_atom1_aux: ∀G,L,T1,T2,d,e. ⦃G, L⦄ ⊢ T1 ▶×[d, e] T2 → ∀J. T1 = ⓪{J} →
166 ∃∃I,K,V,i. d ≤ i & i < d + e &
167 ⇩[O, i] L ≡ K.ⓑ{I}V &
170 #G #L #T1 #T2 #d #e * -G -L -T1 -T2 -d -e
171 [ #I #G #L #d #e #J #H destruct /2 width=1 by or_introl/
172 | #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/
173 | #a #I #G #L #V1 #V2 #T1 #T2 #d #e #_ #_ #J #H destruct
174 | #I #G #L #V1 #V2 #T1 #T2 #d #e #_ #_ #J #H destruct
178 lemma cpy_inv_atom1: ∀I,G,L,T2,d,e. ⦃G, L⦄ ⊢ ⓪{I} ▶×[d, e] T2 →
180 ∃∃J,K,V,i. d ≤ i & i < d + e &
181 ⇩[O, i] L ≡ K.ⓑ{J}V &
184 /2 width=4 by cpy_inv_atom1_aux/ qed-.
186 lemma cpy_inv_sort1: ∀G,L,T2,k,d,e. ⦃G, L⦄ ⊢ ⋆k ▶×[d, e] T2 → T2 = ⋆k.
187 #G #L #T2 #k #d #e #H
188 elim (cpy_inv_atom1 … H) -H //
189 * #I #K #V #i #_ #_ #_ #_ #H destruct
192 lemma cpy_inv_lref1: ∀G,L,T2,i,d,e. ⦃G, L⦄ ⊢ #i ▶×[d, e] T2 →
194 ∃∃I,K,V. d ≤ i & i < d + e &
195 ⇩[O, i] L ≡ K.ⓑ{I}V &
197 #G #L #T2 #i #d #e #H
198 elim (cpy_inv_atom1 … H) -H /2 width=1 by or_introl/
199 * #I #K #V #j #Hdj #Hjde #HLK #HVT2 #H destruct /3 width=5 by ex4_3_intro, or_intror/
202 lemma cpy_inv_gref1: ∀G,L,T2,p,d,e. ⦃G, L⦄ ⊢ §p ▶×[d, e] T2 → T2 = §p.
203 #G #L #T2 #p #d #e #H
204 elim (cpy_inv_atom1 … H) -H //
205 * #I #K #V #i #_ #_ #_ #_ #H destruct
208 fact cpy_inv_bind1_aux: ∀G,L,U1,U2,d,e. ⦃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 ⦃G, L. ⓑ{I}V2⦄ ⊢ T1 ▶×[d + 1, e] T2 &
213 #G #L #U1 #U2 #d #e * -G -L -U1 -U2 -d -e
214 [ #I #G #L #d #e #b #J #W1 #U1 #H destruct
215 | #I #G #L #K #V #W #i #d #e #_ #_ #_ #_ #b #J #W1 #U1 #H destruct
216 | #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/
217 | #I #G #L #V1 #V2 #T1 #T2 #d #e #_ #_ #b #J #W1 #U1 #H destruct
221 lemma cpy_inv_bind1: ∀a,I,G,L,V1,T1,U2,d,e. ⦃G, L⦄ ⊢ ⓑ{a,I} V1. T1 ▶×[d, e] U2 →
222 ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ▶×[d, e] V2 &
223 ⦃G, L.ⓑ{I}V2⦄ ⊢ T1 ▶×[d + 1, e] T2 &
225 /2 width=3 by cpy_inv_bind1_aux/ qed-.
227 fact cpy_inv_flat1_aux: ∀G,L,U1,U2,d,e. ⦃G, L⦄ ⊢ U1 ▶×[d, e] U2 →
228 ∀I,V1,T1. U1 = ⓕ{I}V1.T1 →
229 ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ▶×[d, e] V2 &
230 ⦃G, L⦄ ⊢ T1 ▶×[d, e] T2 &
232 #G #L #U1 #U2 #d #e * -G -L -U1 -U2 -d -e
233 [ #I #G #L #d #e #J #W1 #U1 #H destruct
234 | #I #G #L #K #V #W #i #d #e #_ #_ #_ #_ #J #W1 #U1 #H destruct
235 | #a #I #G #L #V1 #V2 #T1 #T2 #d #e #_ #_ #J #W1 #U1 #H destruct
236 | #I #G #L #V1 #V2 #T1 #T2 #d #e #HV12 #HT12 #J #W1 #U1 #H destruct /2 width=5 by ex3_2_intro/
240 lemma cpy_inv_flat1: ∀I,G,L,V1,T1,U2,d,e. ⦃G, L⦄ ⊢ ⓕ{I} V1. T1 ▶×[d, e] U2 →
241 ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ▶×[d, e] V2 &
242 ⦃G, L⦄ ⊢ T1 ▶×[d, e] T2 &
244 /2 width=3 by cpy_inv_flat1_aux/ qed-.
247 fact cpy_inv_refl_O2_aux: ∀G,L,T1,T2,d,e. ⦃G, L⦄ ⊢ T1 ▶×[d, e] T2 → e = 0 → T1 = T2.
248 #G #L #T1 #T2 #d #e #H elim H -G -L -T1 -T2 -d -e
250 | #I #G #L #K #V #W #i #d #e #Hdi #Hide #_ #_ #H destruct
251 lapply (le_to_lt_to_lt … Hdi … Hide) -Hdi -Hide <plus_n_O #Hdd
252 elim (lt_refl_false … Hdd)
253 | /3 width=1 by eq_f2/
254 | /3 width=1 by eq_f2/
258 lemma cpy_inv_refl_O2: ∀G,L,T1,T2,d. ⦃G, L⦄ ⊢ T1 ▶×[d, 0] T2 → T1 = T2.
259 /2 width=6 by cpy_inv_refl_O2_aux/ qed-.
261 (* Basic forward lemmas *****************************************************)
263 lemma cpy_fwd_tw: ∀G,L,T1,T2,d,e. ⦃G, L⦄ ⊢ T1 ▶×[d, e] T2 → ♯{T1} ≤ ♯{T2}.
264 #G #L #T1 #T2 #d #e #H elim H -G -L -T1 -T2 -d -e normalize
265 /3 width=1 by monotonic_le_plus_l, le_plus/
268 lemma cpy_fwd_shift1: ∀G,L1,L,T1,T,d,e. ⦃G, L⦄ ⊢ L1 @@ T1 ▶×[d, e] T →
269 ∃∃L2,T2. |L1| = |L2| & T = L2 @@ T2.
270 #G #L1 @(lenv_ind_dx … L1) -L1 normalize
271 [ #L #T1 #T #d #e #HT1
272 @(ex2_2_intro … (⋆)) // (**) (* explicit constructor *)
273 | #I #L1 #V1 #IH #L #T1 #X #d #e
274 >shift_append_assoc normalize #H
275 elim (cpy_inv_bind1 … H) -H
276 #V0 #T0 #_ #HT10 #H destruct
277 elim (IH … HT10) -IH -HT10 #L2 #T2 #HL12 #H destruct
278 >append_length >HL12 -HL12
279 @(ex2_2_intro … (⋆.ⓑ{I}V0@@L2) T2) [ >append_length ] (**) (* explicit constructor *)
280 /2 width=3 by trans_eq/