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/pred_6.ma".
16 include "basic_2/static/sd.ma".
17 include "basic_2/reduction/cpr.ma".
19 (* CONTEXT-SENSITIVE EXTENDED PARALLEL REDUCTION FOR TERMS ******************)
22 inductive cpx (h) (g): relation4 genv lenv term term ≝
23 | cpx_atom : ∀I,G,L. cpx h g G L (⓪{I}) (⓪{I})
24 | cpx_sort : ∀G,L,k,l. deg h g k (l+1) → cpx h g G L (⋆k) (⋆(next h k))
25 | cpx_delta: ∀I,G,L,K,V,V2,W2,i.
26 ⇩[0, i] L ≡ K.ⓑ{I}V → cpx h g G K V V2 →
27 ⇧[0, i + 1] V2 ≡ W2 → cpx h g G L (#i) W2
28 | cpx_bind : ∀a,I,G,L,V1,V2,T1,T2.
29 cpx h g G L V1 V2 → cpx h g G (L.ⓑ{I}V1) T1 T2 →
30 cpx h g G L (ⓑ{a,I}V1.T1) (ⓑ{a,I}V2.T2)
31 | cpx_flat : ∀I,G,L,V1,V2,T1,T2.
32 cpx h g G L V1 V2 → cpx h g G L T1 T2 →
33 cpx h g G L (ⓕ{I}V1.T1) (ⓕ{I}V2.T2)
34 | cpx_zeta : ∀G,L,V,T1,T,T2. cpx h g G (L.ⓓV) T1 T →
35 ⇧[0, 1] T2 ≡ T → cpx h g G L (+ⓓV.T1) T2
36 | cpx_tau : ∀G,L,V,T1,T2. cpx h g G L T1 T2 → cpx h g G L (ⓝV.T1) T2
37 | cpx_ti : ∀G,L,V1,V2,T. cpx h g G L V1 V2 → cpx h g G L (ⓝV1.T) V2
38 | cpx_beta : ∀a,G,L,V1,V2,W1,W2,T1,T2.
39 cpx h g G L V1 V2 → cpx h g G L W1 W2 → cpx h g G (L.ⓛW1) T1 T2 →
40 cpx h g G L (ⓐV1.ⓛ{a}W1.T1) (ⓓ{a}ⓝW2.V2.T2)
41 | cpx_theta: ∀a,G,L,V1,V,V2,W1,W2,T1,T2.
42 cpx h g G L V1 V → ⇧[0, 1] V ≡ V2 → cpx h g G L W1 W2 →
43 cpx h g G (L.ⓓW1) T1 T2 →
44 cpx h g G L (ⓐV1.ⓓ{a}W1.T1) (ⓓ{a}W2.ⓐV2.T2)
48 "context-sensitive extended parallel reduction (term)"
49 'PRed h g G L T1 T2 = (cpx h g G L T1 T2).
51 (* Basic properties *********************************************************)
53 lemma lsubr_cpx_trans: ∀h,g,G. lsub_trans … (cpx h g G) lsubr.
54 #h #g #G #L1 #T1 #T2 #H elim H -G -L1 -T1 -T2
57 | #I #G #L1 #K1 #V1 #V2 #W2 #i #HLK1 #_ #HVW2 #IHV12 #L2 #HL12
58 elim (lsubr_fwd_ldrop2_bind … HL12 … HLK1) -HL12 -HLK1 *
59 [ /3 width=7/ | /4 width=7/ ]
66 (* Note: this is "∀h,g,L. reflexive … (cpx h g L)" *)
67 lemma cpx_refl: ∀h,g,G,T,L. ⦃G, L⦄ ⊢ T ➡[h, g] T.
68 #h #g #G #T elim T -T // * /2 width=1/
71 lemma cpr_cpx: ∀h,g,G,L,T1,T2. ⦃G, L⦄ ⊢ T1 ➡ T2 → ⦃G, L⦄ ⊢ T1 ➡[h, g] T2.
72 #h #g #G #L #T1 #T2 #H elim H -L -T1 -T2 // /2 width=1/ /2 width=3/ /2 width=7/
75 lemma cpx_pair_sn: ∀h,g,I,G,L,V1,V2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 →
76 ∀T. ⦃G, L⦄ ⊢ ②{I}V1.T ➡[h, g] ②{I}V2.T.
77 #h #g * /2 width=1/ qed.
79 lemma cpx_delift: ∀h,g,I,G,K,V,T1,L,d. ⇩[0, d] L ≡ (K.ⓑ{I}V) →
80 ∃∃T2,T. ⦃G, L⦄ ⊢ T1 ➡[h, g] T2 & ⇧[d, 1] T ≡ T2.
81 #h #g #I #G #K #V #T1 elim T1 -T1
82 [ * #i #L #d #HLK /2 width=4/
83 elim (lt_or_eq_or_gt i d) #Hid [1,3: /3 width=4/ ]
85 elim (lift_total V 0 (i+1)) #W #HVW
86 elim (lift_split … HVW i i) // /3 width=7/
87 | * [ #a ] #I #W1 #U1 #IHW1 #IHU1 #L #d #HLK
88 elim (IHW1 … HLK) -IHW1 #W2 #W #HW12 #HW2
89 [ elim (IHU1 (L. ⓑ{I} W1) (d+1)) -IHU1 /2 width=1/ -HLK /3 width=9/
90 | elim (IHU1 … HLK) -IHU1 -HLK /3 width=8/
95 lemma cpx_append: ∀h,g,G. l_appendable_sn … (cpx h g G).
96 #h #g #G #K #T1 #T2 #H elim H -G -K -T1 -T2 // /2 width=1/ /2 width=3/
97 #I #G #K #K0 #V1 #V2 #W2 #i #HK0 #_ #HVW2 #IHV12 #L
98 lapply (ldrop_fwd_length_lt2 … HK0) #H
99 @(cpx_delta … I … (L@@K0) V1 … HVW2) //
100 @(ldrop_O1_append_sn_le … HK0) /2 width=2/ (**) (* /3/ does not work *)
103 (* Basic inversion lemmas ***************************************************)
105 fact cpx_inv_atom1_aux: ∀h,g,G,L,T1,T2. ⦃G, L⦄ ⊢ T1 ➡[h, g] T2 → ∀J. T1 = ⓪{J} →
107 | ∃∃k,l. deg h g k (l+1) & T2 = ⋆(next h k) & J = Sort k
108 | ∃∃I,K,V,V2,i. ⇩[O, i] L ≡ K.ⓑ{I}V & ⦃G, K⦄ ⊢ V ➡[h, g] V2 &
109 ⇧[O, i + 1] V2 ≡ T2 & J = LRef i.
110 #G #h #g #L #T1 #T2 * -L -T1 -T2
111 [ #I #G #L #J #H destruct /2 width=1/
112 | #G #L #k #l #Hkl #J #H destruct /3 width=5/
113 | #I #G #L #K #V #V2 #T2 #i #HLK #HV2 #HVT2 #J #H destruct /3 width=9/
114 | #a #I #G #L #V1 #V2 #T1 #T2 #_ #_ #J #H destruct
115 | #I #G #L #V1 #V2 #T1 #T2 #_ #_ #J #H destruct
116 | #G #L #V #T1 #T #T2 #_ #_ #J #H destruct
117 | #G #L #V #T1 #T2 #_ #J #H destruct
118 | #G #L #V1 #V2 #T #_ #J #H destruct
119 | #a #G #L #V1 #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #J #H destruct
120 | #a #G #L #V1 #V #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #_ #J #H destruct
124 lemma cpx_inv_atom1: ∀h,g,J,G,L,T2. ⦃G, L⦄ ⊢ ⓪{J} ➡[h, g] T2 →
126 | ∃∃k,l. deg h g k (l+1) & T2 = ⋆(next h k) & J = Sort k
127 | ∃∃I,K,V,V2,i. ⇩[O, i] L ≡ K.ⓑ{I}V & ⦃G, K⦄ ⊢ V ➡[h, g] V2 &
128 ⇧[O, i + 1] V2 ≡ T2 & J = LRef i.
129 /2 width=3 by cpx_inv_atom1_aux/ qed-.
131 lemma cpx_inv_sort1: ∀h,g,G,L,T2,k. ⦃G, L⦄ ⊢ ⋆k ➡[h, g] T2 → T2 = ⋆k ∨
132 ∃∃l. deg h g k (l+1) & T2 = ⋆(next h k).
133 #h #g #G #L #T2 #k #H
134 elim (cpx_inv_atom1 … H) -H /2 width=1/ *
135 [ #k0 #l0 #Hkl0 #H1 #H2 destruct /3 width=4/
136 | #I #K #V #V2 #i #_ #_ #_ #H destruct
140 lemma cpx_inv_lref1: ∀h,g,G,L,T2,i. ⦃G, L⦄ ⊢ #i ➡[h, g] T2 →
142 ∃∃I,K,V,V2. ⇩[O, i] L ≡ K. ⓑ{I}V & ⦃G, K⦄ ⊢ V ➡[h, g] V2 &
144 #h #g #G #L #T2 #i #H
145 elim (cpx_inv_atom1 … H) -H /2 width=1/ *
146 [ #k #l #_ #_ #H destruct
147 | #I #K #V #V2 #j #HLK #HV2 #HVT2 #H destruct /3 width=7/
151 lemma cpx_inv_gref1: ∀h,g,G,L,T2,p. ⦃G, L⦄ ⊢ §p ➡[h, g] T2 → T2 = §p.
152 #h #g #G #L #T2 #p #H
153 elim (cpx_inv_atom1 … H) -H // *
154 [ #k #l #_ #_ #H destruct
155 | #I #K #V #V2 #i #_ #_ #_ #H destruct
159 fact cpx_inv_bind1_aux: ∀h,g,G,L,U1,U2. ⦃G, L⦄ ⊢ U1 ➡[h, g] U2 →
160 ∀a,J,V1,T1. U1 = ⓑ{a,J}V1.T1 → (
161 ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L.ⓑ{J}V1⦄ ⊢ T1 ➡[h, g] T2 &
164 ∃∃T. ⦃G, L.ⓓV1⦄ ⊢ T1 ➡[h, g] T & ⇧[0, 1] U2 ≡ T &
166 #h #g #G #L #U1 #U2 * -L -U1 -U2
167 [ #I #G #L #b #J #W #U1 #H destruct
168 | #G #L #k #l #_ #b #J #W #U1 #H destruct
169 | #I #G #L #K #V #V2 #W2 #i #_ #_ #_ #b #J #W #U1 #H destruct
170 | #a #I #G #L #V1 #V2 #T1 #T2 #HV12 #HT12 #b #J #W #U1 #H destruct /3 width=5/
171 | #I #G #L #V1 #V2 #T1 #T2 #_ #_ #b #J #W #U1 #H destruct
172 | #G #L #V #T1 #T #T2 #HT1 #HT2 #b #J #W #U1 #H destruct /3 width=3/
173 | #G #L #V #T1 #T2 #_ #b #J #W #U1 #H destruct
174 | #G #L #V1 #V2 #T #_ #b #J #W #U1 #H destruct
175 | #a #G #L #V1 #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #b #J #W #U1 #H destruct
176 | #a #G #L #V1 #V #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #_ #b #J #W #U1 #H destruct
180 lemma cpx_inv_bind1: ∀h,g,a,I,G,L,V1,T1,U2. ⦃G, L⦄ ⊢ ⓑ{a,I}V1.T1 ➡[h, g] U2 → (
181 ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L.ⓑ{I}V1⦄ ⊢ T1 ➡[h, g] T2 &
184 ∃∃T. ⦃G, L.ⓓV1⦄ ⊢ T1 ➡[h, g] T & ⇧[0, 1] U2 ≡ T &
186 /2 width=3 by cpx_inv_bind1_aux/ qed-.
188 lemma cpx_inv_abbr1: ∀h,g,a,G,L,V1,T1,U2. ⦃G, L⦄ ⊢ ⓓ{a}V1.T1 ➡[h, g] U2 → (
189 ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L.ⓓV1⦄ ⊢ T1 ➡[h, g] T2 &
192 ∃∃T. ⦃G, L.ⓓV1⦄ ⊢ T1 ➡[h, g] T & ⇧[0, 1] U2 ≡ T & a = true.
193 #h #g #a #G #L #V1 #T1 #U2 #H
194 elim (cpx_inv_bind1 … H) -H * /3 width=3/ /3 width=5/
197 lemma cpx_inv_abst1: ∀h,g,a,G,L,V1,T1,U2. ⦃G, L⦄ ⊢ ⓛ{a}V1.T1 ➡[h, g] U2 →
198 ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L.ⓛV1⦄ ⊢ T1 ➡[h, g] T2 &
200 #h #g #a #G #L #V1 #T1 #U2 #H
201 elim (cpx_inv_bind1 … H) -H *
203 | #T #_ #_ #_ #H destruct
207 fact cpx_inv_flat1_aux: ∀h,g,G,L,U,U2. ⦃G, L⦄ ⊢ U ➡[h, g] U2 →
208 ∀J,V1,U1. U = ⓕ{J}V1.U1 →
209 ∨∨ ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L⦄ ⊢ U1 ➡[h, g] T2 &
211 | (⦃G, L⦄ ⊢ U1 ➡[h, g] U2 ∧ J = Cast)
212 | (⦃G, L⦄ ⊢ V1 ➡[h, g] U2 ∧ J = Cast)
213 | ∃∃a,V2,W1,W2,T1,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L⦄ ⊢ W1 ➡[h, g] W2 &
214 ⦃G, L.ⓛW1⦄ ⊢ T1 ➡[h, g] T2 &
216 U2 = ⓓ{a}ⓝW2.V2.T2 & J = Appl
217 | ∃∃a,V,V2,W1,W2,T1,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V & ⇧[0,1] V ≡ V2 &
218 ⦃G, L⦄ ⊢ W1 ➡[h, g] W2 & ⦃G, L.ⓓW1⦄ ⊢ T1 ➡[h, g] T2 &
220 U2 = ⓓ{a}W2.ⓐV2.T2 & J = Appl.
221 #h #g #G #L #U #U2 * -L -U -U2
222 [ #I #G #L #J #W #U1 #H destruct
223 | #G #L #k #l #_ #J #W #U1 #H destruct
224 | #I #G #L #K #V #V2 #W2 #i #_ #_ #_ #J #W #U1 #H destruct
225 | #a #I #G #L #V1 #V2 #T1 #T2 #_ #_ #J #W #U1 #H destruct
226 | #I #G #L #V1 #V2 #T1 #T2 #HV12 #HT12 #J #W #U1 #H destruct /3 width=5/
227 | #G #L #V #T1 #T #T2 #_ #_ #J #W #U1 #H destruct
228 | #G #L #V #T1 #T2 #HT12 #J #W #U1 #H destruct /3 width=1/
229 | #G #L #V1 #V2 #T #HV12 #J #W #U1 #H destruct /3 width=1/
230 | #a #G #L #V1 #V2 #W1 #W2 #T1 #T2 #HV12 #HW12 #HT12 #J #W #U1 #H destruct /3 width=11/
231 | #a #G #L #V1 #V #V2 #W1 #W2 #T1 #T2 #HV1 #HV2 #HW12 #HT12 #J #W #U1 #H destruct /3 width=13/
235 lemma cpx_inv_flat1: ∀h,g,I,G,L,V1,U1,U2. ⦃G, L⦄ ⊢ ⓕ{I}V1.U1 ➡[h, g] U2 →
236 ∨∨ ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L⦄ ⊢ U1 ➡[h, g] T2 &
238 | (⦃G, L⦄ ⊢ U1 ➡[h, g] U2 ∧ I = Cast)
239 | (⦃G, L⦄ ⊢ V1 ➡[h, g] U2 ∧ I = Cast)
240 | ∃∃a,V2,W1,W2,T1,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L⦄ ⊢ W1 ➡[h, g] W2 &
241 ⦃G, L.ⓛW1⦄ ⊢ T1 ➡[h, g] T2 &
243 U2 = ⓓ{a}ⓝW2.V2.T2 & I = Appl
244 | ∃∃a,V,V2,W1,W2,T1,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V & ⇧[0,1] V ≡ V2 &
245 ⦃G, L⦄ ⊢ W1 ➡[h, g] W2 & ⦃G, L.ⓓW1⦄ ⊢ T1 ➡[h, g] T2 &
247 U2 = ⓓ{a}W2.ⓐV2.T2 & I = Appl.
248 /2 width=3 by cpx_inv_flat1_aux/ qed-.
250 lemma cpx_inv_appl1: ∀h,g,G,L,V1,U1,U2. ⦃G, L⦄ ⊢ ⓐ V1.U1 ➡[h, g] U2 →
251 ∨∨ ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L⦄ ⊢ U1 ➡[h, g] T2 &
253 | ∃∃a,V2,W1,W2,T1,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L⦄ ⊢ W1 ➡[h, g] W2 &
254 ⦃G, L.ⓛW1⦄ ⊢ T1 ➡[h, g] T2 &
255 U1 = ⓛ{a}W1.T1 & U2 = ⓓ{a}ⓝW2.V2.T2
256 | ∃∃a,V,V2,W1,W2,T1,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V & ⇧[0,1] V ≡ V2 &
257 ⦃G, L⦄ ⊢ W1 ➡[h, g] W2 & ⦃G, L.ⓓW1⦄ ⊢ T1 ➡[h, g] T2 &
258 U1 = ⓓ{a}W1.T1 & U2 = ⓓ{a}W2. ⓐV2. T2.
259 #h #g #G #L #V1 #U1 #U2 #H elim (cpx_inv_flat1 … H) -H *
267 (* Note: the main property of simple terms *)
268 lemma cpx_inv_appl1_simple: ∀h,g,G,L,V1,T1,U. ⦃G, L⦄ ⊢ ⓐV1.T1 ➡[h, g] U → 𝐒⦃T1⦄ →
269 ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L⦄ ⊢ T1 ➡[h, g] T2 &
271 #h #g #G #L #V1 #T1 #U #H #HT1
272 elim (cpx_inv_appl1 … H) -H *
274 | #a #V2 #W1 #W2 #U1 #U2 #_ #_ #_ #H #_ destruct
275 elim (simple_inv_bind … HT1)
276 | #a #V #V2 #W1 #W2 #U1 #U2 #_ #_ #_ #_ #H #_ destruct
277 elim (simple_inv_bind … HT1)
281 lemma cpx_inv_cast1: ∀h,g,G,L,V1,U1,U2. ⦃G, L⦄ ⊢ ⓝV1.U1 ➡[h, g] U2 →
282 ∨∨ ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L⦄ ⊢ U1 ➡[h, g] T2 &
284 | ⦃G, L⦄ ⊢ U1 ➡[h, g] U2
285 | ⦃G, L⦄ ⊢ V1 ➡[h, g] U2.
286 #h #g #G #L #V1 #U1 #U2 #H elim (cpx_inv_flat1 … H) -H *
289 | #a #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #_ #_ #H destruct
290 | #a #V #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #_ #_ #_ #H destruct
294 (* Basic forward lemmas *****************************************************)
296 lemma cpx_fwd_bind1_minus: ∀h,g,I,G,L,V1,T1,T. ⦃G, L⦄ ⊢ -ⓑ{I}V1.T1 ➡[h, g] T → ∀b.
297 ∃∃V2,T2. ⦃G, L⦄ ⊢ ⓑ{b,I}V1.T1 ➡[h, g] ⓑ{b,I}V2.T2 &
299 #h #g #I #G #L #V1 #T1 #T #H #b
300 elim (cpx_inv_bind1 … H) -H *
301 [ #V2 #T2 #HV12 #HT12 #H destruct /3 width=4/
302 | #T2 #_ #_ #H destruct
306 lemma cpx_fwd_shift1: ∀h,g,G,L1,L,T1,T. ⦃G, L⦄ ⊢ L1 @@ T1 ➡[h, g] T →
307 ∃∃L2,T2. |L1| = |L2| & T = L2 @@ T2.
308 #h #g #G #L1 @(lenv_ind_dx … L1) -L1 normalize
310 @(ex2_2_intro … (⋆)) // (**) (* explicit constructor *)
311 | #I #L1 #V1 #IH #L #T1 #X
312 >shift_append_assoc normalize #H
313 elim (cpx_inv_bind1 … H) -H *
314 [ #V0 #T0 #_ #HT10 #H destruct
315 elim (IH … HT10) -IH -HT10 #L2 #T2 #HL12 #H destruct
316 >append_length >HL12 -HL12
317 @(ex2_2_intro … (⋆.ⓑ{I}V0@@L2) T2) [ >append_length ] // /2 width=3/ (**) (* explicit constructor *)
318 | #T #_ #_ #H destruct