]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/lambdadelta/basic_2/reduction/cpr.ma
e1d4af93c702639521faf9bed1eddd589e06861c
[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 *)
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: lsub_trans … cpr lsubr.
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 (* Basic_1: was: pr2_head_1 *)
77 lemma cpr_pair_sn: ∀I,L,V1,V2. L ⊢ V1 ➡ V2 →
78                    ∀T. L ⊢ ②{I}V1.T ➡ ②{I}V2.T.
79 * /2 width=1/ qed.
80
81 lemma cpr_delift: ∀L,K,V,T1,d. ⇩[0, d] L ≡ (K. ⓓV) →
82                   ∃∃T2,T. L ⊢ T1 ➡ T2 & ⇧[d, 1] T ≡ T2.
83 #L #K #V #T1 #d #HLK
84 elim (cpqs_delift … T1 … HLK) -HLK /3 width=4/
85 qed-.
86
87 lemma cpr_append: l_appendable_sn … cpr.
88 #K #T1 #T2 #H elim H -K -T1 -T2 // /2 width=1/ /2 width=3/
89 #K #K0 #V1 #V2 #W2 #i #HK0 #_ #HVW2 #IHV12 #L
90 lapply (ldrop_fwd_length_lt2 … HK0) #H
91 @(cpr_delta … (L@@K0) V1 … HVW2) //
92 @(ldrop_O1_append_sn_le … HK0) /2 width=2/ (**) (* /3/ does not work *)
93 qed.
94
95 lemma cpr_ext_bind: ∀L,V1,V2. L ⊢ V1 ➡ V2 → ∀V,T1,T2. L.ⓛV ⊢ T1 ➡ T2 →
96                     ∀a,I. L ⊢ ⓑ{a,I}V1. T1 ➡ ⓑ{a,I}V2. T2.
97 #L #V1 #V2 #HV12 #V #T1 #T2 #HT12 #a #I
98 lapply (cpr_lsubr_trans … HT12 (L.ⓑ{I}V1) ?) -HT12 /2 width=1/
99 qed.
100
101 (* Basic inversion lemmas ***************************************************)
102
103 fact cpr_inv_atom1_aux: ∀L,T1,T2. L ⊢ T1 ➡ T2 → ∀I. T1 = ⓪{I} →
104                         T2 = ⓪{I} ∨
105                         ∃∃K,V,V2,i. ⇩[O, i] L ≡ K. ⓓV &
106                                     K ⊢ V ➡ V2 &
107                                     ⇧[O, i + 1] V2 ≡ T2 &
108                                     I = LRef i.
109 #L #T1 #T2 * -L -T1 -T2
110 [ #I #L #J #H destruct /2 width=1/
111 | #L #K #V #V2 #T2 #i #HLK #HV2 #HVT2 #J #H destruct /3 width=8/
112 | #a #I #L #V1 #V2 #T1 #T2 #_ #_ #J #H destruct
113 | #I #L #V1 #V2 #T1 #T2 #_ #_ #J #H destruct
114 | #L #V #T1 #T #T2 #_ #_ #J #H destruct
115 | #L #V #T1 #T2 #_ #J #H destruct
116 | #a #L #V1 #V2 #W #T1 #T2 #_ #_ #J #H destruct
117 | #a #L #V1 #V #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #_ #J #H destruct
118 ]
119 qed-.
120
121 lemma cpr_inv_atom1: ∀I,L,T2. L ⊢ ⓪{I} ➡ T2 →
122                      T2 = ⓪{I} ∨
123                      ∃∃K,V,V2,i. ⇩[O, i] L ≡ K. ⓓV &
124                                  K ⊢ V ➡ V2 &
125                                  ⇧[O, i + 1] V2 ≡ T2 &
126                                  I = LRef i.
127 /2 width=3 by cpr_inv_atom1_aux/ qed-.
128
129 (* Basic_1: includes: pr0_gen_sort pr2_gen_sort *)
130 lemma cpr_inv_sort1: ∀L,T2,k. L ⊢ ⋆k ➡ T2 → T2 = ⋆k.
131 #L #T2 #k #H
132 elim (cpr_inv_atom1 … H) -H //
133 * #K #V #V2 #i #_ #_ #_ #H destruct
134 qed-.
135
136 (* Basic_1: includes: pr0_gen_lref pr2_gen_lref *)
137 lemma cpr_inv_lref1: ∀L,T2,i. L ⊢ #i ➡ T2 →
138                      T2 = #i ∨
139                      ∃∃K,V,V2. ⇩[O, i] L ≡ K. ⓓV &
140                                K ⊢ V ➡ V2 &
141                                ⇧[O, i + 1] V2 ≡ T2.
142 #L #T2 #i #H
143 elim (cpr_inv_atom1 … H) -H /2 width=1/
144 * #K #V #V2 #j #HLK #HV2 #HVT2 #H destruct /3 width=6/
145 qed-.
146
147 lemma cpr_inv_gref1: ∀L,T2,p. L ⊢ §p ➡ T2 → T2 = §p.
148 #L #T2 #p #H
149 elim (cpr_inv_atom1 … H) -H //
150 * #K #V #V2 #i #_ #_ #_ #H destruct
151 qed-.
152
153 fact cpr_inv_bind1_aux: ∀L,U1,U2. L ⊢ U1 ➡ U2 →
154                         ∀a,I,V1,T1. U1 = ⓑ{a,I} V1. T1 → (
155                         ∃∃V2,T2. L ⊢ V1 ➡ V2 &
156                                  L. ⓑ{I} V1 ⊢ T1 ➡ T2 &
157                                  U2 = ⓑ{a,I} V2. T2
158                         ) ∨
159                         ∃∃T. L.ⓓV1 ⊢ T1 ➡ T & ⇧[0, 1] U2 ≡ T & a = true & I = Abbr.
160 #L #U1 #U2 * -L -U1 -U2
161 [ #I #L #b #J #W1 #U1 #H destruct
162 | #L #K #V #V2 #W2 #i #_ #_ #_ #b #J #W1 #U1 #H destruct
163 | #a #I #L #V1 #V2 #T1 #T2 #HV12 #HT12 #b #J #W1 #U1 #H destruct /3 width=5/
164 | #I #L #V1 #V2 #T1 #T2 #_ #_ #b #J #W1 #U1 #H destruct
165 | #L #V #T1 #T #T2 #HT1 #HT2 #b #J #W1 #U1 #H destruct /3 width=3/
166 | #L #V #T1 #T2 #_ #b #J #W1 #U1 #H destruct
167 | #a #L #V1 #V2 #W #T1 #T2 #_ #_ #b #J #W1 #U1 #H destruct
168 | #a #L #V1 #V #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #_ #b #J #W1 #U1 #H destruct
169 ]
170 qed-.
171
172 lemma cpr_inv_bind1: ∀a,I,L,V1,T1,U2. L ⊢ ⓑ{a,I} V1. T1 ➡ U2 → (
173                      ∃∃V2,T2. L ⊢ V1 ➡ V2 &
174                               L. ⓑ{I} V1 ⊢ T1 ➡ T2 &
175                               U2 = ⓑ{a,I} V2. T2
176                      ) ∨
177                      ∃∃T. L.ⓓV1 ⊢ T1 ➡ T & ⇧[0, 1] U2 ≡ T & a = true & I = Abbr.
178 /2 width=3 by cpr_inv_bind1_aux/ qed-.
179
180 (* Basic_1: includes: pr0_gen_abbr pr2_gen_abbr *)
181 lemma cpr_inv_abbr1: ∀a,L,V1,T1,U2. L ⊢ ⓓ{a} V1. T1 ➡ U2 → (
182                      ∃∃V2,T2. L ⊢ V1 ➡ V2 &
183                               L. ⓓ V1 ⊢ T1 ➡ T2 &
184                               U2 = ⓓ{a} V2. T2
185                      ) ∨
186                      ∃∃T. L.ⓓV1 ⊢ T1 ➡ T & ⇧[0, 1] U2 ≡ T & a = true.
187 #a #L #V1 #T1 #U2 #H
188 elim (cpr_inv_bind1 … H) -H * /3 width=3/ /3 width=5/
189 qed-.
190
191 (* Basic_1: includes: pr0_gen_abst pr2_gen_abst *)
192 lemma cpr_inv_abst1: ∀a,L,V1,T1,U2. L ⊢ ⓛ{a} V1. T1 ➡ U2 →
193                      ∃∃V2,T2. L ⊢ V1 ➡ V2 & L. ⓛ V1 ⊢ T1 ➡ T2 &
194                               U2 = ⓛ{a} V2. T2.
195 #a #L #V1 #T1 #U2 #H
196 elim (cpr_inv_bind1 … H) -H *
197 [ /3 width=5/
198 | #T #_ #_ #_ #H destruct
199 ]
200 qed-.
201
202 fact cpr_inv_flat1_aux: ∀L,U,U2. L ⊢ U ➡ U2 →
203                         ∀I,V1,U1. U = ⓕ{I} V1. U1 →
204                         ∨∨ ∃∃V2,T2. L ⊢ V1 ➡ V2 & L ⊢ U1 ➡ T2 &
205                                     U2 = ⓕ{I} V2. T2
206                          | (L ⊢ U1 ➡ U2 ∧ I = Cast)
207                          | ∃∃a,V2,W,T1,T2. L ⊢ V1 ➡ V2 & L.ⓛW ⊢ T1 ➡ T2 &
208                                            U1 = ⓛ{a}W. T1 &
209                                            U2 = ⓓ{a}V2. T2 & I = Appl
210                          | ∃∃a,V,V2,W1,W2,T1,T2. L ⊢ V1 ➡ V & ⇧[0,1] V ≡ V2 &
211                                                  L ⊢ W1 ➡ W2 & L.ⓓW1 ⊢ T1 ➡ T2 &
212                                                  U1 = ⓓ{a}W1. T1 &
213                                                  U2 = ⓓ{a}W2. ⓐV2. T2 & I = Appl.
214 #L #U #U2 * -L -U -U2
215 [ #I #L #J #W1 #U1 #H destruct
216 | #L #K #V #V2 #W2 #i #_ #_ #_ #J #W1 #U1 #H destruct
217 | #a #I #L #V1 #V2 #T1 #T2 #_ #_ #J #W1 #U1 #H destruct
218 | #I #L #V1 #V2 #T1 #T2 #HV12 #HT12 #J #W1 #U1 #H destruct /3 width=5/
219 | #L #V #T1 #T #T2 #_ #_ #J #W1 #U1 #H destruct
220 | #L #V #T1 #T2 #HT12 #J #W1 #U1 #H destruct /3 width=1/
221 | #a #L #V1 #V2 #W #T1 #T2 #HV12 #HT12 #J #W1 #U1 #H destruct /3 width=9/
222 | #a #L #V1 #V #V2 #W1 #W2 #T1 #T2 #HV1 #HV2 #HW12 #HT12 #J #W1 #U1 #H destruct /3 width=13/
223 ]
224 qed-.
225
226 lemma cpr_inv_flat1: ∀I,L,V1,U1,U2. L ⊢ ⓕ{I} V1. U1 ➡ U2 →
227                      ∨∨ ∃∃V2,T2. L ⊢ V1 ➡ V2 & L ⊢ U1 ➡ T2 &
228                                  U2 = ⓕ{I} V2. T2
229                       | (L ⊢ U1 ➡ U2 ∧ I = Cast)
230                       | ∃∃a,V2,W,T1,T2. L ⊢ V1 ➡ V2 & L.ⓛW ⊢ T1 ➡ T2 &
231                                         U1 = ⓛ{a}W. T1 &
232                                         U2 = ⓓ{a}V2. T2 & I = Appl
233                       | ∃∃a,V,V2,W1,W2,T1,T2. L ⊢ V1 ➡ V & ⇧[0,1] V ≡ V2 &
234                                               L ⊢ W1 ➡ W2 & L.ⓓW1 ⊢ T1 ➡ T2 &
235                                               U1 = ⓓ{a}W1. T1 &
236                                               U2 = ⓓ{a}W2. ⓐV2. T2 & I = Appl.
237 /2 width=3 by cpr_inv_flat1_aux/ qed-.
238
239 (* Basic_1: includes: pr0_gen_appl pr2_gen_appl *)
240 lemma cpr_inv_appl1: ∀L,V1,U1,U2. L ⊢ ⓐ V1. U1 ➡ U2 →
241                      ∨∨ ∃∃V2,T2. L ⊢ V1 ➡ V2 & L ⊢ U1 ➡ T2 &
242                                  U2 = ⓐ V2. T2
243                       | ∃∃a,V2,W,T1,T2. L ⊢ V1 ➡ V2 & L.ⓛW ⊢ T1 ➡ T2 &
244                                         U1 = ⓛ{a}W. T1 & U2 = ⓓ{a}V2. T2
245                       | ∃∃a,V,V2,W1,W2,T1,T2. L ⊢ V1 ➡ V & ⇧[0,1] V ≡ V2 &
246                                               L ⊢ W1 ➡ W2 & L.ⓓW1 ⊢ T1 ➡ T2 &
247                                               U1 = ⓓ{a}W1. T1 & U2 = ⓓ{a}W2. ⓐV2. T2.
248 #L #V1 #U1 #U2 #H elim (cpr_inv_flat1 … H) -H *
249 [ /3 width=5/
250 | #_ #H destruct
251 | /3 width=9/
252 | /3 width=13/
253 ]
254 qed-.
255
256 (* Note: the main property of simple terms *)
257 lemma cpr_inv_appl1_simple: ∀L,V1,T1,U. L ⊢ ⓐV1. T1 ➡ U → 𝐒⦃T1⦄ →
258                             ∃∃V2,T2. L ⊢ V1 ➡ V2 & L ⊢ T1 ➡ T2 &
259                                      U = ⓐV2. T2.
260 #L #V1 #T1 #U #H #HT1
261 elim (cpr_inv_appl1 … H) -H *
262 [ /2 width=5/
263 | #a #V2 #W #U1 #U2 #_ #_ #H #_ destruct
264   elim (simple_inv_bind … HT1)
265 | #a #V #V2 #W1 #W2 #U1 #U2 #_ #_ #_ #_ #H #_ destruct
266   elim (simple_inv_bind … HT1)
267 ]
268 qed-.
269
270 (* Basic_1: includes: pr0_gen_cast pr2_gen_cast *)
271 lemma cpr_inv_cast1: ∀L,V1,U1,U2. L ⊢ ⓝ V1. U1 ➡ U2 → (
272                      ∃∃V2,T2. L ⊢ V1 ➡ V2 & L ⊢ U1 ➡ T2 &
273                               U2 = ⓝ V2. T2
274                      ) ∨
275                      L ⊢ U1 ➡ U2.
276 #L #V1 #U1 #U2 #H elim (cpr_inv_flat1 … H) -H *
277 [ /3 width=5/
278 | /2 width=1/
279 | #a #V2 #W #T1 #T2 #_ #_ #_ #_ #H destruct
280 | #a #V #V2 #W1 #W2 #T1 #T2 #_ #_ #_ #_ #_ #_ #H destruct
281 ]
282 qed-.
283
284 (* Basic forward lemmas *****************************************************)
285
286 lemma cpr_fwd_abst1: ∀a,L,V1,T1,U2. L ⊢ ⓛ{a}V1.T1 ➡ U2 → ∀I,W.
287                      ∃∃V2,T2. L ⊢ V1 ➡ V2 & L. ⓑ{I} W ⊢ T1 ➡ T2 &
288                               U2 = ⓛ{a} V2. T2.
289 #a #L #V1 #T1 #U2 #H #I #W
290 elim (cpr_inv_abst1 … H) -H #V2 #T2 #HV12 #HT12 #H destruct
291 lapply (cpr_lsubr_trans … HT12 (L.ⓑ{I}W) ?) -HT12 /2 width=1/ /2 width=5/
292 qed-.
293
294
295 lemma cpr_fwd_ext_abst1: ∀a,L,V1,T1,U2. L ⊢ ⓛ{a}V1.T1 ➡ U2 → ∀b,I,W.
296                          ∃∃V2,T2. L ⊢ V1 ➡ V2 & L ⊢ ⓑ{b,I}W.T1 ➡ ⓑ{b,I}W.T2 &
297                                   U2 = ⓛ{a}V2.T2.
298 #a #L #V1 #T1 #U2 #H #b #I #W
299 elim (cpr_fwd_abst1 … H I W) -H /3 width=5/
300 qed-.
301
302 lemma cpr_fwd_bind1_minus: ∀I,L,V1,T1,T. L ⊢ -ⓑ{I}V1.T1 ➡ T → ∀b.
303                            ∃∃V2,T2. L ⊢ ⓑ{b,I}V1.T1 ➡ ⓑ{b,I}V2.T2 &
304                                     T = -ⓑ{I}V2.T2.
305 #I #L #V1 #T1 #T #H #b
306 elim (cpr_inv_bind1 … H) -H *
307 [ #V2 #T2 #HV12 #HT12 #H destruct /3 width=4/
308 | #T2 #_ #_ #H destruct 
309 ]
310 qed-.
311
312 lemma cpr_fwd_shift1: ∀L1,L,T1,T. L ⊢ L1 @@ T1 ➡ T →
313                       ∃∃L2,T2. |L1| = |L2| & T = L2 @@ T2.
314 #L1 @(lenv_ind_dx … L1) -L1 normalize
315 [ #L #T1 #T #HT1
316   @(ex2_2_intro … (⋆)) // (**) (* explicit constructor *)
317 | #I #L1 #V1 #IH #L #T1 #X
318   >shift_append_assoc normalize #H
319   elim (cpr_inv_bind1 … H) -H *
320   [ #V0 #T0 #_ #HT10 #H destruct
321     elim (IH … HT10) -IH -HT10 #L2 #T2 #HL12 #H destruct
322     >append_length >HL12 -HL12
323     @(ex2_2_intro … (⋆.ⓑ{I}V0@@L2) T2) [ >append_length ] // /2 width=3/ (**) (* explicit constructor *)
324   | #T #_ #_ #H destruct
325   ]
326 ]
327 qed-.
328
329 (* Basic_1: removed theorems 11:
330             pr0_subst0_back pr0_subst0_fwd pr0_subst0
331             pr2_head_2 pr2_cflat clear_pr2_trans
332             pr2_gen_csort pr2_gen_cflat pr2_gen_cbind
333             pr2_gen_ctail pr2_ctail
334 *)
335 (* Basic_1: removed local theorems 4:
336             pr0_delta_tau pr0_cong_delta
337             pr2_free_free pr2_free_delta
338 *)