]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/lambdadelta/ground_2/relocation/trace_after.ma
colength and identity relocation
[helm.git] / matita / matita / contribs / lambdadelta / ground_2 / relocation / trace_after.ma
1 (**************************************************************************)
2 (*       ___                                                              *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||         The HELM team.                                      *)
8 (*      ||A||         http://helm.cs.unibo.it                             *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU General Public License Version 2                  *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 include "ground_2/notation/relations/rafter_3.ma".
16 include "ground_2/relocation/trace_at.ma".
17
18 (* RELOCATION TRACE *********************************************************)
19
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).
26
27 interpretation "composition (trace)"
28    'RAfter cs1 cs2 cs = (after cs1 cs2 cs).
29
30 (* Basic properties *********************************************************)
31
32 lemma after_length: ∀cs1,cs2. ∥cs1∥ = |cs2| →
33                     ∃∃cs. cs1 ⊚ cs2 ≡ cs & |cs| = |cs1| & ∥cs∥ = ∥cs2∥.
34 #cs1 elim cs1 -cs1
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
39   ]
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/
42 ]  
43 qed-.
44
45 (* Basic inversion lemmas ***************************************************)
46
47 fact after_inv_empty1_aux: ∀cs1,cs2,cs. cs1 ⊚ cs2 ≡ cs → cs1 = ◊ →
48                            cs2 = ◊ ∧ cs = ◊.
49 #cs1 #cs2 #cs * -cs1 -cs2 -cs
50 [ /2 width=1 by conj/
51 | #cs1 #cs2 #cs #_ #b #H destruct
52 | #cs1 #cs2 #cs #_ #H destruct
53 ]
54 qed-.
55
56 lemma after_inv_empty1: ∀cs2,cs. ◊ ⊚ cs2 ≡ cs → cs2 = ◊ ∧ cs = ◊.
57 /2 width=3 by after_inv_empty1_aux/ qed-.
58
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
62 [ #tl1 #H destruct
63 | #cs1 #cs2 #cs #H12 #b #tl1 #H destruct
64   /2 width=6 by ex3_3_intro/
65 | #cs1 #cs2 #cs #_ #tl1 #H destruct
66 ]
67 qed-.
68
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-.
72
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
76 [ #tl1 #H destruct
77 | #cs1 #cs2 #cs #_ #b #tl1 #H destruct
78 | #cs1 #cs2 #cs #H12 #tl1 #H destruct
79   /2 width=3 by ex2_intro/
80 ]
81 qed-.
82
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-.
86
87 fact after_inv_empty3_aux: ∀cs1,cs2,cs. cs1 ⊚ cs2 ≡ cs → cs = ◊ →
88                            cs1 = ◊ ∧ cs2 = ◊.
89 #cs1 #cs2 #cs * -cs1 -cs2 -cs
90 [ /2 width=1 by conj/
91 | #cs1 #cs2 #cs #_ #b #H destruct
92 | #cs1 #cs2 #cs #_ #H destruct
93 ]
94 qed-.
95
96 lemma after_inv_empty3: ∀cs1,cs2. cs1 ⊚ cs2 ≡ ◊ → cs1 = ◊ ∧ cs2 = ◊.
97 /2 width=3 by after_inv_empty3_aux/ qed-.
98
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
103 [ #tl #b #H destruct
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/
108 ]
109 qed-.
110
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-.
115
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/
120 qed-.
121
122 (* Basic forward lemmas *****************************************************)
123
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/
134     ]
135   | elim (at_inv_false … H) -H
136     #j #H #Hj destruct
137     elim (IH … Hj) -IH -Hj /3 width=3 by at_succ, at_false, ex2_intro/
138   ]
139 | #cs1 #cs2 #cs #_ #IH #i1 #i #H elim (at_inv_false … H) -H
140   #j #H #Hj destruct
141   elim (IH … Hj) -IH -Hj /3 width=3 by at_false, ex2_intro/
142 ]
143 qed-.
144
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/
155     ]
156   | elim (at_inv_false … H) -H
157     #j2 #H #Hj2 destruct
158     elim (IH … Hj2) -IH -Hj2 /3 width=3 by at_succ, at_false, ex2_intro/
159   ]
160 | #cs1 #cs2 #cs #_ #IH #i1 #i2 #H elim (IH … H) -IH -H
161   /3 width=3 by at_false, ex2_intro/
162 ]
163 qed-.
164
165 (* Main properties **********************************************************)
166
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
176     elim (IH … Htl) -cs0
177     /3 width=3 by ex2_intro, after_true/
178   | elim (after_inv_false1 … H) -H
179     #tl4 #H #Htl destruct
180     elim (IH … Htl) -cs0
181     /3 width=3 by ex2_intro, after_true, after_false/
182   ]
183 | #cs1 #cs2 #cs0 #_ #IH #cs3 #cs4 #H
184   elim (after_inv_false1 … H) -H
185   #tl4 #H #Htl destruct
186   elim (IH … Htl) -cs0
187   /3 width=3 by ex2_intro, after_false/
188 ]
189 qed-.
190
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
199     elim (IH … Htl) -cs0
200     /3 width=3 by ex2_intro, after_true/
201   | #tl2 #H1 #H2 #Htl destruct
202     elim (IH … Htl) -cs0
203     /3 width=3 by ex2_intro, after_true, after_false/
204   ]
205 | #cs1 #cs0 #cs4 #_ #IH #cs2 #cs3 #H elim (IH … H) -cs0
206   /3 width=3 by ex2_intro, after_false/
207 ]
208 qed-.
209
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 //
217 ]
218 qed-.
219
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 //
227 ]
228 qed-.