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