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