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 *)
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 (* Basic_1: was: pr2_head_1 *)
77 lemma cpr_pair_sn: ∀I,L,V1,V2. L ⊢ V1 ➡ V2 →
78 ∀T. L⊢ ②{I}V1.T ➡ ②{I}V2.T.
81 lemma cpr_delift: ∀L,K,V,T1,d. ⇩[0, d] L ≡ (K. ⓓV) →
82 ∃∃T2,T. L ⊢ T1 ➡ T2 & ⇧[d, 1] T ≡ T2.
84 elim (cpqs_delift … T1 … HLK) -HLK /3 width=4/
87 lemma cpr_append: l_appendable_sn … cpr.
88 #K #T1 #T2 #H elim H -K -T1 -T2 // /2 width=1/ /2 width=3/
89 #K #K0 #V1 #V2 #W2 #i #HK0 #_ #HVW2 #IHV12 #L
90 lapply (ldrop_fwd_ldrop2_length … HK0) #H
91 @(cpr_delta … (L@@K0) V1 … HVW2) //
92 @(ldrop_O1_append_sn_le … HK0) /2 width=2/ (**) (* /3/ does not work *)
95 lemma cpr_ext_bind: ∀L,V1,V2. L ⊢ V1 ➡ V2 → ∀V,T1,T2. L.ⓛV ⊢ T1 ➡ T2 →
96 ∀a,I. L ⊢ ⓑ{a,I}V1. T1 ➡ ⓑ{a,I}V2. T2.
97 #L #V1 #V2 #HV12 #V #T1 #T2 #HT12 #a #I
98 lapply (cpr_lsubr_trans … HT12 (L.ⓑ{I}V1) ?) -HT12 /2 width=1/
101 (* Basic inversion lemmas ***************************************************)
103 fact cpr_inv_atom1_aux: ∀L,T1,T2. L ⊢ T1 ➡ T2 → ∀I. T1 = ⓪{I} →
105 ∃∃K,V,V2,i. ⇩[O, i] L ≡ K. ⓓV &
107 ⇧[O, i + 1] V2 ≡ T2 &
109 #L #T1 #T2 * -L -T1 -T2
110 [ #I #L #J #H destruct /2 width=1/
111 | #L #K #V #V2 #T2 #i #HLK #HV2 #HVT2 #J #H destruct /3 width=8/
112 | #a #I #L #V1 #V2 #T1 #T2 #_ #_ #J #H destruct
113 | #I #L #V1 #V2 #T1 #T2 #_ #_ #J #H destruct
114 | #L #V #T1 #T #T2 #_ #_ #J #H destruct
115 | #L #V #T1 #T2 #_ #J #H destruct
116 | #a #L #V1 #V2 #W #T1 #T2 #_ #_ #J #H destruct
117 | #a #L #V1 #V #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #_ #J #H destruct
121 lemma cpr_inv_atom1: ∀I,L,T2. L ⊢ ⓪{I} ➡ T2 →
123 ∃∃K,V,V2,i. ⇩[O, i] L ≡ K. ⓓV &
125 ⇧[O, i + 1] V2 ≡ T2 &
127 /2 width=3 by cpr_inv_atom1_aux/ qed-.
129 (* Basic_1: includes: pr0_gen_sort pr2_gen_sort *)
130 lemma cpr_inv_sort1: ∀L,T2,k. L ⊢ ⋆k ➡ T2 → T2 = ⋆k.
132 elim (cpr_inv_atom1 … H) -H //
133 * #K #V #V2 #i #_ #_ #_ #H destruct
136 (* Basic_1: includes: pr0_gen_lref pr2_gen_lref *)
137 lemma cpr_inv_lref1: ∀L,T2,i. L ⊢ #i ➡ T2 →
139 ∃∃K,V,V2. ⇩[O, i] L ≡ K. ⓓV &
143 elim (cpr_inv_atom1 … H) -H /2 width=1/
144 * #K #V #V2 #j #HLK #HV2 #HVT2 #H destruct /3 width=6/
147 lemma cpr_inv_gref1: ∀L,T2,p. L ⊢ §p ➡ T2 → T2 = §p.
149 elim (cpr_inv_atom1 … H) -H //
150 * #K #V #V2 #i #_ #_ #_ #H destruct
153 fact cpr_inv_bind1_aux: ∀L,U1,U2. L ⊢ U1 ➡ U2 →
154 ∀a,I,V1,T1. U1 = ⓑ{a,I} V1. T1 → (
155 ∃∃V2,T2. L ⊢ V1 ➡ V2 &
156 L. ⓑ{I} V1 ⊢ T1 ➡ T2 &
159 ∃∃T. L.ⓓV1 ⊢ T1 ➡ T & ⇧[0, 1] U2 ≡ T & a = true & I = Abbr.
160 #L #U1 #U2 * -L -U1 -U2
161 [ #I #L #b #J #W1 #U1 #H destruct
162 | #L #K #V #V2 #W2 #i #_ #_ #_ #b #J #W1 #U1 #H destruct
163 | #a #I #L #V1 #V2 #T1 #T2 #HV12 #HT12 #b #J #W1 #U1 #H destruct /3 width=5/
164 | #I #L #V1 #V2 #T1 #T2 #_ #_ #b #J #W1 #U1 #H destruct
165 | #L #V #T1 #T #T2 #HT1 #HT2 #b #J #W1 #U1 #H destruct /3 width=3/
166 | #L #V #T1 #T2 #_ #b #J #W1 #U1 #H destruct
167 | #a #L #V1 #V2 #W #T1 #T2 #_ #_ #b #J #W1 #U1 #H destruct
168 | #a #L #V1 #V #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #_ #b #J #W1 #U1 #H destruct
172 lemma cpr_inv_bind1: ∀a,I,L,V1,T1,U2. L ⊢ ⓑ{a,I} V1. T1 ➡ U2 → (
173 ∃∃V2,T2. L ⊢ V1 ➡ V2 &
174 L. ⓑ{I} V1 ⊢ T1 ➡ T2 &
177 ∃∃T. L.ⓓV1 ⊢ T1 ➡ T & ⇧[0, 1] U2 ≡ T & a = true & I = Abbr.
178 /2 width=3 by cpr_inv_bind1_aux/ qed-.
180 (* Basic_1: includes: pr0_gen_abbr pr2_gen_abbr *)
181 lemma cpr_inv_abbr1: ∀a,L,V1,T1,U2. L ⊢ ⓓ{a} V1. T1 ➡ U2 → (
182 ∃∃V2,T2. L ⊢ V1 ➡ V2 &
186 ∃∃T. L.ⓓV1 ⊢ T1 ➡ T & ⇧[0, 1] U2 ≡ T & a = true.
188 elim (cpr_inv_bind1 … H) -H * /3 width=3/ /3 width=5/
191 (* Basic_1: includes: pr0_gen_abst pr2_gen_abst *)
192 lemma cpr_inv_abst1: ∀a,L,V1,T1,U2. L ⊢ ⓛ{a} V1. T1 ➡ U2 →
193 ∃∃V2,T2. L ⊢ V1 ➡ V2 & L. ⓛ V1 ⊢ T1 ➡ T2 &
196 elim (cpr_inv_bind1 … H) -H *
198 | #T #_ #_ #_ #H destruct
202 fact cpr_inv_flat1_aux: ∀L,U,U2. L ⊢ U ➡ U2 →
203 ∀I,V1,U1. U = ⓕ{I} V1. U1 →
204 ∨∨ ∃∃V2,T2. L ⊢ V1 ➡ V2 & L ⊢ U1 ➡ T2 &
206 | (L ⊢ U1 ➡ U2 ∧ I = Cast)
207 | ∃∃a,V2,W,T1,T2. L ⊢ V1 ➡ V2 & L.ⓛW ⊢ T1 ➡ T2 &
209 U2 = ⓓ{a}V2. T2 & I = Appl
210 | ∃∃a,V,V2,W1,W2,T1,T2. L ⊢ V1 ➡ V & ⇧[0,1] V ≡ V2 &
211 L ⊢ W1 ➡ W2 & L.ⓓW1 ⊢ T1 ➡ T2 &
213 U2 = ⓓ{a}W2. ⓐV2. T2 & I = Appl.
214 #L #U #U2 * -L -U -U2
215 [ #I #L #J #W1 #U1 #H destruct
216 | #L #K #V #V2 #W2 #i #_ #_ #_ #J #W1 #U1 #H destruct
217 | #a #I #L #V1 #V2 #T1 #T2 #_ #_ #J #W1 #U1 #H destruct
218 | #I #L #V1 #V2 #T1 #T2 #HV12 #HT12 #J #W1 #U1 #H destruct /3 width=5/
219 | #L #V #T1 #T #T2 #_ #_ #J #W1 #U1 #H destruct
220 | #L #V #T1 #T2 #HT12 #J #W1 #U1 #H destruct /3 width=1/
221 | #a #L #V1 #V2 #W #T1 #T2 #HV12 #HT12 #J #W1 #U1 #H destruct /3 width=9/
222 | #a #L #V1 #V #V2 #W1 #W2 #T1 #T2 #HV1 #HV2 #HW12 #HT12 #J #W1 #U1 #H destruct /3 width=13/
226 lemma cpr_inv_flat1: ∀I,L,V1,U1,U2. L ⊢ ⓕ{I} V1. U1 ➡ U2 →
227 ∨∨ ∃∃V2,T2. L ⊢ V1 ➡ V2 & L ⊢ U1 ➡ T2 &
229 | (L ⊢ U1 ➡ U2 ∧ I = Cast)
230 | ∃∃a,V2,W,T1,T2. L ⊢ V1 ➡ V2 & L.ⓛW ⊢ T1 ➡ T2 &
232 U2 = ⓓ{a}V2. T2 & I = Appl
233 | ∃∃a,V,V2,W1,W2,T1,T2. L ⊢ V1 ➡ V & ⇧[0,1] V ≡ V2 &
234 L ⊢ W1 ➡ W2 & L.ⓓW1 ⊢ T1 ➡ T2 &
236 U2 = ⓓ{a}W2. ⓐV2. T2 & I = Appl.
237 /2 width=3 by cpr_inv_flat1_aux/ qed-.
239 (* Basic_1: includes: pr0_gen_appl pr2_gen_appl *)
240 lemma cpr_inv_appl1: ∀L,V1,U1,U2. L ⊢ ⓐ V1. U1 ➡ U2 →
241 ∨∨ ∃∃V2,T2. L ⊢ V1 ➡ V2 & L ⊢ U1 ➡ T2 &
243 | ∃∃a,V2,W,T1,T2. L ⊢ V1 ➡ V2 & L.ⓛW ⊢ T1 ➡ T2 &
244 U1 = ⓛ{a}W. T1 & U2 = ⓓ{a}V2. T2
245 | ∃∃a,V,V2,W1,W2,T1,T2. L ⊢ V1 ➡ V & ⇧[0,1] V ≡ V2 &
246 L ⊢ W1 ➡ W2 & L.ⓓW1 ⊢ T1 ➡ T2 &
247 U1 = ⓓ{a}W1. T1 & U2 = ⓓ{a}W2. ⓐV2. T2.
248 #L #V1 #U1 #U2 #H elim (cpr_inv_flat1 … H) -H *
256 (* Note: the main property of simple terms *)
257 lemma cpr_inv_appl1_simple: ∀L,V1,T1,U. L ⊢ ⓐV1. T1 ➡ U → 𝐒⦃T1⦄ →
258 ∃∃V2,T2. L ⊢ V1 ➡ V2 & L ⊢ T1 ➡ T2 &
260 #L #V1 #T1 #U #H #HT1
261 elim (cpr_inv_appl1 … H) -H *
263 | #a #V2 #W #U1 #U2 #_ #_ #H #_ destruct
264 elim (simple_inv_bind … HT1)
265 | #a #V #V2 #W1 #W2 #U1 #U2 #_ #_ #_ #_ #H #_ destruct
266 elim (simple_inv_bind … HT1)
270 (* Basic_1: includes: pr0_gen_cast pr2_gen_cast *)
271 lemma cpr_inv_cast1: ∀L,V1,U1,U2. L ⊢ ⓝ V1. U1 ➡ U2 → (
272 ∃∃V2,T2. L ⊢ V1 ➡ V2 & L ⊢ U1 ➡ T2 &
276 #L #V1 #U1 #U2 #H elim (cpr_inv_flat1 … H) -H *
279 | #a #V2 #W #T1 #T2 #_ #_ #_ #_ #H destruct
280 | #a #V #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #_ #_ #_ #H destruct
284 (* Basic forward lemmas *****************************************************)
286 lemma cpr_fwd_abst1: ∀a,L,V1,T1,U2. L ⊢ ⓛ{a}V1.T1 ➡ U2 → ∀I,W.
287 ∃∃V2,T2. L ⊢ V1 ➡ V2 & L. ⓑ{I} W ⊢ T1 ➡ T2 &
289 #a #L #V1 #T1 #U2 #H #I #W
290 elim (cpr_inv_abst1 … H) -H #V2 #T2 #HV12 #HT12 #H destruct
291 lapply (cpr_lsubr_trans … HT12 (L.ⓑ{I}W) ?) -HT12 /2 width=1/ /2 width=5/
295 lemma cpr_fwd_ext_abst1: ∀a,L,V1,T1,U2. L ⊢ ⓛ{a}V1.T1 ➡ U2 → ∀b,I,W.
296 ∃∃V2,T2. L ⊢ V1 ➡ V2 & L ⊢ ⓑ{b,I}W.T1 ➡ ⓑ{b,I}W.T2 &
298 #a #L #V1 #T1 #U2 #H #b #I #W
299 elim (cpr_fwd_abst1 … H I W) -H /3 width=5/
302 lemma cpr_fwd_bind1_minus: ∀I,L,V1,T1,T. L ⊢ -ⓑ{I}V1.T1 ➡ T → ∀b.
303 ∃∃V2,T2. L ⊢ ⓑ{b,I}V1.T1 ➡ ⓑ{b,I}V2.T2 &
305 #I #L #V1 #T1 #T #H #b
306 elim (cpr_inv_bind1 … H) -H *
307 [ #V2 #T2 #HV12 #HT12 #H destruct /3 width=4/
308 | #T2 #_ #_ #H destruct
312 lemma cpr_fwd_shift1: ∀L1,L,T1,T. L ⊢ L1 @@ T1 ➡ T →
313 ∃∃L2,T2. |L1| = |L2| & T = L2 @@ T2.
314 #L1 @(lenv_ind_dx … L1) -L1 normalize
316 @(ex2_2_intro … (⋆)) // (**) (* explicit constructor *)
317 | #I #L1 #V1 #IH #L #T1 #X
318 >shift_append_assoc normalize #H
319 elim (cpr_inv_bind1 … H) -H *
320 [ #V0 #T0 #_ #HT10 #H destruct
321 elim (IH … HT10) -IH -HT10 #L2 #T2 #HL12 #H destruct
322 >append_length >HL12 -HL12
323 @(ex2_2_intro … (⋆.ⓑ{I}V0@@L2) T2) [ >append_length ] // /2 width=3/ (**) (* explicit constructor *)
324 | #T #_ #_ #H destruct
329 (* Basic_1: removed theorems 11:
330 pr0_subst0_back pr0_subst0_fwd pr0_subst0
331 pr2_head_2 pr2_cflat clear_pr2_trans
332 pr2_gen_csort pr2_gen_cflat pr2_gen_cbind
333 pr2_gen_ctail pr2_ctail
335 (* Basic_1: removed local theorems 4:
336 pr0_delta_tau pr0_cong_delta
337 pr2_free_free pr2_free_delta