]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/lambdadelta/basic_2/relocation/lifts.ma
partial commit in the relocation component to move some files ...
[helm.git] / matita / matita / contribs / lambdadelta / basic_2 / relocation / lifts.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_2/relocation/nstream_after.ma".
16 include "basic_2/notation/relations/rliftstar_3.ma".
17 include "basic_2/grammar/term.ma".
18
19 (* GENERIC RELOCATION FOR TERMS *********************************************)
20
21 (* Basic_1: includes:
22             lift_sort lift_lref_lt lift_lref_ge lift_bind lift_flat
23             lifts_nil lifts_cons
24 *)
25 inductive lifts: rtmap → relation term ≝
26 | lifts_sort: ∀s,f. lifts f (⋆s) (⋆s)
27 | lifts_lref: ∀i1,i2,f. @⦃i1, f⦄ ≡ i2 → lifts f (#i1) (#i2)
28 | lifts_gref: ∀l,f. lifts f (§l) (§l)
29 | lifts_bind: ∀p,I,V1,V2,T1,T2,f.
30               lifts f V1 V2 → lifts (↑f) T1 T2 →
31               lifts f (ⓑ{p,I}V1.T1) (ⓑ{p,I}V2.T2)
32 | lifts_flat: ∀I,V1,V2,T1,T2,f.
33               lifts f V1 V2 → lifts f T1 T2 →
34               lifts f (ⓕ{I}V1.T1) (ⓕ{I}V2.T2)
35 .
36
37 interpretation "generic relocation (term)"
38    'RLiftStar cs T1 T2 = (lifts cs T1 T2).
39
40 (* Basic inversion lemmas ***************************************************)
41
42 fact lifts_inv_sort1_aux: ∀X,Y,f. ⬆*[f] X ≡ Y → ∀s. X = ⋆s → Y = ⋆s.
43 #X #Y #f * -X -Y -f //
44 [ #i1 #i2 #f #_ #x #H destruct
45 | #p #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
46 | #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
47 ]
48 qed-.
49
50 (* Basic_1: was: lift1_sort *)
51 (* Basic_2A1: includes: lift_inv_sort1 *)
52 lemma lifts_inv_sort1: ∀Y,s,f. ⬆*[f] ⋆s ≡ Y → Y = ⋆s.
53 /2 width=4 by lifts_inv_sort1_aux/ qed-.
54
55 fact lifts_inv_lref1_aux: ∀X,Y,f. ⬆*[f] X ≡ Y → ∀i1. X = #i1 →
56                           ∃∃i2. @⦃i1, f⦄ ≡ i2 & Y = #i2.
57 #X #Y #f * -X -Y -f
58 [ #s #f #x #H destruct
59 | #i1 #i2 #f #Hi12 #x #H destruct /2 width=3 by ex2_intro/
60 | #l #f #x #H destruct
61 | #p #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
62 | #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
63 ]
64 qed-.
65
66 (* Basic_1: was: lift1_lref *)
67 (* Basic_2A1: includes: lift_inv_lref1 lift_inv_lref1_lt lift_inv_lref1_ge *)
68 lemma lifts_inv_lref1: ∀Y,i1,f. ⬆*[f] #i1 ≡ Y →
69                        ∃∃i2. @⦃i1, f⦄ ≡ i2 & Y = #i2.
70 /2 width=3 by lifts_inv_lref1_aux/ qed-.
71
72 fact lifts_inv_gref1_aux: ∀X,Y,f. ⬆*[f] X ≡ Y → ∀l. X = §l → Y = §l.
73 #X #Y #f * -X -Y -f //
74 [ #i1 #i2 #f #_ #x #H destruct
75 | #p #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
76 | #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
77 ]
78 qed-.
79
80 (* Basic_2A1: includes: lift_inv_gref1 *)
81 lemma lifts_inv_gref1: ∀Y,l,f. ⬆*[f] §l ≡ Y → Y = §l.
82 /2 width=4 by lifts_inv_gref1_aux/ qed-.
83
84 fact lifts_inv_bind1_aux: ∀X,Y,f. ⬆*[f] X ≡ Y →
85                           ∀p,I,V1,T1. X = ⓑ{p,I}V1.T1 →
86                           ∃∃V2,T2. ⬆*[f] V1 ≡ V2 & ⬆*[↑f] T1 ≡ T2 &
87                                    Y = ⓑ{p,I}V2.T2.
88 #X #Y #f * -X -Y -f
89 [ #s #f #q #J #W1 #U1 #H destruct
90 | #i1 #i2 #f #_ #q #J #W1 #U1 #H destruct
91 | #l #f #b #J #W1 #U1 #H destruct
92 | #p #I #V1 #V2 #T1 #T2 #f #HV12 #HT12 #q #J #W1 #U1 #H destruct /2 width=5 by ex3_2_intro/
93 | #I #V1 #V2 #T1 #T2 #f #_ #_ #q #J #W1 #U1 #H destruct
94 ]
95 qed-.
96
97 (* Basic_1: was: lift1_bind *)
98 (* Basic_2A1: includes: lift_inv_bind1 *)
99 lemma lifts_inv_bind1: ∀p,I,V1,T1,Y,f. ⬆*[f] ⓑ{p,I}V1.T1 ≡ Y →
100                        ∃∃V2,T2. ⬆*[f] V1 ≡ V2 & ⬆*[↑f] T1 ≡ T2 &
101                                 Y = ⓑ{p,I}V2.T2.
102 /2 width=3 by lifts_inv_bind1_aux/ qed-.
103
104 fact lifts_inv_flat1_aux: ∀X,Y,f. ⬆*[f] X ≡ Y →
105                           ∀I,V1,T1. X = ⓕ{I}V1.T1 →
106                           ∃∃V2,T2. ⬆*[f] V1 ≡ V2 & ⬆*[f] T1 ≡ T2 &
107                                    Y = ⓕ{I}V2.T2.
108 #X #Y #f * -X -Y -f
109 [ #s #f #J #W1 #U1 #H destruct
110 | #i1 #i2 #f #_ #J #W1 #U1 #H destruct
111 | #l #f #J #W1 #U1 #H destruct
112 | #p #I #V1 #V2 #T1 #T2 #f #_ #_ #J #W1 #U1 #H destruct
113 | #I #V1 #V2 #T1 #T2 #f #HV12 #HT12 #J #W1 #U1 #H destruct /2 width=5 by ex3_2_intro/
114 ]
115 qed-.
116
117 (* Basic_1: was: lift1_flat *)
118 (* Basic_2A1: includes: lift_inv_flat1 *)
119 lemma lifts_inv_flat1: ∀I,V1,T1,Y,f. ⬆*[f] ⓕ{I}V1.T1 ≡ Y →
120                        ∃∃V2,T2. ⬆*[f] V1 ≡ V2 & ⬆*[f] T1 ≡ T2 &
121                                 Y = ⓕ{I}V2.T2.
122 /2 width=3 by lifts_inv_flat1_aux/ qed-.
123
124 fact lifts_inv_sort2_aux: ∀X,Y,f. ⬆*[f] X ≡ Y → ∀s. Y = ⋆s → X = ⋆s.
125 #X #Y #f * -X -Y -f //
126 [ #i1 #i2 #f #_ #x #H destruct
127 | #p #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
128 | #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
129 ]
130 qed-.
131
132 (* Basic_1: includes: lift_gen_sort *)
133 (* Basic_2A1: includes: lift_inv_sort2 *)
134 lemma lifts_inv_sort2: ∀X,s,f. ⬆*[f] X ≡ ⋆s → X = ⋆s.
135 /2 width=4 by lifts_inv_sort2_aux/ qed-.
136
137 fact lifts_inv_lref2_aux: ∀X,Y,f. ⬆*[f] X ≡ Y → ∀i2. Y = #i2 →
138                           ∃∃i1. @⦃i1, f⦄ ≡ i2 & X = #i1.
139 #X #Y #f * -X -Y -f
140 [ #s #f #x #H destruct
141 | #i1 #i2 #f #Hi12 #x #H destruct /2 width=3 by ex2_intro/
142 | #l #f #x #H destruct
143 | #p #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
144 | #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
145 ]
146 qed-.
147
148 (* Basic_1: includes: lift_gen_lref lift_gen_lref_lt lift_gen_lref_false lift_gen_lref_ge *)
149 (* Basic_2A1: includes: lift_inv_lref2 lift_inv_lref2_lt lift_inv_lref2_be lift_inv_lref2_ge lift_inv_lref2_plus *)
150 lemma lifts_inv_lref2: ∀X,i2,f. ⬆*[f] X ≡ #i2 →
151                        ∃∃i1. @⦃i1, f⦄ ≡ i2 & X = #i1.
152 /2 width=3 by lifts_inv_lref2_aux/ qed-.
153
154 fact lifts_inv_gref2_aux: ∀X,Y,f. ⬆*[f] X ≡ Y → ∀l. Y = §l → X = §l.
155 #X #Y #f * -X -Y -f //
156 [ #i1 #i2 #f #_ #x #H destruct
157 | #p #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
158 | #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
159 ]
160 qed-.
161
162 (* Basic_2A1: includes: lift_inv_gref1 *)
163 lemma lifts_inv_gref2: ∀X,l,f. ⬆*[f] X ≡ §l → X = §l.
164 /2 width=4 by lifts_inv_gref2_aux/ qed-.
165
166 fact lifts_inv_bind2_aux: ∀X,Y,f. ⬆*[f] X ≡ Y →
167                           ∀p,I,V2,T2. Y = ⓑ{p,I}V2.T2 →
168                           ∃∃V1,T1. ⬆*[f] V1 ≡ V2 & ⬆*[↑f] T1 ≡ T2 &
169                                    X = ⓑ{p,I}V1.T1.
170 #X #Y #f * -X -Y -f
171 [ #s #f #q #J #W2 #U2 #H destruct
172 | #i1 #i2 #f #_ #q #J #W2 #U2 #H destruct
173 | #l #f #q #J #W2 #U2 #H destruct
174 | #p #I #V1 #V2 #T1 #T2 #f #HV12 #HT12 #q #J #W2 #U2 #H destruct /2 width=5 by ex3_2_intro/
175 | #I #V1 #V2 #T1 #T2 #f #_ #_ #q #J #W2 #U2 #H destruct
176 ]
177 qed-.
178
179 (* Basic_1: includes: lift_gen_bind *)
180 (* Basic_2A1: includes: lift_inv_bind2 *)
181 lemma lifts_inv_bind2: ∀p,I,V2,T2,X,f. ⬆*[f] X ≡ ⓑ{p,I}V2.T2 →
182                        ∃∃V1,T1. ⬆*[f] V1 ≡ V2 & ⬆*[↑f] T1 ≡ T2 &
183                                 X = ⓑ{p,I}V1.T1.
184 /2 width=3 by lifts_inv_bind2_aux/ qed-.
185
186 fact lifts_inv_flat2_aux: ∀X,Y,f. ⬆*[f] X ≡ Y →
187                           ∀I,V2,T2. Y = ⓕ{I}V2.T2 →
188                           ∃∃V1,T1. ⬆*[f] V1 ≡ V2 & ⬆*[f] T1 ≡ T2 &
189                                    X = ⓕ{I}V1.T1.
190 #X #Y #f * -X -Y -f
191 [ #s #f #J #W2 #U2 #H destruct
192 | #i1 #i2 #f #_ #J #W2 #U2 #H destruct
193 | #l #f #J #W2 #U2 #H destruct
194 | #p #I #V1 #V2 #T1 #T2 #f #_ #_ #J #W2 #U2 #H destruct
195 | #I #V1 #V2 #T1 #T2 #f #HV12 #HT12 #J #W2 #U2 #H destruct /2 width=5 by ex3_2_intro/
196 ]
197 qed-.
198
199 (* Basic_1: includes: lift_gen_flat *)
200 (* Basic_2A1: includes: lift_inv_flat2 *)
201 lemma lifts_inv_flat2: ∀I,V2,T2,X,f. ⬆*[f] X ≡ ⓕ{I}V2.T2 →
202                        ∃∃V1,T1. ⬆*[f] V1 ≡ V2 & ⬆*[f] T1 ≡ T2 &
203                                 X = ⓕ{I}V1.T1.
204 /2 width=3 by lifts_inv_flat2_aux/ qed-.
205
206 (* Basic_2A1: includes: lift_inv_pair_xy_x *)
207 lemma lifts_inv_pair_xy_x: ∀I,V,T,f. ⬆*[f] ②{I}V.T ≡ V → ⊥.
208 #J #V elim V -V
209 [ * #i #U #f #H
210   [ lapply (lifts_inv_sort2 … H) -H #H destruct
211   | elim (lifts_inv_lref2 … H) -H
212     #x #_ #H destruct
213   | lapply (lifts_inv_gref2 … H) -H #H destruct
214   ]
215 | * [ #p ] #I #V2 #T2 #IHV2 #_ #U #f #H
216   [ elim (lifts_inv_bind2 … H) -H #V1 #T1 #HV12 #_ #H destruct /2 width=3 by/
217   | elim (lifts_inv_flat2 … H) -H #V1 #T1 #HV12 #_ #H destruct /2 width=3 by/
218   ]
219 ]
220 qed-.
221
222 (* Basic_1: includes: thead_x_lift_y_y *)
223 (* Basic_2A1: includes: lift_inv_pair_xy_y *)
224 lemma lifts_inv_pair_xy_y: ∀I,T,V,f. ⬆*[f] ②{I}V.T ≡ T → ⊥.
225 #J #T elim T -T
226 [ * #i #W #f #H
227   [ lapply (lifts_inv_sort2 … H) -H #H destruct
228   | elim (lifts_inv_lref2 … H) -H
229     #x #_ #H destruct
230   | lapply (lifts_inv_gref2 … H) -H #H destruct
231   ]
232 | * [ #p ] #I #V2 #T2 #_ #IHT2 #W #f #H
233   [ elim (lifts_inv_bind2 … H) -H #V1 #T1 #_ #HT12 #H destruct /2 width=4 by/
234   | elim (lifts_inv_flat2 … H) -H #V1 #T1 #_ #HT12 #H destruct /2 width=4 by/
235   ]
236 ]
237 qed-.
238
239 (* Basic forward lemmas *****************************************************)
240
241 (* Basic_2A1: includes: lift_inv_O2 *)
242 lemma lifts_fwd_isid: ∀T1,T2,f. ⬆*[f] T1 ≡ T2 → 𝐈⦃f⦄ → T1 = T2.
243 #T1 #T2 #f #H elim H -T1 -T2 -f
244 /4 width=3 by isid_inv_at_mono, isid_push, eq_f2, eq_f/
245 qed-.
246
247 (* Basic_2A1: includes: lift_fwd_pair1 *)
248 lemma lifts_fwd_pair1: ∀I,V1,T1,Y,f. ⬆*[f] ②{I}V1.T1 ≡ Y →
249                        ∃∃V2,T2. ⬆*[f] V1 ≡ V2 & Y = ②{I}V2.T2.
250 * [ #p ] #I #V1 #T1 #Y #f #H
251 [ elim (lifts_inv_bind1 … H) -H /2 width=4 by ex2_2_intro/
252 | elim (lifts_inv_flat1 … H) -H /2 width=4 by ex2_2_intro/
253 ]
254 qed-.
255
256 (* Basic_2A1: includes: lift_fwd_pair2 *)
257 lemma lifts_fwd_pair2: ∀I,V2,T2,X,f. ⬆*[f] X ≡ ②{I}V2.T2 →
258                        ∃∃V1,T1. ⬆*[f] V1 ≡ V2 & X = ②{I}V1.T1.
259 * [ #p ] #I #V2 #T2 #X #f #H
260 [ elim (lifts_inv_bind2 … H) -H /2 width=4 by ex2_2_intro/
261 | elim (lifts_inv_flat2 … H) -H /2 width=4 by ex2_2_intro/
262 ]
263 qed-.
264
265 (* Basic properties *********************************************************)
266
267 lemma lifts_eq_repl_back: ∀T1,T2. eq_repl_back … (λf. ⬆*[f] T1 ≡ T2).
268 #T1 #T2 #f1 #H elim H -T1 -T2 -f1
269 /4 width=5 by lifts_flat, lifts_bind, lifts_lref, at_eq_repl_back, eq_push/
270 qed-.
271
272 lemma lifts_eq_repl_fwd: ∀T1,T2. eq_repl_fwd … (λf. ⬆*[f] T1 ≡ T2).
273 #T1 #T2 @eq_repl_sym /2 width=3 by lifts_eq_repl_back/ (**) (* full auto fails *)
274 qed-.
275
276 (* Basic_1: includes: lift_r *)
277 (* Basic_2A1: includes: lift_refl *)
278 lemma lifts_refl: ∀T,f. 𝐈⦃f⦄ → ⬆*[f] T ≡ T.
279 #T elim T -T *
280 /4 width=3 by lifts_flat, lifts_bind, lifts_lref, isid_inv_at, isid_push/
281 qed.
282
283 (* Basic_2A1: includes: lift_total *)
284 lemma lifts_total: ∀T1,f. ∃T2. ⬆*[f] T1 ≡ T2.
285 #T1 elim T1 -T1 *
286 /3 width=2 by lifts_lref, lifts_sort, lifts_gref, ex_intro/
287 [ #p ] #I #V1 #T1 #IHV1 #IHT1 #f
288 elim (IHV1 f) -IHV1 #V2 #HV12
289 [ elim (IHT1 (↑f)) -IHT1 /3 width=2 by lifts_bind, ex_intro/
290 | elim (IHT1 f) -IHT1 /3 width=2 by lifts_flat, ex_intro/
291 ]
292 qed-.
293
294 (* Basic_1: includes: lift_free (right to left) *)
295 (* Basic_2A1: includes: lift_split *)
296 lemma lifts_split_trans: ∀T1,T2,f. ⬆*[f] T1 ≡ T2 →
297                          ∀f1,f2. f2 ⊚ f1 ≡ f →
298                          ∃∃T. ⬆*[f1] T1 ≡ T & ⬆*[f2] T ≡ T2.
299 #T1 #T2 #f #H elim H -T1 -T2 -f
300 [ /3 width=3 by lifts_sort, ex2_intro/
301 | #i1 #i2 #f #Hi #f1 #f2 #Ht elim (after_at_fwd … Hi … Ht) -Hi -Ht
302   /3 width=3 by lifts_lref, ex2_intro/
303 | /3 width=3 by lifts_gref, ex2_intro/
304 | #p #I #V1 #V2 #T1 #T2 #f #_ #_ #IHV #IHT #f1 #f2 #Ht
305   elim (IHV … Ht) elim (IHT (↑f1) (↑f2)) -IHV -IHT
306   /3 width=5 by lifts_bind, after_O2, ex2_intro/
307 | #I #V1 #V2 #T1 #T2 #f #_ #_ #IHV #IHT #f1 #f2 #Ht
308   elim (IHV … Ht) elim (IHT … Ht) -IHV -IHT -Ht
309   /3 width=5 by lifts_flat, ex2_intro/
310 ]
311 qed-.
312
313 (* Note: apparently, this was missing in Basic_2A1 *)
314 lemma lifts_split_div: ∀T1,T2,f1. ⬆*[f1] T1 ≡ T2 →
315                        ∀f2,f. f2 ⊚ f1 ≡ f →
316                        ∃∃T. ⬆*[f2] T2 ≡ T & ⬆*[f] T1 ≡ T.
317 #T1 #T2 #f1 #H elim H -T1 -T2 -f1
318 [ /3 width=3 by lifts_sort, ex2_intro/
319 | #i1 #i2 #f1 #Hi #f2 #f #Ht elim (after_at1_fwd … Hi … Ht) -Hi -Ht
320   /3 width=3 by lifts_lref, ex2_intro/
321 | /3 width=3 by lifts_gref, ex2_intro/
322 | #p #I #V1 #V2 #T1 #T2 #f1 #_ #_ #IHV #IHT #f2 #f #Ht
323   elim (IHV … Ht) elim (IHT (↑f2) (↑f)) -IHV -IHT
324   /3 width=5 by lifts_bind, after_O2, ex2_intro/
325 | #I #V1 #V2 #T1 #T2 #f1 #_ #_ #IHV #IHT #f2 #f #Ht
326   elim (IHV … Ht) elim (IHT … Ht) -IHV -IHT -Ht
327   /3 width=5 by lifts_flat, ex2_intro/
328 ]
329 qed-.
330
331 (* Basic_1: includes: dnf_dec2 dnf_dec *)
332 (* Basic_2A1: includes: is_lift_dec *)
333 lemma is_lifts_dec: ∀T2,f. Decidable (∃T1. ⬆*[f] T1 ≡ T2).
334 #T1 elim T1 -T1
335 [ * [1,3: /3 width=2 by lifts_sort, lifts_gref, ex_intro, or_introl/ ]
336   #i2 #f elim (is_at_dec f i2) //
337   [ * /4 width=3 by lifts_lref, ex_intro, or_introl/
338   | #H @or_intror *
339     #X #HX elim (lifts_inv_lref2 … HX) -HX
340     /3 width=2 by ex_intro/
341   ]
342 | * [ #p ] #I #V2 #T2 #IHV2 #IHT2 #f
343   [ elim (IHV2 f) -IHV2
344     [ * #V1 #HV12 elim (IHT2 (↑f)) -IHT2
345       [ * #T1 #HT12 @or_introl /3 width=2 by lifts_bind, ex_intro/
346       | -V1 #HT2 @or_intror * #X #H
347         elim (lifts_inv_bind2 … H) -H /3 width=2 by ex_intro/
348       ]
349     | -IHT2 #HV2 @or_intror * #X #H
350       elim (lifts_inv_bind2 … H) -H /3 width=2 by ex_intro/
351     ]
352   | elim (IHV2 f) -IHV2
353     [ * #V1 #HV12 elim (IHT2 f) -IHT2
354       [ * #T1 #HT12 /4 width=2 by lifts_flat, ex_intro, or_introl/
355       | -V1 #HT2 @or_intror * #X #H
356         elim (lifts_inv_flat2 … H) -H /3 width=2 by ex_intro/
357       ]
358     | -IHT2 #HV2 @or_intror * #X #H
359       elim (lifts_inv_flat2 … H) -H /3 width=2 by ex_intro/
360     ]
361   ]
362 ]
363 qed-.
364
365 (* Basic_2A1: removed theorems 14:
366               lifts_inv_nil lifts_inv_cons
367               lift_inv_Y1 lift_inv_Y2 lift_inv_lref_Y1 lift_inv_lref_Y2 lift_lref_Y lift_Y1
368               lift_lref_lt_eq lift_lref_ge_eq lift_lref_plus lift_lref_pred
369               lift_lref_ge_minus lift_lref_ge_minus_eq
370 *)
371 (* Basic_1: removed theorems 8:
372             lift_lref_gt            
373             lift_head lift_gen_head 
374             lift_weight_map lift_weight lift_weight_add lift_weight_add_O
375             lift_tlt_dx
376 *)