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 inversion lemmas ***************************************************)
32 fact after_inv_empty1_aux: ∀cs1,cs2,cs. cs1 ⊚ cs2 ≡ cs → cs1 = ◊ →
34 #cs1 #cs2 #cs * -cs1 -cs2 -cs
36 | #cs1 #cs2 #cs #_ #b #H destruct
37 | #cs1 #cs2 #cs #_ #H destruct
41 lemma after_inv_empty1: ∀cs2,cs. ◊ ⊚ cs2 ≡ cs → cs2 = ◊ ∧ cs = ◊.
42 /2 width=3 by after_inv_empty1_aux/ qed-.
44 fact after_inv_true1_aux: ∀cs1,cs2,cs. cs1 ⊚ cs2 ≡ cs → ∀tl1. cs1 = Ⓣ @ tl1 →
45 ∃∃tl2,tl,b. cs2 = b @ tl2 & cs = b @ tl & tl1 ⊚ tl2 ≡ tl.
46 #cs1 #cs2 #cs * -cs1 -cs2 -cs
48 | #cs1 #cs2 #cs #H12 #b #tl1 #H destruct
49 /2 width=6 by ex3_3_intro/
50 | #cs1 #cs2 #cs #_ #tl1 #H destruct
54 lemma after_inv_true1: ∀tl1,cs2,cs. (Ⓣ @ tl1) ⊚ cs2 ≡ cs →
55 ∃∃tl2,tl,b. cs2 = b @ tl2 & cs = b @ tl & tl1 ⊚ tl2 ≡ tl.
56 /2 width=3 by after_inv_true1_aux/ qed-.
58 fact after_inv_false1_aux: ∀cs1,cs2,cs. cs1 ⊚ cs2 ≡ cs → ∀tl1. cs1 = Ⓕ @ tl1 →
59 ∃∃tl. cs = Ⓕ @ tl & tl1 ⊚ cs2 ≡ tl.
60 #cs1 #cs2 #cs * -cs1 -cs2 -cs
62 | #cs1 #cs2 #cs #_ #b #tl1 #H destruct
63 | #cs1 #cs2 #cs #H12 #tl1 #H destruct
64 /2 width=3 by ex2_intro/
68 lemma after_inv_false1: ∀tl1,cs2,cs. (Ⓕ @ tl1) ⊚ cs2 ≡ cs →
69 ∃∃tl. cs = Ⓕ @ tl & tl1 ⊚ cs2 ≡ tl.
70 /2 width=3 by after_inv_false1_aux/ qed-.
72 fact after_inv_empty3_aux: ∀cs1,cs2,cs. cs1 ⊚ cs2 ≡ cs → cs = ◊ →
74 #cs1 #cs2 #cs * -cs1 -cs2 -cs
76 | #cs1 #cs2 #cs #_ #b #H destruct
77 | #cs1 #cs2 #cs #_ #H destruct
81 lemma after_inv_empty3: ∀cs1,cs2. cs1 ⊚ cs2 ≡ ◊ → cs1 = ◊ ∧ cs2 = ◊.
82 /2 width=3 by after_inv_empty3_aux/ qed-.
84 fact after_inv_inh3_aux: ∀cs1,cs2,cs. cs1 ⊚ cs2 ≡ cs → ∀tl,b. cs = b @ tl →
85 (∃∃tl1,tl2. cs1 = Ⓣ @ tl1 & cs2 = b @ tl2 & tl1 ⊚ tl2 ≡ tl) ∨
86 ∃∃tl1. cs1 = Ⓕ @ tl1 & b = Ⓕ & tl1 ⊚ cs2 ≡ tl.
87 #cs1 #cs2 #cs * -cs1 -cs2 -cs
89 | #cs1 #cs2 #cs #H12 #b0 #tl #b #H destruct
90 /3 width=5 by ex3_2_intro, or_introl/
91 | #cs1 #cs2 #cs #H12 #tl #b #H destruct
92 /3 width=3 by ex3_intro, or_intror/
96 lemma after_inv_inh3: ∀cs1,cs2,tl,b. cs1 ⊚ cs2 ≡ b @ tl →
97 (∃∃tl1,tl2. cs1 = Ⓣ @ tl1 & cs2 = b @ tl2 & tl1 ⊚ tl2 ≡ tl) ∨
98 ∃∃tl1. cs1 = Ⓕ @ tl1 & b = Ⓕ & tl1 ⊚ cs2 ≡ tl.
99 /2 width=3 by after_inv_inh3_aux/ qed-.
101 (* Basic forward lemmas *****************************************************)
103 lemma after_at_fwd: ∀cs1,cs2,cs. cs2 ⊚ cs1 ≡ cs → ∀i1,i. @⦃i1, cs⦄ ≡ i →
104 ∃∃i2. @⦃i1, cs1⦄ ≡ i2 & @⦃i2, cs2⦄ ≡ i.
105 #cs1 #cs2 #cs #H elim H -cs1 -cs2 -cs
106 [ #i1 #i #H elim (at_inv_empty … H)
107 | #cs1 #cs2 #cs #_ * #IH #i1 #i #H
108 [ elim (at_inv_true … H) -H *
109 [ -IH #H1 #H2 destruct /2 width=3 by at_zero, ex2_intro/
110 | #j1 #j #H1 #H2 #Hj1 destruct
111 elim (IH … Hj1) -IH -Hj1 /3 width=3 by at_succ, ex2_intro/
113 | elim (at_inv_false … H) -H
115 elim (IH … Hj) -IH -Hj /3 width=3 by at_succ, at_false, ex2_intro/
117 | #cs1 #cs2 #cs #_ #IH #i1 #i #H elim (at_inv_false … H) -H
119 elim (IH … Hj) -IH -Hj /3 width=3 by at_false, ex2_intro/
123 lemma after_fwd_at: ∀cs1,cs2,cs. cs2 ⊚ cs1 ≡ cs → ∀i1,i2. @⦃i1, cs1⦄ ≡ i2 →
124 ∃∃i. @⦃i2, cs2⦄ ≡ i & @⦃i1, cs⦄ ≡ i.
125 #cs1 #cs2 #cs #H elim H -cs1 -cs2 -cs
126 [ #i1 #i2 #H elim (at_inv_empty … H)
127 | #cs1 #cs2 #cs #_ * #IH #i1 #i2 #H
128 [ elim (at_inv_true … H) -H *
129 [ -IH #H1 #H2 destruct /2 width=3 by at_zero, ex2_intro/
130 | #j1 #j2 #H1 #H2 #Hj12 destruct
131 elim (IH … Hj12) -IH -Hj12 /3 width=3 by at_succ, ex2_intro/
133 | elim (at_inv_false … H) -H
135 elim (IH … Hj2) -IH -Hj2 /3 width=3 by at_succ, at_false, ex2_intro/
137 | #cs1 #cs2 #cs #_ #IH #i1 #i2 #H elim (IH … H) -IH -H
138 /3 width=3 by at_false, ex2_intro/
142 (* Main properties **********************************************************)
144 theorem after_trans1: ∀cs1,cs2,cs0. cs1 ⊚ cs2 ≡ cs0 →
145 ∀cs3, cs4. cs0 ⊚ cs3 ≡ cs4 →
146 ∃∃cs. cs2 ⊚ cs3 ≡ cs & cs1 ⊚ cs ≡ cs4.
147 #cs1 #cs2 #cs0 #H elim H -cs1 -cs2 -cs0
148 [ #cs3 #cs4 #H elim (after_inv_empty1 … H) -H
149 #H1 #H2 destruct /2 width=3 by ex2_intro, after_empty/
150 | #cs1 #cs2 #cs0 #_ * #IH #cs3 #cs4 #H
151 [ elim (after_inv_true1 … H) -H
152 #tl3 #tl4 #b #H1 #H2 #Htl destruct
154 /3 width=3 by ex2_intro, after_true/
155 | elim (after_inv_false1 … H) -H
156 #tl4 #H #Htl destruct
158 /3 width=3 by ex2_intro, after_true, after_false/
160 | #cs1 #cs2 #cs0 #_ #IH #cs3 #cs4 #H
161 elim (after_inv_false1 … H) -H
162 #tl4 #H #Htl destruct
164 /3 width=3 by ex2_intro, after_false/
168 theorem after_trans2: ∀cs1,cs0,cs4. cs1 ⊚ cs0 ≡ cs4 →
169 ∀cs2, cs3. cs2 ⊚ cs3 ≡ cs0 →
170 ∃∃cs. cs1 ⊚ cs2 ≡ cs & cs ⊚ cs3 ≡ cs4.
171 #cs1 #cs0 #cs4 #H elim H -cs1 -cs0 -cs4
172 [ #cs2 #cs3 #H elim (after_inv_empty3 … H) -H
173 #H1 #H2 destruct /2 width=3 by ex2_intro, after_empty/
174 | #cs1 #cs0 #cs4 #_ #b #IH #cs2 #cs3 #H elim (after_inv_inh3 … H) -H *
175 [ #tl2 #tl3 #H1 #H2 #Htl destruct
177 /3 width=3 by ex2_intro, after_true/
178 | #tl2 #H1 #H2 #Htl destruct
180 /3 width=3 by ex2_intro, after_true, after_false/
182 | #cs1 #cs0 #cs4 #_ #IH #cs2 #cs3 #H elim (IH … H) -cs0
183 /3 width=3 by ex2_intro, after_false/
187 theorem after_mono: ∀cs1,cs2,x. cs1 ⊚ cs2 ≡ x → ∀y. cs1 ⊚ cs2 ≡ y → x = y.
188 #cs1 #cs2 #x #H elim H -cs1 -cs2 -x
189 [ #y #H elim (after_inv_empty1 … H) -H //
190 | #cs1 #cs #x #_ #b #IH #y #H elim (after_inv_true1 … H) -H
191 #tl #tly #b0 #H1 #H2 #Htl destruct >(IH … Htl) -tl -cs1 -x //
192 | #cs1 #cs2 #x #_ #IH #y #H elim (after_inv_false1 … H) -H
193 #tly #H #Htl destruct >(IH … Htl) -cs1 -cs2 -x //
197 theorem after_inj: ∀cs1,x,cs. cs1 ⊚ x ≡ cs → ∀y. cs1 ⊚ y ≡ cs → x = y.
198 #cs1 #x #cs #H elim H -cs1 -x -cs
199 [ #y #H elim (after_inv_empty1 … H) -H //
200 | #cs1 #x #cs #_ #b #IH #y #H elim (after_inv_true1 … H) -H
201 #tly #tl #b0 #H1 #H2 #Htl destruct >(IH … Htl) -tl -cs1 -x //
202 | #cs1 #x #cs #_ #IH #y #H elim (after_inv_false1 … H) -H
203 #tl #H #Htl destruct >(IH … Htl) -tl -cs1 -x //