]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/lambdadelta/basic_2/reduction/cpr.ma
a8fe7b1c34e6d415174d2bb04969739e65f32af1
[helm.git] / matita / matita / contribs / lambdadelta / basic_2 / reduction / cpr.ma
1 (**************************************************************************)
2 (*       ___                                                              *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||         The HELM team.                                      *)
8 (*      ||A||         http://helm.cs.unibo.it                             *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU General Public License Version 2                  *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 include "basic_2/notation/relations/pred_3.ma".
16 include "basic_2/grammar/cl_shift.ma".
17 include "basic_2/relocation/ldrop_append.ma".
18 include "basic_2/reduction/lsubx.ma".
19
20 (* CONTEXT-SENSITIVE PARALLEL REDUCTION FOR TERMS ***************************)
21
22 (* Basic_1: includes: pr0_delta1 pr2_delta1 pr2_thin_dx *)
23 (* Note: cpr_flat: does not hold in basic_1 *)
24 inductive cpr: lenv → relation term ≝
25 | cpr_atom : ∀I,L. cpr L (⓪{I}) (⓪{I})
26 | cpr_delta: ∀L,K,V,V2,W2,i.
27              ⇩[0, i] L ≡ K. ⓓV → cpr K V V2 →
28              ⇧[0, i + 1] V2 ≡ W2 → cpr L (#i) W2
29 | cpr_bind : ∀a,I,L,V1,V2,T1,T2.
30              cpr L V1 V2 → cpr (L.ⓑ{I}V1) T1 T2 →
31              cpr L (ⓑ{a,I}V1.T1) (ⓑ{a,I}V2.T2)
32 | cpr_flat : ∀I,L,V1,V2,T1,T2.
33              cpr L V1 V2 → cpr L T1 T2 →
34              cpr L (ⓕ{I} V1. T1) (ⓕ{I}V2.T2)
35 | cpr_zeta : ∀L,V,T1,T,T2. cpr (L.ⓓV) T1 T →
36              ⇧[0, 1] T2 ≡ T → cpr L (+ⓓV.T1) T2
37 | cpr_tau  : ∀L,V,T1,T2. cpr L T1 T2 → cpr L (ⓝV.T1) T2
38 | cpr_beta : ∀a,L,V1,V2,W1,W2,T1,T2.
39              cpr L V1 V2 → cpr L W1 W2 → cpr (L.ⓛW1) T1 T2 →
40              cpr L (ⓐV1.ⓛ{a}W1.T1) (ⓓ{a}ⓝW2.V2.T2)
41 | cpr_theta: ∀a,L,V1,V,V2,W1,W2,T1,T2.
42              cpr L V1 V → ⇧[0, 1] V ≡ V2 → cpr L W1 W2 → cpr (L.ⓓW1) T1 T2 →
43              cpr L (ⓐV1.ⓓ{a}W1.T1) (ⓓ{a}W2.ⓐV2.T2)
44 .
45
46 interpretation "context-sensitive parallel reduction (term)"
47    'PRed L T1 T2 = (cpr L T1 T2).
48
49 (* Basic properties *********************************************************)
50
51 lemma lsubx_cpr_trans: lsub_trans … cpr lsubx.
52 #L1 #T1 #T2 #H elim H -L1 -T1 -T2
53 [ //
54 | #L1 #K1 #V1 #V2 #W2 #i #HLK1 #_ #HVW2 #IHV12 #L2 #HL12
55   elim (lsubx_fwd_ldrop2_abbr … HL12 … HLK1) -L1 * /3 width=6/
56 |3,7: /4 width=1/
57 |4,6: /3 width=1/
58 |5,8: /4 width=3/
59 ]
60 qed-.
61
62 (* Basic_1: was by definition: pr2_free *)
63 lemma tpr_cpr: ∀T1,T2. ⋆ ⊢ T1 ➡ T2 → ∀L. L ⊢ T1 ➡ T2.
64 #T1 #T2 #HT12 #L
65 lapply (lsubx_cpr_trans … HT12 L ?) //
66 qed.
67
68 (* Basic_1: includes by definition: pr0_refl *)
69 lemma cpr_refl: ∀T,L. L ⊢ T ➡ T.
70 #T elim T -T // * /2 width=1/
71 qed.
72
73 (* Basic_1: was: pr2_head_1 *)
74 lemma cpr_pair_sn: ∀I,L,V1,V2. L ⊢ V1 ➡ V2 →
75                    ∀T. L ⊢ ②{I}V1.T ➡ ②{I}V2.T.
76 * /2 width=1/ qed.
77
78 lemma cpr_delift: ∀K,V,T1,L,d. ⇩[0, d] L ≡ (K.ⓓV) →
79                   ∃∃T2,T. L ⊢ T1 ➡ T2 & ⇧[d, 1] T ≡ T2.
80 #K #V #T1 elim T1 -T1
81 [ * #i #L #d #HLK /2 width=4/
82   elim (lt_or_eq_or_gt i d) #Hid [1,3: /3 width=4/ ]
83   destruct
84   elim (lift_total V 0 (i+1)) #W #HVW
85   elim (lift_split … HVW i i) // /3 width=6/
86 | * [ #a ] #I #W1 #U1 #IHW1 #IHU1 #L #d #HLK
87   elim (IHW1 … HLK) -IHW1 #W2 #W #HW12 #HW2
88   [ elim (IHU1 (L. ⓑ{I}W1) (d+1)) -IHU1 /2 width=1/ -HLK /3 width=9/
89   | elim (IHU1 … HLK) -IHU1 -HLK /3 width=8/
90   ]
91 ]
92 qed-.
93
94 lemma cpr_append: l_appendable_sn … cpr.
95 #K #T1 #T2 #H elim H -K -T1 -T2 // /2 width=1/ /2 width=3/
96 #K #K0 #V1 #V2 #W2 #i #HK0 #_ #HVW2 #IHV12 #L
97 lapply (ldrop_fwd_length_lt2 … HK0) #H
98 @(cpr_delta … (L@@K0) V1 … HVW2) //
99 @(ldrop_O1_append_sn_le … HK0) /2 width=2/ (**) (* /3/ does not work *)
100 qed.
101
102 (* Basic inversion lemmas ***************************************************)
103
104 fact cpr_inv_atom1_aux: ∀L,T1,T2. L ⊢ T1 ➡ T2 → ∀I. T1 = ⓪{I} →
105                         T2 = ⓪{I} ∨
106                         ∃∃K,V,V2,i. ⇩[O, i] L ≡ K. ⓓV &
107                                     K ⊢ V ➡ V2 &
108                                     ⇧[O, i + 1] V2 ≡ T2 &
109                                     I = LRef i.
110 #L #T1 #T2 * -L -T1 -T2
111 [ #I #L #J #H destruct /2 width=1/
112 | #L #K #V #V2 #T2 #i #HLK #HV2 #HVT2 #J #H destruct /3 width=8/
113 | #a #I #L #V1 #V2 #T1 #T2 #_ #_ #J #H destruct
114 | #I #L #V1 #V2 #T1 #T2 #_ #_ #J #H destruct
115 | #L #V #T1 #T #T2 #_ #_ #J #H destruct
116 | #L #V #T1 #T2 #_ #J #H destruct
117 | #a #L #V1 #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #J #H destruct
118 | #a #L #V1 #V #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #_ #J #H destruct
119 ]
120 qed-.
121
122 lemma cpr_inv_atom1: ∀I,L,T2. L ⊢ ⓪{I} ➡ T2 →
123                      T2 = ⓪{I} ∨
124                      ∃∃K,V,V2,i. ⇩[O, i] L ≡ K. ⓓV &
125                                  K ⊢ V ➡ V2 &
126                                  ⇧[O, i + 1] V2 ≡ T2 &
127                                  I = LRef i.
128 /2 width=3 by cpr_inv_atom1_aux/ qed-.
129
130 (* Basic_1: includes: pr0_gen_sort pr2_gen_sort *)
131 lemma cpr_inv_sort1: ∀L,T2,k. L ⊢ ⋆k ➡ T2 → T2 = ⋆k.
132 #L #T2 #k #H
133 elim (cpr_inv_atom1 … H) -H //
134 * #K #V #V2 #i #_ #_ #_ #H destruct
135 qed-.
136
137 (* Basic_1: includes: pr0_gen_lref pr2_gen_lref *)
138 lemma cpr_inv_lref1: ∀L,T2,i. L ⊢ #i ➡ T2 →
139                      T2 = #i ∨
140                      ∃∃K,V,V2. ⇩[O, i] L ≡ K. ⓓV &
141                                K ⊢ V ➡ V2 &
142                                ⇧[O, i + 1] V2 ≡ T2.
143 #L #T2 #i #H
144 elim (cpr_inv_atom1 … H) -H /2 width=1/
145 * #K #V #V2 #j #HLK #HV2 #HVT2 #H destruct /3 width=6/
146 qed-.
147
148 lemma cpr_inv_gref1: ∀L,T2,p. L ⊢ §p ➡ T2 → T2 = §p.
149 #L #T2 #p #H
150 elim (cpr_inv_atom1 … H) -H //
151 * #K #V #V2 #i #_ #_ #_ #H destruct
152 qed-.
153
154 fact cpr_inv_bind1_aux: ∀L,U1,U2. L ⊢ U1 ➡ U2 →
155                         ∀a,I,V1,T1. U1 = ⓑ{a,I}V1. T1 → (
156                         ∃∃V2,T2. L ⊢ V1 ➡ V2 &
157                                  L. ⓑ{I}V1 ⊢ T1 ➡ T2 &
158                                  U2 = ⓑ{a,I}V2.T2
159                         ) ∨
160                         ∃∃T. L.ⓓV1 ⊢ T1 ➡ T & ⇧[0, 1] U2 ≡ T & a = true & I = Abbr.
161 #L #U1 #U2 * -L -U1 -U2
162 [ #I #L #b #J #W1 #U1 #H destruct
163 | #L #K #V #V2 #W2 #i #_ #_ #_ #b #J #W #U1 #H destruct
164 | #a #I #L #V1 #V2 #T1 #T2 #HV12 #HT12 #b #J #W #U1 #H destruct /3 width=5/
165 | #I #L #V1 #V2 #T1 #T2 #_ #_ #b #J #W #U1 #H destruct
166 | #L #V #T1 #T #T2 #HT1 #HT2 #b #J #W #U1 #H destruct /3 width=3/
167 | #L #V #T1 #T2 #_ #b #J #W #U1 #H destruct
168 | #a #L #V1 #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #b #J #W #U1 #H destruct
169 | #a #L #V1 #V #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #_ #b #J #W #U1 #H destruct
170 ]
171 qed-.
172
173 lemma cpr_inv_bind1: ∀a,I,L,V1,T1,U2. L ⊢ ⓑ{a,I}V1.T1 ➡ U2 → (
174                      ∃∃V2,T2. L ⊢ V1 ➡ V2 &
175                               L. ⓑ{I}V1 ⊢ T1 ➡ T2 &
176                               U2 = ⓑ{a,I}V2.T2
177                      ) ∨
178                      ∃∃T. L.ⓓV1 ⊢ T1 ➡ T & ⇧[0, 1] U2 ≡ T & a = true & I = Abbr.
179 /2 width=3 by cpr_inv_bind1_aux/ qed-.
180
181 (* Basic_1: includes: pr0_gen_abbr pr2_gen_abbr *)
182 lemma cpr_inv_abbr1: ∀a,L,V1,T1,U2. L ⊢ ⓓ{a}V1.T1 ➡ U2 → (
183                      ∃∃V2,T2. L ⊢ V1 ➡ V2 &
184                               L. ⓓV1 ⊢ T1 ➡ T2 &
185                               U2 = ⓓ{a}V2.T2
186                      ) ∨
187                      ∃∃T. L.ⓓV1 ⊢ T1 ➡ T & ⇧[0, 1] U2 ≡ T & a = true.
188 #a #L #V1 #T1 #U2 #H
189 elim (cpr_inv_bind1 … H) -H * /3 width=3/ /3 width=5/
190 qed-.
191
192 (* Basic_1: includes: pr0_gen_abst pr2_gen_abst *)
193 lemma cpr_inv_abst1: ∀a,L,V1,T1,U2. L ⊢ ⓛ{a}V1.T1 ➡ U2 →
194                      ∃∃V2,T2. L ⊢ V1 ➡ V2 & L.ⓛV1 ⊢ T1 ➡ T2 &
195                               U2 = ⓛ{a}V2.T2.
196 #a #L #V1 #T1 #U2 #H
197 elim (cpr_inv_bind1 … H) -H *
198 [ /3 width=5/
199 | #T #_ #_ #_ #H destruct
200 ]
201 qed-.
202
203 fact cpr_inv_flat1_aux: ∀L,U,U2. L ⊢ U ➡ U2 →
204                         ∀I,V1,U1. U = ⓕ{I}V1.U1 →
205                         ∨∨ ∃∃V2,T2. L ⊢ V1 ➡ V2 & L ⊢ U1 ➡ T2 &
206                                     U2 = ⓕ{I} V2. T2
207                          | (L ⊢ U1 ➡ U2 ∧ I = Cast)
208                          | ∃∃a,V2,W1,W2,T1,T2. L ⊢ V1 ➡ V2 & L ⊢ W1 ➡ W2 &
209                                                L.ⓛW1 ⊢ T1 ➡ T2 & U1 = ⓛ{a}W1.T1 &
210                                                U2 = ⓓ{a}ⓝW2.V2.T2 & I = Appl
211                          | ∃∃a,V,V2,W1,W2,T1,T2. L ⊢ V1 ➡ V & ⇧[0,1] V ≡ V2 &
212                                                  L ⊢ W1 ➡ W2 & L.ⓓW1 ⊢ T1 ➡ T2 &
213                                                  U1 = ⓓ{a}W1.T1 &
214                                                  U2 = ⓓ{a}W2.ⓐV2.T2 & I = Appl.
215 #L #U #U2 * -L -U -U2
216 [ #I #L #J #W1 #U1 #H destruct
217 | #L #K #V #V2 #W2 #i #_ #_ #_ #J #W #U1 #H destruct
218 | #a #I #L #V1 #V2 #T1 #T2 #_ #_ #J #W #U1 #H destruct
219 | #I #L #V1 #V2 #T1 #T2 #HV12 #HT12 #J #W #U1 #H destruct /3 width=5/
220 | #L #V #T1 #T #T2 #_ #_ #J #W #U1 #H destruct
221 | #L #V #T1 #T2 #HT12 #J #W #U1 #H destruct /3 width=1/
222 | #a #L #V1 #V2 #W1 #W2 #T1 #T2 #HV12 #HW12 #HT12 #J #W #U1 #H destruct /3 width=11/
223 | #a #L #V1 #V #V2 #W1 #W2 #T1 #T2 #HV1 #HV2 #HW12 #HT12 #J #W #U1 #H destruct /3 width=13/
224 ]
225 qed-.
226
227 lemma cpr_inv_flat1: ∀I,L,V1,U1,U2. L ⊢ ⓕ{I}V1.U1 ➡ U2 →
228                      ∨∨ ∃∃V2,T2. L ⊢ V1 ➡ V2 & L ⊢ U1 ➡ T2 &
229                                  U2 = ⓕ{I}V2.T2
230                       | (L ⊢ U1 ➡ U2 ∧ I = Cast)
231                       | ∃∃a,V2,W1,W2,T1,T2. L ⊢ V1 ➡ V2 & L ⊢ W1 ➡ W2 &
232                                             L.ⓛW1 ⊢ T1 ➡ T2 & U1 = ⓛ{a}W1.T1 &
233                                             U2 = ⓓ{a}ⓝW2.V2.T2 & I = Appl
234                       | ∃∃a,V,V2,W1,W2,T1,T2. L ⊢ V1 ➡ V & ⇧[0,1] V ≡ V2 &
235                                               L ⊢ W1 ➡ W2 & L.ⓓW1 ⊢ T1 ➡ T2 &
236                                               U1 = ⓓ{a}W1.T1 &
237                                               U2 = ⓓ{a}W2.ⓐV2.T2 & I = Appl.
238 /2 width=3 by cpr_inv_flat1_aux/ qed-.
239
240 (* Basic_1: includes: pr0_gen_appl pr2_gen_appl *)
241 lemma cpr_inv_appl1: ∀L,V1,U1,U2. L ⊢ ⓐV1.U1 ➡ U2 →
242                      ∨∨ ∃∃V2,T2. L ⊢ V1 ➡ V2 & L ⊢ U1 ➡ T2 &
243                                  U2 = ⓐV2.T2
244                       | ∃∃a,V2,W1,W2,T1,T2. L ⊢ V1 ➡ V2 & L ⊢ W1 ➡ W2 &
245                                             L.ⓛW1 ⊢ T1 ➡ T2 &
246                                             U1 = ⓛ{a}W1.T1 & U2 = ⓓ{a}ⓝW2.V2.T2
247                       | ∃∃a,V,V2,W1,W2,T1,T2. L ⊢ V1 ➡ V & ⇧[0,1] V ≡ V2 &
248                                               L ⊢ W1 ➡ W2 & L.ⓓW1 ⊢ T1 ➡ T2 &
249                                               U1 = ⓓ{a}W1.T1 & U2 = ⓓ{a}W2.ⓐV2.T2.
250 #L #V1 #U1 #U2 #H elim (cpr_inv_flat1 … H) -H *
251 [ /3 width=5/
252 | #_ #H destruct
253 | /3 width=11/
254 | /3 width=13/
255 ]
256 qed-.
257
258 (* Note: the main property of simple terms *)
259 lemma cpr_inv_appl1_simple: ∀L,V1,T1,U. L ⊢ ⓐV1. T1 ➡ U → 𝐒⦃T1⦄ →
260                             ∃∃V2,T2. L ⊢ V1 ➡ V2 & L ⊢ T1 ➡ T2 &
261                                      U = ⓐV2. T2.
262 #L #V1 #T1 #U #H #HT1
263 elim (cpr_inv_appl1 … H) -H *
264 [ /2 width=5/
265 | #a #V2 #W1 #W2 #U1 #U2 #_ #_ #_ #H #_ destruct
266   elim (simple_inv_bind … HT1)
267 | #a #V #V2 #W1 #W2 #U1 #U2 #_ #_ #_ #_ #H #_ destruct
268   elim (simple_inv_bind … HT1)
269 ]
270 qed-.
271
272 (* Basic_1: includes: pr0_gen_cast pr2_gen_cast *)
273 lemma cpr_inv_cast1: ∀L,V1,U1,U2. L ⊢ ⓝ V1. U1 ➡ U2 → (
274                      ∃∃V2,T2. L ⊢ V1 ➡ V2 & L ⊢ U1 ➡ T2 &
275                               U2 = ⓝ V2. T2
276                      ) ∨
277                      L ⊢ U1 ➡ U2.
278 #L #V1 #U1 #U2 #H elim (cpr_inv_flat1 … H) -H *
279 [ /3 width=5/
280 | /2 width=1/
281 | #a #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #_ #_ #H destruct
282 | #a #V #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #_ #_ #_ #H destruct
283 ]
284 qed-.
285
286 (* Basic forward lemmas *****************************************************)
287
288 lemma cpr_fwd_bind1_minus: ∀I,L,V1,T1,T. L ⊢ -ⓑ{I}V1.T1 ➡ T → ∀b.
289                            ∃∃V2,T2. L ⊢ ⓑ{b,I}V1.T1 ➡ ⓑ{b,I}V2.T2 &
290                                     T = -ⓑ{I}V2.T2.
291 #I #L #V1 #T1 #T #H #b
292 elim (cpr_inv_bind1 … H) -H *
293 [ #V2 #T2 #HV12 #HT12 #H destruct /3 width=4/
294 | #T2 #_ #_ #H destruct 
295 ]
296 qed-.
297
298 lemma cpr_fwd_shift1: ∀L1,L,T1,T. L ⊢ L1 @@ T1 ➡ T →
299                       ∃∃L2,T2. |L1| = |L2| & T = L2 @@ T2.
300 #L1 @(lenv_ind_dx … L1) -L1 normalize
301 [ #L #T1 #T #HT1
302   @(ex2_2_intro … (⋆)) // (**) (* explicit constructor *)
303 | #I #L1 #V1 #IH #L #T1 #X
304   >shift_append_assoc normalize #H
305   elim (cpr_inv_bind1 … H) -H *
306   [ #V0 #T0 #_ #HT10 #H destruct
307     elim (IH … HT10) -IH -HT10 #L2 #T2 #HL12 #H destruct
308     >append_length >HL12 -HL12
309     @(ex2_2_intro … (⋆.ⓑ{I}V0@@L2) T2) [ >append_length ] // /2 width=3/ (**) (* explicit constructor *)
310   | #T #_ #_ #H destruct
311   ]
312 ]
313 qed-.
314
315 (* Basic_1: removed theorems 11:
316             pr0_subst0_back pr0_subst0_fwd pr0_subst0
317             pr2_head_2 pr2_cflat clear_pr2_trans
318             pr2_gen_csort pr2_gen_cflat pr2_gen_cbind
319             pr2_gen_ctail pr2_ctail
320 *)
321 (* Basic_1: removed local theorems 4:
322             pr0_delta_tau pr0_cong_delta
323             pr2_free_free pr2_free_delta
324 *)