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 lemma lifts_inv_atom1: ∀f,I,Y. ⬆*[f] ⓪{I} ≡ Y →
214 ∨∨ ∃∃s. I = Sort s & Y = ⋆s
215 | ∃∃i,j. @⦃i, f⦄ ≡ j & I = LRef i & Y = #j
216 | ∃∃l. I = GRef l & Y = §l.
218 [ lapply (lifts_inv_sort1 … H)
219 | elim (lifts_inv_lref1 … H)
220 | lapply (lifts_inv_gref1 … H)
221 ] -H /3 width=5 by or3_intro0, or3_intro1, or3_intro2, ex3_2_intro, ex2_intro/
224 lemma lifts_inv_atom2: ∀f,I,X. ⬆*[f] X ≡ ⓪{I} →
225 ∨∨ ∃∃s. X = ⋆s & I = Sort s
226 | ∃∃i,j. @⦃i, f⦄ ≡ j & X = #i & I = LRef j
227 | ∃∃l. X = §l & I = GRef l.
229 [ lapply (lifts_inv_sort2 … H)
230 | elim (lifts_inv_lref2 … H)
231 | lapply (lifts_inv_gref2 … H)
232 ] -H /3 width=5 by or3_intro0, or3_intro1, or3_intro2, ex3_2_intro, ex2_intro/
235 (* Basic_2A1: includes: lift_inv_pair_xy_x *)
236 lemma lifts_inv_pair_xy_x: ∀f,I,V,T. ⬆*[f] ②{I}V.T ≡ V → ⊥.
239 [ lapply (lifts_inv_sort2 … H) -H #H destruct
240 | elim (lifts_inv_lref2 … H) -H
242 | lapply (lifts_inv_gref2 … H) -H #H destruct
244 | * [ #p ] #I #V2 #T2 #IHV2 #_ #U #H
245 [ elim (lifts_inv_bind2 … H) -H #V1 #T1 #HV12 #_ #H destruct /2 width=3 by/
246 | elim (lifts_inv_flat2 … H) -H #V1 #T1 #HV12 #_ #H destruct /2 width=3 by/
251 (* Basic_1: includes: thead_x_lift_y_y *)
252 (* Basic_2A1: includes: lift_inv_pair_xy_y *)
253 lemma lifts_inv_pair_xy_y: ∀I,T,V,f. ⬆*[f] ②{I}V.T ≡ T → ⊥.
256 [ lapply (lifts_inv_sort2 … H) -H #H destruct
257 | elim (lifts_inv_lref2 … H) -H
259 | lapply (lifts_inv_gref2 … H) -H #H destruct
261 | * [ #p ] #I #V2 #T2 #_ #IHT2 #W #f #H
262 [ elim (lifts_inv_bind2 … H) -H #V1 #T1 #_ #HT12 #H destruct /2 width=4 by/
263 | elim (lifts_inv_flat2 … H) -H #V1 #T1 #_ #HT12 #H destruct /2 width=4 by/
268 lemma lifts_inv_lref1_uni: ∀l,Y,i. ⬆*[l] #i ≡ Y → Y = #(l+i).
269 #l #Y #i1 #H elim (lifts_inv_lref1 … H) -H /4 width=4 by at_mono, eq_f/
272 (* Basic forward lemmas *****************************************************)
274 (* Basic_2A1: includes: lift_inv_O2 *)
275 lemma lifts_fwd_isid: ∀f,T1,T2. ⬆*[f] T1 ≡ T2 → 𝐈⦃f⦄ → T1 = T2.
276 #f #T1 #T2 #H elim H -f -T1 -T2
277 /4 width=3 by isid_inv_at_mono, isid_push, eq_f2, eq_f/
280 (* Basic_2A1: includes: lift_fwd_pair1 *)
281 lemma lifts_fwd_pair1: ∀f:rtmap. ∀I,V1,T1,Y. ⬆*[f] ②{I}V1.T1 ≡ Y →
282 ∃∃V2,T2. ⬆*[f] V1 ≡ V2 & Y = ②{I}V2.T2.
283 #f * [ #p ] #I #V1 #T1 #Y #H
284 [ elim (lifts_inv_bind1 … H) -H /2 width=4 by ex2_2_intro/
285 | elim (lifts_inv_flat1 … H) -H /2 width=4 by ex2_2_intro/
289 (* Basic_2A1: includes: lift_fwd_pair2 *)
290 lemma lifts_fwd_pair2: ∀f:rtmap. ∀I,V2,T2,X. ⬆*[f] X ≡ ②{I}V2.T2 →
291 ∃∃V1,T1. ⬆*[f] V1 ≡ V2 & X = ②{I}V1.T1.
292 #f * [ #p ] #I #V2 #T2 #X #H
293 [ elim (lifts_inv_bind2 … H) -H /2 width=4 by ex2_2_intro/
294 | elim (lifts_inv_flat2 … H) -H /2 width=4 by ex2_2_intro/
298 (* Basic properties *********************************************************)
300 lemma lifts_eq_repl_back: ∀T1,T2. eq_repl_back … (λf. ⬆*[f] T1 ≡ T2).
301 #T1 #T2 #f1 #H elim H -T1 -T2 -f1
302 /4 width=5 by lifts_flat, lifts_bind, lifts_lref, at_eq_repl_back, eq_push/
305 lemma lifts_eq_repl_fwd: ∀T1,T2. eq_repl_fwd … (λf. ⬆*[f] T1 ≡ T2).
306 #T1 #T2 @eq_repl_sym /2 width=3 by lifts_eq_repl_back/ (**) (* full auto fails *)
309 (* Basic_1: includes: lift_r *)
310 (* Basic_2A1: includes: lift_refl *)
311 lemma lifts_refl: ∀T,f. 𝐈⦃f⦄ → ⬆*[f] T ≡ T.
313 /4 width=3 by lifts_flat, lifts_bind, lifts_lref, isid_inv_at, isid_push/
316 (* Basic_2A1: includes: lift_total *)
317 lemma lifts_total: ∀T1,f. ∃T2. ⬆*[f] T1 ≡ T2.
319 /3 width=2 by lifts_lref, lifts_sort, lifts_gref, ex_intro/
320 [ #p ] #I #V1 #T1 #IHV1 #IHT1 #f
321 elim (IHV1 f) -IHV1 #V2 #HV12
322 [ elim (IHT1 (↑f)) -IHT1 /3 width=2 by lifts_bind, ex_intro/
323 | elim (IHT1 f) -IHT1 /3 width=2 by lifts_flat, ex_intro/
327 lemma lift_lref_uni: ∀l,i. ⬆*[l] #i ≡ #(l+i).
328 #l elim l -l /2 width=1 by lifts_lref/
331 (* Basic_1: includes: lift_free (right to left) *)
332 (* Basic_2A1: includes: lift_split *)
333 lemma lifts_split_trans: ∀f,T1,T2. ⬆*[f] T1 ≡ T2 →
334 ∀f1,f2. f2 ⊚ f1 ≡ f →
335 ∃∃T. ⬆*[f1] T1 ≡ T & ⬆*[f2] T ≡ T2.
336 #f #T1 #T2 #H elim H -f -T1 -T2
337 [ /3 width=3 by lifts_sort, ex2_intro/
338 | #f #i1 #i2 #Hi #f1 #f2 #Ht elim (after_at_fwd … Hi … Ht) -Hi -Ht
339 /3 width=3 by lifts_lref, ex2_intro/
340 | /3 width=3 by lifts_gref, ex2_intro/
341 | #f #p #I #V1 #V2 #T1 #T2 #_ #_ #IHV #IHT #f1 #f2 #Ht
342 elim (IHV … Ht) elim (IHT (↑f1) (↑f2)) -IHV -IHT
343 /3 width=5 by lifts_bind, after_O2, ex2_intro/
344 | #f #I #V1 #V2 #T1 #T2 #_ #_ #IHV #IHT #f1 #f2 #Ht
345 elim (IHV … Ht) elim (IHT … Ht) -IHV -IHT -Ht
346 /3 width=5 by lifts_flat, ex2_intro/
350 (* Note: apparently, this was missing in Basic_2A1 *)
351 lemma lifts_split_div: ∀f1,T1,T2. ⬆*[f1] T1 ≡ T2 →
353 ∃∃T. ⬆*[f2] T2 ≡ T & ⬆*[f] T1 ≡ T.
354 #f1 #T1 #T2 #H elim H -f1 -T1 -T2
355 [ /3 width=3 by lifts_sort, ex2_intro/
356 | #f1 #i1 #i2 #Hi #f2 #f #Ht elim (after_at1_fwd … Hi … Ht) -Hi -Ht
357 /3 width=3 by lifts_lref, ex2_intro/
358 | /3 width=3 by lifts_gref, ex2_intro/
359 | #f1 #p #I #V1 #V2 #T1 #T2 #_ #_ #IHV #IHT #f2 #f #Ht
360 elim (IHV … Ht) elim (IHT (↑f2) (↑f)) -IHV -IHT
361 /3 width=5 by lifts_bind, after_O2, ex2_intro/
362 | #f1 #I #V1 #V2 #T1 #T2 #_ #_ #IHV #IHT #f2 #f #Ht
363 elim (IHV … Ht) elim (IHT … Ht) -IHV -IHT -Ht
364 /3 width=5 by lifts_flat, ex2_intro/
368 (* Basic_1: includes: dnf_dec2 dnf_dec *)
369 (* Basic_2A1: includes: is_lift_dec *)
370 lemma is_lifts_dec: ∀T2,f. Decidable (∃T1. ⬆*[f] T1 ≡ T2).
372 [ * [1,3: /3 width=2 by lifts_sort, lifts_gref, ex_intro, or_introl/ ]
373 #i2 #f elim (is_at_dec f i2) //
374 [ * /4 width=3 by lifts_lref, ex_intro, or_introl/
376 #X #HX elim (lifts_inv_lref2 … HX) -HX
377 /3 width=2 by ex_intro/
379 | * [ #p ] #I #V2 #T2 #IHV2 #IHT2 #f
380 [ elim (IHV2 f) -IHV2
381 [ * #V1 #HV12 elim (IHT2 (↑f)) -IHT2
382 [ * #T1 #HT12 @or_introl /3 width=2 by lifts_bind, ex_intro/
383 | -V1 #HT2 @or_intror * #X #H
384 elim (lifts_inv_bind2 … H) -H /3 width=2 by ex_intro/
386 | -IHT2 #HV2 @or_intror * #X #H
387 elim (lifts_inv_bind2 … H) -H /3 width=2 by ex_intro/
389 | elim (IHV2 f) -IHV2
390 [ * #V1 #HV12 elim (IHT2 f) -IHT2
391 [ * #T1 #HT12 /4 width=2 by lifts_flat, ex_intro, or_introl/
392 | -V1 #HT2 @or_intror * #X #H
393 elim (lifts_inv_flat2 … H) -H /3 width=2 by ex_intro/
395 | -IHT2 #HV2 @or_intror * #X #H
396 elim (lifts_inv_flat2 … H) -H /3 width=2 by ex_intro/
402 (* Properties with uniform relocation ***************************************)
404 lemma lifts_uni: ∀n1,n2,T,U. ⬆*[𝐔❴n1❵∘𝐔❴n2❵] T ≡ U → ⬆*[n1+n2] T ≡ U.
405 /3 width=4 by lifts_eq_repl_back, after_inv_total/ qed.
407 (* Basic_2A1: removed theorems 14:
408 lifts_inv_nil lifts_inv_cons
409 lift_inv_Y1 lift_inv_Y2 lift_inv_lref_Y1 lift_inv_lref_Y2 lift_lref_Y lift_Y1
410 lift_lref_lt_eq lift_lref_ge_eq lift_lref_plus lift_lref_pred
411 lift_lref_ge_minus lift_lref_ge_minus_eq
413 (* Basic_1: removed theorems 8:
415 lift_head lift_gen_head
416 lift_weight_map lift_weight lift_weight_add lift_weight_add_O