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