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_4.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/substitution/lsubr.ma".
21 (* CONTEXT-SENSITIVE PARALLEL REDUCTION FOR TERMS ***************************)
24 (* Basic_1: includes: pr0_delta1 pr2_delta1 pr2_thin_dx *)
25 (* Note: cpr_flat: does not hold in basic_1 *)
26 inductive cpr: relation4 genv lenv term term ≝
27 | cpr_atom : ∀I,G,L. cpr G L (⓪{I}) (⓪{I})
28 | cpr_delta: ∀G,L,K,V,V2,W2,i.
29 ⇩[0, i] L ≡ K. ⓓV → cpr G K V V2 →
30 ⇧[0, i + 1] V2 ≡ W2 → cpr G L (#i) W2
31 | cpr_bind : ∀a,I,G,L,V1,V2,T1,T2.
32 cpr G L V1 V2 → cpr G (L.ⓑ{I}V1) T1 T2 →
33 cpr G L (ⓑ{a,I}V1.T1) (ⓑ{a,I}V2.T2)
34 | cpr_flat : ∀I,G,L,V1,V2,T1,T2.
35 cpr G L V1 V2 → cpr G L T1 T2 →
36 cpr G L (ⓕ{I}V1.T1) (ⓕ{I}V2.T2)
37 | cpr_zeta : ∀G,L,V,T1,T,T2. cpr G (L.ⓓV) T1 T →
38 ⇧[0, 1] T2 ≡ T → cpr G L (+ⓓV.T1) T2
39 | cpr_tau : ∀G,L,V,T1,T2. cpr G L T1 T2 → cpr G L (ⓝV.T1) T2
40 | cpr_beta : ∀a,G,L,V1,V2,W1,W2,T1,T2.
41 cpr G L V1 V2 → cpr G L W1 W2 → cpr G (L.ⓛW1) T1 T2 →
42 cpr G L (ⓐV1.ⓛ{a}W1.T1) (ⓓ{a}ⓝW2.V2.T2)
43 | cpr_theta: ∀a,G,L,V1,V,V2,W1,W2,T1,T2.
44 cpr G L V1 V → ⇧[0, 1] V ≡ V2 → cpr G L W1 W2 → cpr G (L.ⓓW1) T1 T2 →
45 cpr G L (ⓐV1.ⓓ{a}W1.T1) (ⓓ{a}W2.ⓐV2.T2)
48 interpretation "context-sensitive parallel reduction (term)"
49 'PRed G L T1 T2 = (cpr G L T1 T2).
51 (* Basic properties *********************************************************)
53 lemma lsubr_cpr_trans: ∀G. lsub_trans … (cpr G) lsubr.
54 #G #L1 #T1 #T2 #H elim H -G -L1 -T1 -T2
56 | #G #L1 #K1 #V1 #V2 #W2 #i #HLK1 #_ #HVW2 #IHV12 #L2 #HL12
57 elim (lsubr_fwd_ldrop2_abbr … HL12 … HLK1) -L1 * /3 width=6/
64 (* Basic_1: was by definition: pr2_free *)
65 lemma tpr_cpr: ∀G,T1,T2. ⦃G, ⋆⦄ ⊢ T1 ➡ T2 → ∀L. ⦃G, L⦄ ⊢ T1 ➡ T2.
67 lapply (lsubr_cpr_trans … HT12 L ?) //
70 (* Basic_1: includes by definition: pr0_refl *)
71 lemma cpr_refl: ∀G,T,L. ⦃G, L⦄ ⊢ T ➡ T.
72 #G #T elim T -T // * /2 width=1/
75 (* Basic_1: was: pr2_head_1 *)
76 lemma cpr_pair_sn: ∀I,G,L,V1,V2. ⦃G, L⦄ ⊢ V1 ➡ V2 →
77 ∀T. ⦃G, L⦄ ⊢ ②{I}V1.T ➡ ②{I}V2.T.
80 lemma cpr_delift: ∀G,K,V,T1,L,d. ⇩[0, d] L ≡ (K.ⓓV) →
81 ∃∃T2,T. ⦃G, L⦄ ⊢ T1 ➡ T2 & ⇧[d, 1] T ≡ T2.
82 #G #K #V #T1 elim T1 -T1
83 [ * #i #L #d #HLK /2 width=4/
84 elim (lt_or_eq_or_gt i d) #Hid [1,3: /3 width=4/ ]
86 elim (lift_total V 0 (i+1)) #W #HVW
87 elim (lift_split … HVW i i) // /3 width=6/
88 | * [ #a ] #I #W1 #U1 #IHW1 #IHU1 #L #d #HLK
89 elim (IHW1 … HLK) -IHW1 #W2 #W #HW12 #HW2
90 [ elim (IHU1 (L. ⓑ{I}W1) (d+1)) -IHU1 /2 width=1/ -HLK /3 width=9/
91 | elim (IHU1 … HLK) -IHU1 -HLK /3 width=8/
96 lemma cpr_append: ∀G. l_appendable_sn … (cpr G).
97 #G #K #T1 #T2 #H elim H -G -K -T1 -T2 // /2 width=1/ /2 width=3/
98 #G #K #K0 #V1 #V2 #W2 #i #HK0 #_ #HVW2 #IHV12 #L
99 lapply (ldrop_fwd_length_lt2 … HK0) #H
100 @(cpr_delta … (L@@K0) V1 … HVW2) //
101 @(ldrop_O1_append_sn_le … HK0) /2 width=2/ (**) (* /3/ does not work *)
104 (* Basic inversion lemmas ***************************************************)
106 fact cpr_inv_atom1_aux: ∀G,L,T1,T2. ⦃G, L⦄ ⊢ T1 ➡ T2 → ∀I. T1 = ⓪{I} →
108 ∃∃K,V,V2,i. ⇩[O, i] L ≡ K. ⓓV & ⦃G, K⦄ ⊢ V ➡ V2 &
109 ⇧[O, i + 1] V2 ≡ T2 & I = LRef i.
110 #G #L #T1 #T2 * -G -L -T1 -T2
111 [ #I #G #L #J #H destruct /2 width=1/
112 | #L #G #K #V #V2 #T2 #i #HLK #HV2 #HVT2 #J #H destruct /3 width=8/
113 | #a #I #G #L #V1 #V2 #T1 #T2 #_ #_ #J #H destruct
114 | #I #G #L #V1 #V2 #T1 #T2 #_ #_ #J #H destruct
115 | #G #L #V #T1 #T #T2 #_ #_ #J #H destruct
116 | #G #L #V #T1 #T2 #_ #J #H destruct
117 | #a #G #L #V1 #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #J #H destruct
118 | #a #G #L #V1 #V #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #_ #J #H destruct
122 lemma cpr_inv_atom1: ∀I,G,L,T2. ⦃G, L⦄ ⊢ ⓪{I} ➡ T2 →
124 ∃∃K,V,V2,i. ⇩[O, i] L ≡ K. ⓓV & ⦃G, K⦄ ⊢ V ➡ V2 &
125 ⇧[O, i + 1] V2 ≡ T2 & I = LRef i.
126 /2 width=3 by cpr_inv_atom1_aux/ qed-.
128 (* Basic_1: includes: pr0_gen_sort pr2_gen_sort *)
129 lemma cpr_inv_sort1: ∀G,L,T2,k. ⦃G, L⦄ ⊢ ⋆k ➡ T2 → T2 = ⋆k.
131 elim (cpr_inv_atom1 … H) -H //
132 * #K #V #V2 #i #_ #_ #_ #H destruct
135 (* Basic_1: includes: pr0_gen_lref pr2_gen_lref *)
136 lemma cpr_inv_lref1: ∀G,L,T2,i. ⦃G, L⦄ ⊢ #i ➡ T2 →
138 ∃∃K,V,V2. ⇩[O, i] L ≡ K. ⓓV & ⦃G, K⦄ ⊢ V ➡ V2 &
141 elim (cpr_inv_atom1 … H) -H /2 width=1/
142 * #K #V #V2 #j #HLK #HV2 #HVT2 #H destruct /3 width=6/
145 lemma cpr_inv_gref1: ∀G,L,T2,p. ⦃G, L⦄ ⊢ §p ➡ T2 → T2 = §p.
147 elim (cpr_inv_atom1 … H) -H //
148 * #K #V #V2 #i #_ #_ #_ #H destruct
151 fact cpr_inv_bind1_aux: ∀G,L,U1,U2. ⦃G, L⦄ ⊢ U1 ➡ U2 →
152 ∀a,I,V1,T1. U1 = ⓑ{a,I}V1. T1 → (
153 ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡ V2 & ⦃G, L.ⓑ{I}V1⦄ ⊢ T1 ➡ T2 &
156 ∃∃T. ⦃G, L.ⓓV1⦄ ⊢ T1 ➡ T & ⇧[0, 1] U2 ≡ T &
158 #G #L #U1 #U2 * -L -U1 -U2
159 [ #I #G #L #b #J #W1 #U1 #H destruct
160 | #L #G #K #V #V2 #W2 #i #_ #_ #_ #b #J #W #U1 #H destruct
161 | #a #I #G #L #V1 #V2 #T1 #T2 #HV12 #HT12 #b #J #W #U1 #H destruct /3 width=5/
162 | #I #G #L #V1 #V2 #T1 #T2 #_ #_ #b #J #W #U1 #H destruct
163 | #G #L #V #T1 #T #T2 #HT1 #HT2 #b #J #W #U1 #H destruct /3 width=3/
164 | #G #L #V #T1 #T2 #_ #b #J #W #U1 #H destruct
165 | #a #G #L #V1 #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #b #J #W #U1 #H destruct
166 | #a #G #L #V1 #V #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #_ #b #J #W #U1 #H destruct
170 lemma cpr_inv_bind1: ∀a,I,G,L,V1,T1,U2. ⦃G, L⦄ ⊢ ⓑ{a,I}V1.T1 ➡ U2 → (
171 ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡ V2 & ⦃G, L.ⓑ{I}V1⦄ ⊢ T1 ➡ T2 &
174 ∃∃T. ⦃G, L.ⓓV1⦄ ⊢ T1 ➡ T & ⇧[0, 1] U2 ≡ T &
176 /2 width=3 by cpr_inv_bind1_aux/ qed-.
178 (* Basic_1: includes: pr0_gen_abbr pr2_gen_abbr *)
179 lemma cpr_inv_abbr1: ∀a,G,L,V1,T1,U2. ⦃G, L⦄ ⊢ ⓓ{a}V1.T1 ➡ U2 → (
180 ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡ V2 & ⦃G, L. ⓓV1⦄ ⊢ T1 ➡ T2 &
183 ∃∃T. ⦃G, L.ⓓV1⦄ ⊢ T1 ➡ T & ⇧[0, 1] U2 ≡ T & a = true.
184 #a #G #L #V1 #T1 #U2 #H
185 elim (cpr_inv_bind1 … H) -H * /3 width=3/ /3 width=5/
188 (* Basic_1: includes: pr0_gen_abst pr2_gen_abst *)
189 lemma cpr_inv_abst1: ∀a,G,L,V1,T1,U2. ⦃G, L⦄ ⊢ ⓛ{a}V1.T1 ➡ U2 →
190 ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡ V2 & ⦃G, L.ⓛV1⦄ ⊢ T1 ➡ T2 &
192 #a #G #L #V1 #T1 #U2 #H
193 elim (cpr_inv_bind1 … H) -H *
195 | #T #_ #_ #_ #H destruct
199 fact cpr_inv_flat1_aux: ∀G,L,U,U2. ⦃G, L⦄ ⊢ U ➡ U2 →
200 ∀I,V1,U1. U = ⓕ{I}V1.U1 →
201 ∨∨ ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡ V2 & ⦃G, L⦄ ⊢ U1 ➡ T2 &
203 | (⦃G, L⦄ ⊢ U1 ➡ U2 ∧ I = Cast)
204 | ∃∃a,V2,W1,W2,T1,T2. ⦃G, L⦄ ⊢ V1 ➡ V2 & ⦃G, L⦄ ⊢ W1 ➡ W2 &
205 ⦃G, L.ⓛW1⦄ ⊢ T1 ➡ T2 & U1 = ⓛ{a}W1.T1 &
206 U2 = ⓓ{a}ⓝW2.V2.T2 & I = Appl
207 | ∃∃a,V,V2,W1,W2,T1,T2. ⦃G, L⦄ ⊢ V1 ➡ V & ⇧[0,1] V ≡ V2 &
208 ⦃G, L⦄ ⊢ W1 ➡ W2 & ⦃G, L.ⓓW1⦄ ⊢ T1 ➡ T2 &
210 U2 = ⓓ{a}W2.ⓐV2.T2 & I = Appl.
211 #G #L #U #U2 * -L -U -U2
212 [ #I #G #L #J #W1 #U1 #H destruct
213 | #G #L #K #V #V2 #W2 #i #_ #_ #_ #J #W #U1 #H destruct
214 | #a #I #G #L #V1 #V2 #T1 #T2 #_ #_ #J #W #U1 #H destruct
215 | #I #G #L #V1 #V2 #T1 #T2 #HV12 #HT12 #J #W #U1 #H destruct /3 width=5/
216 | #G #L #V #T1 #T #T2 #_ #_ #J #W #U1 #H destruct
217 | #G #L #V #T1 #T2 #HT12 #J #W #U1 #H destruct /3 width=1/
218 | #a #G #L #V1 #V2 #W1 #W2 #T1 #T2 #HV12 #HW12 #HT12 #J #W #U1 #H destruct /3 width=11/
219 | #a #G #L #V1 #V #V2 #W1 #W2 #T1 #T2 #HV1 #HV2 #HW12 #HT12 #J #W #U1 #H destruct /3 width=13/
223 lemma cpr_inv_flat1: ∀I,G,L,V1,U1,U2. ⦃G, L⦄ ⊢ ⓕ{I}V1.U1 ➡ U2 →
224 ∨∨ ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡ V2 & ⦃G, L⦄ ⊢ U1 ➡ T2 &
226 | (⦃G, L⦄ ⊢ U1 ➡ U2 ∧ I = Cast)
227 | ∃∃a,V2,W1,W2,T1,T2. ⦃G, L⦄ ⊢ V1 ➡ V2 & ⦃G, L⦄ ⊢ W1 ➡ W2 &
228 ⦃G, L.ⓛW1⦄ ⊢ T1 ➡ T2 & U1 = ⓛ{a}W1.T1 &
229 U2 = ⓓ{a}ⓝW2.V2.T2 & I = Appl
230 | ∃∃a,V,V2,W1,W2,T1,T2. ⦃G, L⦄ ⊢ V1 ➡ V & ⇧[0,1] V ≡ V2 &
231 ⦃G, L⦄ ⊢ W1 ➡ W2 & ⦃G, L.ⓓW1⦄ ⊢ T1 ➡ T2 &
233 U2 = ⓓ{a}W2.ⓐV2.T2 & I = Appl.
234 /2 width=3 by cpr_inv_flat1_aux/ qed-.
236 (* Basic_1: includes: pr0_gen_appl pr2_gen_appl *)
237 lemma cpr_inv_appl1: ∀G,L,V1,U1,U2. ⦃G, L⦄ ⊢ ⓐV1.U1 ➡ U2 →
238 ∨∨ ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡ V2 & ⦃G, L⦄ ⊢ U1 ➡ T2 &
240 | ∃∃a,V2,W1,W2,T1,T2. ⦃G, L⦄ ⊢ V1 ➡ V2 & ⦃G, L⦄ ⊢ W1 ➡ W2 &
241 ⦃G, L.ⓛW1⦄ ⊢ T1 ➡ T2 &
242 U1 = ⓛ{a}W1.T1 & U2 = ⓓ{a}ⓝW2.V2.T2
243 | ∃∃a,V,V2,W1,W2,T1,T2. ⦃G, L⦄ ⊢ V1 ➡ V & ⇧[0,1] V ≡ V2 &
244 ⦃G, L⦄ ⊢ W1 ➡ W2 & ⦃G, L.ⓓW1⦄ ⊢ T1 ➡ T2 &
245 U1 = ⓓ{a}W1.T1 & U2 = ⓓ{a}W2.ⓐV2.T2.
246 #G #L #V1 #U1 #U2 #H elim (cpr_inv_flat1 … H) -H *
254 (* Note: the main property of simple terms *)
255 lemma cpr_inv_appl1_simple: ∀G,L,V1,T1,U. ⦃G, L⦄ ⊢ ⓐV1. T1 ➡ U → 𝐒⦃T1⦄ →
256 ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡ V2 & ⦃G, L⦄ ⊢ T1 ➡ T2 &
258 #G #L #V1 #T1 #U #H #HT1
259 elim (cpr_inv_appl1 … H) -H *
261 | #a #V2 #W1 #W2 #U1 #U2 #_ #_ #_ #H #_ destruct
262 elim (simple_inv_bind … HT1)
263 | #a #V #V2 #W1 #W2 #U1 #U2 #_ #_ #_ #_ #H #_ destruct
264 elim (simple_inv_bind … HT1)
268 (* Basic_1: includes: pr0_gen_cast pr2_gen_cast *)
269 lemma cpr_inv_cast1: ∀G,L,V1,U1,U2. ⦃G, L⦄ ⊢ ⓝ V1. U1 ➡ U2 → (
270 ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡ V2 & ⦃G, L⦄ ⊢ U1 ➡ T2 &
272 ) ∨ ⦃G, L⦄ ⊢ U1 ➡ U2.
273 #G #L #V1 #U1 #U2 #H elim (cpr_inv_flat1 … H) -H *
276 | #a #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #_ #_ #H destruct
277 | #a #V #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #_ #_ #_ #H destruct
281 (* Basic forward lemmas *****************************************************)
283 lemma cpr_fwd_bind1_minus: ∀I,G,L,V1,T1,T. ⦃G, L⦄ ⊢ -ⓑ{I}V1.T1 ➡ T → ∀b.
284 ∃∃V2,T2. ⦃G, L⦄ ⊢ ⓑ{b,I}V1.T1 ➡ ⓑ{b,I}V2.T2 &
286 #I #G #L #V1 #T1 #T #H #b
287 elim (cpr_inv_bind1 … H) -H *
288 [ #V2 #T2 #HV12 #HT12 #H destruct /3 width=4/
289 | #T2 #_ #_ #H destruct
293 lemma cpr_fwd_shift1: ∀G,L1,L,T1,T. ⦃G, L⦄ ⊢ L1 @@ T1 ➡ T →
294 ∃∃L2,T2. |L1| = |L2| & T = L2 @@ T2.
295 #G #L1 @(lenv_ind_dx … L1) -L1 normalize
297 @(ex2_2_intro … (⋆)) // (**) (* explicit constructor *)
298 | #I #L1 #V1 #IH #L #T1 #X
299 >shift_append_assoc normalize #H
300 elim (cpr_inv_bind1 … H) -H *
301 [ #V0 #T0 #_ #HT10 #H destruct
302 elim (IH … HT10) -IH -HT10 #L2 #T2 #HL12 #H destruct
303 >append_length >HL12 -HL12
304 @(ex2_2_intro … (⋆.ⓑ{I}V0@@L2) T2) [ >append_length ] // /2 width=3/ (**) (* explicit constructor *)
305 | #T #_ #_ #H destruct
310 (* Basic_1: removed theorems 11:
311 pr0_subst0_back pr0_subst0_fwd pr0_subst0
312 pr2_head_2 pr2_cflat clear_pr2_trans
313 pr2_gen_csort pr2_gen_cflat pr2_gen_cbind
314 pr2_gen_ctail pr2_ctail
316 (* Basic_1: removed local theorems 4:
317 pr0_delta_tau pr0_cong_delta
318 pr2_free_free pr2_free_delta