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 "generic relocation (term)"
38 'RLiftStar cs T1 T2 = (lifts cs T1 T2).
40 (* Basic inversion lemmas ***************************************************)
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
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-.
55 fact lifts_inv_lref1_aux: ∀X,Y,f. ⬆*[f] X ≡ Y → ∀i1. X = #i1 →
56 ∃∃i2. @⦃i1, f⦄ ≡ i2 & Y = #i2.
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
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-.
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
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-.
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 &
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
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 &
102 /2 width=3 by lifts_inv_bind1_aux/ qed-.
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 &
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/
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 &
122 /2 width=3 by lifts_inv_flat1_aux/ qed-.
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
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-.
137 fact lifts_inv_lref2_aux: ∀X,Y,f. ⬆*[f] X ≡ Y → ∀i2. Y = #i2 →
138 ∃∃i1. @⦃i1, f⦄ ≡ i2 & X = #i1.
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
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-.
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
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-.
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 &
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
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 &
184 /2 width=3 by lifts_inv_bind2_aux/ qed-.
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 &
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/
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 &
204 /2 width=3 by lifts_inv_flat2_aux/ qed-.
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 → ⊥.
210 [ lapply (lifts_inv_sort2 … H) -H #H destruct
211 | elim (lifts_inv_lref2 … H) -H
213 | lapply (lifts_inv_gref2 … H) -H #H destruct
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/
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 → ⊥.
227 [ lapply (lifts_inv_sort2 … H) -H #H destruct
228 | elim (lifts_inv_lref2 … H) -H
230 | lapply (lifts_inv_gref2 … H) -H #H destruct
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/
239 (* Basic forward lemmas *****************************************************)
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/
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/
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/
265 (* Basic properties *********************************************************)
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/
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 *)
276 (* Basic_1: includes: lift_r *)
277 (* Basic_2A1: includes: lift_refl *)
278 lemma lifts_refl: ∀T,f. 𝐈⦃f⦄ → ⬆*[f] T ≡ T.
280 /4 width=3 by lifts_flat, lifts_bind, lifts_lref, isid_inv_at, isid_push/
283 (* Basic_2A1: includes: lift_total *)
284 lemma lifts_total: ∀T1,f. ∃T2. ⬆*[f] T1 ≡ T2.
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/
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/
313 (* Note: apparently, this was missing in Basic_2A1 *)
314 lemma lifts_split_div: ∀T1,T2,f1. ⬆*[f1] T1 ≡ T2 →
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/
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).
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/
339 #X #HX elim (lifts_inv_lref2 … HX) -HX
340 /3 width=2 by ex_intro/
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/
349 | -IHT2 #HV2 @or_intror * #X #H
350 elim (lifts_inv_bind2 … H) -H /3 width=2 by ex_intro/
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/
358 | -IHT2 #HV2 @or_intror * #X #H
359 elim (lifts_inv_flat2 … H) -H /3 width=2 by ex_intro/
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
371 (* Basic_1: removed theorems 8:
373 lift_head lift_gen_head
374 lift_weight_map lift_weight lift_weight_add lift_weight_add_O