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/notation/relations/rafter_3.ma".
16 include "ground_2/relocation/trace_at.ma".
18 (* RELOCATION TRACE *********************************************************)
20 inductive after: relation3 trace trace trace ≝
21 | after_empty: after (◊) (◊) (◊)
22 | after_true : ∀cs1,cs2,cs. after cs1 cs2 cs →
23 ∀b. after (Ⓣ @ cs1) (b @ cs2) (b @ cs)
24 | after_false: ∀cs1,cs2,cs. after cs1 cs2 cs →
25 after (Ⓕ @ cs1) cs2 (Ⓕ @ cs).
27 interpretation "composition (trace)"
28 'RAfter cs1 cs2 cs = (after cs1 cs2 cs).
30 (* Basic properties *********************************************************)
32 lemma after_length: ∀cs1,cs2. ∥cs1∥ = |cs2| →
33 ∃∃cs. cs1 ⊚ cs2 ≡ cs & |cs| = |cs1| & ∥cs∥ = ∥cs2∥.
35 [ #cs2 #H >(length_inv_zero_sn … H) -cs2 /2 width=4 by after_empty, ex3_intro/
36 | * #cs1 #IH #cs2 #Hcs
37 [ elim (length_inv_succ_sn … Hcs) -Hcs
38 #tl #b #Hcs #H destruct
40 elim (IH … Hcs) -IH -Hcs
41 #cs #Hcs #H1 #H2 [ @(ex3_intro … (b@cs)) | @(ex3_intro … (Ⓕ@cs)) ] /2 width=1 by after_true, after_false, colength_cons/
45 (* Basic inversion lemmas ***************************************************)
47 fact after_inv_empty1_aux: ∀cs1,cs2,cs. cs1 ⊚ cs2 ≡ cs → cs1 = ◊ →
49 #cs1 #cs2 #cs * -cs1 -cs2 -cs
51 | #cs1 #cs2 #cs #_ #b #H destruct
52 | #cs1 #cs2 #cs #_ #H destruct
56 lemma after_inv_empty1: ∀cs2,cs. ◊ ⊚ cs2 ≡ cs → cs2 = ◊ ∧ cs = ◊.
57 /2 width=3 by after_inv_empty1_aux/ qed-.
59 fact after_inv_true1_aux: ∀cs1,cs2,cs. cs1 ⊚ cs2 ≡ cs → ∀tl1. cs1 = Ⓣ @ tl1 →
60 ∃∃tl2,tl,b. cs2 = b @ tl2 & cs = b @ tl & tl1 ⊚ tl2 ≡ tl.
61 #cs1 #cs2 #cs * -cs1 -cs2 -cs
63 | #cs1 #cs2 #cs #H12 #b #tl1 #H destruct
64 /2 width=6 by ex3_3_intro/
65 | #cs1 #cs2 #cs #_ #tl1 #H destruct
69 lemma after_inv_true1: ∀tl1,cs2,cs. (Ⓣ @ tl1) ⊚ cs2 ≡ cs →
70 ∃∃tl2,tl,b. cs2 = b @ tl2 & cs = b @ tl & tl1 ⊚ tl2 ≡ tl.
71 /2 width=3 by after_inv_true1_aux/ qed-.
73 fact after_inv_false1_aux: ∀cs1,cs2,cs. cs1 ⊚ cs2 ≡ cs → ∀tl1. cs1 = Ⓕ @ tl1 →
74 ∃∃tl. cs = Ⓕ @ tl & tl1 ⊚ cs2 ≡ tl.
75 #cs1 #cs2 #cs * -cs1 -cs2 -cs
77 | #cs1 #cs2 #cs #_ #b #tl1 #H destruct
78 | #cs1 #cs2 #cs #H12 #tl1 #H destruct
79 /2 width=3 by ex2_intro/
83 lemma after_inv_false1: ∀tl1,cs2,cs. (Ⓕ @ tl1) ⊚ cs2 ≡ cs →
84 ∃∃tl. cs = Ⓕ @ tl & tl1 ⊚ cs2 ≡ tl.
85 /2 width=3 by after_inv_false1_aux/ qed-.
87 fact after_inv_empty3_aux: ∀cs1,cs2,cs. cs1 ⊚ cs2 ≡ cs → cs = ◊ →
89 #cs1 #cs2 #cs * -cs1 -cs2 -cs
91 | #cs1 #cs2 #cs #_ #b #H destruct
92 | #cs1 #cs2 #cs #_ #H destruct
96 lemma after_inv_empty3: ∀cs1,cs2. cs1 ⊚ cs2 ≡ ◊ → cs1 = ◊ ∧ cs2 = ◊.
97 /2 width=3 by after_inv_empty3_aux/ qed-.
99 fact after_inv_inh3_aux: ∀cs1,cs2,cs. cs1 ⊚ cs2 ≡ cs → ∀tl,b. cs = b @ tl →
100 (∃∃tl1,tl2. cs1 = Ⓣ @ tl1 & cs2 = b @ tl2 & tl1 ⊚ tl2 ≡ tl) ∨
101 ∃∃tl1. cs1 = Ⓕ @ tl1 & b = Ⓕ & tl1 ⊚ cs2 ≡ tl.
102 #cs1 #cs2 #cs * -cs1 -cs2 -cs
104 | #cs1 #cs2 #cs #H12 #b0 #tl #b #H destruct
105 /3 width=5 by ex3_2_intro, or_introl/
106 | #cs1 #cs2 #cs #H12 #tl #b #H destruct
107 /3 width=3 by ex3_intro, or_intror/
111 lemma after_inv_inh3: ∀cs1,cs2,tl,b. cs1 ⊚ cs2 ≡ b @ tl →
112 (∃∃tl1,tl2. cs1 = Ⓣ @ tl1 & cs2 = b @ tl2 & tl1 ⊚ tl2 ≡ tl) ∨
113 ∃∃tl1. cs1 = Ⓕ @ tl1 & b = Ⓕ & tl1 ⊚ cs2 ≡ tl.
114 /2 width=3 by after_inv_inh3_aux/ qed-.
116 lemma after_inv_length: ∀cs1,cs2,cs. cs1 ⊚ cs2 ≡ cs →
117 ∧∧ ∥cs1∥ = |cs2| & |cs| = |cs1| & ∥cs∥ = ∥cs2∥.
118 #cs1 #cs2 #cs #H elim H -cs1 -cs2 -cs /2 width=1 by and3_intro/
119 #cs1 #cs2 #cs #_ [ * ] * /2 width=1 by and3_intro/
122 (* Basic forward lemmas *****************************************************)
124 lemma after_at_fwd: ∀cs1,cs2,cs. cs2 ⊚ cs1 ≡ cs → ∀i1,i. @⦃i1, cs⦄ ≡ i →
125 ∃∃i2. @⦃i1, cs1⦄ ≡ i2 & @⦃i2, cs2⦄ ≡ i.
126 #cs1 #cs2 #cs #H elim H -cs1 -cs2 -cs
127 [ #i1 #i #H elim (at_inv_empty … H) -H
128 #H1 #H2 destruct /2 width=3 by at_empty, ex2_intro/
129 | #cs1 #cs2 #cs #_ * #IH #i1 #i #H
130 [ elim (at_inv_true … H) -H *
131 [ -IH #H1 #H2 destruct /2 width=3 by at_zero, ex2_intro/
132 | #j1 #j #H1 #H2 #Hj1 destruct
133 elim (IH … Hj1) -IH -Hj1 /3 width=3 by at_succ, ex2_intro/
135 | elim (at_inv_false … H) -H
137 elim (IH … Hj) -IH -Hj /3 width=3 by at_succ, at_false, ex2_intro/
139 | #cs1 #cs2 #cs #_ #IH #i1 #i #H elim (at_inv_false … H) -H
141 elim (IH … Hj) -IH -Hj /3 width=3 by at_false, ex2_intro/
145 lemma after_fwd_at: ∀cs1,cs2,cs. cs2 ⊚ cs1 ≡ cs → ∀i1,i2. @⦃i1, cs1⦄ ≡ i2 →
146 ∃∃i. @⦃i2, cs2⦄ ≡ i & @⦃i1, cs⦄ ≡ i.
147 #cs1 #cs2 #cs #H elim H -cs1 -cs2 -cs
148 [ #i1 #i2 #H elim (at_inv_empty … H) -H
149 #H1 #H2 destruct /2 width=3 by at_empty, ex2_intro/
150 | #cs1 #cs2 #cs #_ * #IH #i1 #i2 #H
151 [ elim (at_inv_true … H) -H *
152 [ -IH #H1 #H2 destruct /2 width=3 by at_zero, ex2_intro/
153 | #j1 #j2 #H1 #H2 #Hj12 destruct
154 elim (IH … Hj12) -IH -Hj12 /3 width=3 by at_succ, ex2_intro/
156 | elim (at_inv_false … H) -H
158 elim (IH … Hj2) -IH -Hj2 /3 width=3 by at_succ, at_false, ex2_intro/
160 | #cs1 #cs2 #cs #_ #IH #i1 #i2 #H elim (IH … H) -IH -H
161 /3 width=3 by at_false, ex2_intro/
165 (* Main properties **********************************************************)
167 theorem after_trans1: ∀cs1,cs2,cs0. cs1 ⊚ cs2 ≡ cs0 →
168 ∀cs3, cs4. cs0 ⊚ cs3 ≡ cs4 →
169 ∃∃cs. cs2 ⊚ cs3 ≡ cs & cs1 ⊚ cs ≡ cs4.
170 #cs1 #cs2 #cs0 #H elim H -cs1 -cs2 -cs0
171 [ #cs3 #cs4 #H elim (after_inv_empty1 … H) -H
172 #H1 #H2 destruct /2 width=3 by ex2_intro, after_empty/
173 | #cs1 #cs2 #cs0 #_ * #IH #cs3 #cs4 #H
174 [ elim (after_inv_true1 … H) -H
175 #tl3 #tl4 #b #H1 #H2 #Htl destruct
177 /3 width=3 by ex2_intro, after_true/
178 | elim (after_inv_false1 … H) -H
179 #tl4 #H #Htl destruct
181 /3 width=3 by ex2_intro, after_true, after_false/
183 | #cs1 #cs2 #cs0 #_ #IH #cs3 #cs4 #H
184 elim (after_inv_false1 … H) -H
185 #tl4 #H #Htl destruct
187 /3 width=3 by ex2_intro, after_false/
191 theorem after_trans2: ∀cs1,cs0,cs4. cs1 ⊚ cs0 ≡ cs4 →
192 ∀cs2, cs3. cs2 ⊚ cs3 ≡ cs0 →
193 ∃∃cs. cs1 ⊚ cs2 ≡ cs & cs ⊚ cs3 ≡ cs4.
194 #cs1 #cs0 #cs4 #H elim H -cs1 -cs0 -cs4
195 [ #cs2 #cs3 #H elim (after_inv_empty3 … H) -H
196 #H1 #H2 destruct /2 width=3 by ex2_intro, after_empty/
197 | #cs1 #cs0 #cs4 #_ #b #IH #cs2 #cs3 #H elim (after_inv_inh3 … H) -H *
198 [ #tl2 #tl3 #H1 #H2 #Htl destruct
200 /3 width=3 by ex2_intro, after_true/
201 | #tl2 #H1 #H2 #Htl destruct
203 /3 width=3 by ex2_intro, after_true, after_false/
205 | #cs1 #cs0 #cs4 #_ #IH #cs2 #cs3 #H elim (IH … H) -cs0
206 /3 width=3 by ex2_intro, after_false/
210 theorem after_mono: ∀cs1,cs2,x. cs1 ⊚ cs2 ≡ x → ∀y. cs1 ⊚ cs2 ≡ y → x = y.
211 #cs1 #cs2 #x #H elim H -cs1 -cs2 -x
212 [ #y #H elim (after_inv_empty1 … H) -H //
213 | #cs1 #cs #x #_ #b #IH #y #H elim (after_inv_true1 … H) -H
214 #tl #tly #b0 #H1 #H2 #Htl destruct >(IH … Htl) -tl -cs1 -x //
215 | #cs1 #cs2 #x #_ #IH #y #H elim (after_inv_false1 … H) -H
216 #tly #H #Htl destruct >(IH … Htl) -cs1 -cs2 -x //
220 theorem after_inj: ∀cs1,x,cs. cs1 ⊚ x ≡ cs → ∀y. cs1 ⊚ y ≡ cs → x = y.
221 #cs1 #x #cs #H elim H -cs1 -x -cs
222 [ #y #H elim (after_inv_empty1 … H) -H //
223 | #cs1 #x #cs #_ #b #IH #y #H elim (after_inv_true1 … H) -H
224 #tly #tl #b0 #H1 #H2 #Htl destruct >(IH … Htl) -tl -cs1 -x //
225 | #cs1 #x #cs #_ #IH #y #H elim (after_inv_false1 … H) -H
226 #tl #H #Htl destruct >(IH … Htl) -tl -cs1 -x //