]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/lambdadelta/ground_2/relocation/nstream_at.ma
a40ba30ad1de6ccd87ff640e80803494c1835012
[helm.git] / matita / matita / contribs / lambdadelta / ground_2 / relocation / nstream_at.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.tcs.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/functions/apply_2.ma".
16 include "ground_2/notation/relations/rat_3.ma".
17 include "ground_2/relocation/nstream.ma".
18
19 (* RELOCATION N-STREAM ******************************************************)
20
21 let rec apply (i: nat) on i: rtmap → nat ≝ ?.
22 * #b #f cases i -i
23 [ @b
24 | #i lapply (apply i f) -apply -i -f
25   #i @(⫯(b+i))
26 ]
27 qed.
28
29 interpretation "functional application (nstream)"
30    'Apply f i = (apply i f).
31
32 inductive at: rtmap → relation nat ≝
33 | at_zero: ∀f. at (0 @ f) 0 0
34 | at_skip: ∀f,i1,i2. at f i1 i2 → at (0 @ f) (⫯i1) (⫯i2)
35 | at_lift: ∀f,b,i1,i2. at (b @ f) i1 i2 → at (⫯b @ f) i1 (⫯i2)
36 .
37
38 interpretation "relational application (nstream)"
39    'RAt i1 f i2 = (at f i1 i2).
40
41 (* Basic properties on apply ************************************************)
42
43 lemma apply_S1: ∀f,a,i. (⫯a@f)@❴i❵ = ⫯((a@f)@❴i❵).
44 #a #f * //
45 qed.
46
47 (* Basic inversion lemmas on at *********************************************)
48
49 fact at_inv_xOx_aux: ∀f,i1,i2. @⦃i1, f⦄ ≡ i2 → ∀g. f = 0@g →
50                      (i1 = 0 ∧ i2 = 0) ∨
51                      ∃∃j1,j2. @⦃j1, g⦄ ≡ j2 & i1 = ⫯j1 & i2 = ⫯j2.
52 #f #i1 #i2 * -f -i1 -i2
53 [ /3 width=1 by or_introl, conj/
54 | #f #i1 #i2 #Hi #g #H destruct /3 width=5 by ex3_2_intro, or_intror/
55 | #f #b #i1 #i2 #_ #g #H destruct
56 ]
57 qed-.
58
59 lemma at_inv_xOx: ∀f,i1,i2. @⦃i1, 0@f⦄ ≡ i2 →
60                   (i1 = 0 ∧ i2 = 0) ∨
61                   ∃∃j1,j2. @⦃j1, f⦄ ≡ j2 & i1 = ⫯j1 & i2 = ⫯j2.
62 /2 width=3 by at_inv_xOx_aux/ qed-.
63
64 lemma at_inv_OOx: ∀f,i. @⦃0, 0 @ f⦄ ≡ i → i = 0.
65 #f #i #H elim (at_inv_xOx … H) -H * //
66 #j1 #j2 #_ #H destruct
67 qed-.
68
69 lemma at_inv_xOO: ∀f,i. @⦃i, 0@f⦄ ≡ 0 → i = 0.
70 #f #i #H elim (at_inv_xOx … H) -H * //
71 #j1 #j2 #_ #_ #H destruct
72 qed-.
73
74 lemma at_inv_SOx: ∀f,i1,i2. @⦃⫯i1, 0@f⦄ ≡ i2 →
75                   ∃∃j2. @⦃i1, f⦄ ≡ j2 & i2 = ⫯j2.
76 #f #i1 #i2 #H elim (at_inv_xOx … H) -H *
77 [ #H destruct
78 | #j1 #j2 #Hj #H1 #H2 destruct /2 width=3 by ex2_intro/
79 ]
80 qed-.
81
82 lemma at_inv_xOS: ∀f,i1,i2. @⦃i1, 0@f⦄ ≡ ⫯i2 →
83                   ∃∃j1. @⦃j1, f⦄ ≡ i2 & i1 = ⫯j1.
84 #f #i1 #i2 #H elim (at_inv_xOx … H) -H *
85 [ #_ #H destruct
86 | #j1 #j2 #Hj #H1 #H2 destruct /2 width=3 by ex2_intro/
87 ]
88 qed-.
89
90 lemma at_inv_SOS: ∀f,i1,i2. @⦃⫯i1, 0@f⦄ ≡ ⫯i2 → @⦃i1, f⦄ ≡ i2.
91 #f #i1 #i2 #H elim (at_inv_xOx … H) -H *
92 [ #H destruct
93 | #j1 #j2 #Hj #H1 #H2 destruct //
94 ]
95 qed-.
96
97 lemma at_inv_OOS: ∀f,i. @⦃0, 0@f⦄ ≡ ⫯i → ⊥.
98 #f #i #H elim (at_inv_xOx … H) -H *
99 [ #_ #H destruct
100 | #j1 #j2 #_ #H destruct
101 ]
102 qed-.
103
104 lemma at_inv_SOO: ∀f,i. @⦃⫯i, 0@f⦄ ≡ 0 → ⊥.
105 #f #i #H elim (at_inv_xOx … H) -H *
106 [ #H destruct
107 | #j1 #j2 #_ #_ #H destruct
108 ]
109 qed-.
110
111 fact at_inv_xSx_aux: ∀f,i1,i2. @⦃i1, f⦄ ≡ i2 → ∀g,a. f = ⫯a @ g →
112                      ∃∃j2. @⦃i1, a@g⦄ ≡ j2 & i2 = ⫯j2.
113 #f #i1 #i2 * -f -i1 -i2
114 [ #f #g #a #H destruct
115 | #f #i1 #i2 #_ #g #a #H destruct
116 | #f #b #i1 #i2 #Hi #g #a #H destruct /2 width=3 by ex2_intro/
117 ]
118 qed-.
119
120 lemma at_inv_xSx: ∀f,b,i1,i2. @⦃i1, ⫯b@f⦄ ≡ i2 →
121                   ∃∃j2. @⦃i1, b@f⦄ ≡ j2 & i2 = ⫯j2.
122 /2 width=3 by at_inv_xSx_aux/ qed-.
123
124 lemma at_inv_xSS: ∀f,b,i1,i2. @⦃i1, ⫯b @ f⦄ ≡ ⫯i2 → @⦃i1, b@f⦄ ≡ i2.
125 #f #b #i1 #i2 #H elim (at_inv_xSx … H) -H
126 #j2 #Hj #H destruct //
127 qed-.
128
129 lemma at_inv_xSO: ∀f,b,i. @⦃i, ⫯b@f⦄ ≡ 0 → ⊥.
130 #f #b #i #H elim (at_inv_xSx … H) -H
131 #j2 #_ #H destruct
132 qed-.
133
134 (* alternative definition ***************************************************)
135
136 lemma at_O1: ∀b,f. @⦃0, b@f⦄ ≡ b.
137 #b elim b -b /2 width=1 by at_lift/
138 qed.
139
140 lemma at_S1: ∀b,f,i1,i2. @⦃i1, f⦄ ≡ i2 → @⦃⫯i1, b@f⦄ ≡ ⫯(b+i2).
141 #b elim b -b /3 width=1 by at_skip, at_lift/
142 qed.
143
144 lemma at_inv_O1: ∀f,b,i2. @⦃0, b@f⦄ ≡ i2 → i2 = b.
145 #f #b elim b -b /2 width=2 by at_inv_OOx/
146 #b #IH #i2 #H elim (at_inv_xSx … H) -H
147 #j2 #Hj #H destruct /3 width=1 by eq_f/
148 qed-.
149
150 lemma at_inv_S1: ∀f,b,j1,i2. @⦃⫯j1, b@f⦄ ≡ i2 → ∃∃j2. @⦃j1, f⦄ ≡ j2 & i2 =⫯(b+j2).
151 #f #b elim b -b /2 width=1 by at_inv_SOx/
152 #b #IH #j1 #i2 #H elim (at_inv_xSx … H) -H
153 #j2 #Hj #H destruct elim (IH … Hj) -IH -Hj
154 #i2 #Hi #H destruct /2 width=3 by ex2_intro/
155 qed-.
156
157 lemma at_total: ∀i,f. @⦃i, f⦄ ≡ f@❴i❵.
158 #i elim i -i
159 [ * // | #i #IH * /3 width=1 by at_S1/ ]
160 qed.
161
162 (* Advanced forward lemmas on at ********************************************)
163
164 lemma at_increasing: ∀f,i1,i2. @⦃i1, f⦄ ≡ i2 → i1 ≤ i2.
165 #f #i1 #i2 #H elim H -f -i1 -i2 /2 width=1 by le_S_S, le_S/
166 qed-.
167
168 lemma at_increasing_plus: ∀f,b,i1,i2. @⦃i1, b@f⦄ ≡ i2 → i1 + b ≤ i2.
169 #f #b *
170 [ #i2 #H >(at_inv_O1 … H) -i2 //
171 | #i1 #i2 #H elim (at_inv_S1 … H) -H
172   #j1 #Ht #H destruct
173   /4 width=2 by at_increasing, monotonic_le_plus_r, le_S_S/
174 ]
175 qed-.
176
177 lemma at_increasing_strict: ∀f,b,i1,i2. @⦃i1, ⫯b @ f⦄ ≡ i2 →
178                             i1 < i2 ∧ @⦃i1, b@f⦄ ≡ ⫰i2.
179 #f #b #i1 #i2 #H elim (at_inv_xSx … H) -H
180 #j2 #Hj #H destruct /4 width=2 by conj, at_increasing, le_S_S/
181 qed-.
182
183 lemma at_fwd_id: ∀f,b,i. @⦃i, b@f⦄ ≡ i → b = 0.
184 #f #b *
185 [ #H <(at_inv_O1 … H) -f -b //
186 | #i #H elim (at_inv_S1 … H) -H
187   #j #H #H0 destruct lapply (at_increasing … H) -H
188   #H lapply (eq_minus_O … H) -H //
189 ]
190 qed.
191
192 (* Main properties on at ****************************************************)
193
194 lemma at_id_le: ∀i1,i2. i1 ≤ i2 → ∀f. @⦃i2, f⦄ ≡ i2 → @⦃i1, f⦄ ≡ i1.
195 #i1 #i2 #H @(le_elim … H) -i1 -i2 [ #i2 | #i1 #i2 #IH ]
196 * #b #f #H lapply (at_fwd_id … H)
197 #H0 destruct /4 width=1 by at_S1, at_inv_SOS/
198 qed-.
199
200 let corec at_ext: ∀f1,f2. (∀i,i1,i2. @⦃i, f1⦄ ≡ i1 → @⦃i, f2⦄ ≡ i2 → i1 = i2) → f1 ≐ f2 ≝ ?.
201 * #b1 #f1 * #b2 #f2 #Hi lapply (Hi 0 b1 b2 ? ?) //
202 #H lapply (at_ext f1 f2 ?) /2 width=1 by eq_seq/ -at_ext
203 #j #j1 #j2 #H1 #H2 @(injective_plus_r … b2) /4 width=5 by at_S1, injective_S/ (**) (* full auto fails *)
204 qed-.
205
206 theorem at_monotonic: ∀i1,i2. i1 < i2 → ∀f1,f2. f1 ≐ f2 → ∀j1,j2. @⦃i1, f1⦄ ≡ j1 → @⦃i2, f2⦄ ≡ j2 → j1 < j2.
207 #i1 #i2 #H @(lt_elim … H) -i1 -i2
208 [ #i2 * #b1 #f1 * #b2 #f2 #H elim (eq_stream_inv_seq ????? H) -H
209   #H #Ht #j1 #j2 #H1 #H2 destruct
210   >(at_inv_O1 … H1) elim (at_inv_S1 … H2) -H2 -j1 //
211 | #i1 #i2 #IH * #b1 #f1 * #b2 #f2 #H elim (eq_stream_inv_seq ????? H) -H
212   #H #Ht #j1 #j2 #H1 #H2 destruct
213   elim (at_inv_S1 … H2) elim (at_inv_S1 … H1) -H1 -H2
214   #x1 #Hx1 #H1 #x2 #Hx2 #H2 destruct /4 width=5 by lt_S_S, monotonic_lt_plus_r/
215 ]
216 qed-.
217
218 theorem at_inv_monotonic: ∀f1,i1,j1. @⦃i1, f1⦄ ≡ j1 → ∀f2,i2,j2. @⦃i2, f2⦄ ≡ j2 → f1 ≐ f2 → j2 < j1 → i2 < i1.
219 #f1 #i1 #j1 #H elim H -f1 -i1 -j1
220 [ #f1 #f2 #i2 #j2 #_ #_ #H elim (lt_le_false … H) //
221 | #f1 #i1 #j1 #_ #IH * #b2 #f2 #i2 #j2 #H #Ht #Hj elim (eq_stream_inv_seq ????? Ht) -Ht
222   #H0 #Ht destruct elim (at_inv_xOx … H) -H *
223   [ #H1 #H2 destruct //
224   | #x2 #y2 #Hxy #H1 #H2 destruct /4 width=5 by lt_S_S_to_lt, lt_S_S/
225   ]
226 | #f1 #b1 #i1 #j1 #_ #IH * #b2 #f2 #i2 #j2 #H #Ht #Hj elim (eq_stream_inv_seq ????? Ht) -Ht
227   #H0 #Ht destruct elim (at_inv_xSx … H) -H
228   #y2 #Hy #H destruct /3 width=5 by eq_seq, lt_S_S_to_lt/
229 ]
230 qed-.
231
232 theorem at_mono: ∀f1,f2. f1 ≐ f2 → ∀i,i1. @⦃i, f1⦄ ≡ i1 → ∀i2. @⦃i, f2⦄ ≡ i2 → i2 = i1.
233 #f1 #f2 #Ht #i #i1 #H1 #i2 #H2 elim (lt_or_eq_or_gt i2 i1) //
234 #Hi elim (lt_le_false i i) /3 width=8 by at_inv_monotonic, eq_stream_sym/
235 qed-.
236
237 theorem at_inj: ∀f1,f2. f1 ≐ f2 → ∀i1,i. @⦃i1, f1⦄ ≡ i → ∀i2. @⦃i2, f2⦄ ≡ i → i1 = i2.
238 #f1 #f2 #Ht #i1 #i #H1 #i2 #H2 elim (lt_or_eq_or_gt i2 i1) //
239 #Hi elim (lt_le_false i i) /3 width=8 by at_monotonic, eq_stream_sym/
240 qed-.
241
242 lemma at_inv_total: ∀f,i1,i2. @⦃i1, f⦄ ≡ i2 → i2 = f@❴i1❵.
243 /2 width=6 by at_mono/ qed-.
244
245 lemma at_repl_back: ∀i1,i2. eq_stream_repl_back ? (λf. @⦃i1, f⦄ ≡ i2).
246 #i1 #i2 #f1 #f2 #Ht #H1 lapply (at_total i1 f2)
247 #H2 <(at_mono … Ht … H1 … H2) -f1 -i2 //
248 qed-.
249
250 lemma at_repl_fwd: ∀i1,i2. eq_stream_repl_fwd ? (λf. @⦃i1, f⦄ ≡ i2).
251 #i1 #i2 @eq_stream_repl_sym /2 width=3 by at_repl_back/
252 qed-.
253
254 (* Advanced properties on at ************************************************)
255
256 (* Note: see also: trace_at/at_dec *)
257 lemma at_dec: ∀f,i1,i2. Decidable (@⦃i1, f⦄ ≡ i2).
258 #f #i1 #i2 lapply (at_total i1 f)
259 #Ht elim (eq_nat_dec i2 (f@❴i1❵))
260 [ #H destruct /2 width=1 by or_introl/
261 | /4 width=6 by at_mono, or_intror/
262 ]
263 qed-.
264
265 lemma is_at_dec_le: ∀f,i2,i. (∀i1. i1 + i ≤ i2 → @⦃i1, f⦄ ≡ i2 → ⊥) → Decidable (∃i1. @⦃i1, f⦄ ≡ i2).
266 #f #i2 #i elim i -i
267 [ #Ht @or_intror * /3 width=3 by at_increasing/
268 | #i #IH #Ht elim (at_dec f (i2-i) i2) /3 width=2 by ex_intro, or_introl/
269   #Hi2 @IH -IH #i1 #H #Hi elim (le_to_or_lt_eq … H) -H /2 width=3 by/
270   #H destruct -Ht /2 width=1 by/
271 ]
272 qed-.
273
274 (* Note: see also: trace_at/is_at_dec *)
275 lemma is_at_dec: ∀f,i2. Decidable (∃i1. @⦃i1, f⦄ ≡ i2).
276 #f #i2 @(is_at_dec_le ? ? (⫯i2)) /2 width=4 by lt_le_false/
277 qed-.
278
279 (* Advanced properties on apply *********************************************)
280
281 fact apply_inj_aux: ∀f1,f2. f1 ≐ f2 → ∀i,i1,i2. i = f1@❴i1❵ → i = f2@❴i2❵ → i1 = i2.
282 /2 width=6 by at_inj/ qed-.