2 (**************************************************************************)
5 (* ||A|| A project by Andrea Asperti *)
7 (* ||I|| Developers: *)
8 (* ||T|| The HELM team. *)
9 (* ||A|| http://helm.cs.unibo.it *)
11 (* \ / This file is distributed under the terms of the *)
12 (* v GNU General Public License Version 2 *)
14 (**************************************************************************)
16 include "ground_2/relocation/nstream_after.ma".
17 include "basic_2/notation/relations/rliftstar_3.ma".
18 include "basic_2/grammar/term.ma".
20 (* GENERIC RELOCATION FOR TERMS *********************************************)
23 lift_sort lift_lref_lt lift_lref_ge lift_bind lift_flat
26 inductive lifts: rtmap → relation term ≝
27 | lifts_sort: ∀s,f. lifts f (⋆s) (⋆s)
28 | lifts_lref: ∀i1,i2,f. @⦃i1, f⦄ ≡ i2 → lifts f (#i1) (#i2)
29 | lifts_gref: ∀l,f. lifts f (§l) (§l)
30 | lifts_bind: ∀p,I,V1,V2,T1,T2,f.
31 lifts f V1 V2 → lifts (↑f) T1 T2 →
32 lifts f (ⓑ{p,I}V1.T1) (ⓑ{p,I}V2.T2)
33 | lifts_flat: ∀I,V1,V2,T1,T2,f.
34 lifts f V1 V2 → lifts f T1 T2 →
35 lifts f (ⓕ{I}V1.T1) (ⓕ{I}V2.T2)
38 interpretation "uniform relocation (term)"
39 'RLiftStar i T1 T2 = (lifts (uni i) T1 T2).
41 interpretation "generic relocation (term)"
42 'RLiftStar f T1 T2 = (lifts f T1 T2).
45 (* Basic inversion lemmas ***************************************************)
47 fact lifts_inv_sort1_aux: ∀X,Y,f. ⬆*[f] X ≡ Y → ∀s. X = ⋆s → Y = ⋆s.
48 #X #Y #f * -X -Y -f //
49 [ #i1 #i2 #f #_ #x #H destruct
50 | #p #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
51 | #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
55 (* Basic_1: was: lift1_sort *)
56 (* Basic_2A1: includes: lift_inv_sort1 *)
57 lemma lifts_inv_sort1: ∀Y,s,f. ⬆*[f] ⋆s ≡ Y → Y = ⋆s.
58 /2 width=4 by lifts_inv_sort1_aux/ qed-.
60 fact lifts_inv_lref1_aux: ∀X,Y,f. ⬆*[f] X ≡ Y → ∀i1. X = #i1 →
61 ∃∃i2. @⦃i1, f⦄ ≡ i2 & Y = #i2.
63 [ #s #f #x #H destruct
64 | #i1 #i2 #f #Hi12 #x #H destruct /2 width=3 by ex2_intro/
65 | #l #f #x #H destruct
66 | #p #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
67 | #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
71 (* Basic_1: was: lift1_lref *)
72 (* Basic_2A1: includes: lift_inv_lref1 lift_inv_lref1_lt lift_inv_lref1_ge *)
73 lemma lifts_inv_lref1: ∀Y,i1,f. ⬆*[f] #i1 ≡ Y →
74 ∃∃i2. @⦃i1, f⦄ ≡ i2 & Y = #i2.
75 /2 width=3 by lifts_inv_lref1_aux/ qed-.
77 fact lifts_inv_gref1_aux: ∀X,Y,f. ⬆*[f] X ≡ Y → ∀l. X = §l → Y = §l.
78 #X #Y #f * -X -Y -f //
79 [ #i1 #i2 #f #_ #x #H destruct
80 | #p #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
81 | #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
85 (* Basic_2A1: includes: lift_inv_gref1 *)
86 lemma lifts_inv_gref1: ∀Y,l,f. ⬆*[f] §l ≡ Y → Y = §l.
87 /2 width=4 by lifts_inv_gref1_aux/ qed-.
89 fact lifts_inv_bind1_aux: ∀X,Y,f. ⬆*[f] X ≡ Y →
90 ∀p,I,V1,T1. X = ⓑ{p,I}V1.T1 →
91 ∃∃V2,T2. ⬆*[f] V1 ≡ V2 & ⬆*[↑f] T1 ≡ T2 &
94 [ #s #f #q #J #W1 #U1 #H destruct
95 | #i1 #i2 #f #_ #q #J #W1 #U1 #H destruct
96 | #l #f #b #J #W1 #U1 #H destruct
97 | #p #I #V1 #V2 #T1 #T2 #f #HV12 #HT12 #q #J #W1 #U1 #H destruct /2 width=5 by ex3_2_intro/
98 | #I #V1 #V2 #T1 #T2 #f #_ #_ #q #J #W1 #U1 #H destruct
102 (* Basic_1: was: lift1_bind *)
103 (* Basic_2A1: includes: lift_inv_bind1 *)
104 lemma lifts_inv_bind1: ∀p,I,V1,T1,Y,f. ⬆*[f] ⓑ{p,I}V1.T1 ≡ Y →
105 ∃∃V2,T2. ⬆*[f] V1 ≡ V2 & ⬆*[↑f] T1 ≡ T2 &
107 /2 width=3 by lifts_inv_bind1_aux/ qed-.
109 fact lifts_inv_flat1_aux: ∀X,Y. ∀f:rtmap. ⬆*[f] X ≡ Y →
110 ∀I,V1,T1. X = ⓕ{I}V1.T1 →
111 ∃∃V2,T2. ⬆*[f] V1 ≡ V2 & ⬆*[f] T1 ≡ T2 &
114 [ #s #f #J #W1 #U1 #H destruct
115 | #i1 #i2 #f #_ #J #W1 #U1 #H destruct
116 | #l #f #J #W1 #U1 #H destruct
117 | #p #I #V1 #V2 #T1 #T2 #f #_ #_ #J #W1 #U1 #H destruct
118 | #I #V1 #V2 #T1 #T2 #f #HV12 #HT12 #J #W1 #U1 #H destruct /2 width=5 by ex3_2_intro/
122 (* Basic_1: was: lift1_flat *)
123 (* Basic_2A1: includes: lift_inv_flat1 *)
124 lemma lifts_inv_flat1: ∀I,V1,T1,Y. ∀f:rtmap. ⬆*[f] ⓕ{I}V1.T1 ≡ Y →
125 ∃∃V2,T2. ⬆*[f] V1 ≡ V2 & ⬆*[f] T1 ≡ T2 &
127 /2 width=3 by lifts_inv_flat1_aux/ qed-.
129 fact lifts_inv_sort2_aux: ∀X,Y,f. ⬆*[f] X ≡ Y → ∀s. Y = ⋆s → X = ⋆s.
130 #X #Y #f * -X -Y -f //
131 [ #i1 #i2 #f #_ #x #H destruct
132 | #p #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
133 | #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
137 (* Basic_1: includes: lift_gen_sort *)
138 (* Basic_2A1: includes: lift_inv_sort2 *)
139 lemma lifts_inv_sort2: ∀X,s,f. ⬆*[f] X ≡ ⋆s → X = ⋆s.
140 /2 width=4 by lifts_inv_sort2_aux/ qed-.
142 fact lifts_inv_lref2_aux: ∀X,Y,f. ⬆*[f] X ≡ Y → ∀i2. Y = #i2 →
143 ∃∃i1. @⦃i1, f⦄ ≡ i2 & X = #i1.
145 [ #s #f #x #H destruct
146 | #i1 #i2 #f #Hi12 #x #H destruct /2 width=3 by ex2_intro/
147 | #l #f #x #H destruct
148 | #p #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
149 | #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
153 (* Basic_1: includes: lift_gen_lref lift_gen_lref_lt lift_gen_lref_false lift_gen_lref_ge *)
154 (* Basic_2A1: includes: lift_inv_lref2 lift_inv_lref2_lt lift_inv_lref2_be lift_inv_lref2_ge lift_inv_lref2_plus *)
155 lemma lifts_inv_lref2: ∀X,i2,f. ⬆*[f] X ≡ #i2 →
156 ∃∃i1. @⦃i1, f⦄ ≡ i2 & X = #i1.
157 /2 width=3 by lifts_inv_lref2_aux/ qed-.
159 fact lifts_inv_gref2_aux: ∀X,Y,f. ⬆*[f] X ≡ Y → ∀l. Y = §l → X = §l.
160 #X #Y #f * -X -Y -f //
161 [ #i1 #i2 #f #_ #x #H destruct
162 | #p #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
163 | #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
167 (* Basic_2A1: includes: lift_inv_gref1 *)
168 lemma lifts_inv_gref2: ∀X,l,f. ⬆*[f] X ≡ §l → X = §l.
169 /2 width=4 by lifts_inv_gref2_aux/ qed-.
171 fact lifts_inv_bind2_aux: ∀X,Y,f. ⬆*[f] X ≡ Y →
172 ∀p,I,V2,T2. Y = ⓑ{p,I}V2.T2 →
173 ∃∃V1,T1. ⬆*[f] V1 ≡ V2 & ⬆*[↑f] T1 ≡ T2 &
176 [ #s #f #q #J #W2 #U2 #H destruct
177 | #i1 #i2 #f #_ #q #J #W2 #U2 #H destruct
178 | #l #f #q #J #W2 #U2 #H destruct
179 | #p #I #V1 #V2 #T1 #T2 #f #HV12 #HT12 #q #J #W2 #U2 #H destruct /2 width=5 by ex3_2_intro/
180 | #I #V1 #V2 #T1 #T2 #f #_ #_ #q #J #W2 #U2 #H destruct
184 (* Basic_1: includes: lift_gen_bind *)
185 (* Basic_2A1: includes: lift_inv_bind2 *)
186 lemma lifts_inv_bind2: ∀p,I,V2,T2,X,f. ⬆*[f] X ≡ ⓑ{p,I}V2.T2 →
187 ∃∃V1,T1. ⬆*[f] V1 ≡ V2 & ⬆*[↑f] T1 ≡ T2 &
189 /2 width=3 by lifts_inv_bind2_aux/ qed-.
191 fact lifts_inv_flat2_aux: ∀X,Y. ∀f:rtmap. ⬆*[f] X ≡ Y →
192 ∀I,V2,T2. Y = ⓕ{I}V2.T2 →
193 ∃∃V1,T1. ⬆*[f] V1 ≡ V2 & ⬆*[f] T1 ≡ T2 &
196 [ #s #f #J #W2 #U2 #H destruct
197 | #i1 #i2 #f #_ #J #W2 #U2 #H destruct
198 | #l #f #J #W2 #U2 #H destruct
199 | #p #I #V1 #V2 #T1 #T2 #f #_ #_ #J #W2 #U2 #H destruct
200 | #I #V1 #V2 #T1 #T2 #f #HV12 #HT12 #J #W2 #U2 #H destruct /2 width=5 by ex3_2_intro/
204 (* Basic_1: includes: lift_gen_flat *)
205 (* Basic_2A1: includes: lift_inv_flat2 *)
206 lemma lifts_inv_flat2: ∀I,V2,T2,X. ∀f:rtmap. ⬆*[f] X ≡ ⓕ{I}V2.T2 →
207 ∃∃V1,T1. ⬆*[f] V1 ≡ V2 & ⬆*[f] T1 ≡ T2 &
209 /2 width=3 by lifts_inv_flat2_aux/ qed-.
211 (* Basic_2A1: includes: lift_inv_pair_xy_x *)
212 lemma lifts_inv_pair_xy_x: ∀I,V,T,f. ⬆*[f] ②{I}V.T ≡ V → ⊥.
215 [ lapply (lifts_inv_sort2 … H) -H #H destruct
216 | elim (lifts_inv_lref2 … H) -H
218 | lapply (lifts_inv_gref2 … H) -H #H destruct
220 | * [ #p ] #I #V2 #T2 #IHV2 #_ #U #f #H
221 [ elim (lifts_inv_bind2 … H) -H #V1 #T1 #HV12 #_ #H destruct /2 width=3 by/
222 | elim (lifts_inv_flat2 … H) -H #V1 #T1 #HV12 #_ #H destruct /2 width=3 by/
227 (* Basic_1: includes: thead_x_lift_y_y *)
228 (* Basic_2A1: includes: lift_inv_pair_xy_y *)
229 lemma lifts_inv_pair_xy_y: ∀I,T,V,f. ⬆*[f] ②{I}V.T ≡ T → ⊥.
232 [ lapply (lifts_inv_sort2 … H) -H #H destruct
233 | elim (lifts_inv_lref2 … H) -H
235 | lapply (lifts_inv_gref2 … H) -H #H destruct
237 | * [ #p ] #I #V2 #T2 #_ #IHT2 #W #f #H
238 [ elim (lifts_inv_bind2 … H) -H #V1 #T1 #_ #HT12 #H destruct /2 width=4 by/
239 | elim (lifts_inv_flat2 … H) -H #V1 #T1 #_ #HT12 #H destruct /2 width=4 by/
244 (* Basic forward lemmas *****************************************************)
246 (* Basic_2A1: includes: lift_inv_O2 *)
247 lemma lifts_fwd_isid: ∀T1,T2,f. ⬆*[f] T1 ≡ T2 → 𝐈⦃f⦄ → T1 = T2.
248 #T1 #T2 #f #H elim H -T1 -T2 -f
249 /4 width=3 by isid_inv_at_mono, isid_push, eq_f2, eq_f/
252 (* Basic_2A1: includes: lift_fwd_pair1 *)
253 lemma lifts_fwd_pair1: ∀I,V1,T1,Y. ∀f:rtmap. ⬆*[f] ②{I}V1.T1 ≡ Y →
254 ∃∃V2,T2. ⬆*[f] V1 ≡ V2 & Y = ②{I}V2.T2.
255 * [ #p ] #I #V1 #T1 #Y #f #H
256 [ elim (lifts_inv_bind1 … H) -H /2 width=4 by ex2_2_intro/
257 | elim (lifts_inv_flat1 … H) -H /2 width=4 by ex2_2_intro/
261 (* Basic_2A1: includes: lift_fwd_pair2 *)
262 lemma lifts_fwd_pair2: ∀I,V2,T2,X. ∀f:rtmap. ⬆*[f] X ≡ ②{I}V2.T2 →
263 ∃∃V1,T1. ⬆*[f] V1 ≡ V2 & X = ②{I}V1.T1.
264 * [ #p ] #I #V2 #T2 #X #f #H
265 [ elim (lifts_inv_bind2 … H) -H /2 width=4 by ex2_2_intro/
266 | elim (lifts_inv_flat2 … H) -H /2 width=4 by ex2_2_intro/
270 (* Basic properties *********************************************************)
272 lemma lifts_eq_repl_back: ∀T1,T2. eq_repl_back … (λf. ⬆*[f] T1 ≡ T2).
273 #T1 #T2 #f1 #H elim H -T1 -T2 -f1
274 /4 width=5 by lifts_flat, lifts_bind, lifts_lref, at_eq_repl_back, eq_push/
277 lemma lifts_eq_repl_fwd: ∀T1,T2. eq_repl_fwd … (λf. ⬆*[f] T1 ≡ T2).
278 #T1 #T2 @eq_repl_sym /2 width=3 by lifts_eq_repl_back/ (**) (* full auto fails *)
281 (* Basic_1: includes: lift_r *)
282 (* Basic_2A1: includes: lift_refl *)
283 lemma lifts_refl: ∀T,f. 𝐈⦃f⦄ → ⬆*[f] T ≡ T.
285 /4 width=3 by lifts_flat, lifts_bind, lifts_lref, isid_inv_at, isid_push/
288 (* Basic_2A1: includes: lift_total *)
289 lemma lifts_total: ∀T1,f. ∃T2. ⬆*[f] T1 ≡ T2.
291 /3 width=2 by lifts_lref, lifts_sort, lifts_gref, ex_intro/
292 [ #p ] #I #V1 #T1 #IHV1 #IHT1 #f
293 elim (IHV1 f) -IHV1 #V2 #HV12
294 [ elim (IHT1 (↑f)) -IHT1 /3 width=2 by lifts_bind, ex_intro/
295 | elim (IHT1 f) -IHT1 /3 width=2 by lifts_flat, ex_intro/
299 lemma lift_lref_uni: ∀l,i. ⬆*[l] #i ≡ #(l+i).
300 #l elim l -l /2 width=1 by lifts_lref/
303 (* Basic_1: includes: lift_free (right to left) *)
304 (* Basic_2A1: includes: lift_split *)
305 lemma lifts_split_trans: ∀T1,T2,f. ⬆*[f] T1 ≡ T2 →
306 ∀f1,f2. f2 ⊚ f1 ≡ f →
307 ∃∃T. ⬆*[f1] T1 ≡ T & ⬆*[f2] T ≡ T2.
308 #T1 #T2 #f #H elim H -T1 -T2 -f
309 [ /3 width=3 by lifts_sort, ex2_intro/
310 | #i1 #i2 #f #Hi #f1 #f2 #Ht elim (after_at_fwd … Hi … Ht) -Hi -Ht
311 /3 width=3 by lifts_lref, ex2_intro/
312 | /3 width=3 by lifts_gref, ex2_intro/
313 | #p #I #V1 #V2 #T1 #T2 #f #_ #_ #IHV #IHT #f1 #f2 #Ht
314 elim (IHV … Ht) elim (IHT (↑f1) (↑f2)) -IHV -IHT
315 /3 width=5 by lifts_bind, after_O2, ex2_intro/
316 | #I #V1 #V2 #T1 #T2 #f #_ #_ #IHV #IHT #f1 #f2 #Ht
317 elim (IHV … Ht) elim (IHT … Ht) -IHV -IHT -Ht
318 /3 width=5 by lifts_flat, ex2_intro/
322 (* Note: apparently, this was missing in Basic_2A1 *)
323 lemma lifts_split_div: ∀T1,T2,f1. ⬆*[f1] T1 ≡ T2 →
325 ∃∃T. ⬆*[f2] T2 ≡ T & ⬆*[f] T1 ≡ T.
326 #T1 #T2 #f1 #H elim H -T1 -T2 -f1
327 [ /3 width=3 by lifts_sort, ex2_intro/
328 | #i1 #i2 #f1 #Hi #f2 #f #Ht elim (after_at1_fwd … Hi … Ht) -Hi -Ht
329 /3 width=3 by lifts_lref, ex2_intro/
330 | /3 width=3 by lifts_gref, ex2_intro/
331 | #p #I #V1 #V2 #T1 #T2 #f1 #_ #_ #IHV #IHT #f2 #f #Ht
332 elim (IHV … Ht) elim (IHT (↑f2) (↑f)) -IHV -IHT
333 /3 width=5 by lifts_bind, after_O2, ex2_intro/
334 | #I #V1 #V2 #T1 #T2 #f1 #_ #_ #IHV #IHT #f2 #f #Ht
335 elim (IHV … Ht) elim (IHT … Ht) -IHV -IHT -Ht
336 /3 width=5 by lifts_flat, ex2_intro/
340 (* Basic_1: includes: dnf_dec2 dnf_dec *)
341 (* Basic_2A1: includes: is_lift_dec *)
342 lemma is_lifts_dec: ∀T2,f. Decidable (∃T1. ⬆*[f] T1 ≡ T2).
344 [ * [1,3: /3 width=2 by lifts_sort, lifts_gref, ex_intro, or_introl/ ]
345 #i2 #f elim (is_at_dec f i2) //
346 [ * /4 width=3 by lifts_lref, ex_intro, or_introl/
348 #X #HX elim (lifts_inv_lref2 … HX) -HX
349 /3 width=2 by ex_intro/
351 | * [ #p ] #I #V2 #T2 #IHV2 #IHT2 #f
352 [ elim (IHV2 f) -IHV2
353 [ * #V1 #HV12 elim (IHT2 (↑f)) -IHT2
354 [ * #T1 #HT12 @or_introl /3 width=2 by lifts_bind, ex_intro/
355 | -V1 #HT2 @or_intror * #X #H
356 elim (lifts_inv_bind2 … H) -H /3 width=2 by ex_intro/
358 | -IHT2 #HV2 @or_intror * #X #H
359 elim (lifts_inv_bind2 … H) -H /3 width=2 by ex_intro/
361 | elim (IHV2 f) -IHV2
362 [ * #V1 #HV12 elim (IHT2 f) -IHT2
363 [ * #T1 #HT12 /4 width=2 by lifts_flat, ex_intro, or_introl/
364 | -V1 #HT2 @or_intror * #X #H
365 elim (lifts_inv_flat2 … H) -H /3 width=2 by ex_intro/
367 | -IHT2 #HV2 @or_intror * #X #H
368 elim (lifts_inv_flat2 … H) -H /3 width=2 by ex_intro/
374 (* Basic_2A1: removed theorems 14:
375 lifts_inv_nil lifts_inv_cons
376 lift_inv_Y1 lift_inv_Y2 lift_inv_lref_Y1 lift_inv_lref_Y2 lift_lref_Y lift_Y1
377 lift_lref_lt_eq lift_lref_ge_eq lift_lref_plus lift_lref_pred
378 lift_lref_ge_minus lift_lref_ge_minus_eq
380 (* Basic_1: removed theorems 8:
382 lift_head lift_gen_head
383 lift_weight_map lift_weight lift_weight_add lift_weight_add_O