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/static/ssta.ma".
16 include "basic_2/reduction/cpr.ma".
18 (* CONTEXT-SENSITIVE EXTENDED PARALLEL REDUCTION FOR TERMS ******************)
20 inductive cpx (h) (g): lenv → relation term ≝
21 | cpx_atom : ∀I,L. cpx h g L (⓪{I}) (⓪{I})
22 | cpx_sort : ∀L,k,l. deg h g k (l+1) → cpx h g L (⋆k) (⋆(next h k))
23 | cpx_delta: ∀I,L,K,V,V2,W2,i.
24 ⇩[0, i] L ≡ K.ⓑ{I}V → cpx h g K V V2 →
25 ⇧[0, i + 1] V2 ≡ W2 → cpx h g L (#i) W2
26 | cpx_bind : ∀a,I,L,V1,V2,T1,T2.
27 cpx h g L V1 V2 → cpx h g (L. ⓑ{I} V1) T1 T2 →
28 cpx h g L (ⓑ{a,I} V1. T1) (ⓑ{a,I} V2. T2)
29 | cpx_flat : ∀I,L,V1,V2,T1,T2.
30 cpx h g L V1 V2 → cpx h g L T1 T2 →
31 cpx h g L (ⓕ{I} V1. T1) (ⓕ{I} V2. T2)
32 | cpx_zeta : ∀L,V,T1,T,T2. cpx h g (L.ⓓV) T1 T →
33 ⇧[0, 1] T2 ≡ T → cpx h g L (+ⓓV. T1) T2
34 | cpx_tau : ∀L,V,T1,T2. cpx h g L T1 T2 → cpx h g L (ⓝV. T1) T2
35 | cpx_beta : ∀a,L,V1,V2,W,T1,T2.
36 cpx h g L V1 V2 → cpx h g (L.ⓛW) T1 T2 →
37 cpx h g L (ⓐV1. ⓛ{a}W. T1) (ⓓ{a}V2. T2)
38 | cpx_theta: ∀a,L,V1,V,V2,W1,W2,T1,T2.
39 cpx h g L V1 V → ⇧[0, 1] V ≡ V2 → cpx h g L W1 W2 → cpx h g (L.ⓓW1) T1 T2 →
40 cpx h g L (ⓐV1. ⓓ{a}W1. T1) (ⓓ{a}W2. ⓐV2. T2)
44 "context-sensitive extended parallel reduction (term)"
45 'PRed h g L T1 T2 = (cpx h g L T1 T2).
47 (* Basic properties *********************************************************)
49 (* Note: this is "∀h,g,L. reflexive … (cpx h g L)" *)
50 lemma cpx_refl: ∀h,g,T,L. ⦃h, L⦄ ⊢ T ➡[g] T.
51 #h #g #T elim T -T // * /2 width=1/
54 lemma cpr_cpx: ∀h,g,L,T1,T2. L ⊢ T1 ➡ T2 → ⦃h, L⦄ ⊢ T1 ➡[g] T2.
55 #h #g #L #T1 #T2 #H elim H -L -T1 -T2 // /2 width=1/ /2 width=3/ /2 width=7/
58 fact ssta_cpx_aux: ∀h,g,L,T1,T2,l0. ⦃h, L⦄ ⊢ T1 •[g] ⦃l0, T2⦄ →
59 ∀l. l0 = l+1 → ⦃h, L⦄ ⊢ T1 ➡[g] T2.
60 #h #g #L #T1 #T2 #l0 #H elim H -L -T1 -T2 -l0 /2 width=2/ /2 width=7/ /3 width=2/ /3 width=7/
63 lemma ssta_cpx: ∀h,g,L,T1,T2,l. ⦃h, L⦄ ⊢ T1 •[g] ⦃l+1, T2⦄ → ⦃h, L⦄ ⊢ T1 ➡[g] T2.
64 /2 width=4 by ssta_cpx_aux/ qed.
66 lemma cpx_pair_sn: ∀h,g,I,L,V1,V2. ⦃h, L⦄ ⊢ V1 ➡[g] V2 →
67 ∀T. ⦃h, L⦄ ⊢ ②{I}V1.T ➡[g] ②{I}V2.T.
68 #h #g * /2 width=1/ qed.
70 lemma cpx_delift: ∀h,g,L,K,V,T1,d. ⇩[0, d] L ≡ (K. ⓓV) →
71 ∃∃T2,T. ⦃h, L⦄ ⊢ T1 ➡[g] T2 & ⇧[d, 1] T ≡ T2.
72 #h #g #L #K #V #T1 #d #HLK
73 elim (cpr_delift … HLK) -HLK /3 width=4/
76 lemma cpx_append: ∀h,g. l_appendable_sn … (cpx h g).
77 #h #g #K #T1 #T2 #H elim H -K -T1 -T2 // /2 width=1/ /2 width=3/
78 #I #K #K0 #V1 #V2 #W2 #i #HK0 #_ #HVW2 #IHV12 #L
79 lapply (ldrop_fwd_ldrop2_length … HK0) #H
80 @(cpx_delta … I … (L@@K0) V1 … HVW2) //
81 @(ldrop_O1_append_sn_le … HK0) /2 width=2/ (**) (* /3/ does not work *)
84 (* Basic inversion lemmas ***************************************************)
86 fact cpx_inv_atom1_aux: ∀h,g,L,T1,T2. ⦃h, L⦄ ⊢ T1 ➡[g] T2 → ∀J. T1 = ⓪{J} →
88 | ∃∃k,l. deg h g k (l+1) & T2 = ⋆(next h k) & J = Sort k
89 | ∃∃I,K,V,V2,i. ⇩[O, i] L ≡ K.ⓑ{I}V & ⦃h, K⦄ ⊢ V ➡[g] V2 &
90 ⇧[O, i + 1] V2 ≡ T2 & J = LRef i.
91 #h #g #L #T1 #T2 * -L -T1 -T2
92 [ #I #L #J #H destruct /2 width=1/
93 | #L #k #l #Hkl #J #H destruct /3 width=5/
94 | #I #L #K #V #V2 #T2 #i #HLK #HV2 #HVT2 #J #H destruct /3 width=9/
95 | #a #I #L #V1 #V2 #T1 #T2 #_ #_ #J #H destruct
96 | #I #L #V1 #V2 #T1 #T2 #_ #_ #J #H destruct
97 | #L #V #T1 #T #T2 #_ #_ #J #H destruct
98 | #L #V #T1 #T2 #_ #J #H destruct
99 | #a #L #V1 #V2 #W #T1 #T2 #_ #_ #J #H destruct
100 | #a #L #V1 #V #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #_ #J #H destruct
104 lemma cpx_inv_atom1: ∀h,g,J,L,T2. ⦃h, L⦄ ⊢ ⓪{J} ➡[g] T2 →
106 | ∃∃k,l. deg h g k (l+1) & T2 = ⋆(next h k) & J = Sort k
107 | ∃∃I,K,V,V2,i. ⇩[O, i] L ≡ K.ⓑ{I}V & ⦃h, K⦄ ⊢ V ➡[g] V2 &
108 ⇧[O, i + 1] V2 ≡ T2 & J = LRef i.
109 /2 width=3 by cpx_inv_atom1_aux/ qed-.
111 lemma cpx_inv_sort1: ∀h,g,L,T2,k. ⦃h, L⦄ ⊢ ⋆k ➡[g] T2 → T2 = ⋆k ∨
112 ∃∃l. deg h g k (l+1) & T2 = ⋆(next h k).
114 elim (cpx_inv_atom1 … H) -H /2 width=1/ *
115 [ #k0 #l0 #Hkl0 #H1 #H2 destruct /3 width=4/
116 | #I #K #V #V2 #i #_ #_ #_ #H destruct
120 lemma cpx_inv_lref1: ∀h,g,L,T2,i. ⦃h, L⦄ ⊢ #i ➡[g] T2 →
122 ∃∃I,K,V,V2. ⇩[O, i] L ≡ K. ⓑ{I}V & ⦃h, K⦄ ⊢ V ➡[g] V2 &
125 elim (cpx_inv_atom1 … H) -H /2 width=1/ *
126 [ #k #l #_ #_ #H destruct
127 | #I #K #V #V2 #j #HLK #HV2 #HVT2 #H destruct /3 width=7/
131 lemma cpx_inv_gref1: ∀h,g,L,T2,p. ⦃h, L⦄ ⊢ §p ➡[g] T2 → T2 = §p.
133 elim (cpx_inv_atom1 … H) -H // *
134 [ #k #l #_ #_ #H destruct
135 | #I #K #V #V2 #i #_ #_ #_ #H destruct
139 fact cpx_inv_bind1_aux: ∀h,g,L,U1,U2. ⦃h, L⦄ ⊢ U1 ➡[g] U2 →
140 ∀a,J,V1,T1. U1 = ⓑ{a,J} V1. T1 → (
141 ∃∃V2,T2. ⦃h, L⦄ ⊢ V1 ➡[g] V2 & ⦃h, L.ⓑ{J}V1⦄ ⊢ T1 ➡[g] T2 &
144 ∃∃T. ⦃h, L.ⓓV1⦄ ⊢ T1 ➡[g] T & ⇧[0, 1] U2 ≡ T &
146 #h #g #L #U1 #U2 * -L -U1 -U2
147 [ #I #L #b #J #W1 #U1 #H destruct
148 | #L #k #l #_ #b #J #W1 #U1 #H destruct
149 | #I #L #K #V #V2 #W2 #i #_ #_ #_ #b #J #W1 #U1 #H destruct
150 | #a #I #L #V1 #V2 #T1 #T2 #HV12 #HT12 #b #J #W1 #U1 #H destruct /3 width=5/
151 | #I #L #V1 #V2 #T1 #T2 #_ #_ #b #J #W1 #U1 #H destruct
152 | #L #V #T1 #T #T2 #HT1 #HT2 #b #J #W1 #U1 #H destruct /3 width=3/
153 | #L #V #T1 #T2 #_ #b #J #W1 #U1 #H destruct
154 | #a #L #V1 #V2 #W #T1 #T2 #_ #_ #b #J #W1 #U1 #H destruct
155 | #a #L #V1 #V #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #_ #b #J #W1 #U1 #H destruct
159 lemma cpx_inv_bind1: ∀h,g,a,I,L,V1,T1,U2. ⦃h, L⦄ ⊢ ⓑ{a,I}V1.T1 ➡[g] U2 → (
160 ∃∃V2,T2. ⦃h, L⦄ ⊢ V1 ➡[g] V2 & ⦃h, L.ⓑ{I}V1⦄ ⊢ T1 ➡[g] T2 &
163 ∃∃T. ⦃h, L.ⓓV1⦄ ⊢ T1 ➡[g] T & ⇧[0, 1] U2 ≡ T &
165 /2 width=3 by cpx_inv_bind1_aux/ qed-.
167 lemma cpx_inv_abbr1: ∀h,g,a,L,V1,T1,U2. ⦃h, L⦄ ⊢ ⓓ{a}V1.T1 ➡[g] U2 → (
168 ∃∃V2,T2. ⦃h, L⦄ ⊢ V1 ➡[g] V2 & ⦃h, L.ⓓ V1⦄ ⊢ T1 ➡[g] T2 &
171 ∃∃T. ⦃h, L.ⓓV1⦄ ⊢ T1 ➡[g] T & ⇧[0, 1] U2 ≡ T & a = true.
172 #h #g #a #L #V1 #T1 #U2 #H
173 elim (cpx_inv_bind1 … H) -H * /3 width=3/ /3 width=5/
176 lemma cpx_inv_abst1: ∀h,g,a,L,V1,T1,U2. ⦃h, L⦄ ⊢ ⓛ{a}V1.T1 ➡[g] U2 →
177 ∃∃V2,T2. ⦃h, L⦄ ⊢ V1 ➡[g] V2 & ⦃h, L.ⓛ V1⦄ ⊢ T1 ➡[g] T2 &
179 #h #g #a #L #V1 #T1 #U2 #H
180 elim (cpx_inv_bind1 … H) -H *
182 | #T #_ #_ #_ #H destruct
186 fact cpx_inv_flat1_aux: ∀h,g,L,U,U2. ⦃h, L⦄ ⊢ U ➡[g] U2 →
187 ∀J,V1,U1. U = ⓕ{J} V1. U1 →
188 ∨∨ ∃∃V2,T2. ⦃h, L⦄ ⊢ V1 ➡[g] V2 & ⦃h, L⦄ ⊢ U1 ➡[g] T2 &
190 | (⦃h, L⦄ ⊢ U1 ➡[g] U2 ∧ J = Cast)
191 | ∃∃a,V2,W,T1,T2. ⦃h, L⦄ ⊢ V1 ➡[g] V2 & ⦃h, L.ⓛW⦄ ⊢ T1 ➡[g] T2 &
193 U2 = ⓓ{a}V2. T2 & J = Appl
194 | ∃∃a,V,V2,W1,W2,T1,T2. ⦃h, L⦄ ⊢ V1 ➡[g] V & ⇧[0,1] V ≡ V2 &
195 ⦃h, L⦄ ⊢ W1 ➡[g] W2 & ⦃h, L.ⓓW1⦄ ⊢ T1 ➡[g] T2 &
197 U2 = ⓓ{a}W2. ⓐV2. T2 & J = Appl.
198 #h #g #L #U #U2 * -L -U -U2
199 [ #I #L #J #W1 #U1 #H destruct
200 | #L #k #l #_ #J #W1 #U1 #H destruct
201 | #I #L #K #V #V2 #W2 #i #_ #_ #_ #J #W1 #U1 #H destruct
202 | #a #I #L #V1 #V2 #T1 #T2 #_ #_ #J #W1 #U1 #H destruct
203 | #I #L #V1 #V2 #T1 #T2 #HV12 #HT12 #J #W1 #U1 #H destruct /3 width=5/
204 | #L #V #T1 #T #T2 #_ #_ #J #W1 #U1 #H destruct
205 | #L #V #T1 #T2 #HT12 #J #W1 #U1 #H destruct /3 width=1/
206 | #a #L #V1 #V2 #W #T1 #T2 #HV12 #HT12 #J #W1 #U1 #H destruct /3 width=9/
207 | #a #L #V1 #V #V2 #W1 #W2 #T1 #T2 #HV1 #HV2 #HW12 #HT12 #J #W1 #U1 #H destruct /3 width=13/
211 lemma cpx_inv_flat1: ∀h,g,I,L,V1,U1,U2. ⦃h, L⦄ ⊢ ⓕ{I}V1.U1 ➡[g] U2 →
212 ∨∨ ∃∃V2,T2. ⦃h, L⦄ ⊢ V1 ➡[g] V2 & ⦃h, L⦄ ⊢ U1 ➡[g] T2 &
214 | (⦃h, L⦄ ⊢ U1 ➡[g] U2 ∧ I = Cast)
215 | ∃∃a,V2,W,T1,T2. ⦃h, L⦄ ⊢ V1 ➡[g] V2 & ⦃h, L.ⓛW⦄ ⊢ T1 ➡[g] T2 &
217 U2 = ⓓ{a}V2. T2 & I = Appl
218 | ∃∃a,V,V2,W1,W2,T1,T2. ⦃h, L⦄ ⊢ V1 ➡[g] V & ⇧[0,1] V ≡ V2 &
219 ⦃h, L⦄ ⊢ W1 ➡[g] W2 & ⦃h, L.ⓓW1⦄ ⊢ T1 ➡[g] T2 &
221 U2 = ⓓ{a}W2. ⓐV2. T2 & I = Appl.
222 /2 width=3 by cpx_inv_flat1_aux/ qed-.
224 lemma cpx_inv_appl1: ∀h,g,L,V1,U1,U2. ⦃h, L⦄ ⊢ ⓐ V1.U1 ➡[g] U2 →
225 ∨∨ ∃∃V2,T2. ⦃h, L⦄ ⊢ V1 ➡[g] V2 & ⦃h, L⦄ ⊢ U1 ➡[g] T2 &
227 | ∃∃a,V2,W,T1,T2. ⦃h, L⦄ ⊢ V1 ➡[g] V2 & ⦃h, L.ⓛW⦄ ⊢ T1 ➡[g] T2 &
228 U1 = ⓛ{a}W. T1 & U2 = ⓓ{a}V2. T2
229 | ∃∃a,V,V2,W1,W2,T1,T2. ⦃h, L⦄ ⊢ V1 ➡[g] V & ⇧[0,1] V ≡ V2 &
230 ⦃h, L⦄ ⊢ W1 ➡[g] W2 & ⦃h, L.ⓓW1⦄ ⊢ T1 ➡[g] T2 &
231 U1 = ⓓ{a}W1. T1 & U2 = ⓓ{a}W2. ⓐV2. T2.
232 #h #g #L #V1 #U1 #U2 #H elim (cpx_inv_flat1 … H) -H *
240 (* Note: the main property of simple terms *)
241 lemma cpx_inv_appl1_simple: ∀h,g,L,V1,T1,U. ⦃h, L⦄ ⊢ ⓐV1.T1 ➡[g] U → 𝐒⦃T1⦄ →
242 ∃∃V2,T2. ⦃h, L⦄ ⊢ V1 ➡[g] V2 & ⦃h, L⦄ ⊢ T1 ➡[g] T2 &
244 #h #g #L #V1 #T1 #U #H #HT1
245 elim (cpx_inv_appl1 … H) -H *
247 | #a #V2 #W #U1 #U2 #_ #_ #H #_ destruct
248 elim (simple_inv_bind … HT1)
249 | #a #V #V2 #W1 #W2 #U1 #U2 #_ #_ #_ #_ #H #_ destruct
250 elim (simple_inv_bind … HT1)
254 lemma cpx_inv_cast1: ∀h,g,L,V1,U1,U2. ⦃h, L⦄ ⊢ ⓝ V1.U1 ➡[g] U2 → (
255 ∃∃V2,T2. ⦃h, L⦄ ⊢ V1 ➡[g] V2 & ⦃h, L⦄ ⊢ U1 ➡[g] T2 &
257 ) ∨ ⦃h, L⦄ ⊢ U1 ➡[g] U2.
258 #h #g #L #V1 #U1 #U2 #H elim (cpx_inv_flat1 … H) -H *
261 | #a #V2 #W #T1 #T2 #_ #_ #_ #_ #H destruct
262 | #a #V #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #_ #_ #_ #H destruct
266 (* Basic forward lemmas *****************************************************)
268 lemma cpx_fwd_bind1_minus: ∀h,g,I,L,V1,T1,T. ⦃h, L⦄ ⊢ -ⓑ{I}V1.T1 ➡[g] T → ∀b.
269 ∃∃V2,T2. ⦃h, L⦄ ⊢ ⓑ{b,I}V1.T1 ➡[g] ⓑ{b,I}V2.T2 &
271 #h #g #I #L #V1 #T1 #T #H #b
272 elim (cpx_inv_bind1 … H) -H *
273 [ #V2 #T2 #HV12 #HT12 #H destruct /3 width=4/
274 | #T2 #_ #_ #H destruct
278 lemma cpx_fwd_shift1: ∀h,g,L1,L,T1,T. ⦃h, L⦄ ⊢ L1 @@ T1 ➡[g] T →
279 ∃∃L2,T2. |L1| = |L2| & T = L2 @@ T2.
280 #h #g #L1 @(lenv_ind_dx … L1) -L1 normalize
282 @(ex2_2_intro … (⋆)) // (**) (* explicit constructor *)
283 | #I #L1 #V1 #IH #L #T1 #X
284 >shift_append_assoc normalize #H
285 elim (cpx_inv_bind1 … H) -H *
286 [ #V0 #T0 #_ #HT10 #H destruct
287 elim (IH … HT10) -IH -HT10 #L2 #T2 #HL12 #H destruct
288 >append_length >HL12 -HL12
289 @(ex2_2_intro … (⋆.ⓑ{I}V0@@L2) T2) [ >append_length ] // /2 width=3/ (**) (* explicit constructor *)
290 | #T #_ #_ #H destruct