author | blanchet |
Mon, 23 Sep 2013 17:43:23 +0200 | |
changeset 53805 | 4163160853fd |
parent 53694 | 7b453b619b5f |
child 53806 | de4653037e0d |
permissions | -rw-r--r-- |
50518 | 1 |
(* Title: HOL/BNF/Examples/Stream.thy |
2 |
Author: Dmitriy Traytel, TU Muenchen |
|
3 |
Author: Andrei Popescu, TU Muenchen |
|
51778 | 4 |
Copyright 2012, 2013 |
50518 | 5 |
|
6 |
Infinite streams. |
|
7 |
*) |
|
8 |
||
9 |
header {* Infinite Streams *} |
|
10 |
||
11 |
theory Stream |
|
12 |
imports "../BNF" |
|
13 |
begin |
|
14 |
||
51804
be6e703908f4
renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents:
51788
diff
changeset
|
15 |
codatatype (sset: 'a) stream (map: smap rel: stream_all2) = |
be6e703908f4
renamed BNF "(co)data" commands to names that are closer to their final names
blanchet
parents:
51788
diff
changeset
|
16 |
Stream (shd: 'a) (stl: "'a stream") (infixr "##" 65) |
50518 | 17 |
|
51409 | 18 |
declaration {* |
19 |
Nitpick_HOL.register_codatatype |
|
20 |
@{typ "'stream_element_type stream"} @{const_name stream_case} [dest_Const @{term Stream}] |
|
21 |
(*FIXME: long type variable name required to reduce the probability of |
|
22 |
a name clash of Nitpick in context. E.g.: |
|
23 |
context |
|
24 |
fixes x :: 'stream_element_type |
|
25 |
begin |
|
26 |
||
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
27 |
lemma "sset s = {}" |
51409 | 28 |
nitpick |
29 |
oops |
|
30 |
||
31 |
end |
|
32 |
*) |
|
33 |
*} |
|
34 |
||
35 |
code_datatype Stream |
|
36 |
||
37 |
lemma stream_case_cert: |
|
38 |
assumes "CASE \<equiv> stream_case c" |
|
39 |
shows "CASE (a ## s) \<equiv> c a s" |
|
40 |
using assms by simp_all |
|
41 |
||
42 |
setup {* |
|
43 |
Code.add_case @{thm stream_case_cert} |
|
44 |
*} |
|
45 |
||
51462 | 46 |
(*for code generation only*) |
47 |
definition smember :: "'a \<Rightarrow> 'a stream \<Rightarrow> bool" where |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
48 |
[code_abbrev]: "smember x s \<longleftrightarrow> x \<in> sset s" |
51462 | 49 |
|
50 |
lemma smember_code[code, simp]: "smember x (Stream y s) = (if x = y then True else smember x s)" |
|
51 |
unfolding smember_def by auto |
|
52 |
||
53 |
hide_const (open) smember |
|
54 |
||
50518 | 55 |
(* TODO: Provide by the package*) |
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
56 |
theorem sset_induct: |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
57 |
"\<lbrakk>\<And>s. P (shd s) s; \<And>s y. \<lbrakk>y \<in> sset (stl s); P y (stl s)\<rbrakk> \<Longrightarrow> P y s\<rbrakk> \<Longrightarrow> |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
58 |
\<forall>y \<in> sset s. P y s" |
52991 | 59 |
apply (rule stream.dtor_set_induct) |
60 |
apply (auto simp add: shd_def stl_def fsts_def snds_def split_beta) |
|
61 |
apply (metis Stream_def fst_conv stream.case stream.dtor_ctor stream.exhaust) |
|
62 |
by (metis Stream_def sndI stl_def stream.collapse stream.dtor_ctor) |
|
51141 | 63 |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
64 |
lemma smap_simps[simp]: |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
65 |
"shd (smap f s) = f (shd s)" "stl (smap f s) = smap f (stl s)" |
52991 | 66 |
by (case_tac [!] s) auto |
51141 | 67 |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
68 |
theorem shd_sset: "shd s \<in> sset s" |
52991 | 69 |
by (case_tac s) auto |
50518 | 70 |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
71 |
theorem stl_sset: "y \<in> sset (stl s) \<Longrightarrow> y \<in> sset s" |
52991 | 72 |
by (case_tac s) auto |
50518 | 73 |
|
74 |
(* only for the non-mutual case: *) |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
75 |
theorem sset_induct1[consumes 1, case_names shd stl, induct set: "sset"]: |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
76 |
assumes "y \<in> sset s" and "\<And>s. P (shd s) s" |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
77 |
and "\<And>s y. \<lbrakk>y \<in> sset (stl s); P y (stl s)\<rbrakk> \<Longrightarrow> P y s" |
50518 | 78 |
shows "P y s" |
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
79 |
using assms sset_induct by blast |
50518 | 80 |
(* end TODO *) |
81 |
||
82 |
||
83 |
subsection {* prepend list to stream *} |
|
84 |
||
85 |
primrec shift :: "'a list \<Rightarrow> 'a stream \<Rightarrow> 'a stream" (infixr "@-" 65) where |
|
86 |
"shift [] s = s" |
|
51023
550f265864e3
infix syntax for streams (reflecting the one for lists)
traytel
parents:
50518
diff
changeset
|
87 |
| "shift (x # xs) s = x ## shift xs s" |
50518 | 88 |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
89 |
lemma smap_shift[simp]: "smap f (xs @- s) = map f xs @- smap f s" |
51353 | 90 |
by (induct xs) auto |
91 |
||
50518 | 92 |
lemma shift_append[simp]: "(xs @ ys) @- s = xs @- ys @- s" |
51141 | 93 |
by (induct xs) auto |
50518 | 94 |
|
95 |
lemma shift_simps[simp]: |
|
96 |
"shd (xs @- s) = (if xs = [] then shd s else hd xs)" |
|
97 |
"stl (xs @- s) = (if xs = [] then stl s else tl xs @- s)" |
|
51141 | 98 |
by (induct xs) auto |
50518 | 99 |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
100 |
lemma sset_shift[simp]: "sset (xs @- s) = set xs \<union> sset s" |
51141 | 101 |
by (induct xs) auto |
50518 | 102 |
|
51352 | 103 |
lemma shift_left_inj[simp]: "xs @- s1 = xs @- s2 \<longleftrightarrow> s1 = s2" |
104 |
by (induct xs) auto |
|
105 |
||
50518 | 106 |
|
51141 | 107 |
subsection {* set of streams with elements in some fixes set *} |
50518 | 108 |
|
109 |
coinductive_set |
|
110 |
streams :: "'a set => 'a stream set" |
|
111 |
for A :: "'a set" |
|
112 |
where |
|
51023
550f265864e3
infix syntax for streams (reflecting the one for lists)
traytel
parents:
50518
diff
changeset
|
113 |
Stream[intro!, simp, no_atp]: "\<lbrakk>a \<in> A; s \<in> streams A\<rbrakk> \<Longrightarrow> a ## s \<in> streams A" |
50518 | 114 |
|
115 |
lemma shift_streams: "\<lbrakk>w \<in> lists A; s \<in> streams A\<rbrakk> \<Longrightarrow> w @- s \<in> streams A" |
|
51141 | 116 |
by (induct w) auto |
50518 | 117 |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
118 |
lemma sset_streams: |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
119 |
assumes "sset s \<subseteq> A" |
50518 | 120 |
shows "s \<in> streams A" |
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
121 |
proof (coinduct rule: streams.coinduct[of "\<lambda>s'. \<exists>a s. s' = a ## s \<and> a \<in> A \<and> sset s \<subseteq> A"]) |
50518 | 122 |
case streams from assms show ?case by (cases s) auto |
123 |
next |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
124 |
fix s' assume "\<exists>a s. s' = a ## s \<and> a \<in> A \<and> sset s \<subseteq> A" |
50518 | 125 |
then guess a s by (elim exE) |
51023
550f265864e3
infix syntax for streams (reflecting the one for lists)
traytel
parents:
50518
diff
changeset
|
126 |
with assms show "\<exists>a l. s' = a ## l \<and> |
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
127 |
a \<in> A \<and> ((\<exists>a s. l = a ## s \<and> a \<in> A \<and> sset s \<subseteq> A) \<or> l \<in> streams A)" |
50518 | 128 |
by (cases s) auto |
129 |
qed |
|
130 |
||
131 |
||
51141 | 132 |
subsection {* nth, take, drop for streams *} |
133 |
||
134 |
primrec snth :: "'a stream \<Rightarrow> nat \<Rightarrow> 'a" (infixl "!!" 100) where |
|
135 |
"s !! 0 = shd s" |
|
136 |
| "s !! Suc n = stl s !! n" |
|
137 |
||
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
138 |
lemma snth_smap[simp]: "smap f s !! n = f (s !! n)" |
51141 | 139 |
by (induct n arbitrary: s) auto |
140 |
||
141 |
lemma shift_snth_less[simp]: "p < length xs \<Longrightarrow> (xs @- s) !! p = xs ! p" |
|
142 |
by (induct p arbitrary: xs) (auto simp: hd_conv_nth nth_tl) |
|
143 |
||
144 |
lemma shift_snth_ge[simp]: "p \<ge> length xs \<Longrightarrow> (xs @- s) !! p = s !! (p - length xs)" |
|
145 |
by (induct p arbitrary: xs) (auto simp: Suc_diff_eq_diff_pred) |
|
146 |
||
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
147 |
lemma snth_sset[simp]: "s !! n \<in> sset s" |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
148 |
by (induct n arbitrary: s) (auto intro: shd_sset stl_sset) |
51141 | 149 |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
150 |
lemma sset_range: "sset s = range (snth s)" |
51141 | 151 |
proof (intro equalityI subsetI) |
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
152 |
fix x assume "x \<in> sset s" |
51141 | 153 |
thus "x \<in> range (snth s)" |
154 |
proof (induct s) |
|
155 |
case (stl s x) |
|
156 |
then obtain n where "x = stl s !! n" by auto |
|
157 |
thus ?case by (auto intro: range_eqI[of _ _ "Suc n"]) |
|
158 |
qed (auto intro: range_eqI[of _ _ 0]) |
|
159 |
qed auto |
|
50518 | 160 |
|
161 |
primrec stake :: "nat \<Rightarrow> 'a stream \<Rightarrow> 'a list" where |
|
162 |
"stake 0 s = []" |
|
163 |
| "stake (Suc n) s = shd s # stake n (stl s)" |
|
164 |
||
51141 | 165 |
lemma length_stake[simp]: "length (stake n s) = n" |
166 |
by (induct n arbitrary: s) auto |
|
167 |
||
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
168 |
lemma stake_smap[simp]: "stake n (smap f s) = map f (stake n s)" |
51141 | 169 |
by (induct n arbitrary: s) auto |
170 |
||
50518 | 171 |
primrec sdrop :: "nat \<Rightarrow> 'a stream \<Rightarrow> 'a stream" where |
172 |
"sdrop 0 s = s" |
|
173 |
| "sdrop (Suc n) s = sdrop n (stl s)" |
|
174 |
||
51141 | 175 |
lemma sdrop_simps[simp]: |
176 |
"shd (sdrop n s) = s !! n" "stl (sdrop n s) = sdrop (Suc n) s" |
|
177 |
by (induct n arbitrary: s) auto |
|
178 |
||
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
179 |
lemma sdrop_smap[simp]: "sdrop n (smap f s) = smap f (sdrop n s)" |
51141 | 180 |
by (induct n arbitrary: s) auto |
50518 | 181 |
|
51352 | 182 |
lemma sdrop_stl: "sdrop n (stl s) = stl (sdrop n s)" |
183 |
by (induct n) auto |
|
184 |
||
50518 | 185 |
lemma stake_sdrop: "stake n s @- sdrop n s = s" |
51141 | 186 |
by (induct n arbitrary: s) auto |
187 |
||
188 |
lemma id_stake_snth_sdrop: |
|
189 |
"s = stake i s @- s !! i ## sdrop (Suc i) s" |
|
190 |
by (subst stake_sdrop[symmetric, of _ i]) (metis sdrop_simps stream.collapse) |
|
50518 | 191 |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
192 |
lemma smap_alt: "smap f s = s' \<longleftrightarrow> (\<forall>n. f (s !! n) = s' !! n)" (is "?L = ?R") |
51141 | 193 |
proof |
194 |
assume ?R |
|
195 |
thus ?L |
|
51779 | 196 |
by (coinduct rule: stream.coinduct[of "\<lambda>s1 s2. \<exists>n. s1 = smap f (sdrop n s) \<and> s2 = sdrop n s'", consumes 0]) |
51141 | 197 |
(auto intro: exI[of _ 0] simp del: sdrop.simps(2)) |
198 |
qed auto |
|
199 |
||
200 |
lemma stake_invert_Nil[iff]: "stake n s = [] \<longleftrightarrow> n = 0" |
|
201 |
by (induct n) auto |
|
50518 | 202 |
|
203 |
lemma sdrop_shift: "\<lbrakk>s = w @- s'; length w = n\<rbrakk> \<Longrightarrow> sdrop n s = s'" |
|
51141 | 204 |
by (induct n arbitrary: w s) auto |
50518 | 205 |
|
206 |
lemma stake_shift: "\<lbrakk>s = w @- s'; length w = n\<rbrakk> \<Longrightarrow> stake n s = w" |
|
51141 | 207 |
by (induct n arbitrary: w s) auto |
50518 | 208 |
|
209 |
lemma stake_add[simp]: "stake m s @ stake n (sdrop m s) = stake (m + n) s" |
|
51141 | 210 |
by (induct m arbitrary: s) auto |
50518 | 211 |
|
212 |
lemma sdrop_add[simp]: "sdrop n (sdrop m s) = sdrop (m + n) s" |
|
51141 | 213 |
by (induct m arbitrary: s) auto |
214 |
||
51430 | 215 |
partial_function (tailrec) sdrop_while :: "('a \<Rightarrow> bool) \<Rightarrow> 'a stream \<Rightarrow> 'a stream" where |
216 |
"sdrop_while P s = (if P (shd s) then sdrop_while P (stl s) else s)" |
|
217 |
||
218 |
lemma sdrop_while_Stream[code]: |
|
219 |
"sdrop_while P (Stream a s) = (if P a then sdrop_while P s else Stream a s)" |
|
220 |
by (subst sdrop_while.simps) simp |
|
221 |
||
222 |
lemma sdrop_while_sdrop_LEAST: |
|
223 |
assumes "\<exists>n. P (s !! n)" |
|
224 |
shows "sdrop_while (Not o P) s = sdrop (LEAST n. P (s !! n)) s" |
|
225 |
proof - |
|
226 |
from assms obtain m where "P (s !! m)" "\<And>n. P (s !! n) \<Longrightarrow> m \<le> n" |
|
227 |
and *: "(LEAST n. P (s !! n)) = m" by atomize_elim (auto intro: LeastI Least_le) |
|
228 |
thus ?thesis unfolding * |
|
229 |
proof (induct m arbitrary: s) |
|
230 |
case (Suc m) |
|
231 |
hence "sdrop_while (Not \<circ> P) (stl s) = sdrop m (stl s)" |
|
232 |
by (metis (full_types) not_less_eq_eq snth.simps(2)) |
|
233 |
moreover from Suc(3) have "\<not> (P (s !! 0))" by blast |
|
234 |
ultimately show ?case by (subst sdrop_while.simps) simp |
|
235 |
qed (metis comp_apply sdrop.simps(1) sdrop_while.simps snth.simps(1)) |
|
236 |
qed |
|
237 |
||
52905 | 238 |
definition "sfilter P = stream_unfold (shd o sdrop_while (Not o P)) (stl o sdrop_while (Not o P))" |
239 |
||
240 |
lemma sfilter_Stream: "sfilter P (x ## s) = (if P x then x ## sfilter P s else sfilter P s)" |
|
241 |
proof (cases "P x") |
|
242 |
case True thus ?thesis unfolding sfilter_def |
|
243 |
by (subst stream.unfold) (simp add: sdrop_while_Stream) |
|
244 |
next |
|
245 |
case False thus ?thesis unfolding sfilter_def |
|
246 |
by (subst (1 2) stream.unfold) (simp add: sdrop_while_Stream) |
|
247 |
qed |
|
248 |
||
51141 | 249 |
|
250 |
subsection {* unary predicates lifted to streams *} |
|
251 |
||
252 |
definition "stream_all P s = (\<forall>p. P (s !! p))" |
|
253 |
||
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
254 |
lemma stream_all_iff[iff]: "stream_all P s \<longleftrightarrow> Ball (sset s) P" |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
255 |
unfolding stream_all_def sset_range by auto |
51141 | 256 |
|
257 |
lemma stream_all_shift[simp]: "stream_all P (xs @- s) = (list_all P xs \<and> stream_all P s)" |
|
258 |
unfolding stream_all_iff list_all_iff by auto |
|
259 |
||
260 |
||
261 |
subsection {* recurring stream out of a list *} |
|
262 |
||
263 |
definition cycle :: "'a list \<Rightarrow> 'a stream" where |
|
264 |
"cycle = stream_unfold hd (\<lambda>xs. tl xs @ [hd xs])" |
|
265 |
||
266 |
lemma cycle_simps[simp]: |
|
267 |
"shd (cycle u) = hd u" |
|
268 |
"stl (cycle u) = cycle (tl u @ [hd u])" |
|
269 |
by (auto simp: cycle_def) |
|
270 |
||
271 |
lemma cycle_decomp: "u \<noteq> [] \<Longrightarrow> cycle u = u @- cycle u" |
|
51788 | 272 |
proof (coinduct rule: stream.coinduct[of "\<lambda>s1 s2. \<exists>u. s1 = cycle u \<and> s2 = u @- cycle u \<and> u \<noteq> []", consumes 0, case_names _ Eq_stream]) |
273 |
case (Eq_stream s1 s2) |
|
51141 | 274 |
then obtain u where "s1 = cycle u \<and> s2 = u @- cycle u \<and> u \<noteq> []" by blast |
275 |
thus ?case using stream.unfold[of hd "\<lambda>xs. tl xs @ [hd xs]" u] by (auto simp: cycle_def) |
|
276 |
qed auto |
|
277 |
||
51409 | 278 |
lemma cycle_Cons[code]: "cycle (x # xs) = x ## cycle (xs @ [x])" |
51788 | 279 |
proof (coinduct rule: stream.coinduct[of "\<lambda>s1 s2. \<exists>x xs. s1 = cycle (x # xs) \<and> s2 = x ## cycle (xs @ [x])", consumes 0, case_names _ Eq_stream]) |
280 |
case (Eq_stream s1 s2) |
|
51141 | 281 |
then obtain x xs where "s1 = cycle (x # xs) \<and> s2 = x ## cycle (xs @ [x])" by blast |
282 |
thus ?case |
|
283 |
by (auto simp: cycle_def intro!: exI[of _ "hd (xs @ [x])"] exI[of _ "tl (xs @ [x])"] stream.unfold) |
|
284 |
qed auto |
|
50518 | 285 |
|
286 |
lemma cycle_rotated: "\<lbrakk>v \<noteq> []; cycle u = v @- s\<rbrakk> \<Longrightarrow> cycle (tl u @ [hd u]) = tl v @- s" |
|
51141 | 287 |
by (auto dest: arg_cong[of _ _ stl]) |
50518 | 288 |
|
289 |
lemma stake_append: "stake n (u @- s) = take (min (length u) n) u @ stake (n - length u) s" |
|
290 |
proof (induct n arbitrary: u) |
|
291 |
case (Suc n) thus ?case by (cases u) auto |
|
292 |
qed auto |
|
293 |
||
294 |
lemma stake_cycle_le[simp]: |
|
295 |
assumes "u \<noteq> []" "n < length u" |
|
296 |
shows "stake n (cycle u) = take n u" |
|
297 |
using min_absorb2[OF less_imp_le_nat[OF assms(2)]] |
|
51141 | 298 |
by (subst cycle_decomp[OF assms(1)], subst stake_append) auto |
50518 | 299 |
|
300 |
lemma stake_cycle_eq[simp]: "u \<noteq> [] \<Longrightarrow> stake (length u) (cycle u) = u" |
|
51141 | 301 |
by (metis cycle_decomp stake_shift) |
50518 | 302 |
|
303 |
lemma sdrop_cycle_eq[simp]: "u \<noteq> [] \<Longrightarrow> sdrop (length u) (cycle u) = cycle u" |
|
51141 | 304 |
by (metis cycle_decomp sdrop_shift) |
50518 | 305 |
|
306 |
lemma stake_cycle_eq_mod_0[simp]: "\<lbrakk>u \<noteq> []; n mod length u = 0\<rbrakk> \<Longrightarrow> |
|
307 |
stake n (cycle u) = concat (replicate (n div length u) u)" |
|
51141 | 308 |
by (induct "n div length u" arbitrary: n u) (auto simp: stake_add[symmetric]) |
50518 | 309 |
|
310 |
lemma sdrop_cycle_eq_mod_0[simp]: "\<lbrakk>u \<noteq> []; n mod length u = 0\<rbrakk> \<Longrightarrow> |
|
311 |
sdrop n (cycle u) = cycle u" |
|
51141 | 312 |
by (induct "n div length u" arbitrary: n u) (auto simp: sdrop_add[symmetric]) |
50518 | 313 |
|
314 |
lemma stake_cycle: "u \<noteq> [] \<Longrightarrow> |
|
315 |
stake n (cycle u) = concat (replicate (n div length u) u) @ take (n mod length u) u" |
|
51141 | 316 |
by (subst mod_div_equality[of n "length u", symmetric], unfold stake_add[symmetric]) auto |
50518 | 317 |
|
318 |
lemma sdrop_cycle: "u \<noteq> [] \<Longrightarrow> sdrop n (cycle u) = cycle (rotate (n mod length u) u)" |
|
51141 | 319 |
by (induct n arbitrary: u) (auto simp: rotate1_rotate_swap rotate1_hd_tl rotate_conv_mod[symmetric]) |
320 |
||
321 |
||
322 |
subsection {* stream repeating a single element *} |
|
323 |
||
324 |
definition "same x = stream_unfold (\<lambda>_. x) id ()" |
|
325 |
||
326 |
lemma same_simps[simp]: "shd (same x) = x" "stl (same x) = same x" |
|
327 |
unfolding same_def by auto |
|
328 |
||
51409 | 329 |
lemma same_unfold[code]: "same x = x ## same x" |
51141 | 330 |
by (metis same_simps stream.collapse) |
331 |
||
332 |
lemma snth_same[simp]: "same x !! n = x" |
|
333 |
unfolding same_def by (induct n) auto |
|
334 |
||
335 |
lemma stake_same[simp]: "stake n (same x) = replicate n x" |
|
336 |
unfolding same_def by (induct n) (auto simp: upt_rec) |
|
337 |
||
338 |
lemma sdrop_same[simp]: "sdrop n (same x) = same x" |
|
339 |
unfolding same_def by (induct n) auto |
|
340 |
||
341 |
lemma shift_replicate_same[simp]: "replicate n x @- same x = same x" |
|
342 |
by (metis sdrop_same stake_same stake_sdrop) |
|
343 |
||
344 |
lemma stream_all_same[simp]: "stream_all P (same x) \<longleftrightarrow> P x" |
|
345 |
unfolding stream_all_def by auto |
|
346 |
||
347 |
lemma same_cycle: "same x = cycle [x]" |
|
348 |
by (coinduct rule: stream.coinduct[of "\<lambda>s1 s2. s1 = same x \<and> s2 = cycle [x]"]) auto |
|
349 |
||
350 |
||
351 |
subsection {* stream of natural numbers *} |
|
352 |
||
353 |
definition "fromN n = stream_unfold id Suc n" |
|
354 |
||
355 |
lemma fromN_simps[simp]: "shd (fromN n) = n" "stl (fromN n) = fromN (Suc n)" |
|
356 |
unfolding fromN_def by auto |
|
357 |
||
51409 | 358 |
lemma fromN_unfold[code]: "fromN n = n ## fromN (Suc n)" |
359 |
unfolding fromN_def by (metis id_def stream.unfold) |
|
360 |
||
51141 | 361 |
lemma snth_fromN[simp]: "fromN n !! m = n + m" |
362 |
unfolding fromN_def by (induct m arbitrary: n) auto |
|
363 |
||
364 |
lemma stake_fromN[simp]: "stake m (fromN n) = [n ..< m + n]" |
|
365 |
unfolding fromN_def by (induct m arbitrary: n) (auto simp: upt_rec) |
|
366 |
||
367 |
lemma sdrop_fromN[simp]: "sdrop m (fromN n) = fromN (n + m)" |
|
368 |
unfolding fromN_def by (induct m arbitrary: n) auto |
|
369 |
||
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
370 |
lemma sset_fromN[simp]: "sset (fromN n) = {n ..}" (is "?L = ?R") |
51352 | 371 |
proof safe |
372 |
fix m assume "m : ?L" |
|
373 |
moreover |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
374 |
{ fix s assume "m \<in> sset s" "\<exists>n'\<ge>n. s = fromN n'" |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
375 |
hence "n \<le> m" by (induct arbitrary: n rule: sset_induct1) fastforce+ |
51352 | 376 |
} |
377 |
ultimately show "n \<le> m" by blast |
|
378 |
next |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
379 |
fix m assume "n \<le> m" thus "m \<in> ?L" by (metis le_iff_add snth_fromN snth_sset) |
51352 | 380 |
qed |
381 |
||
51141 | 382 |
abbreviation "nats \<equiv> fromN 0" |
383 |
||
384 |
||
51462 | 385 |
subsection {* flatten a stream of lists *} |
386 |
||
387 |
definition flat where |
|
388 |
"flat \<equiv> stream_unfold (hd o shd) (\<lambda>s. if tl (shd s) = [] then stl s else tl (shd s) ## stl s)" |
|
389 |
||
390 |
lemma flat_simps[simp]: |
|
391 |
"shd (flat ws) = hd (shd ws)" |
|
392 |
"stl (flat ws) = flat (if tl (shd ws) = [] then stl ws else tl (shd ws) ## stl ws)" |
|
393 |
unfolding flat_def by auto |
|
394 |
||
395 |
lemma flat_Cons[simp, code]: "flat ((x # xs) ## ws) = x ## flat (if xs = [] then ws else xs ## ws)" |
|
396 |
unfolding flat_def using stream.unfold[of "hd o shd" _ "(x # xs) ## ws"] by auto |
|
397 |
||
398 |
lemma flat_Stream[simp]: "xs \<noteq> [] \<Longrightarrow> flat (xs ## ws) = xs @- flat ws" |
|
399 |
by (induct xs) auto |
|
400 |
||
401 |
lemma flat_unfold: "shd ws \<noteq> [] \<Longrightarrow> flat ws = shd ws @- flat (stl ws)" |
|
402 |
by (cases ws) auto |
|
403 |
||
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
404 |
lemma flat_snth: "\<forall>xs \<in> sset s. xs \<noteq> [] \<Longrightarrow> flat s !! n = (if n < length (shd s) then |
51462 | 405 |
shd s ! n else flat (stl s) !! (n - length (shd s)))" |
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
406 |
by (metis flat_unfold not_less shd_sset shift_snth_ge shift_snth_less) |
51462 | 407 |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
408 |
lemma sset_flat[simp]: "\<forall>xs \<in> sset s. xs \<noteq> [] \<Longrightarrow> |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
409 |
sset (flat s) = (\<Union>xs \<in> sset s. set xs)" (is "?P \<Longrightarrow> ?L = ?R") |
51462 | 410 |
proof safe |
411 |
fix x assume ?P "x : ?L" |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
412 |
then obtain m where "x = flat s !! m" by (metis image_iff sset_range) |
51462 | 413 |
with `?P` obtain n m' where "x = s !! n ! m'" "m' < length (s !! n)" |
414 |
proof (atomize_elim, induct m arbitrary: s rule: less_induct) |
|
415 |
case (less y) |
|
416 |
thus ?case |
|
417 |
proof (cases "y < length (shd s)") |
|
418 |
case True thus ?thesis by (metis flat_snth less(2,3) snth.simps(1)) |
|
419 |
next |
|
420 |
case False |
|
421 |
hence "x = flat (stl s) !! (y - length (shd s))" by (metis less(2,3) flat_snth) |
|
422 |
moreover |
|
53374
a14d2a854c02
tuned proofs -- clarified flow of facts wrt. calculation;
wenzelm
parents:
53290
diff
changeset
|
423 |
{ from less(2) have *: "length (shd s) > 0" by (cases s) simp_all |
a14d2a854c02
tuned proofs -- clarified flow of facts wrt. calculation;
wenzelm
parents:
53290
diff
changeset
|
424 |
with False have "y > 0" by (cases y) simp_all |
a14d2a854c02
tuned proofs -- clarified flow of facts wrt. calculation;
wenzelm
parents:
53290
diff
changeset
|
425 |
with * have "y - length (shd s) < y" by simp |
51462 | 426 |
} |
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
427 |
moreover have "\<forall>xs \<in> sset (stl s). xs \<noteq> []" using less(2) by (cases s) auto |
51462 | 428 |
ultimately have "\<exists>n m'. x = stl s !! n ! m' \<and> m' < length (stl s !! n)" by (intro less(1)) auto |
429 |
thus ?thesis by (metis snth.simps(2)) |
|
430 |
qed |
|
431 |
qed |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
432 |
thus "x \<in> ?R" by (auto simp: sset_range dest!: nth_mem) |
51462 | 433 |
next |
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
434 |
fix x xs assume "xs \<in> sset s" ?P "x \<in> set xs" thus "x \<in> ?L" |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
435 |
by (induct rule: sset_induct1) |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
436 |
(metis UnI1 flat_unfold shift.simps(1) sset_shift, |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
437 |
metis UnI2 flat_unfold shd_sset stl_sset sset_shift) |
51462 | 438 |
qed |
439 |
||
440 |
||
441 |
subsection {* merge a stream of streams *} |
|
442 |
||
443 |
definition smerge :: "'a stream stream \<Rightarrow> 'a stream" where |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
444 |
"smerge ss = flat (smap (\<lambda>n. map (\<lambda>s. s !! n) (stake (Suc n) ss) @ stake n (ss !! n)) nats)" |
51462 | 445 |
|
446 |
lemma stake_nth[simp]: "m < n \<Longrightarrow> stake n s ! m = s !! m" |
|
447 |
by (induct n arbitrary: s m) (auto simp: nth_Cons', metis Suc_pred snth.simps(2)) |
|
448 |
||
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
449 |
lemma snth_sset_smerge: "ss !! n !! m \<in> sset (smerge ss)" |
51462 | 450 |
proof (cases "n \<le> m") |
451 |
case False thus ?thesis unfolding smerge_def |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
452 |
by (subst sset_flat) |
53290 | 453 |
(auto simp: stream.set_map in_set_conv_nth simp del: stake.simps |
51462 | 454 |
intro!: exI[of _ n, OF disjI2] exI[of _ m, OF mp]) |
455 |
next |
|
456 |
case True thus ?thesis unfolding smerge_def |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
457 |
by (subst sset_flat) |
53290 | 458 |
(auto simp: stream.set_map in_set_conv_nth image_iff simp del: stake.simps snth.simps |
51462 | 459 |
intro!: exI[of _ m, OF disjI1] bexI[of _ "ss !! n"] exI[of _ n, OF mp]) |
460 |
qed |
|
461 |
||
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
462 |
lemma sset_smerge: "sset (smerge ss) = UNION (sset ss) sset" |
51462 | 463 |
proof safe |
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
464 |
fix x assume "x \<in> sset (smerge ss)" |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
465 |
thus "x \<in> UNION (sset ss) sset" |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
466 |
unfolding smerge_def by (subst (asm) sset_flat) |
53290 | 467 |
(auto simp: stream.set_map in_set_conv_nth sset_range simp del: stake.simps, fast+) |
51462 | 468 |
next |
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
469 |
fix s x assume "s \<in> sset ss" "x \<in> sset s" |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
470 |
thus "x \<in> sset (smerge ss)" using snth_sset_smerge by (auto simp: sset_range) |
51462 | 471 |
qed |
472 |
||
473 |
||
474 |
subsection {* product of two streams *} |
|
475 |
||
476 |
definition sproduct :: "'a stream \<Rightarrow> 'b stream \<Rightarrow> ('a \<times> 'b) stream" where |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
477 |
"sproduct s1 s2 = smerge (smap (\<lambda>x. smap (Pair x) s2) s1)" |
51462 | 478 |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
479 |
lemma sset_sproduct: "sset (sproduct s1 s2) = sset s1 \<times> sset s2" |
53290 | 480 |
unfolding sproduct_def sset_smerge by (auto simp: stream.set_map) |
51462 | 481 |
|
482 |
||
483 |
subsection {* interleave two streams *} |
|
484 |
||
485 |
definition sinterleave :: "'a stream \<Rightarrow> 'a stream \<Rightarrow> 'a stream" where |
|
486 |
[code del]: "sinterleave s1 s2 = |
|
487 |
stream_unfold (\<lambda>(s1, s2). shd s1) (\<lambda>(s1, s2). (s2, stl s1)) (s1, s2)" |
|
488 |
||
489 |
lemma sinterleave_simps[simp]: |
|
490 |
"shd (sinterleave s1 s2) = shd s1" "stl (sinterleave s1 s2) = sinterleave s2 (stl s1)" |
|
491 |
unfolding sinterleave_def by auto |
|
492 |
||
493 |
lemma sinterleave_code[code]: |
|
494 |
"sinterleave (x ## s1) s2 = x ## sinterleave s2 s1" |
|
53694 | 495 |
by (metis sinterleave_simps stream.exhaust stream.sel) |
51462 | 496 |
|
497 |
lemma sinterleave_snth[simp]: |
|
498 |
"even n \<Longrightarrow> sinterleave s1 s2 !! n = s1 !! (n div 2)" |
|
499 |
"odd n \<Longrightarrow> sinterleave s1 s2 !! n = s2 !! (n div 2)" |
|
500 |
by (induct n arbitrary: s1 s2) |
|
501 |
(auto dest: even_nat_Suc_div_2 odd_nat_plus_one_div_two[folded nat_2]) |
|
502 |
||
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
503 |
lemma sset_sinterleave: "sset (sinterleave s1 s2) = sset s1 \<union> sset s2" |
51462 | 504 |
proof (intro equalityI subsetI) |
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
505 |
fix x assume "x \<in> sset (sinterleave s1 s2)" |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
506 |
then obtain n where "x = sinterleave s1 s2 !! n" unfolding sset_range by blast |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
507 |
thus "x \<in> sset s1 \<union> sset s2" by (cases "even n") auto |
51462 | 508 |
next |
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
509 |
fix x assume "x \<in> sset s1 \<union> sset s2" |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
510 |
thus "x \<in> sset (sinterleave s1 s2)" |
51462 | 511 |
proof |
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
512 |
assume "x \<in> sset s1" |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
513 |
then obtain n where "x = s1 !! n" unfolding sset_range by blast |
51462 | 514 |
hence "sinterleave s1 s2 !! (2 * n) = x" by simp |
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
515 |
thus ?thesis unfolding sset_range by blast |
51462 | 516 |
next |
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
517 |
assume "x \<in> sset s2" |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
518 |
then obtain n where "x = s2 !! n" unfolding sset_range by blast |
51462 | 519 |
hence "sinterleave s1 s2 !! (2 * n + 1) = x" by simp |
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
520 |
thus ?thesis unfolding sset_range by blast |
51462 | 521 |
qed |
522 |
qed |
|
523 |
||
524 |
||
51141 | 525 |
subsection {* zip *} |
526 |
||
527 |
definition "szip s1 s2 = |
|
528 |
stream_unfold (map_pair shd shd) (map_pair stl stl) (s1, s2)" |
|
529 |
||
530 |
lemma szip_simps[simp]: |
|
531 |
"shd (szip s1 s2) = (shd s1, shd s2)" "stl (szip s1 s2) = szip (stl s1) (stl s2)" |
|
532 |
unfolding szip_def by auto |
|
533 |
||
51409 | 534 |
lemma szip_unfold[code]: "szip (Stream a s1) (Stream b s2) = Stream (a, b) (szip s1 s2)" |
535 |
unfolding szip_def by (subst stream.unfold) simp |
|
536 |
||
51141 | 537 |
lemma snth_szip[simp]: "szip s1 s2 !! n = (s1 !! n, s2 !! n)" |
538 |
by (induct n arbitrary: s1 s2) auto |
|
539 |
||
540 |
||
541 |
subsection {* zip via function *} |
|
542 |
||
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
543 |
definition "smap2 f s1 s2 = |
51141 | 544 |
stream_unfold (\<lambda>(s1,s2). f (shd s1) (shd s2)) (map_pair stl stl) (s1, s2)" |
545 |
||
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
546 |
lemma smap2_simps[simp]: |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
547 |
"shd (smap2 f s1 s2) = f (shd s1) (shd s2)" |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
548 |
"stl (smap2 f s1 s2) = smap2 f (stl s1) (stl s2)" |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
549 |
unfolding smap2_def by auto |
51141 | 550 |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
551 |
lemma smap2_unfold[code]: |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
552 |
"smap2 f (Stream a s1) (Stream b s2) = Stream (f a b) (smap2 f s1 s2)" |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
553 |
unfolding smap2_def by (subst stream.unfold) simp |
51409 | 554 |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
555 |
lemma smap2_szip: |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
556 |
"smap2 f s1 s2 = smap (split f) (szip s1 s2)" |
51141 | 557 |
by (coinduct rule: stream.coinduct[of |
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
558 |
"\<lambda>s1 s2. \<exists>s1' s2'. s1 = smap2 f s1' s2' \<and> s2 = smap (split f) (szip s1' s2')"]) |
51141 | 559 |
fastforce+ |
50518 | 560 |
|
51462 | 561 |
|
562 |
subsection {* iterated application of a function *} |
|
563 |
||
564 |
definition siterate :: "('a \<Rightarrow> 'a) \<Rightarrow> 'a \<Rightarrow> 'a stream" where |
|
565 |
"siterate f x = x ## stream_unfold f f x" |
|
566 |
||
567 |
lemma siterate_simps[simp]: "shd (siterate f x) = x" "stl (siterate f x) = siterate f (f x)" |
|
568 |
unfolding siterate_def by (auto intro: stream.unfold) |
|
569 |
||
570 |
lemma siterate_code[code]: "siterate f x = x ## siterate f (f x)" |
|
571 |
by (metis siterate_def stream.unfold) |
|
572 |
||
573 |
lemma stake_Suc: "stake (Suc n) s = stake n s @ [s !! n]" |
|
574 |
by (induct n arbitrary: s) auto |
|
575 |
||
576 |
lemma snth_siterate[simp]: "siterate f x !! n = (f^^n) x" |
|
577 |
by (induct n arbitrary: x) (auto simp: funpow_swap1) |
|
578 |
||
579 |
lemma sdrop_siterate[simp]: "sdrop n (siterate f x) = siterate f ((f^^n) x)" |
|
580 |
by (induct n arbitrary: x) (auto simp: funpow_swap1) |
|
581 |
||
582 |
lemma stake_siterate[simp]: "stake n (siterate f x) = map (\<lambda>n. (f^^n) x) [0 ..< n]" |
|
583 |
by (induct n arbitrary: x) (auto simp del: stake.simps(2) simp: stake_Suc) |
|
584 |
||
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
585 |
lemma sset_siterate: "sset (siterate f x) = {(f^^n) x | n. True}" |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
586 |
by (auto simp: sset_range) |
51462 | 587 |
|
50518 | 588 |
end |