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