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