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_2A/notation/relations/pred_6.ma".
16 include "basic_2A/static/sd.ma".
17 include "basic_2A/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_st : ∀G,L,k,d. deg h g k (d+1) → cpx h g G L (⋆k) (⋆(next h k))
25 | cpx_delta: ∀I,G,L,K,V,V2,W2,i.
26 ⬇[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_eps : ∀G,L,V,T1,T2. cpx h g G L T1 T2 → cpx h g G L (ⓝV.T1) T2
37 | cpx_ct : ∀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
56 | /2 width=2 by cpx_st/
57 | #I #G #L1 #K1 #V1 #V2 #W2 #i #HLK1 #_ #HVW2 #IHV12 #L2 #HL12
58 elim (lsubr_fwd_drop2_pair … HL12 … HLK1) -HL12 -HLK1 *
59 /4 width=7 by cpx_delta, cpx_ct/
60 |4,9: /4 width=1 by cpx_bind, cpx_beta, lsubr_pair/
61 |5,7,8: /3 width=1 by cpx_flat, cpx_eps, cpx_ct/
62 |6,10: /4 width=3 by cpx_zeta, cpx_theta, lsubr_pair/
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 by cpx_bind, cpx_flat/
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
73 /2 width=7 by cpx_delta, cpx_bind, cpx_flat, cpx_zeta, cpx_eps, cpx_beta, cpx_theta/
76 lemma cpx_pair_sn: ∀h,g,I,G,L,V1,V2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 →
77 ∀T. ⦃G, L⦄ ⊢ ②{I}V1.T ➡[h, g] ②{I}V2.T.
78 #h #g * /2 width=1 by cpx_bind, cpx_flat/
81 lemma cpx_delift: ∀h,g,I,G,K,V,T1,L,l. ⬇[l] L ≡ (K.ⓑ{I}V) →
82 ∃∃T2,T. ⦃G, L⦄ ⊢ T1 ➡[h, g] T2 & ⬆[l, 1] T ≡ T2.
83 #h #g #I #G #K #V #T1 elim T1 -T1
84 [ * #i #L #l /2 width=4 by cpx_atom, lift_sort, lift_gref, ex2_2_intro/
85 elim (lt_or_eq_or_gt i l) #Hil [1,3: /3 width=4 by cpx_atom, lift_lref_ge_minus, lift_lref_lt, ex2_2_intro/ ]
87 elim (lift_total V 0 (i+1)) #W #HVW
88 elim (lift_split … HVW i i) /3 width=7 by cpx_delta, ex2_2_intro/
89 | * [ #a ] #I #W1 #U1 #IHW1 #IHU1 #L #l #HLK
90 elim (IHW1 … HLK) -IHW1 #W2 #W #HW12 #HW2
91 [ elim (IHU1 (L. ⓑ{I} W1) (l+1)) -IHU1 /3 width=9 by cpx_bind, drop_drop, lift_bind, ex2_2_intro/
92 | elim (IHU1 … HLK) -IHU1 -HLK /3 width=8 by cpx_flat, lift_flat, ex2_2_intro/
97 (* Basic inversion lemmas ***************************************************)
99 fact cpx_inv_atom1_aux: ∀h,g,G,L,T1,T2. ⦃G, L⦄ ⊢ T1 ➡[h, g] T2 → ∀J. T1 = ⓪{J} →
101 | ∃∃k,d. deg h g k (d+1) & T2 = ⋆(next h k) & J = Sort k
102 | ∃∃I,K,V,V2,i. ⬇[i] L ≡ K.ⓑ{I}V & ⦃G, K⦄ ⊢ V ➡[h, g] V2 &
103 ⬆[O, i+1] V2 ≡ T2 & J = LRef i.
104 #G #h #g #L #T1 #T2 * -L -T1 -T2
105 [ #I #G #L #J #H destruct /2 width=1 by or3_intro0/
106 | #G #L #k #d #Hkd #J #H destruct /3 width=5 by or3_intro1, ex3_2_intro/
107 | #I #G #L #K #V #V2 #T2 #i #HLK #HV2 #HVT2 #J #H destruct /3 width=9 by or3_intro2, ex4_5_intro/
108 | #a #I #G #L #V1 #V2 #T1 #T2 #_ #_ #J #H destruct
109 | #I #G #L #V1 #V2 #T1 #T2 #_ #_ #J #H destruct
110 | #G #L #V #T1 #T #T2 #_ #_ #J #H destruct
111 | #G #L #V #T1 #T2 #_ #J #H destruct
112 | #G #L #V1 #V2 #T #_ #J #H destruct
113 | #a #G #L #V1 #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #J #H destruct
114 | #a #G #L #V1 #V #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #_ #J #H destruct
118 lemma cpx_inv_atom1: ∀h,g,J,G,L,T2. ⦃G, L⦄ ⊢ ⓪{J} ➡[h, g] T2 →
120 | ∃∃k,d. deg h g k (d+1) & T2 = ⋆(next h k) & J = Sort k
121 | ∃∃I,K,V,V2,i. ⬇[i] L ≡ K.ⓑ{I}V & ⦃G, K⦄ ⊢ V ➡[h, g] V2 &
122 ⬆[O, i+1] V2 ≡ T2 & J = LRef i.
123 /2 width=3 by cpx_inv_atom1_aux/ qed-.
125 lemma cpx_inv_sort1: ∀h,g,G,L,T2,k. ⦃G, L⦄ ⊢ ⋆k ➡[h, g] T2 → T2 = ⋆k ∨
126 ∃∃d. deg h g k (d+1) & T2 = ⋆(next h k).
127 #h #g #G #L #T2 #k #H
128 elim (cpx_inv_atom1 … H) -H /2 width=1 by or_introl/ *
129 [ #k0 #d0 #Hkd0 #H1 #H2 destruct /3 width=4 by ex2_intro, or_intror/
130 | #I #K #V #V2 #i #_ #_ #_ #H destruct
134 lemma cpx_inv_lref1: ∀h,g,G,L,T2,i. ⦃G, L⦄ ⊢ #i ➡[h, g] T2 →
136 ∃∃I,K,V,V2. ⬇[i] L ≡ K. ⓑ{I}V & ⦃G, K⦄ ⊢ V ➡[h, g] V2 &
138 #h #g #G #L #T2 #i #H
139 elim (cpx_inv_atom1 … H) -H /2 width=1 by or_introl/ *
140 [ #k #d #_ #_ #H destruct
141 | #I #K #V #V2 #j #HLK #HV2 #HVT2 #H destruct /3 width=7 by ex3_4_intro, or_intror/
145 lemma cpx_inv_lref1_ge: ∀h,g,G,L,T2,i. ⦃G, L⦄ ⊢ #i ➡[h, g] T2 → |L| ≤ i → T2 = #i.
146 #h #g #G #L #T2 #i #H elim (cpx_inv_lref1 … H) -H // *
147 #I #K #V1 #V2 #HLK #_ #_ #HL -h -G -V2 lapply (drop_fwd_length_lt2 … HLK) -K -I -V1
148 #H elim (lt_refl_false i) /2 width=3 by lt_to_le_to_lt/
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 #d #_ #_ #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 #d #_ #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 by ex3_2_intro, or_introl/
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 by ex4_intro, or_intror/
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=5 by ex3_2_intro, ex3_intro, or_introl, or_intror/
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 *
202 [ /3 width=5 by ex3_2_intro/
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 #d #_ #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 by or5_intro0, ex3_2_intro/
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 by or5_intro1, conj/
229 | #G #L #V1 #V2 #T #HV12 #J #W #U1 #H destruct /3 width=1 by or5_intro2, conj/
230 | #a #G #L #V1 #V2 #W1 #W2 #T1 #T2 #HV12 #HW12 #HT12 #J #W #U1 #H destruct /3 width=11 by or5_intro3, ex6_6_intro/
231 | #a #G #L #V1 #V #V2 #W1 #W2 #T1 #T2 #HV1 #HV2 #HW12 #HT12 #J #W #U1 #H destruct /3 width=13 by or5_intro4, ex7_7_intro/
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 *
260 [ /3 width=5 by or3_intro0, ex3_2_intro/
262 | /3 width=11 by or3_intro1, ex5_6_intro/
263 | /3 width=13 by or3_intro2, ex6_7_intro/
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 *
273 [ /2 width=5 by ex3_2_intro/
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 *
287 [ /3 width=5 by or3_intro0, ex3_2_intro/
288 |2,3: /2 width=1 by or3_intro1, or3_intro2/
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 by cpx_bind, ex2_2_intro/
302 | #T2 #_ #_ #H destruct