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