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/ssta.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 fact ssta_cpx_aux: ∀h,g,G,L,T1,T2,l0. ⦃G, L⦄ ⊢ T1 •[h, g] ⦃l0, T2⦄ →
76 ∀l. l0 = l+1 → ⦃G, L⦄ ⊢ T1 ➡[h, g] T2.
77 #h #g #G #L #T1 #T2 #l0 #H elim H -L -T1 -T2 -l0 /2 width=2/ /2 width=7/ /3 width=2/ /3 width=7/
80 lemma ssta_cpx: ∀h,g,G,L,T1,T2,l. ⦃G, L⦄ ⊢ T1 •[h, g] ⦃l+1, T2⦄ → ⦃G, L⦄ ⊢ T1 ➡[h, g] T2.
81 /2 width=4 by ssta_cpx_aux/ qed.
83 lemma cpx_pair_sn: ∀h,g,I,G,L,V1,V2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 →
84 ∀T. ⦃G, L⦄ ⊢ ②{I}V1.T ➡[h, g] ②{I}V2.T.
85 #h #g * /2 width=1/ qed.
87 lemma cpx_delift: ∀h,g,I,G,K,V,T1,L,d. ⇩[0, d] L ≡ (K.ⓑ{I}V) →
88 ∃∃T2,T. ⦃G, L⦄ ⊢ T1 ➡[h, g] T2 & ⇧[d, 1] T ≡ T2.
89 #h #g #I #G #K #V #T1 elim T1 -T1
90 [ * #i #L #d #HLK /2 width=4/
91 elim (lt_or_eq_or_gt i d) #Hid [1,3: /3 width=4/ ]
93 elim (lift_total V 0 (i+1)) #W #HVW
94 elim (lift_split … HVW i i) // /3 width=7/
95 | * [ #a ] #I #W1 #U1 #IHW1 #IHU1 #L #d #HLK
96 elim (IHW1 … HLK) -IHW1 #W2 #W #HW12 #HW2
97 [ elim (IHU1 (L. ⓑ{I} W1) (d+1)) -IHU1 /2 width=1/ -HLK /3 width=9/
98 | elim (IHU1 … HLK) -IHU1 -HLK /3 width=8/
103 lemma cpx_append: ∀h,g,G. l_appendable_sn … (cpx h g G).
104 #h #g #G #K #T1 #T2 #H elim H -G -K -T1 -T2 // /2 width=1/ /2 width=3/
105 #I #G #K #K0 #V1 #V2 #W2 #i #HK0 #_ #HVW2 #IHV12 #L
106 lapply (ldrop_fwd_length_lt2 … HK0) #H
107 @(cpx_delta … I … (L@@K0) V1 … HVW2) //
108 @(ldrop_O1_append_sn_le … HK0) /2 width=2/ (**) (* /3/ does not work *)
111 (* Basic inversion lemmas ***************************************************)
113 fact cpx_inv_atom1_aux: ∀h,g,G,L,T1,T2. ⦃G, L⦄ ⊢ T1 ➡[h, g] T2 → ∀J. T1 = ⓪{J} →
115 | ∃∃k,l. deg h g k (l+1) & T2 = ⋆(next h k) & J = Sort k
116 | ∃∃I,K,V,V2,i. ⇩[O, i] L ≡ K.ⓑ{I}V & ⦃G, K⦄ ⊢ V ➡[h, g] V2 &
117 ⇧[O, i + 1] V2 ≡ T2 & J = LRef i.
118 #G #h #g #L #T1 #T2 * -L -T1 -T2
119 [ #I #G #L #J #H destruct /2 width=1/
120 | #G #L #k #l #Hkl #J #H destruct /3 width=5/
121 | #I #G #L #K #V #V2 #T2 #i #HLK #HV2 #HVT2 #J #H destruct /3 width=9/
122 | #a #I #G #L #V1 #V2 #T1 #T2 #_ #_ #J #H destruct
123 | #I #G #L #V1 #V2 #T1 #T2 #_ #_ #J #H destruct
124 | #G #L #V #T1 #T #T2 #_ #_ #J #H destruct
125 | #G #L #V #T1 #T2 #_ #J #H destruct
126 | #G #L #V1 #V2 #T #_ #J #H destruct
127 | #a #G #L #V1 #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #J #H destruct
128 | #a #G #L #V1 #V #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #_ #J #H destruct
132 lemma cpx_inv_atom1: ∀h,g,J,G,L,T2. ⦃G, L⦄ ⊢ ⓪{J} ➡[h, g] T2 →
134 | ∃∃k,l. deg h g k (l+1) & T2 = ⋆(next h k) & J = Sort k
135 | ∃∃I,K,V,V2,i. ⇩[O, i] L ≡ K.ⓑ{I}V & ⦃G, K⦄ ⊢ V ➡[h, g] V2 &
136 ⇧[O, i + 1] V2 ≡ T2 & J = LRef i.
137 /2 width=3 by cpx_inv_atom1_aux/ qed-.
139 lemma cpx_inv_sort1: ∀h,g,G,L,T2,k. ⦃G, L⦄ ⊢ ⋆k ➡[h, g] T2 → T2 = ⋆k ∨
140 ∃∃l. deg h g k (l+1) & T2 = ⋆(next h k).
141 #h #g #G #L #T2 #k #H
142 elim (cpx_inv_atom1 … H) -H /2 width=1/ *
143 [ #k0 #l0 #Hkl0 #H1 #H2 destruct /3 width=4/
144 | #I #K #V #V2 #i #_ #_ #_ #H destruct
148 lemma cpx_inv_lref1: ∀h,g,G,L,T2,i. ⦃G, L⦄ ⊢ #i ➡[h, g] T2 →
150 ∃∃I,K,V,V2. ⇩[O, i] L ≡ K. ⓑ{I}V & ⦃G, K⦄ ⊢ V ➡[h, g] V2 &
152 #h #g #G #L #T2 #i #H
153 elim (cpx_inv_atom1 … H) -H /2 width=1/ *
154 [ #k #l #_ #_ #H destruct
155 | #I #K #V #V2 #j #HLK #HV2 #HVT2 #H destruct /3 width=7/
159 lemma cpx_inv_gref1: ∀h,g,G,L,T2,p. ⦃G, L⦄ ⊢ §p ➡[h, g] T2 → T2 = §p.
160 #h #g #G #L #T2 #p #H
161 elim (cpx_inv_atom1 … H) -H // *
162 [ #k #l #_ #_ #H destruct
163 | #I #K #V #V2 #i #_ #_ #_ #H destruct
167 fact cpx_inv_bind1_aux: ∀h,g,G,L,U1,U2. ⦃G, L⦄ ⊢ U1 ➡[h, g] U2 →
168 ∀a,J,V1,T1. U1 = ⓑ{a,J}V1.T1 → (
169 ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L.ⓑ{J}V1⦄ ⊢ T1 ➡[h, g] T2 &
172 ∃∃T. ⦃G, L.ⓓV1⦄ ⊢ T1 ➡[h, g] T & ⇧[0, 1] U2 ≡ T &
174 #h #g #G #L #U1 #U2 * -L -U1 -U2
175 [ #I #G #L #b #J #W #U1 #H destruct
176 | #G #L #k #l #_ #b #J #W #U1 #H destruct
177 | #I #G #L #K #V #V2 #W2 #i #_ #_ #_ #b #J #W #U1 #H destruct
178 | #a #I #G #L #V1 #V2 #T1 #T2 #HV12 #HT12 #b #J #W #U1 #H destruct /3 width=5/
179 | #I #G #L #V1 #V2 #T1 #T2 #_ #_ #b #J #W #U1 #H destruct
180 | #G #L #V #T1 #T #T2 #HT1 #HT2 #b #J #W #U1 #H destruct /3 width=3/
181 | #G #L #V #T1 #T2 #_ #b #J #W #U1 #H destruct
182 | #G #L #V1 #V2 #T #_ #b #J #W #U1 #H destruct
183 | #a #G #L #V1 #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #b #J #W #U1 #H destruct
184 | #a #G #L #V1 #V #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #_ #b #J #W #U1 #H destruct
188 lemma cpx_inv_bind1: ∀h,g,a,I,G,L,V1,T1,U2. ⦃G, L⦄ ⊢ ⓑ{a,I}V1.T1 ➡[h, g] U2 → (
189 ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L.ⓑ{I}V1⦄ ⊢ T1 ➡[h, g] T2 &
192 ∃∃T. ⦃G, L.ⓓV1⦄ ⊢ T1 ➡[h, g] T & ⇧[0, 1] U2 ≡ T &
194 /2 width=3 by cpx_inv_bind1_aux/ qed-.
196 lemma cpx_inv_abbr1: ∀h,g,a,G,L,V1,T1,U2. ⦃G, L⦄ ⊢ ⓓ{a}V1.T1 ➡[h, g] U2 → (
197 ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L.ⓓV1⦄ ⊢ T1 ➡[h, g] T2 &
200 ∃∃T. ⦃G, L.ⓓV1⦄ ⊢ T1 ➡[h, g] T & ⇧[0, 1] U2 ≡ T & a = true.
201 #h #g #a #G #L #V1 #T1 #U2 #H
202 elim (cpx_inv_bind1 … H) -H * /3 width=3/ /3 width=5/
205 lemma cpx_inv_abst1: ∀h,g,a,G,L,V1,T1,U2. ⦃G, L⦄ ⊢ ⓛ{a}V1.T1 ➡[h, g] U2 →
206 ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L.ⓛV1⦄ ⊢ T1 ➡[h, g] T2 &
208 #h #g #a #G #L #V1 #T1 #U2 #H
209 elim (cpx_inv_bind1 … H) -H *
211 | #T #_ #_ #_ #H destruct
215 fact cpx_inv_flat1_aux: ∀h,g,G,L,U,U2. ⦃G, L⦄ ⊢ U ➡[h, g] U2 →
216 ∀J,V1,U1. U = ⓕ{J}V1.U1 →
217 ∨∨ ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L⦄ ⊢ U1 ➡[h, g] T2 &
219 | (⦃G, L⦄ ⊢ U1 ➡[h, g] U2 ∧ J = Cast)
220 | (⦃G, L⦄ ⊢ V1 ➡[h, g] U2 ∧ J = Cast)
221 | ∃∃a,V2,W1,W2,T1,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L⦄ ⊢ W1 ➡[h, g] W2 &
222 ⦃G, L.ⓛW1⦄ ⊢ T1 ➡[h, g] T2 &
224 U2 = ⓓ{a}ⓝW2.V2.T2 & J = Appl
225 | ∃∃a,V,V2,W1,W2,T1,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V & ⇧[0,1] V ≡ V2 &
226 ⦃G, L⦄ ⊢ W1 ➡[h, g] W2 & ⦃G, L.ⓓW1⦄ ⊢ T1 ➡[h, g] T2 &
228 U2 = ⓓ{a}W2.ⓐV2.T2 & J = Appl.
229 #h #g #G #L #U #U2 * -L -U -U2
230 [ #I #G #L #J #W #U1 #H destruct
231 | #G #L #k #l #_ #J #W #U1 #H destruct
232 | #I #G #L #K #V #V2 #W2 #i #_ #_ #_ #J #W #U1 #H destruct
233 | #a #I #G #L #V1 #V2 #T1 #T2 #_ #_ #J #W #U1 #H destruct
234 | #I #G #L #V1 #V2 #T1 #T2 #HV12 #HT12 #J #W #U1 #H destruct /3 width=5/
235 | #G #L #V #T1 #T #T2 #_ #_ #J #W #U1 #H destruct
236 | #G #L #V #T1 #T2 #HT12 #J #W #U1 #H destruct /3 width=1/
237 | #G #L #V1 #V2 #T #HV12 #J #W #U1 #H destruct /3 width=1/
238 | #a #G #L #V1 #V2 #W1 #W2 #T1 #T2 #HV12 #HW12 #HT12 #J #W #U1 #H destruct /3 width=11/
239 | #a #G #L #V1 #V #V2 #W1 #W2 #T1 #T2 #HV1 #HV2 #HW12 #HT12 #J #W #U1 #H destruct /3 width=13/
243 lemma cpx_inv_flat1: ∀h,g,I,G,L,V1,U1,U2. ⦃G, L⦄ ⊢ ⓕ{I}V1.U1 ➡[h, g] U2 →
244 ∨∨ ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L⦄ ⊢ U1 ➡[h, g] T2 &
246 | (⦃G, L⦄ ⊢ U1 ➡[h, g] U2 ∧ I = Cast)
247 | (⦃G, L⦄ ⊢ V1 ➡[h, g] U2 ∧ I = Cast)
248 | ∃∃a,V2,W1,W2,T1,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L⦄ ⊢ W1 ➡[h, g] W2 &
249 ⦃G, L.ⓛW1⦄ ⊢ T1 ➡[h, g] T2 &
251 U2 = ⓓ{a}ⓝW2.V2.T2 & I = Appl
252 | ∃∃a,V,V2,W1,W2,T1,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V & ⇧[0,1] V ≡ V2 &
253 ⦃G, L⦄ ⊢ W1 ➡[h, g] W2 & ⦃G, L.ⓓW1⦄ ⊢ T1 ➡[h, g] T2 &
255 U2 = ⓓ{a}W2.ⓐV2.T2 & I = Appl.
256 /2 width=3 by cpx_inv_flat1_aux/ qed-.
258 lemma cpx_inv_appl1: ∀h,g,G,L,V1,U1,U2. ⦃G, L⦄ ⊢ ⓐ V1.U1 ➡[h, g] U2 →
259 ∨∨ ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L⦄ ⊢ U1 ➡[h, g] T2 &
261 | ∃∃a,V2,W1,W2,T1,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L⦄ ⊢ W1 ➡[h, g] W2 &
262 ⦃G, L.ⓛW1⦄ ⊢ T1 ➡[h, g] T2 &
263 U1 = ⓛ{a}W1.T1 & U2 = ⓓ{a}ⓝW2.V2.T2
264 | ∃∃a,V,V2,W1,W2,T1,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V & ⇧[0,1] V ≡ V2 &
265 ⦃G, L⦄ ⊢ W1 ➡[h, g] W2 & ⦃G, L.ⓓW1⦄ ⊢ T1 ➡[h, g] T2 &
266 U1 = ⓓ{a}W1.T1 & U2 = ⓓ{a}W2. ⓐV2. T2.
267 #h #g #G #L #V1 #U1 #U2 #H elim (cpx_inv_flat1 … H) -H *
275 (* Note: the main property of simple terms *)
276 lemma cpx_inv_appl1_simple: ∀h,g,G,L,V1,T1,U. ⦃G, L⦄ ⊢ ⓐV1.T1 ➡[h, g] U → 𝐒⦃T1⦄ →
277 ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L⦄ ⊢ T1 ➡[h, g] T2 &
279 #h #g #G #L #V1 #T1 #U #H #HT1
280 elim (cpx_inv_appl1 … H) -H *
282 | #a #V2 #W1 #W2 #U1 #U2 #_ #_ #_ #H #_ destruct
283 elim (simple_inv_bind … HT1)
284 | #a #V #V2 #W1 #W2 #U1 #U2 #_ #_ #_ #_ #H #_ destruct
285 elim (simple_inv_bind … HT1)
289 lemma cpx_inv_cast1: ∀h,g,G,L,V1,U1,U2. ⦃G, L⦄ ⊢ ⓝV1.U1 ➡[h, g] U2 →
290 ∨∨ ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L⦄ ⊢ U1 ➡[h, g] T2 &
292 | ⦃G, L⦄ ⊢ U1 ➡[h, g] U2
293 | ⦃G, L⦄ ⊢ V1 ➡[h, g] U2.
294 #h #g #G #L #V1 #U1 #U2 #H elim (cpx_inv_flat1 … H) -H *
297 | #a #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #_ #_ #H destruct
298 | #a #V #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #_ #_ #_ #H destruct
302 (* Basic forward lemmas *****************************************************)
304 lemma cpx_fwd_bind1_minus: ∀h,g,I,G,L,V1,T1,T. ⦃G, L⦄ ⊢ -ⓑ{I}V1.T1 ➡[h, g] T → ∀b.
305 ∃∃V2,T2. ⦃G, L⦄ ⊢ ⓑ{b,I}V1.T1 ➡[h, g] ⓑ{b,I}V2.T2 &
307 #h #g #I #G #L #V1 #T1 #T #H #b
308 elim (cpx_inv_bind1 … H) -H *
309 [ #V2 #T2 #HV12 #HT12 #H destruct /3 width=4/
310 | #T2 #_ #_ #H destruct
314 lemma cpx_fwd_shift1: ∀h,g,G,L1,L,T1,T. ⦃G, L⦄ ⊢ L1 @@ T1 ➡[h, g] T →
315 ∃∃L2,T2. |L1| = |L2| & T = L2 @@ T2.
316 #h #g #G #L1 @(lenv_ind_dx … L1) -L1 normalize
318 @(ex2_2_intro … (⋆)) // (**) (* explicit constructor *)
319 | #I #L1 #V1 #IH #L #T1 #X
320 >shift_append_assoc normalize #H
321 elim (cpx_inv_bind1 … H) -H *
322 [ #V0 #T0 #_ #HT10 #H destruct
323 elim (IH … HT10) -IH -HT10 #L2 #T2 #HL12 #H destruct
324 >append_length >HL12 -HL12
325 @(ex2_2_intro … (⋆.ⓑ{I}V0@@L2) T2) [ >append_length ] // /2 width=3/ (**) (* explicit constructor *)
326 | #T #_ #_ #H destruct