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 "ground/xoa/ex_3_4.ma".
16 include "ground/xoa/ex_4_5.ma".
17 include "ground/xoa/or_5.ma".
18 include "basic_2A/notation/relations/pred_6.ma".
19 include "basic_2A/static/sd.ma".
20 include "basic_2A/reduction/cpr.ma".
22 (* CONTEXT-SENSITIVE EXTENDED PARALLEL REDUCTION FOR TERMS ******************)
25 inductive cpx (h) (g): relation4 genv lenv term term ≝
26 | cpx_atom : ∀I,G,L. cpx h g G L (⓪{I}) (⓪{I})
27 | cpx_st : ∀G,L,k,d. deg h g k (d+1) → cpx h g G L (⋆k) (⋆(next h k))
28 | cpx_delta: ∀I,G,L,K,V,V2,W2,i.
29 ⬇[i] L ≡ K.ⓑ{I}V → cpx h g G K V V2 →
30 ⬆[0, i+1] V2 ≡ W2 → cpx h g G L (#i) W2
31 | cpx_bind : ∀a,I,G,L,V1,V2,T1,T2.
32 cpx h g G L V1 V2 → cpx h g G (L.ⓑ{I}V1) T1 T2 →
33 cpx h g G L (ⓑ{a,I}V1.T1) (ⓑ{a,I}V2.T2)
34 | cpx_flat : ∀I,G,L,V1,V2,T1,T2.
35 cpx h g G L V1 V2 → cpx h g G L T1 T2 →
36 cpx h g G L (ⓕ{I}V1.T1) (ⓕ{I}V2.T2)
37 | cpx_zeta : ∀G,L,V,T1,T,T2. cpx h g G (L.ⓓV) T1 T →
38 ⬆[0, 1] T2 ≡ T → cpx h g G L (+ⓓV.T1) T2
39 | cpx_eps : ∀G,L,V,T1,T2. cpx h g G L T1 T2 → cpx h g G L (ⓝV.T1) T2
40 | cpx_ct : ∀G,L,V1,V2,T. cpx h g G L V1 V2 → cpx h g G L (ⓝV1.T) V2
41 | cpx_beta : ∀a,G,L,V1,V2,W1,W2,T1,T2.
42 cpx h g G L V1 V2 → cpx h g G L W1 W2 → cpx h g G (L.ⓛW1) T1 T2 →
43 cpx h g G L (ⓐV1.ⓛ{a}W1.T1) (ⓓ{a}ⓝW2.V2.T2)
44 | cpx_theta: ∀a,G,L,V1,V,V2,W1,W2,T1,T2.
45 cpx h g G L V1 V → ⬆[0, 1] V ≡ V2 → cpx h g G L W1 W2 →
46 cpx h g G (L.ⓓW1) T1 T2 →
47 cpx h g G L (ⓐV1.ⓓ{a}W1.T1) (ⓓ{a}W2.ⓐV2.T2)
51 "context-sensitive extended parallel reduction (term)"
52 'PRed h g G L T1 T2 = (cpx h g G L T1 T2).
54 (* Basic properties *********************************************************)
56 lemma lsubr_cpx_trans: ∀h,g,G. lsub_trans … (cpx h g G) lsubr.
57 #h #g #G #L1 #T1 #T2 #H elim H -G -L1 -T1 -T2
59 | /2 width=2 by cpx_st/
60 | #I #G #L1 #K1 #V1 #V2 #W2 #i #HLK1 #_ #HVW2 #IHV12 #L2 #HL12
61 elim (lsubr_fwd_drop2_pair … HL12 … HLK1) -HL12 -HLK1 *
62 /4 width=7 by cpx_delta, cpx_ct/
63 |4,9: /4 width=1 by cpx_bind, cpx_beta, lsubr_pair/
64 |5,7,8: /3 width=1 by cpx_flat, cpx_eps, cpx_ct/
65 |6,10: /4 width=3 by cpx_zeta, cpx_theta, lsubr_pair/
69 (* Note: this is "∀h,g,L. reflexive … (cpx h g L)" *)
70 lemma cpx_refl: ∀h,g,G,T,L. ⦃G, L⦄ ⊢ T ➡[h, g] T.
71 #h #g #G #T elim T -T // * /2 width=1 by cpx_bind, cpx_flat/
74 lemma cpr_cpx: ∀h,g,G,L,T1,T2. ⦃G, L⦄ ⊢ T1 ➡ T2 → ⦃G, L⦄ ⊢ T1 ➡[h, g] T2.
75 #h #g #G #L #T1 #T2 #H elim H -L -T1 -T2
76 /2 width=7 by cpx_delta, cpx_bind, cpx_flat, cpx_zeta, cpx_eps, cpx_beta, cpx_theta/
79 lemma cpx_pair_sn: ∀h,g,I,G,L,V1,V2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 →
80 ∀T. ⦃G, L⦄ ⊢ ②{I}V1.T ➡[h, g] ②{I}V2.T.
81 #h #g * /2 width=1 by cpx_bind, cpx_flat/
84 lemma cpx_delift: ∀h,g,I,G,K,V,T1,L,l. ⬇[l] L ≡ (K.ⓑ{I}V) →
85 ∃∃T2,T. ⦃G, L⦄ ⊢ T1 ➡[h, g] T2 & ⬆[l, 1] T ≡ T2.
86 #h #g #I #G #K #V #T1 elim T1 -T1
87 [ * #i #L #l /2 width=4 by cpx_atom, lift_sort, lift_gref, ex2_2_intro/
88 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/ ]
90 elim (lift_total V 0 (i+1)) #W #HVW
91 elim (lift_split … HVW i i) /3 width=7 by cpx_delta, ex2_2_intro/
92 | * [ #a ] #I #W1 #U1 #IHW1 #IHU1 #L #l #HLK
93 elim (IHW1 … HLK) -IHW1 #W2 #W #HW12 #HW2
94 [ elim (IHU1 (L. ⓑ{I} W1) (l+1)) -IHU1 /3 width=9 by cpx_bind, drop_drop, lift_bind, ex2_2_intro/
95 | elim (IHU1 … HLK) -IHU1 -HLK /3 width=8 by cpx_flat, lift_flat, ex2_2_intro/
100 (* Basic inversion lemmas ***************************************************)
102 fact cpx_inv_atom1_aux: ∀h,g,G,L,T1,T2. ⦃G, L⦄ ⊢ T1 ➡[h, g] T2 → ∀J. T1 = ⓪{J} →
104 | ∃∃k,d. deg h g k (d+1) & T2 = ⋆(next h k) & J = Sort k
105 | ∃∃I,K,V,V2,i. ⬇[i] L ≡ K.ⓑ{I}V & ⦃G, K⦄ ⊢ V ➡[h, g] V2 &
106 ⬆[O, i+1] V2 ≡ T2 & J = LRef i.
107 #G #h #g #L #T1 #T2 * -L -T1 -T2
108 [ #I #G #L #J #H destruct /2 width=1 by or3_intro0/
109 | #G #L #k #d #Hkd #J #H destruct /3 width=5 by or3_intro1, ex3_2_intro/
110 | #I #G #L #K #V #V2 #T2 #i #HLK #HV2 #HVT2 #J #H destruct /3 width=9 by or3_intro2, ex4_5_intro/
111 | #a #I #G #L #V1 #V2 #T1 #T2 #_ #_ #J #H destruct
112 | #I #G #L #V1 #V2 #T1 #T2 #_ #_ #J #H destruct
113 | #G #L #V #T1 #T #T2 #_ #_ #J #H destruct
114 | #G #L #V #T1 #T2 #_ #J #H destruct
115 | #G #L #V1 #V2 #T #_ #J #H destruct
116 | #a #G #L #V1 #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #J #H destruct
117 | #a #G #L #V1 #V #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #_ #J #H destruct
121 lemma cpx_inv_atom1: ∀h,g,J,G,L,T2. ⦃G, L⦄ ⊢ ⓪{J} ➡[h, g] T2 →
123 | ∃∃k,d. deg h g k (d+1) & T2 = ⋆(next h k) & J = Sort k
124 | ∃∃I,K,V,V2,i. ⬇[i] L ≡ K.ⓑ{I}V & ⦃G, K⦄ ⊢ V ➡[h, g] V2 &
125 ⬆[O, i+1] V2 ≡ T2 & J = LRef i.
126 /2 width=3 by cpx_inv_atom1_aux/ qed-.
128 lemma cpx_inv_sort1: ∀h,g,G,L,T2,k. ⦃G, L⦄ ⊢ ⋆k ➡[h, g] T2 → T2 = ⋆k ∨
129 ∃∃d. deg h g k (d+1) & T2 = ⋆(next h k).
130 #h #g #G #L #T2 #k #H
131 elim (cpx_inv_atom1 … H) -H /2 width=1 by or_introl/ *
132 [ #k0 #d0 #Hkd0 #H1 #H2 destruct /3 width=4 by ex2_intro, or_intror/
133 | #I #K #V #V2 #i #_ #_ #_ #H destruct
137 lemma cpx_inv_lref1: ∀h,g,G,L,T2,i. ⦃G, L⦄ ⊢ #i ➡[h, g] T2 →
139 ∃∃I,K,V,V2. ⬇[i] L ≡ K. ⓑ{I}V & ⦃G, K⦄ ⊢ V ➡[h, g] V2 &
141 #h #g #G #L #T2 #i #H
142 elim (cpx_inv_atom1 … H) -H /2 width=1 by or_introl/ *
143 [ #k #d #_ #_ #H destruct
144 | #I #K #V #V2 #j #HLK #HV2 #HVT2 #H destruct /3 width=7 by ex3_4_intro, or_intror/
148 lemma cpx_inv_lref1_ge: ∀h,g,G,L,T2,i. ⦃G, L⦄ ⊢ #i ➡[h, g] T2 → |L| ≤ i → T2 = #i.
149 #h #g #G #L #T2 #i #H elim (cpx_inv_lref1 … H) -H // *
150 #I #K #V1 #V2 #HLK #_ #_ #HL -h -G -V2 lapply (drop_fwd_length_lt2 … HLK) -K -I -V1
151 #H elim (lt_refl_false i) /2 width=3 by lt_to_le_to_lt/
154 lemma cpx_inv_gref1: ∀h,g,G,L,T2,p. ⦃G, L⦄ ⊢ §p ➡[h, g] T2 → T2 = §p.
155 #h #g #G #L #T2 #p #H
156 elim (cpx_inv_atom1 … H) -H // *
157 [ #k #d #_ #_ #H destruct
158 | #I #K #V #V2 #i #_ #_ #_ #H destruct
162 fact cpx_inv_bind1_aux: ∀h,g,G,L,U1,U2. ⦃G, L⦄ ⊢ U1 ➡[h, g] U2 →
163 ∀a,J,V1,T1. U1 = ⓑ{a,J}V1.T1 → (
164 ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L.ⓑ{J}V1⦄ ⊢ T1 ➡[h, g] T2 &
167 ∃∃T. ⦃G, L.ⓓV1⦄ ⊢ T1 ➡[h, g] T & ⬆[0, 1] U2 ≡ T &
169 #h #g #G #L #U1 #U2 * -L -U1 -U2
170 [ #I #G #L #b #J #W #U1 #H destruct
171 | #G #L #k #d #_ #b #J #W #U1 #H destruct
172 | #I #G #L #K #V #V2 #W2 #i #_ #_ #_ #b #J #W #U1 #H destruct
173 | #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/
174 | #I #G #L #V1 #V2 #T1 #T2 #_ #_ #b #J #W #U1 #H destruct
175 | #G #L #V #T1 #T #T2 #HT1 #HT2 #b #J #W #U1 #H destruct /3 width=3 by ex4_intro, or_intror/
176 | #G #L #V #T1 #T2 #_ #b #J #W #U1 #H destruct
177 | #G #L #V1 #V2 #T #_ #b #J #W #U1 #H destruct
178 | #a #G #L #V1 #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #b #J #W #U1 #H destruct
179 | #a #G #L #V1 #V #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #_ #b #J #W #U1 #H destruct
183 lemma cpx_inv_bind1: ∀h,g,a,I,G,L,V1,T1,U2. ⦃G, L⦄ ⊢ ⓑ{a,I}V1.T1 ➡[h, g] U2 → (
184 ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L.ⓑ{I}V1⦄ ⊢ T1 ➡[h, g] T2 &
187 ∃∃T. ⦃G, L.ⓓV1⦄ ⊢ T1 ➡[h, g] T & ⬆[0, 1] U2 ≡ T &
189 /2 width=3 by cpx_inv_bind1_aux/ qed-.
191 lemma cpx_inv_abbr1: ∀h,g,a,G,L,V1,T1,U2. ⦃G, L⦄ ⊢ ⓓ{a}V1.T1 ➡[h, g] U2 → (
192 ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L.ⓓV1⦄ ⊢ T1 ➡[h, g] T2 &
195 ∃∃T. ⦃G, L.ⓓV1⦄ ⊢ T1 ➡[h, g] T & ⬆[0, 1] U2 ≡ T & a = true.
196 #h #g #a #G #L #V1 #T1 #U2 #H
197 elim (cpx_inv_bind1 … H) -H * /3 width=5 by ex3_2_intro, ex3_intro, or_introl, or_intror/
200 lemma cpx_inv_abst1: ∀h,g,a,G,L,V1,T1,U2. ⦃G, L⦄ ⊢ ⓛ{a}V1.T1 ➡[h, g] U2 →
201 ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L.ⓛV1⦄ ⊢ T1 ➡[h, g] T2 &
203 #h #g #a #G #L #V1 #T1 #U2 #H
204 elim (cpx_inv_bind1 … H) -H *
205 [ /3 width=5 by ex3_2_intro/
206 | #T #_ #_ #_ #H destruct
210 fact cpx_inv_flat1_aux: ∀h,g,G,L,U,U2. ⦃G, L⦄ ⊢ U ➡[h, g] U2 →
211 ∀J,V1,U1. U = ⓕ{J}V1.U1 →
212 ∨∨ ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L⦄ ⊢ U1 ➡[h, g] T2 &
214 | (⦃G, L⦄ ⊢ U1 ➡[h, g] U2 ∧ J = Cast)
215 | (⦃G, L⦄ ⊢ V1 ➡[h, g] U2 ∧ J = Cast)
216 | ∃∃a,V2,W1,W2,T1,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L⦄ ⊢ W1 ➡[h, g] W2 &
217 ⦃G, L.ⓛW1⦄ ⊢ T1 ➡[h, g] T2 &
219 U2 = ⓓ{a}ⓝW2.V2.T2 & J = Appl
220 | ∃∃a,V,V2,W1,W2,T1,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V & ⬆[0,1] V ≡ V2 &
221 ⦃G, L⦄ ⊢ W1 ➡[h, g] W2 & ⦃G, L.ⓓW1⦄ ⊢ T1 ➡[h, g] T2 &
223 U2 = ⓓ{a}W2.ⓐV2.T2 & J = Appl.
224 #h #g #G #L #U #U2 * -L -U -U2
225 [ #I #G #L #J #W #U1 #H destruct
226 | #G #L #k #d #_ #J #W #U1 #H destruct
227 | #I #G #L #K #V #V2 #W2 #i #_ #_ #_ #J #W #U1 #H destruct
228 | #a #I #G #L #V1 #V2 #T1 #T2 #_ #_ #J #W #U1 #H destruct
229 | #I #G #L #V1 #V2 #T1 #T2 #HV12 #HT12 #J #W #U1 #H destruct /3 width=5 by or5_intro0, ex3_2_intro/
230 | #G #L #V #T1 #T #T2 #_ #_ #J #W #U1 #H destruct
231 | #G #L #V #T1 #T2 #HT12 #J #W #U1 #H destruct /3 width=1 by or5_intro1, conj/
232 | #G #L #V1 #V2 #T #HV12 #J #W #U1 #H destruct /3 width=1 by or5_intro2, conj/
233 | #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/
234 | #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/
238 lemma cpx_inv_flat1: ∀h,g,I,G,L,V1,U1,U2. ⦃G, L⦄ ⊢ ⓕ{I}V1.U1 ➡[h, g] U2 →
239 ∨∨ ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L⦄ ⊢ U1 ➡[h, g] T2 &
241 | (⦃G, L⦄ ⊢ U1 ➡[h, g] U2 ∧ I = Cast)
242 | (⦃G, L⦄ ⊢ V1 ➡[h, g] U2 ∧ I = Cast)
243 | ∃∃a,V2,W1,W2,T1,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L⦄ ⊢ W1 ➡[h, g] W2 &
244 ⦃G, L.ⓛW1⦄ ⊢ T1 ➡[h, g] T2 &
246 U2 = ⓓ{a}ⓝW2.V2.T2 & I = Appl
247 | ∃∃a,V,V2,W1,W2,T1,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V & ⬆[0,1] V ≡ V2 &
248 ⦃G, L⦄ ⊢ W1 ➡[h, g] W2 & ⦃G, L.ⓓW1⦄ ⊢ T1 ➡[h, g] T2 &
250 U2 = ⓓ{a}W2.ⓐV2.T2 & I = Appl.
251 /2 width=3 by cpx_inv_flat1_aux/ qed-.
253 lemma cpx_inv_appl1: ∀h,g,G,L,V1,U1,U2. ⦃G, L⦄ ⊢ ⓐ V1.U1 ➡[h, g] U2 →
254 ∨∨ ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L⦄ ⊢ U1 ➡[h, g] T2 &
256 | ∃∃a,V2,W1,W2,T1,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L⦄ ⊢ W1 ➡[h, g] W2 &
257 ⦃G, L.ⓛW1⦄ ⊢ T1 ➡[h, g] T2 &
258 U1 = ⓛ{a}W1.T1 & U2 = ⓓ{a}ⓝW2.V2.T2
259 | ∃∃a,V,V2,W1,W2,T1,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V & ⬆[0,1] V ≡ V2 &
260 ⦃G, L⦄ ⊢ W1 ➡[h, g] W2 & ⦃G, L.ⓓW1⦄ ⊢ T1 ➡[h, g] T2 &
261 U1 = ⓓ{a}W1.T1 & U2 = ⓓ{a}W2. ⓐV2. T2.
262 #h #g #G #L #V1 #U1 #U2 #H elim (cpx_inv_flat1 … H) -H *
263 [ /3 width=5 by or3_intro0, ex3_2_intro/
265 | /3 width=11 by or3_intro1, ex5_6_intro/
266 | /3 width=13 by or3_intro2, ex6_7_intro/
270 (* Note: the main property of simple terms *)
271 lemma cpx_inv_appl1_simple: ∀h,g,G,L,V1,T1,U. ⦃G, L⦄ ⊢ ⓐV1.T1 ➡[h, g] U → 𝐒⦃T1⦄ →
272 ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L⦄ ⊢ T1 ➡[h, g] T2 &
274 #h #g #G #L #V1 #T1 #U #H #HT1
275 elim (cpx_inv_appl1 … H) -H *
276 [ /2 width=5 by ex3_2_intro/
277 | #a #V2 #W1 #W2 #U1 #U2 #_ #_ #_ #H #_ destruct
278 elim (simple_inv_bind … HT1)
279 | #a #V #V2 #W1 #W2 #U1 #U2 #_ #_ #_ #_ #H #_ destruct
280 elim (simple_inv_bind … HT1)
284 lemma cpx_inv_cast1: ∀h,g,G,L,V1,U1,U2. ⦃G, L⦄ ⊢ ⓝV1.U1 ➡[h, g] U2 →
285 ∨∨ ∃∃V2,T2. ⦃G, L⦄ ⊢ V1 ➡[h, g] V2 & ⦃G, L⦄ ⊢ U1 ➡[h, g] T2 &
287 | ⦃G, L⦄ ⊢ U1 ➡[h, g] U2
288 | ⦃G, L⦄ ⊢ V1 ➡[h, g] U2.
289 #h #g #G #L #V1 #U1 #U2 #H elim (cpx_inv_flat1 … H) -H *
290 [ /3 width=5 by or3_intro0, ex3_2_intro/
291 |2,3: /2 width=1 by or3_intro1, or3_intro2/
292 | #a #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #_ #_ #H destruct
293 | #a #V #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #_ #_ #_ #H destruct
297 (* Basic forward lemmas *****************************************************)
299 lemma cpx_fwd_bind1_minus: ∀h,g,I,G,L,V1,T1,T. ⦃G, L⦄ ⊢ -ⓑ{I}V1.T1 ➡[h, g] T → ∀b.
300 ∃∃V2,T2. ⦃G, L⦄ ⊢ ⓑ{b,I}V1.T1 ➡[h, g] ⓑ{b,I}V2.T2 &
302 #h #g #I #G #L #V1 #T1 #T #H #b
303 elim (cpx_inv_bind1 … H) -H *
304 [ #V2 #T2 #HV12 #HT12 #H destruct /3 width=4 by cpx_bind, ex2_2_intro/
305 | #T2 #_ #_ #H destruct