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/trace_isid.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: trace → relation term ≝
26 | lifts_sort: ∀k,t. lifts t (⋆k) (⋆k)
27 | lifts_lref: ∀i1,i2,t. @⦃i1, t⦄ ≡ i2 → lifts t (#i1) (#i2)
28 | lifts_gref: ∀p,t. lifts t (§p) (§p)
29 | lifts_bind: ∀a,I,V1,V2,T1,T2,t.
30 lifts t V1 V2 → lifts (Ⓣ@t) T1 T2 →
31 lifts t (ⓑ{a,I}V1.T1) (ⓑ{a,I}V2.T2)
32 | lifts_flat: ∀I,V1,V2,T1,T2,t.
33 lifts t V1 V2 → lifts t T1 T2 →
34 lifts t (ⓕ{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,t. ⬆*[t] X ≡ Y → ∀k. X = ⋆k → Y = ⋆k.
43 #X #Y #t * -X -Y -t //
44 [ #i1 #i2 #t #_ #x #H destruct
45 | #a #I #V1 #V2 #T1 #T2 #t #_ #_ #x #H destruct
46 | #I #V1 #V2 #T1 #T2 #t #_ #_ #x #H destruct
50 (* Basic_1: was: lift1_sort *)
51 (* Basic_2A1: includes: lift_inv_sort1 *)
52 lemma lifts_inv_sort1: ∀Y,k,t. ⬆*[t] ⋆k ≡ Y → Y = ⋆k.
53 /2 width=4 by lifts_inv_sort1_aux/ qed-.
55 fact lifts_inv_lref1_aux: ∀X,Y,t. ⬆*[t] X ≡ Y → ∀i1. X = #i1 →
56 ∃∃i2. @⦃i1, t⦄ ≡ i2 & Y = #i2.
58 [ #k #t #x #H destruct
59 | #i1 #i2 #t #Hi12 #x #H destruct /2 width=3 by ex2_intro/
60 | #p #t #x #H destruct
61 | #a #I #V1 #V2 #T1 #T2 #t #_ #_ #x #H destruct
62 | #I #V1 #V2 #T1 #T2 #t #_ #_ #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,t. ⬆*[t] #i1 ≡ Y →
69 ∃∃i2. @⦃i1, t⦄ ≡ i2 & Y = #i2.
70 /2 width=3 by lifts_inv_lref1_aux/ qed-.
72 fact lifts_inv_gref1_aux: ∀X,Y,t. ⬆*[t] X ≡ Y → ∀p. X = §p → Y = §p.
73 #X #Y #t * -X -Y -t //
74 [ #i1 #i2 #t #_ #x #H destruct
75 | #a #I #V1 #V2 #T1 #T2 #t #_ #_ #x #H destruct
76 | #I #V1 #V2 #T1 #T2 #t #_ #_ #x #H destruct
80 (* Basic_2A1: includes: lift_inv_gref1 *)
81 lemma lifts_inv_gref1: ∀Y,p,t. ⬆*[t] §p ≡ Y → Y = §p.
82 /2 width=4 by lifts_inv_gref1_aux/ qed-.
84 fact lifts_inv_bind1_aux: ∀X,Y,t. ⬆*[t] X ≡ Y →
85 ∀a,I,V1,T1. X = ⓑ{a,I}V1.T1 →
86 ∃∃V2,T2. ⬆*[t] V1 ≡ V2 & ⬆*[Ⓣ@t] T1 ≡ T2 &
89 [ #k #t #b #J #W1 #U1 #H destruct
90 | #i1 #i2 #t #_ #b #J #W1 #U1 #H destruct
91 | #p #t #b #J #W1 #U1 #H destruct
92 | #a #I #V1 #V2 #T1 #T2 #t #HV12 #HT12 #b #J #W1 #U1 #H destruct /2 width=5 by ex3_2_intro/
93 | #I #V1 #V2 #T1 #T2 #t #_ #_ #b #J #W1 #U1 #H destruct
97 (* Basic_1: was: lift1_bind *)
98 (* Basic_2A1: includes: lift_inv_bind1 *)
99 lemma lifts_inv_bind1: ∀a,I,V1,T1,Y,t. ⬆*[t] ⓑ{a,I}V1.T1 ≡ Y →
100 ∃∃V2,T2. ⬆*[t] V1 ≡ V2 & ⬆*[Ⓣ@t] T1 ≡ T2 &
102 /2 width=3 by lifts_inv_bind1_aux/ qed-.
104 fact lifts_inv_flat1_aux: ∀X,Y,t. ⬆*[t] X ≡ Y →
105 ∀I,V1,T1. X = ⓕ{I}V1.T1 →
106 ∃∃V2,T2. ⬆*[t] V1 ≡ V2 & ⬆*[t] T1 ≡ T2 &
109 [ #k #t #J #W1 #U1 #H destruct
110 | #i1 #i2 #t #_ #J #W1 #U1 #H destruct
111 | #p #t #J #W1 #U1 #H destruct
112 | #a #I #V1 #V2 #T1 #T2 #t #_ #_ #J #W1 #U1 #H destruct
113 | #I #V1 #V2 #T1 #T2 #t #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,t. ⬆*[t] ⓕ{I}V1.T1 ≡ Y →
120 ∃∃V2,T2. ⬆*[t] V1 ≡ V2 & ⬆*[t] T1 ≡ T2 &
122 /2 width=3 by lifts_inv_flat1_aux/ qed-.
124 fact lifts_inv_sort2_aux: ∀X,Y,t. ⬆*[t] X ≡ Y → ∀k. Y = ⋆k → X = ⋆k.
125 #X #Y #t * -X -Y -t //
126 [ #i1 #i2 #t #_ #x #H destruct
127 | #a #I #V1 #V2 #T1 #T2 #t #_ #_ #x #H destruct
128 | #I #V1 #V2 #T1 #T2 #t #_ #_ #x #H destruct
132 (* Basic_1: includes: lift_gen_sort *)
133 (* Basic_2A1: includes: lift_inv_sort2 *)
134 lemma lifts_inv_sort2: ∀X,k,t. ⬆*[t] X ≡ ⋆k → X = ⋆k.
135 /2 width=4 by lifts_inv_sort2_aux/ qed-.
137 fact lifts_inv_lref2_aux: ∀X,Y,t. ⬆*[t] X ≡ Y → ∀i2. Y = #i2 →
138 ∃∃i1. @⦃i1, t⦄ ≡ i2 & X = #i1.
140 [ #k #t #x #H destruct
141 | #i1 #i2 #t #Hi12 #x #H destruct /2 width=3 by ex2_intro/
142 | #p #t #x #H destruct
143 | #a #I #V1 #V2 #T1 #T2 #t #_ #_ #x #H destruct
144 | #I #V1 #V2 #T1 #T2 #t #_ #_ #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,t. ⬆*[t] X ≡ #i2 →
151 ∃∃i1. @⦃i1, t⦄ ≡ i2 & X = #i1.
152 /2 width=3 by lifts_inv_lref2_aux/ qed-.
154 fact lifts_inv_gref2_aux: ∀X,Y,t. ⬆*[t] X ≡ Y → ∀p. Y = §p → X = §p.
155 #X #Y #t * -X -Y -t //
156 [ #i1 #i2 #t #_ #x #H destruct
157 | #a #I #V1 #V2 #T1 #T2 #t #_ #_ #x #H destruct
158 | #I #V1 #V2 #T1 #T2 #t #_ #_ #x #H destruct
162 (* Basic_2A1: includes: lift_inv_gref1 *)
163 lemma lifts_inv_gref2: ∀X,p,t. ⬆*[t] X ≡ §p → X = §p.
164 /2 width=4 by lifts_inv_gref2_aux/ qed-.
166 fact lifts_inv_bind2_aux: ∀X,Y,t. ⬆*[t] X ≡ Y →
167 ∀a,I,V2,T2. Y = ⓑ{a,I}V2.T2 →
168 ∃∃V1,T1. ⬆*[t] V1 ≡ V2 & ⬆*[Ⓣ@t] T1 ≡ T2 &
171 [ #k #t #b #J #W2 #U2 #H destruct
172 | #i1 #i2 #t #_ #b #J #W2 #U2 #H destruct
173 | #p #t #b #J #W2 #U2 #H destruct
174 | #a #I #V1 #V2 #T1 #T2 #t #HV12 #HT12 #b #J #W2 #U2 #H destruct /2 width=5 by ex3_2_intro/
175 | #I #V1 #V2 #T1 #T2 #t #_ #_ #b #J #W2 #U2 #H destruct
179 (* Basic_1: includes: lift_gen_bind *)
180 (* Basic_2A1: includes: lift_inv_bind2 *)
181 lemma lifts_inv_bind2: ∀a,I,V2,T2,X,t. ⬆*[t] X ≡ ⓑ{a,I}V2.T2 →
182 ∃∃V1,T1. ⬆*[t] V1 ≡ V2 & ⬆*[Ⓣ@t] T1 ≡ T2 &
184 /2 width=3 by lifts_inv_bind2_aux/ qed-.
186 fact lifts_inv_flat2_aux: ∀X,Y,t. ⬆*[t] X ≡ Y →
187 ∀I,V2,T2. Y = ⓕ{I}V2.T2 →
188 ∃∃V1,T1. ⬆*[t] V1 ≡ V2 & ⬆*[t] T1 ≡ T2 &
191 [ #k #t #J #W2 #U2 #H destruct
192 | #i1 #i2 #t #_ #J #W2 #U2 #H destruct
193 | #p #t #J #W2 #U2 #H destruct
194 | #a #I #V1 #V2 #T1 #T2 #t #_ #_ #J #W2 #U2 #H destruct
195 | #I #V1 #V2 #T1 #T2 #t #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,t. ⬆*[t] X ≡ ⓕ{I}V2.T2 →
202 ∃∃V1,T1. ⬆*[t] V1 ≡ V2 & ⬆*[t] 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,t. ⬆*[t] ②{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 | * [ #a ] #I #V2 #T2 #IHV2 #_ #U #t #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,t. ⬆*[t] ②{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 | * [ #a ] #I #V2 #T2 #_ #IHT2 #W #t #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,t. ⬆*[t] T1 ≡ T2 → 𝐈⦃t⦄ → T1 = T2.
243 #T1 #T2 #t #H elim H -T1 -T2 -t /4 width=3 by isid_inv_at, eq_f2, eq_f/
246 (* Basic_2A1: includes: lift_fwd_pair1 *)
247 lemma lifts_fwd_pair1: ∀I,V1,T1,Y,t. ⬆*[t] ②{I}V1.T1 ≡ Y →
248 ∃∃V2,T2. ⬆*[t] V1 ≡ V2 & Y = ②{I}V2.T2.
249 * [ #a ] #I #V1 #T1 #Y #t #H
250 [ elim (lifts_inv_bind1 … H) -H /2 width=4 by ex2_2_intro/
251 | elim (lifts_inv_flat1 … H) -H /2 width=4 by ex2_2_intro/
255 (* Basic_2A1: includes: lift_fwd_pair2 *)
256 lemma lifts_fwd_pair2: ∀I,V2,T2,X,t. ⬆*[t] X ≡ ②{I}V2.T2 →
257 ∃∃V1,T1. ⬆*[t] V1 ≡ V2 & X = ②{I}V1.T1.
258 * [ #a ] #I #V2 #T2 #X #t #H
259 [ elim (lifts_inv_bind2 … H) -H /2 width=4 by ex2_2_intro/
260 | elim (lifts_inv_flat2 … H) -H /2 width=4 by ex2_2_intro/
264 (* Basic properties *********************************************************)
266 (* Basic_1: includes: lift_free (right to left) *)
267 (* Basic_2A1: includes: lift_split *)
268 lemma lifts_split_trans: ∀T1,T2,t. ⬆*[t] T1 ≡ T2 →
269 ∀t1,t2. t2 ⊚ t1 ≡ t →
270 ∃∃T. ⬆*[t1] T1 ≡ T & ⬆*[t2] T ≡ T2.
271 #T1 #T2 #t #H elim H -T1 -T2 -t
272 [ /3 width=3 by lifts_sort, ex2_intro/
273 | #i1 #i2 #t #Hi #t1 #t2 #Ht elim (after_at_fwd … Ht … Hi) -Ht -Hi
274 /3 width=3 by lifts_lref, ex2_intro/
275 | /3 width=3 by lifts_gref, ex2_intro/
276 | #a #I #V1 #V2 #T1 #T2 #t #_ #_ #IHV #IHT #t1 #t2 #Ht
277 elim (IHV … Ht) elim (IHT (Ⓣ@t1) (Ⓣ@t2)) -IHV -IHT
278 /3 width=5 by lifts_bind, after_true, ex2_intro/
279 | #I #V1 #V2 #T1 #T2 #t #_ #_ #IHV #IHT #t1 #t2 #Ht
280 elim (IHV … Ht) elim (IHT … Ht) -IHV -IHT -Ht
281 /3 width=5 by lifts_flat, ex2_intro/
285 (* Note: apparently, this was missing in Basic_2A1 *)
286 lemma lifts_split_div: ∀T1,T2,t1. ⬆*[t1] T1 ≡ T2 →
288 ∃∃T. ⬆*[t2] T2 ≡ T & ⬆*[t] T1 ≡ T.
289 #T1 #T2 #t1 #H elim H -T1 -T2 -t1
290 [ /3 width=3 by lifts_sort, ex2_intro/
291 | #i1 #i2 #t1 #Hi #t2 #t #Ht elim (after_at1_fwd … Ht … Hi) -Ht -Hi
292 /3 width=3 by lifts_lref, ex2_intro/
293 | /3 width=3 by lifts_gref, ex2_intro/
294 | #a #I #V1 #V2 #T1 #T2 #t1 #_ #_ #IHV #IHT #t2 #t #Ht
295 elim (IHV … Ht) elim (IHT (Ⓣ@t2) (Ⓣ@t)) -IHV -IHT
296 /3 width=5 by lifts_bind, after_true, ex2_intro/
297 | #I #V1 #V2 #T1 #T2 #t1 #_ #_ #IHV #IHT #t2 #t #Ht
298 elim (IHV … Ht) elim (IHT … Ht) -IHV -IHT -Ht
299 /3 width=5 by lifts_flat, ex2_intro/
303 (* Basic_1: includes: dnf_dec2 dnf_dec *)
304 (* Basic_2A1: includes: is_lift_dec *)
305 lemma is_lifts_dec: ∀T2,t. Decidable (∃T1. ⬆*[t] T1 ≡ T2).
307 [ * [1,3: /3 width=2 by lifts_sort, lifts_gref, ex_intro, or_introl/ ]
308 #i2 #t elim (is_at_dec t i2)
309 [ * /4 width=3 by lifts_lref, ex_intro, or_introl/
311 #X #HX elim (lifts_inv_lref2 … HX) -HX
312 /3 width=2 by ex_intro/
314 | * [ #a ] #I #V2 #T2 #IHV2 #IHT2 #t
315 [ elim (IHV2 t) -IHV2
316 [ * #V1 #HV12 elim (IHT2 (Ⓣ@t)) -IHT2
317 [ * #T1 #HT12 @or_introl /3 width=2 by lifts_bind, ex_intro/
318 | -V1 #HT2 @or_intror * #X #H
319 elim (lifts_inv_bind2 … H) -H /3 width=2 by ex_intro/
321 | -IHT2 #HV2 @or_intror * #X #H
322 elim (lifts_inv_bind2 … H) -H /3 width=2 by ex_intro/
324 | elim (IHV2 t) -IHV2
325 [ * #V1 #HV12 elim (IHT2 t) -IHT2
326 [ * #T1 #HT12 /4 width=2 by lifts_flat, ex_intro, or_introl/
327 | -V1 #HT2 @or_intror * #X #H
328 elim (lifts_inv_flat2 … H) -H /3 width=2 by ex_intro/
330 | -IHT2 #HV2 @or_intror * #X #H
331 elim (lifts_inv_flat2 … H) -H /3 width=2 by ex_intro/
337 (* Basic_2A1: removed theorems 14:
338 lifts_inv_nil lifts_inv_cons
339 lift_inv_Y1 lift_inv_Y2 lift_inv_lref_Y1 lift_inv_lref_Y2 lift_lref_Y lift_Y1
340 lift_lref_lt_eq lift_lref_ge_eq lift_lref_plus lift_lref_pred
341 lift_lref_ge_minus lift_lref_ge_minus_eq
343 (* Basic_1: removed theorems 8:
345 lift_head lift_gen_head
346 lift_weight_map lift_weight lift_weight_add lift_weight_add_O