1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| The HELM team. *)
8 (* ||A|| http://helm.cs.unibo.it *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU General Public License Version 2 *)
13 (**************************************************************************)
15 include "ground_2/relocation/nstream_after.ma".
16 include "basic_2/notation/relations/rliftstar_3.ma".
17 include "basic_2/grammar/term.ma".
19 (* GENERIC RELOCATION FOR TERMS *********************************************)
22 lift_sort lift_lref_lt lift_lref_ge lift_bind lift_flat
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)
37 interpretation "uniform relocation (term)"
38 'RLiftStar i T1 T2 = (lifts (uni i) T1 T2).
40 interpretation "generic relocation (term)"
41 'RLiftStar f T1 T2 = (lifts f T1 T2).
44 (* Basic inversion lemmas ***************************************************)
46 fact lifts_inv_sort1_aux: ∀X,Y,f. ⬆*[f] X ≡ Y → ∀s. X = ⋆s → Y = ⋆s.
47 #X #Y #f * -X -Y -f //
48 [ #i1 #i2 #f #_ #x #H destruct
49 | #p #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
50 | #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
54 (* Basic_1: was: lift1_sort *)
55 (* Basic_2A1: includes: lift_inv_sort1 *)
56 lemma lifts_inv_sort1: ∀Y,s,f. ⬆*[f] ⋆s ≡ Y → Y = ⋆s.
57 /2 width=4 by lifts_inv_sort1_aux/ qed-.
59 fact lifts_inv_lref1_aux: ∀X,Y,f. ⬆*[f] X ≡ Y → ∀i1. X = #i1 →
60 ∃∃i2. @⦃i1, f⦄ ≡ i2 & Y = #i2.
62 [ #s #f #x #H destruct
63 | #i1 #i2 #f #Hi12 #x #H destruct /2 width=3 by ex2_intro/
64 | #l #f #x #H destruct
65 | #p #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
66 | #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
70 (* Basic_1: was: lift1_lref *)
71 (* Basic_2A1: includes: lift_inv_lref1 lift_inv_lref1_lt lift_inv_lref1_ge *)
72 lemma lifts_inv_lref1: ∀Y,i1,f. ⬆*[f] #i1 ≡ Y →
73 ∃∃i2. @⦃i1, f⦄ ≡ i2 & Y = #i2.
74 /2 width=3 by lifts_inv_lref1_aux/ qed-.
76 fact lifts_inv_gref1_aux: ∀X,Y,f. ⬆*[f] X ≡ Y → ∀l. X = §l → Y = §l.
77 #X #Y #f * -X -Y -f //
78 [ #i1 #i2 #f #_ #x #H destruct
79 | #p #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
80 | #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
84 (* Basic_2A1: includes: lift_inv_gref1 *)
85 lemma lifts_inv_gref1: ∀Y,l,f. ⬆*[f] §l ≡ Y → Y = §l.
86 /2 width=4 by lifts_inv_gref1_aux/ qed-.
88 fact lifts_inv_bind1_aux: ∀X,Y,f. ⬆*[f] X ≡ Y →
89 ∀p,I,V1,T1. X = ⓑ{p,I}V1.T1 →
90 ∃∃V2,T2. ⬆*[f] V1 ≡ V2 & ⬆*[↑f] T1 ≡ T2 &
93 [ #s #f #q #J #W1 #U1 #H destruct
94 | #i1 #i2 #f #_ #q #J #W1 #U1 #H destruct
95 | #l #f #b #J #W1 #U1 #H destruct
96 | #p #I #V1 #V2 #T1 #T2 #f #HV12 #HT12 #q #J #W1 #U1 #H destruct /2 width=5 by ex3_2_intro/
97 | #I #V1 #V2 #T1 #T2 #f #_ #_ #q #J #W1 #U1 #H destruct
101 (* Basic_1: was: lift1_bind *)
102 (* Basic_2A1: includes: lift_inv_bind1 *)
103 lemma lifts_inv_bind1: ∀p,I,V1,T1,Y,f. ⬆*[f] ⓑ{p,I}V1.T1 ≡ Y →
104 ∃∃V2,T2. ⬆*[f] V1 ≡ V2 & ⬆*[↑f] T1 ≡ T2 &
106 /2 width=3 by lifts_inv_bind1_aux/ qed-.
108 fact lifts_inv_flat1_aux: ∀X,Y. ∀f:rtmap. ⬆*[f] X ≡ Y →
109 ∀I,V1,T1. X = ⓕ{I}V1.T1 →
110 ∃∃V2,T2. ⬆*[f] V1 ≡ V2 & ⬆*[f] T1 ≡ T2 &
113 [ #s #f #J #W1 #U1 #H destruct
114 | #i1 #i2 #f #_ #J #W1 #U1 #H destruct
115 | #l #f #J #W1 #U1 #H destruct
116 | #p #I #V1 #V2 #T1 #T2 #f #_ #_ #J #W1 #U1 #H destruct
117 | #I #V1 #V2 #T1 #T2 #f #HV12 #HT12 #J #W1 #U1 #H destruct /2 width=5 by ex3_2_intro/
121 (* Basic_1: was: lift1_flat *)
122 (* Basic_2A1: includes: lift_inv_flat1 *)
123 lemma lifts_inv_flat1: ∀I,V1,T1,Y. ∀f:rtmap. ⬆*[f] ⓕ{I}V1.T1 ≡ Y →
124 ∃∃V2,T2. ⬆*[f] V1 ≡ V2 & ⬆*[f] T1 ≡ T2 &
126 /2 width=3 by lifts_inv_flat1_aux/ qed-.
128 fact lifts_inv_sort2_aux: ∀X,Y,f. ⬆*[f] X ≡ Y → ∀s. Y = ⋆s → X = ⋆s.
129 #X #Y #f * -X -Y -f //
130 [ #i1 #i2 #f #_ #x #H destruct
131 | #p #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
132 | #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
136 (* Basic_1: includes: lift_gen_sort *)
137 (* Basic_2A1: includes: lift_inv_sort2 *)
138 lemma lifts_inv_sort2: ∀X,s,f. ⬆*[f] X ≡ ⋆s → X = ⋆s.
139 /2 width=4 by lifts_inv_sort2_aux/ qed-.
141 fact lifts_inv_lref2_aux: ∀X,Y,f. ⬆*[f] X ≡ Y → ∀i2. Y = #i2 →
142 ∃∃i1. @⦃i1, f⦄ ≡ i2 & X = #i1.
144 [ #s #f #x #H destruct
145 | #i1 #i2 #f #Hi12 #x #H destruct /2 width=3 by ex2_intro/
146 | #l #f #x #H destruct
147 | #p #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
148 | #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
152 (* Basic_1: includes: lift_gen_lref lift_gen_lref_lt lift_gen_lref_false lift_gen_lref_ge *)
153 (* Basic_2A1: includes: lift_inv_lref2 lift_inv_lref2_lt lift_inv_lref2_be lift_inv_lref2_ge lift_inv_lref2_plus *)
154 lemma lifts_inv_lref2: ∀X,i2,f. ⬆*[f] X ≡ #i2 →
155 ∃∃i1. @⦃i1, f⦄ ≡ i2 & X = #i1.
156 /2 width=3 by lifts_inv_lref2_aux/ qed-.
158 fact lifts_inv_gref2_aux: ∀X,Y,f. ⬆*[f] X ≡ Y → ∀l. Y = §l → X = §l.
159 #X #Y #f * -X -Y -f //
160 [ #i1 #i2 #f #_ #x #H destruct
161 | #p #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
162 | #I #V1 #V2 #T1 #T2 #f #_ #_ #x #H destruct
166 (* Basic_2A1: includes: lift_inv_gref1 *)
167 lemma lifts_inv_gref2: ∀X,l,f. ⬆*[f] X ≡ §l → X = §l.
168 /2 width=4 by lifts_inv_gref2_aux/ qed-.
170 fact lifts_inv_bind2_aux: ∀X,Y,f. ⬆*[f] X ≡ Y →
171 ∀p,I,V2,T2. Y = ⓑ{p,I}V2.T2 →
172 ∃∃V1,T1. ⬆*[f] V1 ≡ V2 & ⬆*[↑f] T1 ≡ T2 &
175 [ #s #f #q #J #W2 #U2 #H destruct
176 | #i1 #i2 #f #_ #q #J #W2 #U2 #H destruct
177 | #l #f #q #J #W2 #U2 #H destruct
178 | #p #I #V1 #V2 #T1 #T2 #f #HV12 #HT12 #q #J #W2 #U2 #H destruct /2 width=5 by ex3_2_intro/
179 | #I #V1 #V2 #T1 #T2 #f #_ #_ #q #J #W2 #U2 #H destruct
183 (* Basic_1: includes: lift_gen_bind *)
184 (* Basic_2A1: includes: lift_inv_bind2 *)
185 lemma lifts_inv_bind2: ∀p,I,V2,T2,X,f. ⬆*[f] X ≡ ⓑ{p,I}V2.T2 →
186 ∃∃V1,T1. ⬆*[f] V1 ≡ V2 & ⬆*[↑f] T1 ≡ T2 &
188 /2 width=3 by lifts_inv_bind2_aux/ qed-.
190 fact lifts_inv_flat2_aux: ∀X,Y. ∀f:rtmap. ⬆*[f] X ≡ Y →
191 ∀I,V2,T2. Y = ⓕ{I}V2.T2 →
192 ∃∃V1,T1. ⬆*[f] V1 ≡ V2 & ⬆*[f] T1 ≡ T2 &
195 [ #s #f #J #W2 #U2 #H destruct
196 | #i1 #i2 #f #_ #J #W2 #U2 #H destruct
197 | #l #f #J #W2 #U2 #H destruct
198 | #p #I #V1 #V2 #T1 #T2 #f #_ #_ #J #W2 #U2 #H destruct
199 | #I #V1 #V2 #T1 #T2 #f #HV12 #HT12 #J #W2 #U2 #H destruct /2 width=5 by ex3_2_intro/
203 (* Basic_1: includes: lift_gen_flat *)
204 (* Basic_2A1: includes: lift_inv_flat2 *)
205 lemma lifts_inv_flat2: ∀I,V2,T2,X. ∀f:rtmap. ⬆*[f] X ≡ ⓕ{I}V2.T2 →
206 ∃∃V1,T1. ⬆*[f] V1 ≡ V2 & ⬆*[f] T1 ≡ T2 &
208 /2 width=3 by lifts_inv_flat2_aux/ qed-.
210 (* Basic_2A1: includes: lift_inv_pair_xy_x *)
211 lemma lifts_inv_pair_xy_x: ∀I,V,T,f. ⬆*[f] ②{I}V.T ≡ V → ⊥.
214 [ lapply (lifts_inv_sort2 … H) -H #H destruct
215 | elim (lifts_inv_lref2 … H) -H
217 | lapply (lifts_inv_gref2 … H) -H #H destruct
219 | * [ #p ] #I #V2 #T2 #IHV2 #_ #U #f #H
220 [ elim (lifts_inv_bind2 … H) -H #V1 #T1 #HV12 #_ #H destruct /2 width=3 by/
221 | elim (lifts_inv_flat2 … H) -H #V1 #T1 #HV12 #_ #H destruct /2 width=3 by/
226 (* Basic_1: includes: thead_x_lift_y_y *)
227 (* Basic_2A1: includes: lift_inv_pair_xy_y *)
228 lemma lifts_inv_pair_xy_y: ∀I,T,V,f. ⬆*[f] ②{I}V.T ≡ T → ⊥.
231 [ lapply (lifts_inv_sort2 … H) -H #H destruct
232 | elim (lifts_inv_lref2 … H) -H
234 | lapply (lifts_inv_gref2 … H) -H #H destruct
236 | * [ #p ] #I #V2 #T2 #_ #IHT2 #W #f #H
237 [ elim (lifts_inv_bind2 … H) -H #V1 #T1 #_ #HT12 #H destruct /2 width=4 by/
238 | elim (lifts_inv_flat2 … H) -H #V1 #T1 #_ #HT12 #H destruct /2 width=4 by/
243 (* Basic forward lemmas *****************************************************)
245 (* Basic_2A1: includes: lift_inv_O2 *)
246 lemma lifts_fwd_isid: ∀T1,T2,f. ⬆*[f] T1 ≡ T2 → 𝐈⦃f⦄ → T1 = T2.
247 #T1 #T2 #f #H elim H -T1 -T2 -f
248 /4 width=3 by isid_inv_at_mono, isid_push, eq_f2, eq_f/
251 (* Basic_2A1: includes: lift_fwd_pair1 *)
252 lemma lifts_fwd_pair1: ∀I,V1,T1,Y. ∀f:rtmap. ⬆*[f] ②{I}V1.T1 ≡ Y →
253 ∃∃V2,T2. ⬆*[f] V1 ≡ V2 & Y = ②{I}V2.T2.
254 * [ #p ] #I #V1 #T1 #Y #f #H
255 [ elim (lifts_inv_bind1 … H) -H /2 width=4 by ex2_2_intro/
256 | elim (lifts_inv_flat1 … H) -H /2 width=4 by ex2_2_intro/
260 (* Basic_2A1: includes: lift_fwd_pair2 *)
261 lemma lifts_fwd_pair2: ∀I,V2,T2,X. ∀f:rtmap. ⬆*[f] X ≡ ②{I}V2.T2 →
262 ∃∃V1,T1. ⬆*[f] V1 ≡ V2 & X = ②{I}V1.T1.
263 * [ #p ] #I #V2 #T2 #X #f #H
264 [ elim (lifts_inv_bind2 … H) -H /2 width=4 by ex2_2_intro/
265 | elim (lifts_inv_flat2 … H) -H /2 width=4 by ex2_2_intro/
269 (* Basic properties *********************************************************)
271 lemma lifts_eq_repl_back: ∀T1,T2. eq_repl_back … (λf. ⬆*[f] T1 ≡ T2).
272 #T1 #T2 #f1 #H elim H -T1 -T2 -f1
273 /4 width=5 by lifts_flat, lifts_bind, lifts_lref, at_eq_repl_back, eq_push/
276 lemma lifts_eq_repl_fwd: ∀T1,T2. eq_repl_fwd … (λf. ⬆*[f] T1 ≡ T2).
277 #T1 #T2 @eq_repl_sym /2 width=3 by lifts_eq_repl_back/ (**) (* full auto fails *)
280 (* Basic_1: includes: lift_r *)
281 (* Basic_2A1: includes: lift_refl *)
282 lemma lifts_refl: ∀T,f. 𝐈⦃f⦄ → ⬆*[f] T ≡ T.
284 /4 width=3 by lifts_flat, lifts_bind, lifts_lref, isid_inv_at, isid_push/
287 (* Basic_2A1: includes: lift_total *)
288 lemma lifts_total: ∀T1,f. ∃T2. ⬆*[f] T1 ≡ T2.
290 /3 width=2 by lifts_lref, lifts_sort, lifts_gref, ex_intro/
291 [ #p ] #I #V1 #T1 #IHV1 #IHT1 #f
292 elim (IHV1 f) -IHV1 #V2 #HV12
293 [ elim (IHT1 (↑f)) -IHT1 /3 width=2 by lifts_bind, ex_intro/
294 | elim (IHT1 f) -IHT1 /3 width=2 by lifts_flat, ex_intro/
298 lemma lift_SO: ∀i. ⬆*[1] #i ≡ #(⫯i).
299 /2 width=1 by lifts_lref/ qed.
301 (* Basic_1: includes: lift_free (right to left) *)
302 (* Basic_2A1: includes: lift_split *)
303 lemma lifts_split_trans: ∀T1,T2,f. ⬆*[f] T1 ≡ T2 →
304 ∀f1,f2. f2 ⊚ f1 ≡ f →
305 ∃∃T. ⬆*[f1] T1 ≡ T & ⬆*[f2] T ≡ T2.
306 #T1 #T2 #f #H elim H -T1 -T2 -f
307 [ /3 width=3 by lifts_sort, ex2_intro/
308 | #i1 #i2 #f #Hi #f1 #f2 #Ht elim (after_at_fwd … Hi … Ht) -Hi -Ht
309 /3 width=3 by lifts_lref, ex2_intro/
310 | /3 width=3 by lifts_gref, ex2_intro/
311 | #p #I #V1 #V2 #T1 #T2 #f #_ #_ #IHV #IHT #f1 #f2 #Ht
312 elim (IHV … Ht) elim (IHT (↑f1) (↑f2)) -IHV -IHT
313 /3 width=5 by lifts_bind, after_O2, ex2_intro/
314 | #I #V1 #V2 #T1 #T2 #f #_ #_ #IHV #IHT #f1 #f2 #Ht
315 elim (IHV … Ht) elim (IHT … Ht) -IHV -IHT -Ht
316 /3 width=5 by lifts_flat, ex2_intro/
320 (* Note: apparently, this was missing in Basic_2A1 *)
321 lemma lifts_split_div: ∀T1,T2,f1. ⬆*[f1] T1 ≡ T2 →
323 ∃∃T. ⬆*[f2] T2 ≡ T & ⬆*[f] T1 ≡ T.
324 #T1 #T2 #f1 #H elim H -T1 -T2 -f1
325 [ /3 width=3 by lifts_sort, ex2_intro/
326 | #i1 #i2 #f1 #Hi #f2 #f #Ht elim (after_at1_fwd … Hi … Ht) -Hi -Ht
327 /3 width=3 by lifts_lref, ex2_intro/
328 | /3 width=3 by lifts_gref, ex2_intro/
329 | #p #I #V1 #V2 #T1 #T2 #f1 #_ #_ #IHV #IHT #f2 #f #Ht
330 elim (IHV … Ht) elim (IHT (↑f2) (↑f)) -IHV -IHT
331 /3 width=5 by lifts_bind, after_O2, ex2_intro/
332 | #I #V1 #V2 #T1 #T2 #f1 #_ #_ #IHV #IHT #f2 #f #Ht
333 elim (IHV … Ht) elim (IHT … Ht) -IHV -IHT -Ht
334 /3 width=5 by lifts_flat, ex2_intro/
338 (* Basic_1: includes: dnf_dec2 dnf_dec *)
339 (* Basic_2A1: includes: is_lift_dec *)
340 lemma is_lifts_dec: ∀T2,f. Decidable (∃T1. ⬆*[f] T1 ≡ T2).
342 [ * [1,3: /3 width=2 by lifts_sort, lifts_gref, ex_intro, or_introl/ ]
343 #i2 #f elim (is_at_dec f i2) //
344 [ * /4 width=3 by lifts_lref, ex_intro, or_introl/
346 #X #HX elim (lifts_inv_lref2 … HX) -HX
347 /3 width=2 by ex_intro/
349 | * [ #p ] #I #V2 #T2 #IHV2 #IHT2 #f
350 [ elim (IHV2 f) -IHV2
351 [ * #V1 #HV12 elim (IHT2 (↑f)) -IHT2
352 [ * #T1 #HT12 @or_introl /3 width=2 by lifts_bind, ex_intro/
353 | -V1 #HT2 @or_intror * #X #H
354 elim (lifts_inv_bind2 … H) -H /3 width=2 by ex_intro/
356 | -IHT2 #HV2 @or_intror * #X #H
357 elim (lifts_inv_bind2 … H) -H /3 width=2 by ex_intro/
359 | elim (IHV2 f) -IHV2
360 [ * #V1 #HV12 elim (IHT2 f) -IHT2
361 [ * #T1 #HT12 /4 width=2 by lifts_flat, ex_intro, or_introl/
362 | -V1 #HT2 @or_intror * #X #H
363 elim (lifts_inv_flat2 … H) -H /3 width=2 by ex_intro/
365 | -IHT2 #HV2 @or_intror * #X #H
366 elim (lifts_inv_flat2 … H) -H /3 width=2 by ex_intro/
372 (* Basic_2A1: removed theorems 14:
373 lifts_inv_nil lifts_inv_cons
374 lift_inv_Y1 lift_inv_Y2 lift_inv_lref_Y1 lift_inv_lref_Y2 lift_lref_Y lift_Y1
375 lift_lref_lt_eq lift_lref_ge_eq lift_lref_plus lift_lref_pred
376 lift_lref_ge_minus lift_lref_ge_minus_eq
378 (* Basic_1: removed theorems 8:
380 lift_head lift_gen_head
381 lift_weight_map lift_weight lift_weight_add lift_weight_add_O