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: ∀f,s. lifts f (⋆s) (⋆s)
28 | lifts_lref: ∀f,i1,i2. @⦃i1, f⦄ ≡ i2 → lifts f (#i1) (#i2)
29 | lifts_gref: ∀f,l. lifts f (§l) (§l)
30 | lifts_bind: ∀f,p,I,V1,V2,T1,T2.
31 lifts f V1 V2 → lifts (↑f) T1 T2 →
32 lifts f (ⓑ{p,I}V1.T1) (ⓑ{p,I}V2.T2)
33 | lifts_flat: ∀f,I,V1,V2,T1,T2.
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: ∀f,X,Y. ⬆*[f] X ≡ Y → ∀s. X = ⋆s → Y = ⋆s.
48 #f #X #Y * -f -X -Y //
49 [ #f #i1 #i2 #_ #x #H destruct
50 | #f #p #I #V1 #V2 #T1 #T2 #_ #_ #x #H destruct
51 | #f #I #V1 #V2 #T1 #T2 #_ #_ #x #H destruct
55 (* Basic_1: was: lift1_sort *)
56 (* Basic_2A1: includes: lift_inv_sort1 *)
57 lemma lifts_inv_sort1: ∀f,Y,s. ⬆*[f] ⋆s ≡ Y → Y = ⋆s.
58 /2 width=4 by lifts_inv_sort1_aux/ qed-.
60 fact lifts_inv_lref1_aux: ∀f,X,Y. ⬆*[f] X ≡ Y → ∀i1. X = #i1 →
61 ∃∃i2. @⦃i1, f⦄ ≡ i2 & Y = #i2.
63 [ #f #s #x #H destruct
64 | #f #i1 #i2 #Hi12 #x #H destruct /2 width=3 by ex2_intro/
65 | #f #l #x #H destruct
66 | #f #p #I #V1 #V2 #T1 #T2 #_ #_ #x #H destruct
67 | #f #I #V1 #V2 #T1 #T2 #_ #_ #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: ∀f,Y,i1. ⬆*[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: ∀f,X,Y. ⬆*[f] X ≡ Y → ∀l. X = §l → Y = §l.
78 #f #X #Y * -f -X -Y //
79 [ #f #i1 #i2 #_ #x #H destruct
80 | #f #p #I #V1 #V2 #T1 #T2 #_ #_ #x #H destruct
81 | #f #I #V1 #V2 #T1 #T2 #_ #_ #x #H destruct
85 (* Basic_2A1: includes: lift_inv_gref1 *)
86 lemma lifts_inv_gref1: ∀f,Y,l. ⬆*[f] §l ≡ Y → Y = §l.
87 /2 width=4 by lifts_inv_gref1_aux/ qed-.
89 fact lifts_inv_bind1_aux: ∀f,X,Y. ⬆*[f] X ≡ Y →
90 ∀p,I,V1,T1. X = ⓑ{p,I}V1.T1 →
91 ∃∃V2,T2. ⬆*[f] V1 ≡ V2 & ⬆*[↑f] T1 ≡ T2 &
94 [ #f #s #q #J #W1 #U1 #H destruct
95 | #f #i1 #i2 #_ #q #J #W1 #U1 #H destruct
96 | #f #l #b #J #W1 #U1 #H destruct
97 | #f #p #I #V1 #V2 #T1 #T2 #HV12 #HT12 #q #J #W1 #U1 #H destruct /2 width=5 by ex3_2_intro/
98 | #f #I #V1 #V2 #T1 #T2 #_ #_ #q #J #W1 #U1 #H destruct
102 (* Basic_1: was: lift1_bind *)
103 (* Basic_2A1: includes: lift_inv_bind1 *)
104 lemma lifts_inv_bind1: ∀f,p,I,V1,T1,Y. ⬆*[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: ∀f:rtmap. ∀X,Y. ⬆*[f] X ≡ Y →
110 ∀I,V1,T1. X = ⓕ{I}V1.T1 →
111 ∃∃V2,T2. ⬆*[f] V1 ≡ V2 & ⬆*[f] T1 ≡ T2 &
114 [ #f #s #J #W1 #U1 #H destruct
115 | #f #i1 #i2 #_ #J #W1 #U1 #H destruct
116 | #f #l #J #W1 #U1 #H destruct
117 | #f #p #I #V1 #V2 #T1 #T2 #_ #_ #J #W1 #U1 #H destruct
118 | #f #I #V1 #V2 #T1 #T2 #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: ∀f:rtmap. ∀I,V1,T1,Y. ⬆*[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: ∀f,X,Y. ⬆*[f] X ≡ Y → ∀s. Y = ⋆s → X = ⋆s.
130 #f #X #Y * -f -X -Y //
131 [ #f #i1 #i2 #_ #x #H destruct
132 | #f #p #I #V1 #V2 #T1 #T2 #_ #_ #x #H destruct
133 | #f #I #V1 #V2 #T1 #T2 #_ #_ #x #H destruct
137 (* Basic_1: includes: lift_gen_sort *)
138 (* Basic_2A1: includes: lift_inv_sort2 *)
139 lemma lifts_inv_sort2: ∀f,X,s. ⬆*[f] X ≡ ⋆s → X = ⋆s.
140 /2 width=4 by lifts_inv_sort2_aux/ qed-.
142 fact lifts_inv_lref2_aux: ∀f,X,Y. ⬆*[f] X ≡ Y → ∀i2. Y = #i2 →
143 ∃∃i1. @⦃i1, f⦄ ≡ i2 & X = #i1.
145 [ #f #s #x #H destruct
146 | #f #i1 #i2 #Hi12 #x #H destruct /2 width=3 by ex2_intro/
147 | #f #l #x #H destruct
148 | #f #p #I #V1 #V2 #T1 #T2 #_ #_ #x #H destruct
149 | #f #I #V1 #V2 #T1 #T2 #_ #_ #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: ∀f,X,i2. ⬆*[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: ∀f,X,Y. ⬆*[f] X ≡ Y → ∀l. Y = §l → X = §l.
160 #f #X #Y * -f -X -Y //
161 [ #f #i1 #i2 #_ #x #H destruct
162 | #f #p #I #V1 #V2 #T1 #T2 #_ #_ #x #H destruct
163 | #f #I #V1 #V2 #T1 #T2 #_ #_ #x #H destruct
167 (* Basic_2A1: includes: lift_inv_gref1 *)
168 lemma lifts_inv_gref2: ∀f,X,l. ⬆*[f] X ≡ §l → X = §l.
169 /2 width=4 by lifts_inv_gref2_aux/ qed-.
171 fact lifts_inv_bind2_aux: ∀f,X,Y. ⬆*[f] X ≡ Y →
172 ∀p,I,V2,T2. Y = ⓑ{p,I}V2.T2 →
173 ∃∃V1,T1. ⬆*[f] V1 ≡ V2 & ⬆*[↑f] T1 ≡ T2 &
176 [ #f #s #q #J #W2 #U2 #H destruct
177 | #f #i1 #i2 #_ #q #J #W2 #U2 #H destruct
178 | #f #l #q #J #W2 #U2 #H destruct
179 | #f #p #I #V1 #V2 #T1 #T2 #HV12 #HT12 #q #J #W2 #U2 #H destruct /2 width=5 by ex3_2_intro/
180 | #f #I #V1 #V2 #T1 #T2 #_ #_ #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: ∀f,p,I,V2,T2,X. ⬆*[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: ∀f:rtmap. ∀X,Y. ⬆*[f] X ≡ Y →
192 ∀I,V2,T2. Y = ⓕ{I}V2.T2 →
193 ∃∃V1,T1. ⬆*[f] V1 ≡ V2 & ⬆*[f] T1 ≡ T2 &
196 [ #f #s #J #W2 #U2 #H destruct
197 | #f #i1 #i2 #_ #J #W2 #U2 #H destruct
198 | #f #l #J #W2 #U2 #H destruct
199 | #f #p #I #V1 #V2 #T1 #T2 #_ #_ #J #W2 #U2 #H destruct
200 | #f #I #V1 #V2 #T1 #T2 #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: ∀f:rtmap. ∀I,V2,T2,X. ⬆*[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 (* Advanced inversion lemmas ************************************************)
213 (* Basic_2A1: includes: lift_inv_pair_xy_x *)
214 lemma lifts_inv_pair_xy_x: ∀f,I,V,T. ⬆*[f] ②{I}V.T ≡ V → ⊥.
217 [ lapply (lifts_inv_sort2 … H) -H #H destruct
218 | elim (lifts_inv_lref2 … H) -H
220 | lapply (lifts_inv_gref2 … H) -H #H destruct
222 | * [ #p ] #I #V2 #T2 #IHV2 #_ #U #H
223 [ elim (lifts_inv_bind2 … H) -H #V1 #T1 #HV12 #_ #H destruct /2 width=3 by/
224 | elim (lifts_inv_flat2 … H) -H #V1 #T1 #HV12 #_ #H destruct /2 width=3 by/
229 (* Basic_1: includes: thead_x_lift_y_y *)
230 (* Basic_2A1: includes: lift_inv_pair_xy_y *)
231 lemma lifts_inv_pair_xy_y: ∀I,T,V,f. ⬆*[f] ②{I}V.T ≡ T → ⊥.
234 [ lapply (lifts_inv_sort2 … H) -H #H destruct
235 | elim (lifts_inv_lref2 … H) -H
237 | lapply (lifts_inv_gref2 … H) -H #H destruct
239 | * [ #p ] #I #V2 #T2 #_ #IHT2 #W #f #H
240 [ elim (lifts_inv_bind2 … H) -H #V1 #T1 #_ #HT12 #H destruct /2 width=4 by/
241 | elim (lifts_inv_flat2 … H) -H #V1 #T1 #_ #HT12 #H destruct /2 width=4 by/
246 lemma lifts_inv_lref1_uni: ∀l,Y,i. ⬆*[l] #i ≡ Y → Y = #(l+i).
247 #l #Y #i1 #H elim (lifts_inv_lref1 … H) -H /4 width=4 by at_mono, eq_f/
250 (* Basic forward lemmas *****************************************************)
252 (* Basic_2A1: includes: lift_inv_O2 *)
253 lemma lifts_fwd_isid: ∀f,T1,T2. ⬆*[f] T1 ≡ T2 → 𝐈⦃f⦄ → T1 = T2.
254 #f #T1 #T2 #H elim H -f -T1 -T2
255 /4 width=3 by isid_inv_at_mono, isid_push, eq_f2, eq_f/
258 (* Basic_2A1: includes: lift_fwd_pair1 *)
259 lemma lifts_fwd_pair1: ∀f:rtmap. ∀I,V1,T1,Y. ⬆*[f] ②{I}V1.T1 ≡ Y →
260 ∃∃V2,T2. ⬆*[f] V1 ≡ V2 & Y = ②{I}V2.T2.
261 #f * [ #p ] #I #V1 #T1 #Y #H
262 [ elim (lifts_inv_bind1 … H) -H /2 width=4 by ex2_2_intro/
263 | elim (lifts_inv_flat1 … H) -H /2 width=4 by ex2_2_intro/
267 (* Basic_2A1: includes: lift_fwd_pair2 *)
268 lemma lifts_fwd_pair2: ∀f:rtmap. ∀I,V2,T2,X. ⬆*[f] X ≡ ②{I}V2.T2 →
269 ∃∃V1,T1. ⬆*[f] V1 ≡ V2 & X = ②{I}V1.T1.
270 #f * [ #p ] #I #V2 #T2 #X #H
271 [ elim (lifts_inv_bind2 … H) -H /2 width=4 by ex2_2_intro/
272 | elim (lifts_inv_flat2 … H) -H /2 width=4 by ex2_2_intro/
276 (* Basic properties *********************************************************)
278 lemma lifts_eq_repl_back: ∀T1,T2. eq_repl_back … (λf. ⬆*[f] T1 ≡ T2).
279 #T1 #T2 #f1 #H elim H -T1 -T2 -f1
280 /4 width=5 by lifts_flat, lifts_bind, lifts_lref, at_eq_repl_back, eq_push/
283 lemma lifts_eq_repl_fwd: ∀T1,T2. eq_repl_fwd … (λf. ⬆*[f] T1 ≡ T2).
284 #T1 #T2 @eq_repl_sym /2 width=3 by lifts_eq_repl_back/ (**) (* full auto fails *)
287 (* Basic_1: includes: lift_r *)
288 (* Basic_2A1: includes: lift_refl *)
289 lemma lifts_refl: ∀T,f. 𝐈⦃f⦄ → ⬆*[f] T ≡ T.
291 /4 width=3 by lifts_flat, lifts_bind, lifts_lref, isid_inv_at, isid_push/
294 (* Basic_2A1: includes: lift_total *)
295 lemma lifts_total: ∀T1,f. ∃T2. ⬆*[f] T1 ≡ T2.
297 /3 width=2 by lifts_lref, lifts_sort, lifts_gref, ex_intro/
298 [ #p ] #I #V1 #T1 #IHV1 #IHT1 #f
299 elim (IHV1 f) -IHV1 #V2 #HV12
300 [ elim (IHT1 (↑f)) -IHT1 /3 width=2 by lifts_bind, ex_intro/
301 | elim (IHT1 f) -IHT1 /3 width=2 by lifts_flat, ex_intro/
305 lemma lift_lref_uni: ∀l,i. ⬆*[l] #i ≡ #(l+i).
306 #l elim l -l /2 width=1 by lifts_lref/
309 (* Basic_1: includes: lift_free (right to left) *)
310 (* Basic_2A1: includes: lift_split *)
311 lemma lifts_split_trans: ∀f,T1,T2. ⬆*[f] T1 ≡ T2 →
312 ∀f1,f2. f2 ⊚ f1 ≡ f →
313 ∃∃T. ⬆*[f1] T1 ≡ T & ⬆*[f2] T ≡ T2.
314 #f #T1 #T2 #H elim H -f -T1 -T2
315 [ /3 width=3 by lifts_sort, ex2_intro/
316 | #f #i1 #i2 #Hi #f1 #f2 #Ht elim (after_at_fwd … Hi … Ht) -Hi -Ht
317 /3 width=3 by lifts_lref, ex2_intro/
318 | /3 width=3 by lifts_gref, ex2_intro/
319 | #f #p #I #V1 #V2 #T1 #T2 #_ #_ #IHV #IHT #f1 #f2 #Ht
320 elim (IHV … Ht) elim (IHT (↑f1) (↑f2)) -IHV -IHT
321 /3 width=5 by lifts_bind, after_O2, ex2_intro/
322 | #f #I #V1 #V2 #T1 #T2 #_ #_ #IHV #IHT #f1 #f2 #Ht
323 elim (IHV … Ht) elim (IHT … Ht) -IHV -IHT -Ht
324 /3 width=5 by lifts_flat, ex2_intro/
328 (* Note: apparently, this was missing in Basic_2A1 *)
329 lemma lifts_split_div: ∀f1,T1,T2. ⬆*[f1] T1 ≡ T2 →
331 ∃∃T. ⬆*[f2] T2 ≡ T & ⬆*[f] T1 ≡ T.
332 #f1 #T1 #T2 #H elim H -f1 -T1 -T2
333 [ /3 width=3 by lifts_sort, ex2_intro/
334 | #f1 #i1 #i2 #Hi #f2 #f #Ht elim (after_at1_fwd … Hi … Ht) -Hi -Ht
335 /3 width=3 by lifts_lref, ex2_intro/
336 | /3 width=3 by lifts_gref, ex2_intro/
337 | #f1 #p #I #V1 #V2 #T1 #T2 #_ #_ #IHV #IHT #f2 #f #Ht
338 elim (IHV … Ht) elim (IHT (↑f2) (↑f)) -IHV -IHT
339 /3 width=5 by lifts_bind, after_O2, ex2_intro/
340 | #f1 #I #V1 #V2 #T1 #T2 #_ #_ #IHV #IHT #f2 #f #Ht
341 elim (IHV … Ht) elim (IHT … Ht) -IHV -IHT -Ht
342 /3 width=5 by lifts_flat, ex2_intro/
346 (* Basic_1: includes: dnf_dec2 dnf_dec *)
347 (* Basic_2A1: includes: is_lift_dec *)
348 lemma is_lifts_dec: ∀T2,f. Decidable (∃T1. ⬆*[f] T1 ≡ T2).
350 [ * [1,3: /3 width=2 by lifts_sort, lifts_gref, ex_intro, or_introl/ ]
351 #i2 #f elim (is_at_dec f i2) //
352 [ * /4 width=3 by lifts_lref, ex_intro, or_introl/
354 #X #HX elim (lifts_inv_lref2 … HX) -HX
355 /3 width=2 by ex_intro/
357 | * [ #p ] #I #V2 #T2 #IHV2 #IHT2 #f
358 [ elim (IHV2 f) -IHV2
359 [ * #V1 #HV12 elim (IHT2 (↑f)) -IHT2
360 [ * #T1 #HT12 @or_introl /3 width=2 by lifts_bind, ex_intro/
361 | -V1 #HT2 @or_intror * #X #H
362 elim (lifts_inv_bind2 … H) -H /3 width=2 by ex_intro/
364 | -IHT2 #HV2 @or_intror * #X #H
365 elim (lifts_inv_bind2 … H) -H /3 width=2 by ex_intro/
367 | elim (IHV2 f) -IHV2
368 [ * #V1 #HV12 elim (IHT2 f) -IHT2
369 [ * #T1 #HT12 /4 width=2 by lifts_flat, ex_intro, or_introl/
370 | -V1 #HT2 @or_intror * #X #H
371 elim (lifts_inv_flat2 … H) -H /3 width=2 by ex_intro/
373 | -IHT2 #HV2 @or_intror * #X #H
374 elim (lifts_inv_flat2 … H) -H /3 width=2 by ex_intro/
380 (* Properties with uniform relocation ***************************************)
382 lemma lifts_uni: ∀n1,n2,T,U. ⬆*[𝐔❴n1❵∘𝐔❴n2❵] T ≡ U → ⬆*[n1+n2] T ≡ U.
383 /3 width=4 by lifts_eq_repl_back, after_inv_total/ qed.
385 (* Basic_2A1: removed theorems 14:
386 lifts_inv_nil lifts_inv_cons
387 lift_inv_Y1 lift_inv_Y2 lift_inv_lref_Y1 lift_inv_lref_Y2 lift_lref_Y lift_Y1
388 lift_lref_lt_eq lift_lref_ge_eq lift_lref_plus lift_lref_pred
389 lift_lref_ge_minus lift_lref_ge_minus_eq
391 (* Basic_1: removed theorems 8:
393 lift_head lift_gen_head
394 lift_weight_map lift_weight lift_weight_add lift_weight_add_O