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/unfold/cpqs.ma".
17 (* CONTEXT-SENSITIVE PARALLEL REDUCTION FOR TERMS ***************************)
19 (* Basic_1: includes: pr0_delta1 pr2_delta1 pr2_thin_dx pr2_head_1 *)
20 (* Note: cpr_flat: does not hold in basic_1 *)
21 inductive cpr: lenv → relation term ≝
22 | cpr_atom : ∀I,L. cpr L (⓪{I}) (⓪{I})
23 | cpr_delta: ∀L,K,V,V2,W2,i.
24 ⇩[0, i] L ≡ K. ⓓV → cpr K V V2 →
25 ⇧[0, i + 1] V2 ≡ W2 → cpr L (#i) W2
26 | cpr_bind : ∀a,I,L,V1,V2,T1,T2.
27 cpr L V1 V2 → cpr (L. ⓑ{I} V1) T1 T2 →
28 cpr L (ⓑ{a,I} V1. T1) (ⓑ{a,I} V2. T2)
29 | cpr_flat : ∀I,L,V1,V2,T1,T2.
30 cpr L V1 V2 → cpr L T1 T2 →
31 cpr L (ⓕ{I} V1. T1) (ⓕ{I} V2. T2)
32 | cpr_zeta : ∀L,V,T1,T,T2. cpr (L.ⓓV) T1 T →
33 ⇧[0, 1] T2 ≡ T → cpr L (+ⓓV. T1) T2
34 | cpr_tau : ∀L,V,T1,T2. cpr L T1 T2 → cpr L (ⓝV. T1) T2
35 | cpr_beta : ∀a,L,V1,V2,W,T1,T2.
36 cpr L V1 V2 → cpr (L.ⓛW) T1 T2 →
37 cpr L (ⓐV1. ⓛ{a}W. T1) (ⓓ{a}V2. T2)
38 | cpr_theta: ∀a,L,V1,V,V2,W1,W2,T1,T2.
39 cpr L V1 V → ⇧[0, 1] V ≡ V2 → cpr L W1 W2 → cpr (L.ⓓW1) T1 T2 →
40 cpr L (ⓐV1. ⓓ{a}W1. T1) (ⓓ{a}W2. ⓐV2. T2)
43 interpretation "context-sensitive parallel reduction (term)"
44 'PRed L T1 T2 = (cpr L T1 T2).
46 (* Basic properties *********************************************************)
48 lemma cpr_lsubr_trans: lsubr_trans … cpr.
49 #L1 #T1 #T2 #H elim H -L1 -T1 -T2
51 | #L1 #K1 #V1 #V2 #W2 #i #HLK1 #_ #HVW2 #IHV12 #L2 #HL12
52 elim (lsubr_fwd_ldrop2_abbr … HL12 … HLK1) -HL12 -HLK1 /3 width=6/
59 (* Basic_1: was by definition: pr2_free *)
60 lemma tpr_cpr: ∀T1,T2. ⋆ ⊢ T1 ➡ T2 → ∀L. L ⊢ T1 ➡ T2.
62 lapply (cpr_lsubr_trans … HT12 L ?) //
65 lemma cpqs_cpr: ∀L,T1,T2. L ⊢ T1 ➤* T2 → L ⊢ T1 ➡ T2.
66 #L #T1 #T2 #H elim H -L -T1 -T2 // /2 width=1/ /2 width=6/
69 lemma cpss_cpr: ∀L,T1,T2. L ⊢ T1 ▶* T2 → L ⊢ T1 ➡ T2.
72 (* Basic_1: includes by definition: pr0_refl *)
73 lemma cpr_refl: ∀T,L. L ⊢ T ➡ T.
76 lemma cpr_delift: ∀L,K,V,T1,d. ⇩[0, d] L ≡ (K. ⓓV) →
77 ∃∃T2,T. L ⊢ T1 ➡ T2 & ⇧[d, 1] T ≡ T2.
79 elim (cpqs_delift … T1 … HLK) -HLK /3 width=4/
82 lemma cpr_append: l_appendable_sn … cpr.
83 #K #T1 #T2 #H elim H -K -T1 -T2 // /2 width=1/ /2 width=3/
84 #K #K0 #V1 #V2 #W2 #i #HK0 #_ #HVW2 #IHV12 #L
85 lapply (ldrop_fwd_ldrop2_length … HK0) #H
86 @(cpr_delta … (L@@K0) V1 … HVW2) //
87 @(ldrop_O1_append_sn_le … HK0) /2 width=2/ (**) (* /3/ does not work *)
90 lemma cpr_ext_bind: ∀L,V1,V2. L ⊢ V1 ➡ V2 → ∀V,T1,T2. L.ⓛV ⊢ T1 ➡ T2 →
91 ∀a,I. L ⊢ ⓑ{a,I}V1. T1 ➡ ⓑ{a,I}V2. T2.
92 #L #V1 #V2 #HV12 #V #T1 #T2 #HT12 #a #I
93 lapply (cpr_lsubr_trans … HT12 (L.ⓑ{I}V1) ?) -HT12 /2 width=1/
96 (* Basic inversion lemmas ***************************************************)
98 fact cpr_inv_atom1_aux: ∀L,T1,T2. L ⊢ T1 ➡ T2 → ∀I. T1 = ⓪{I} →
100 ∃∃K,V,V2,i. ⇩[O, i] L ≡ K. ⓓV &
102 ⇧[O, i + 1] V2 ≡ T2 &
104 #L #T1 #T2 * -L -T1 -T2
105 [ #I #L #J #H destruct /2 width=1/
106 | #L #K #V #V2 #T2 #i #HLK #HV2 #HVT2 #J #H destruct /3 width=8/
107 | #a #I #L #V1 #V2 #T1 #T2 #_ #_ #J #H destruct
108 | #I #L #V1 #V2 #T1 #T2 #_ #_ #J #H destruct
109 | #L #V #T1 #T #T2 #_ #_ #J #H destruct
110 | #L #V #T1 #T2 #_ #J #H destruct
111 | #a #L #V1 #V2 #W #T1 #T2 #_ #_ #J #H destruct
112 | #a #L #V1 #V #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #_ #J #H destruct
116 lemma cpr_inv_atom1: ∀I,L,T2. L ⊢ ⓪{I} ➡ T2 →
118 ∃∃K,V,V2,i. ⇩[O, i] L ≡ K. ⓓV &
120 ⇧[O, i + 1] V2 ≡ T2 &
122 /2 width=3 by cpr_inv_atom1_aux/ qed-.
124 (* Basic_1: includes: pr0_gen_sort pr2_gen_sort *)
125 lemma cpr_inv_sort1: ∀L,T2,k. L ⊢ ⋆k ➡ T2 → T2 = ⋆k.
127 elim (cpr_inv_atom1 … H) -H //
128 * #K #V #V2 #i #_ #_ #_ #H destruct
131 (* Basic_1: includes: pr0_gen_lref pr2_gen_lref *)
132 lemma cpr_inv_lref1: ∀L,T2,i. L ⊢ #i ➡ T2 →
134 ∃∃K,V,V2. ⇩[O, i] L ≡ K. ⓓV &
138 elim (cpr_inv_atom1 … H) -H /2 width=1/
139 * #K #V #V2 #j #HLK #HV2 #HVT2 #H destruct /3 width=6/
142 lemma cpr_inv_gref1: ∀L,T2,p. L ⊢ §p ➡ T2 → T2 = §p.
144 elim (cpr_inv_atom1 … H) -H //
145 * #K #V #V2 #i #_ #_ #_ #H destruct
148 fact cpr_inv_bind1_aux: ∀L,U1,U2. L ⊢ U1 ➡ U2 →
149 ∀a,I,V1,T1. U1 = ⓑ{a,I} V1. T1 → (
150 ∃∃V2,T2. L ⊢ V1 ➡ V2 &
151 L. ⓑ{I} V1 ⊢ T1 ➡ T2 &
154 ∃∃T. L.ⓓV1 ⊢ T1 ➡ T & ⇧[0, 1] U2 ≡ T & a = true & I = Abbr.
155 #L #U1 #U2 * -L -U1 -U2
156 [ #I #L #b #J #W1 #U1 #H destruct
157 | #L #K #V #V2 #W2 #i #_ #_ #_ #b #J #W1 #U1 #H destruct
158 | #a #I #L #V1 #V2 #T1 #T2 #HV12 #HT12 #b #J #W1 #U1 #H destruct /3 width=5/
159 | #I #L #V1 #V2 #T1 #T2 #_ #_ #b #J #W1 #U1 #H destruct
160 | #L #V #T1 #T #T2 #HT1 #HT2 #b #J #W1 #U1 #H destruct /3 width=3/
161 | #L #V #T1 #T2 #_ #b #J #W1 #U1 #H destruct
162 | #a #L #V1 #V2 #W #T1 #T2 #_ #_ #b #J #W1 #U1 #H destruct
163 | #a #L #V1 #V #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #_ #b #J #W1 #U1 #H destruct
167 lemma cpr_inv_bind1: ∀a,I,L,V1,T1,U2. L ⊢ ⓑ{a,I} V1. T1 ➡ U2 → (
168 ∃∃V2,T2. L ⊢ V1 ➡ V2 &
169 L. ⓑ{I} V1 ⊢ T1 ➡ T2 &
172 ∃∃T. L.ⓓV1 ⊢ T1 ➡ T & ⇧[0, 1] U2 ≡ T & a = true & I = Abbr.
173 /2 width=3 by cpr_inv_bind1_aux/ qed-.
175 (* Basic_1: includes: pr0_gen_abbr pr2_gen_abbr *)
176 lemma cpr_inv_abbr1: ∀a,L,V1,T1,U2. L ⊢ ⓓ{a} V1. T1 ➡ U2 → (
177 ∃∃V2,T2. L ⊢ V1 ➡ V2 &
181 ∃∃T. L.ⓓV1 ⊢ T1 ➡ T & ⇧[0, 1] U2 ≡ T & a = true.
183 elim (cpr_inv_bind1 … H) -H * /3 width=3/ /3 width=5/
186 (* Basic_1: includes: pr0_gen_abst pr2_gen_abst *)
187 lemma cpr_inv_abst1: ∀a,L,V1,T1,U2. L ⊢ ⓛ{a} V1. T1 ➡ U2 →
188 ∃∃V2,T2. L ⊢ V1 ➡ V2 & L. ⓛ V1 ⊢ T1 ➡ T2 &
191 elim (cpr_inv_bind1 … H) -H *
193 | #T #_ #_ #_ #H destruct
197 fact cpr_inv_flat1_aux: ∀L,U,U2. L ⊢ U ➡ U2 →
198 ∀I,V1,U1. U = ⓕ{I} V1. U1 →
199 ∨∨ ∃∃V2,T2. L ⊢ V1 ➡ V2 & L ⊢ U1 ➡ T2 &
201 | (L ⊢ U1 ➡ U2 ∧ I = Cast)
202 | ∃∃a,V2,W,T1,T2. L ⊢ V1 ➡ V2 & L.ⓛW ⊢ T1 ➡ T2 &
204 U2 = ⓓ{a}V2. T2 & I = Appl
205 | ∃∃a,V,V2,W1,W2,T1,T2. L ⊢ V1 ➡ V & ⇧[0,1] V ≡ V2 &
206 L ⊢ W1 ➡ W2 & L.ⓓW1 ⊢ T1 ➡ T2 &
208 U2 = ⓓ{a}W2. ⓐV2. T2 & I = Appl.
209 #L #U #U2 * -L -U -U2
210 [ #I #L #J #W1 #U1 #H destruct
211 | #L #K #V #V2 #W2 #i #_ #_ #_ #J #W1 #U1 #H destruct
212 | #a #I #L #V1 #V2 #T1 #T2 #_ #_ #J #W1 #U1 #H destruct
213 | #I #L #V1 #V2 #T1 #T2 #HV12 #HT12 #J #W1 #U1 #H destruct /3 width=5/
214 | #L #V #T1 #T #T2 #_ #_ #J #W1 #U1 #H destruct
215 | #L #V #T1 #T2 #HT12 #J #W1 #U1 #H destruct /3 width=1/
216 | #a #L #V1 #V2 #W #T1 #T2 #HV12 #HT12 #J #W1 #U1 #H destruct /3 width=9/
217 | #a #L #V1 #V #V2 #W1 #W2 #T1 #T2 #HV1 #HV2 #HW12 #HT12 #J #W1 #U1 #H destruct /3 width=13/
221 lemma cpr_inv_flat1: ∀I,L,V1,U1,U2. L ⊢ ⓕ{I} V1. U1 ➡ U2 →
222 ∨∨ ∃∃V2,T2. L ⊢ V1 ➡ V2 & L ⊢ U1 ➡ T2 &
224 | (L ⊢ U1 ➡ U2 ∧ I = Cast)
225 | ∃∃a,V2,W,T1,T2. L ⊢ V1 ➡ V2 & L.ⓛW ⊢ T1 ➡ T2 &
227 U2 = ⓓ{a}V2. T2 & I = Appl
228 | ∃∃a,V,V2,W1,W2,T1,T2. L ⊢ V1 ➡ V & ⇧[0,1] V ≡ V2 &
229 L ⊢ W1 ➡ W2 & L.ⓓW1 ⊢ T1 ➡ T2 &
231 U2 = ⓓ{a}W2. ⓐV2. T2 & I = Appl.
232 /2 width=3 by cpr_inv_flat1_aux/ qed-.
234 (* Basic_1: includes: pr0_gen_appl pr2_gen_appl *)
235 lemma cpr_inv_appl1: ∀L,V1,U1,U2. L ⊢ ⓐ V1. U1 ➡ U2 →
236 ∨∨ ∃∃V2,T2. L ⊢ V1 ➡ V2 & L ⊢ U1 ➡ T2 &
238 | ∃∃a,V2,W,T1,T2. L ⊢ V1 ➡ V2 & L.ⓛW ⊢ T1 ➡ T2 &
239 U1 = ⓛ{a}W. T1 & U2 = ⓓ{a}V2. T2
240 | ∃∃a,V,V2,W1,W2,T1,T2. L ⊢ V1 ➡ V & ⇧[0,1] V ≡ V2 &
241 L ⊢ W1 ➡ W2 & L.ⓓW1 ⊢ T1 ➡ T2 &
242 U1 = ⓓ{a}W1. T1 & U2 = ⓓ{a}W2. ⓐV2. T2.
243 #L #V1 #U1 #U2 #H elim (cpr_inv_flat1 … H) -H *
251 (* Note: the main property of simple terms *)
252 lemma cpr_inv_appl1_simple: ∀L,V1,T1,U. L ⊢ ⓐV1. T1 ➡ U → 𝐒⦃T1⦄ →
253 ∃∃V2,T2. L ⊢ V1 ➡ V2 & L ⊢ T1 ➡ T2 &
255 #L #V1 #T1 #U #H #HT1
256 elim (cpr_inv_appl1 … H) -H *
258 | #a #V2 #W #U1 #U2 #_ #_ #H #_ destruct
259 elim (simple_inv_bind … HT1)
260 | #a #V #V2 #W1 #W2 #U1 #U2 #_ #_ #_ #_ #H #_ destruct
261 elim (simple_inv_bind … HT1)
265 (* Basic_1: includes: pr0_gen_cast pr2_gen_cast *)
266 lemma cpr_inv_cast1: ∀L,V1,U1,U2. L ⊢ ⓝ V1. U1 ➡ U2 → (
267 ∃∃V2,T2. L ⊢ V1 ➡ V2 & L ⊢ U1 ➡ T2 &
271 #L #V1 #U1 #U2 #H elim (cpr_inv_flat1 … H) -H *
274 | #a #V2 #W #T1 #T2 #_ #_ #_ #_ #H destruct
275 | #a #V #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #_ #_ #_ #H destruct
279 (* Basic forward lemmas *****************************************************)
281 lemma cpr_fwd_abst1: ∀a,L,V1,T1,U2. L ⊢ ⓛ{a}V1.T1 ➡ U2 → ∀I,W.
282 ∃∃V2,T2. L ⊢ V1 ➡ V2 & L. ⓑ{I} W ⊢ T1 ➡ T2 &
284 #a #L #V1 #T1 #U2 #H #I #W
285 elim (cpr_inv_abst1 … H) -H #V2 #T2 #HV12 #HT12 #H destruct
286 lapply (cpr_lsubr_trans … HT12 (L.ⓑ{I}W) ?) -HT12 /2 width=1/ /2 width=5/
290 lemma cpr_fwd_ext_abst1: ∀a,L,V1,T1,U2. L ⊢ ⓛ{a}V1.T1 ➡ U2 → ∀b,I,W.
291 ∃∃V2,T2. L ⊢ V1 ➡ V2 & L ⊢ ⓑ{b,I}W.T1 ➡ ⓑ{b,I}W.T2 &
293 #a #L #V1 #T1 #U2 #H #b #I #W
294 elim (cpr_fwd_abst1 … H I W) -H /3 width=5/
297 lemma cpr_fwd_bind1_minus: ∀I,L,V1,T1,T. L ⊢ -ⓑ{I}V1.T1 ➡ T → ∀b.
298 ∃∃V2,T2. L ⊢ ⓑ{b,I}V1.T1 ➡ ⓑ{b,I}V2.T2 &
300 #I #L #V1 #T1 #T #H #b
301 elim (cpr_inv_bind1 … H) -H *
302 [ #V2 #T2 #HV12 #HT12 #H destruct /3 width=4/
303 | #T2 #_ #_ #H destruct
307 lemma cpr_fwd_shift1: ∀L1,L,T1,T. L ⊢ L1 @@ T1 ➡ T →
308 ∃∃L2,T2. |L1| = |L2| & T = L2 @@ T2.
309 #L1 @(lenv_ind_dx … L1) -L1 normalize
311 @(ex2_2_intro … (⋆)) // (**) (* explicit constructor *)
312 | #I #L1 #V1 #IH #L #T1 #X
313 >shift_append_assoc normalize #H
314 elim (cpr_inv_bind1 … H) -H *
315 [ #V0 #T0 #_ #HT10 #H destruct
316 elim (IH … HT10) -IH -HT10 #L2 #T2 #HL12 #H destruct
317 >append_length >HL12 -HL12
318 @(ex2_2_intro … (⋆.ⓑ{I}V0@@L2) T2) [ >append_length ] // /2 width=3/ (**) (* explicit constructor *)
319 | #T #_ #_ #H destruct
324 (* Basic_1: removed theorems 12:
325 pr0_subst0_back pr0_subst0_fwd pr0_subst0
326 pr2_head_2 pr2_cflat clear_pr2_trans
327 pr2_gen_csort pr2_gen_cflat pr2_gen_cbind
329 pr2_gen_ctail pr2_ctail
331 (* Basic_1: removed local theorems 4:
332 pr0_delta_tau pr0_cong_delta
333 pr2_free_free pr2_free_delta