author | blanchet |
Tue, 19 Nov 2013 15:43:08 +0100 | |
changeset 54493 | 5b34a5b93ec2 |
parent 54469 | 0ccec59194af |
child 54498 | f7fef6b00bfe |
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 |
code_datatype Stream |
19 |
||
20 |
lemma stream_case_cert: |
|
54493
5b34a5b93ec2
use type suffixes instead of prefixes for 'case', '(un)fold', '(co)rec'
blanchet
parents:
54469
diff
changeset
|
21 |
assumes "CASE \<equiv> case_stream c" |
51409 | 22 |
shows "CASE (a ## s) \<equiv> c a s" |
23 |
using assms by simp_all |
|
24 |
||
25 |
setup {* |
|
26 |
Code.add_case @{thm stream_case_cert} |
|
27 |
*} |
|
28 |
||
51462 | 29 |
(*for code generation only*) |
30 |
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
|
31 |
[code_abbrev]: "smember x s \<longleftrightarrow> x \<in> sset s" |
51462 | 32 |
|
33 |
lemma smember_code[code, simp]: "smember x (Stream y s) = (if x = y then True else smember x s)" |
|
34 |
unfolding smember_def by auto |
|
35 |
||
36 |
hide_const (open) smember |
|
37 |
||
50518 | 38 |
(* TODO: Provide by the package*) |
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
39 |
theorem sset_induct: |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
40 |
"\<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
|
41 |
\<forall>y \<in> sset s. P y s" |
52991 | 42 |
apply (rule stream.dtor_set_induct) |
43 |
apply (auto simp add: shd_def stl_def fsts_def snds_def split_beta) |
|
44 |
apply (metis Stream_def fst_conv stream.case stream.dtor_ctor stream.exhaust) |
|
45 |
by (metis Stream_def sndI stl_def stream.collapse stream.dtor_ctor) |
|
51141 | 46 |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
47 |
lemma smap_simps[simp]: |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
48 |
"shd (smap f s) = f (shd s)" "stl (smap f s) = smap f (stl s)" |
52991 | 49 |
by (case_tac [!] s) auto |
51141 | 50 |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
51 |
theorem shd_sset: "shd s \<in> sset s" |
52991 | 52 |
by (case_tac s) auto |
50518 | 53 |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
54 |
theorem stl_sset: "y \<in> sset (stl s) \<Longrightarrow> y \<in> sset s" |
52991 | 55 |
by (case_tac s) auto |
50518 | 56 |
|
57 |
(* 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
|
58 |
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
|
59 |
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
|
60 |
and "\<And>s y. \<lbrakk>y \<in> sset (stl s); P y (stl s)\<rbrakk> \<Longrightarrow> P y s" |
50518 | 61 |
shows "P y s" |
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
62 |
using assms sset_induct by blast |
50518 | 63 |
(* end TODO *) |
64 |
||
65 |
||
66 |
subsection {* prepend list to stream *} |
|
67 |
||
68 |
primrec shift :: "'a list \<Rightarrow> 'a stream \<Rightarrow> 'a stream" (infixr "@-" 65) where |
|
69 |
"shift [] s = s" |
|
51023
550f265864e3
infix syntax for streams (reflecting the one for lists)
traytel
parents:
50518
diff
changeset
|
70 |
| "shift (x # xs) s = x ## shift xs s" |
50518 | 71 |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
72 |
lemma smap_shift[simp]: "smap f (xs @- s) = map f xs @- smap f s" |
51353 | 73 |
by (induct xs) auto |
74 |
||
50518 | 75 |
lemma shift_append[simp]: "(xs @ ys) @- s = xs @- ys @- s" |
51141 | 76 |
by (induct xs) auto |
50518 | 77 |
|
78 |
lemma shift_simps[simp]: |
|
79 |
"shd (xs @- s) = (if xs = [] then shd s else hd xs)" |
|
80 |
"stl (xs @- s) = (if xs = [] then stl s else tl xs @- s)" |
|
51141 | 81 |
by (induct xs) auto |
50518 | 82 |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
83 |
lemma sset_shift[simp]: "sset (xs @- s) = set xs \<union> sset s" |
51141 | 84 |
by (induct xs) auto |
50518 | 85 |
|
51352 | 86 |
lemma shift_left_inj[simp]: "xs @- s1 = xs @- s2 \<longleftrightarrow> s1 = s2" |
87 |
by (induct xs) auto |
|
88 |
||
50518 | 89 |
|
54469 | 90 |
subsection {* set of streams with elements in some fixed set *} |
50518 | 91 |
|
92 |
coinductive_set |
|
54469 | 93 |
streams :: "'a set \<Rightarrow> 'a stream set" |
50518 | 94 |
for A :: "'a set" |
95 |
where |
|
51023
550f265864e3
infix syntax for streams (reflecting the one for lists)
traytel
parents:
50518
diff
changeset
|
96 |
Stream[intro!, simp, no_atp]: "\<lbrakk>a \<in> A; s \<in> streams A\<rbrakk> \<Longrightarrow> a ## s \<in> streams A" |
50518 | 97 |
|
98 |
lemma shift_streams: "\<lbrakk>w \<in> lists A; s \<in> streams A\<rbrakk> \<Longrightarrow> w @- s \<in> streams A" |
|
51141 | 99 |
by (induct w) auto |
50518 | 100 |
|
54469 | 101 |
lemma streams_Stream: "x ## s \<in> streams A \<longleftrightarrow> x \<in> A \<and> s \<in> streams A" |
102 |
by (auto elim: streams.cases) |
|
103 |
||
104 |
lemma streams_stl: "s \<in> streams A \<Longrightarrow> stl s \<in> streams A" |
|
105 |
by (cases s) (auto simp: streams_Stream) |
|
106 |
||
107 |
lemma streams_shd: "s \<in> streams A \<Longrightarrow> shd s \<in> A" |
|
108 |
by (cases s) (auto simp: streams_Stream) |
|
109 |
||
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
110 |
lemma sset_streams: |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
111 |
assumes "sset s \<subseteq> A" |
50518 | 112 |
shows "s \<in> streams A" |
54027
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
113 |
using assms proof (coinduction arbitrary: s) |
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
114 |
case streams then show ?case by (cases s) simp |
50518 | 115 |
qed |
116 |
||
54469 | 117 |
lemma streams_sset: |
118 |
assumes "s \<in> streams A" |
|
119 |
shows "sset s \<subseteq> A" |
|
120 |
proof |
|
121 |
fix x assume "x \<in> sset s" from this `s \<in> streams A` show "x \<in> A" |
|
122 |
by (induct s) (auto intro: streams_shd streams_stl) |
|
123 |
qed |
|
124 |
||
125 |
lemma streams_iff_sset: "s \<in> streams A \<longleftrightarrow> sset s \<subseteq> A" |
|
126 |
by (metis sset_streams streams_sset) |
|
127 |
||
128 |
lemma streams_mono: "s \<in> streams A \<Longrightarrow> A \<subseteq> B \<Longrightarrow> s \<in> streams B" |
|
129 |
unfolding streams_iff_sset by auto |
|
130 |
||
131 |
lemma smap_streams: "s \<in> streams A \<Longrightarrow> (\<And>x. x \<in> A \<Longrightarrow> f x \<in> B) \<Longrightarrow> smap f s \<in> streams B" |
|
132 |
unfolding streams_iff_sset stream.set_map by auto |
|
133 |
||
134 |
lemma streams_empty: "streams {} = {}" |
|
135 |
by (auto elim: streams.cases) |
|
136 |
||
137 |
lemma streams_UNIV[simp]: "streams UNIV = UNIV" |
|
138 |
by (auto simp: streams_iff_sset) |
|
50518 | 139 |
|
51141 | 140 |
subsection {* nth, take, drop for streams *} |
141 |
||
142 |
primrec snth :: "'a stream \<Rightarrow> nat \<Rightarrow> 'a" (infixl "!!" 100) where |
|
143 |
"s !! 0 = shd s" |
|
144 |
| "s !! Suc n = stl s !! n" |
|
145 |
||
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
146 |
lemma snth_smap[simp]: "smap f s !! n = f (s !! n)" |
51141 | 147 |
by (induct n arbitrary: s) auto |
148 |
||
149 |
lemma shift_snth_less[simp]: "p < length xs \<Longrightarrow> (xs @- s) !! p = xs ! p" |
|
150 |
by (induct p arbitrary: xs) (auto simp: hd_conv_nth nth_tl) |
|
151 |
||
152 |
lemma shift_snth_ge[simp]: "p \<ge> length xs \<Longrightarrow> (xs @- s) !! p = s !! (p - length xs)" |
|
153 |
by (induct p arbitrary: xs) (auto simp: Suc_diff_eq_diff_pred) |
|
154 |
||
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
155 |
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
|
156 |
by (induct n arbitrary: s) (auto intro: shd_sset stl_sset) |
51141 | 157 |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
158 |
lemma sset_range: "sset s = range (snth s)" |
51141 | 159 |
proof (intro equalityI subsetI) |
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
160 |
fix x assume "x \<in> sset s" |
51141 | 161 |
thus "x \<in> range (snth s)" |
162 |
proof (induct s) |
|
163 |
case (stl s x) |
|
164 |
then obtain n where "x = stl s !! n" by auto |
|
165 |
thus ?case by (auto intro: range_eqI[of _ _ "Suc n"]) |
|
166 |
qed (auto intro: range_eqI[of _ _ 0]) |
|
167 |
qed auto |
|
50518 | 168 |
|
169 |
primrec stake :: "nat \<Rightarrow> 'a stream \<Rightarrow> 'a list" where |
|
170 |
"stake 0 s = []" |
|
171 |
| "stake (Suc n) s = shd s # stake n (stl s)" |
|
172 |
||
51141 | 173 |
lemma length_stake[simp]: "length (stake n s) = n" |
174 |
by (induct n arbitrary: s) auto |
|
175 |
||
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
176 |
lemma stake_smap[simp]: "stake n (smap f s) = map f (stake n s)" |
51141 | 177 |
by (induct n arbitrary: s) auto |
178 |
||
50518 | 179 |
primrec sdrop :: "nat \<Rightarrow> 'a stream \<Rightarrow> 'a stream" where |
180 |
"sdrop 0 s = s" |
|
181 |
| "sdrop (Suc n) s = sdrop n (stl s)" |
|
182 |
||
51141 | 183 |
lemma sdrop_simps[simp]: |
184 |
"shd (sdrop n s) = s !! n" "stl (sdrop n s) = sdrop (Suc n) s" |
|
185 |
by (induct n arbitrary: s) auto |
|
186 |
||
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
187 |
lemma sdrop_smap[simp]: "sdrop n (smap f s) = smap f (sdrop n s)" |
51141 | 188 |
by (induct n arbitrary: s) auto |
50518 | 189 |
|
51352 | 190 |
lemma sdrop_stl: "sdrop n (stl s) = stl (sdrop n s)" |
191 |
by (induct n) auto |
|
192 |
||
50518 | 193 |
lemma stake_sdrop: "stake n s @- sdrop n s = s" |
51141 | 194 |
by (induct n arbitrary: s) auto |
195 |
||
196 |
lemma id_stake_snth_sdrop: |
|
197 |
"s = stake i s @- s !! i ## sdrop (Suc i) s" |
|
198 |
by (subst stake_sdrop[symmetric, of _ i]) (metis sdrop_simps stream.collapse) |
|
50518 | 199 |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
200 |
lemma smap_alt: "smap f s = s' \<longleftrightarrow> (\<forall>n. f (s !! n) = s' !! n)" (is "?L = ?R") |
51141 | 201 |
proof |
202 |
assume ?R |
|
54027
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
203 |
then have "\<And>n. smap f (sdrop n s) = sdrop n s'" |
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
204 |
by coinduction (auto intro: exI[of _ 0] simp del: sdrop.simps(2)) |
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
205 |
then show ?L using sdrop.simps(1) by metis |
51141 | 206 |
qed auto |
207 |
||
208 |
lemma stake_invert_Nil[iff]: "stake n s = [] \<longleftrightarrow> n = 0" |
|
209 |
by (induct n) auto |
|
50518 | 210 |
|
211 |
lemma sdrop_shift: "\<lbrakk>s = w @- s'; length w = n\<rbrakk> \<Longrightarrow> sdrop n s = s'" |
|
51141 | 212 |
by (induct n arbitrary: w s) auto |
50518 | 213 |
|
214 |
lemma stake_shift: "\<lbrakk>s = w @- s'; length w = n\<rbrakk> \<Longrightarrow> stake n s = w" |
|
51141 | 215 |
by (induct n arbitrary: w s) auto |
50518 | 216 |
|
217 |
lemma stake_add[simp]: "stake m s @ stake n (sdrop m s) = stake (m + n) s" |
|
51141 | 218 |
by (induct m arbitrary: s) auto |
50518 | 219 |
|
220 |
lemma sdrop_add[simp]: "sdrop n (sdrop m s) = sdrop (m + n) s" |
|
51141 | 221 |
by (induct m arbitrary: s) auto |
222 |
||
51430 | 223 |
partial_function (tailrec) sdrop_while :: "('a \<Rightarrow> bool) \<Rightarrow> 'a stream \<Rightarrow> 'a stream" where |
224 |
"sdrop_while P s = (if P (shd s) then sdrop_while P (stl s) else s)" |
|
225 |
||
226 |
lemma sdrop_while_Stream[code]: |
|
227 |
"sdrop_while P (Stream a s) = (if P a then sdrop_while P s else Stream a s)" |
|
228 |
by (subst sdrop_while.simps) simp |
|
229 |
||
230 |
lemma sdrop_while_sdrop_LEAST: |
|
231 |
assumes "\<exists>n. P (s !! n)" |
|
232 |
shows "sdrop_while (Not o P) s = sdrop (LEAST n. P (s !! n)) s" |
|
233 |
proof - |
|
234 |
from assms obtain m where "P (s !! m)" "\<And>n. P (s !! n) \<Longrightarrow> m \<le> n" |
|
235 |
and *: "(LEAST n. P (s !! n)) = m" by atomize_elim (auto intro: LeastI Least_le) |
|
236 |
thus ?thesis unfolding * |
|
237 |
proof (induct m arbitrary: s) |
|
238 |
case (Suc m) |
|
239 |
hence "sdrop_while (Not \<circ> P) (stl s) = sdrop m (stl s)" |
|
240 |
by (metis (full_types) not_less_eq_eq snth.simps(2)) |
|
241 |
moreover from Suc(3) have "\<not> (P (s !! 0))" by blast |
|
242 |
ultimately show ?case by (subst sdrop_while.simps) simp |
|
243 |
qed (metis comp_apply sdrop.simps(1) sdrop_while.simps snth.simps(1)) |
|
244 |
qed |
|
245 |
||
54027
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
246 |
primcorec sfilter where |
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
247 |
"shd (sfilter P s) = shd (sdrop_while (Not o P) s)" |
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
248 |
| "stl (sfilter P s) = sfilter P (stl (sdrop_while (Not o P) s))" |
52905 | 249 |
|
250 |
lemma sfilter_Stream: "sfilter P (x ## s) = (if P x then x ## sfilter P s else sfilter P s)" |
|
251 |
proof (cases "P x") |
|
54027
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
252 |
case True thus ?thesis by (subst sfilter.ctr) (simp add: sdrop_while_Stream) |
52905 | 253 |
next |
54027
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
254 |
case False thus ?thesis by (subst (1 2) sfilter.ctr) (simp add: sdrop_while_Stream) |
52905 | 255 |
qed |
256 |
||
51141 | 257 |
|
258 |
subsection {* unary predicates lifted to streams *} |
|
259 |
||
260 |
definition "stream_all P s = (\<forall>p. P (s !! p))" |
|
261 |
||
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
262 |
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
|
263 |
unfolding stream_all_def sset_range by auto |
51141 | 264 |
|
265 |
lemma stream_all_shift[simp]: "stream_all P (xs @- s) = (list_all P xs \<and> stream_all P s)" |
|
266 |
unfolding stream_all_iff list_all_iff by auto |
|
267 |
||
54469 | 268 |
lemma stream_all_Stream: "stream_all P (x ## X) \<longleftrightarrow> P x \<and> stream_all P X" |
269 |
by simp |
|
270 |
||
51141 | 271 |
|
272 |
subsection {* recurring stream out of a list *} |
|
273 |
||
54027
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
274 |
primcorec cycle :: "'a list \<Rightarrow> 'a stream" where |
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
275 |
"shd (cycle xs) = hd xs" |
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
276 |
| "stl (cycle xs) = cycle (tl xs @ [hd xs])" |
51141 | 277 |
lemma cycle_decomp: "u \<noteq> [] \<Longrightarrow> cycle u = u @- cycle u" |
54027
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
278 |
proof (coinduction arbitrary: u) |
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
279 |
case Eq_stream then show ?case using stream.collapse[of "cycle u"] |
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
280 |
by (auto intro!: exI[of _ "tl u @ [hd u]"]) |
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
281 |
qed |
51141 | 282 |
|
51409 | 283 |
lemma cycle_Cons[code]: "cycle (x # xs) = x ## cycle (xs @ [x])" |
54027
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
284 |
by (subst cycle.ctr) simp |
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 |
||
54027
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
324 |
primcorec same where |
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
325 |
"shd (same x) = x" |
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
326 |
| "stl (same x) = same x" |
51141 | 327 |
|
328 |
lemma snth_same[simp]: "same x !! n = x" |
|
329 |
unfolding same_def by (induct n) auto |
|
330 |
||
331 |
lemma stake_same[simp]: "stake n (same x) = replicate n x" |
|
332 |
unfolding same_def by (induct n) (auto simp: upt_rec) |
|
333 |
||
334 |
lemma sdrop_same[simp]: "sdrop n (same x) = same x" |
|
335 |
unfolding same_def by (induct n) auto |
|
336 |
||
337 |
lemma shift_replicate_same[simp]: "replicate n x @- same x = same x" |
|
338 |
by (metis sdrop_same stake_same stake_sdrop) |
|
339 |
||
340 |
lemma stream_all_same[simp]: "stream_all P (same x) \<longleftrightarrow> P x" |
|
341 |
unfolding stream_all_def by auto |
|
342 |
||
343 |
lemma same_cycle: "same x = cycle [x]" |
|
54027
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
344 |
by coinduction auto |
51141 | 345 |
|
346 |
||
347 |
subsection {* stream of natural numbers *} |
|
348 |
||
54027
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
349 |
primcorec fromN :: "nat \<Rightarrow> nat stream" where |
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
350 |
"fromN n = n ## fromN (n + 1)" |
51409 | 351 |
|
51141 | 352 |
lemma snth_fromN[simp]: "fromN n !! m = n + m" |
353 |
unfolding fromN_def by (induct m arbitrary: n) auto |
|
354 |
||
355 |
lemma stake_fromN[simp]: "stake m (fromN n) = [n ..< m + n]" |
|
356 |
unfolding fromN_def by (induct m arbitrary: n) (auto simp: upt_rec) |
|
357 |
||
358 |
lemma sdrop_fromN[simp]: "sdrop m (fromN n) = fromN (n + m)" |
|
359 |
unfolding fromN_def by (induct m arbitrary: n) auto |
|
360 |
||
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
361 |
lemma sset_fromN[simp]: "sset (fromN n) = {n ..}" (is "?L = ?R") |
51352 | 362 |
proof safe |
54027
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
363 |
fix m assume "m \<in> ?L" |
51352 | 364 |
moreover |
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
365 |
{ fix s assume "m \<in> sset s" "\<exists>n'\<ge>n. s = fromN n'" |
54027
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
366 |
hence "n \<le> m" by (induct arbitrary: n rule: sset_induct1) fastforce+ |
51352 | 367 |
} |
54027
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
368 |
ultimately show "n \<le> m" by auto |
51352 | 369 |
next |
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
370 |
fix m assume "n \<le> m" thus "m \<in> ?L" by (metis le_iff_add snth_fromN snth_sset) |
51352 | 371 |
qed |
372 |
||
54469 | 373 |
lemma fromN_Suc_eq_smap: "fromN (Suc n) = smap Suc (fromN n)" |
374 |
by (coinduction arbitrary: n) auto |
|
375 |
||
51141 | 376 |
abbreviation "nats \<equiv> fromN 0" |
377 |
||
378 |
||
51462 | 379 |
subsection {* flatten a stream of lists *} |
380 |
||
54027
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
381 |
primcorec flat where |
51462 | 382 |
"shd (flat ws) = hd (shd ws)" |
54027
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
383 |
| "stl (flat ws) = flat (if tl (shd ws) = [] then stl ws else tl (shd ws) ## stl ws)" |
51462 | 384 |
|
385 |
lemma flat_Cons[simp, code]: "flat ((x # xs) ## ws) = x ## flat (if xs = [] then ws else xs ## ws)" |
|
54027
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
386 |
by (subst flat.ctr) simp |
51462 | 387 |
|
388 |
lemma flat_Stream[simp]: "xs \<noteq> [] \<Longrightarrow> flat (xs ## ws) = xs @- flat ws" |
|
389 |
by (induct xs) auto |
|
390 |
||
391 |
lemma flat_unfold: "shd ws \<noteq> [] \<Longrightarrow> flat ws = shd ws @- flat (stl ws)" |
|
392 |
by (cases ws) auto |
|
393 |
||
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
394 |
lemma flat_snth: "\<forall>xs \<in> sset s. xs \<noteq> [] \<Longrightarrow> flat s !! n = (if n < length (shd s) then |
51462 | 395 |
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
|
396 |
by (metis flat_unfold not_less shd_sset shift_snth_ge shift_snth_less) |
51462 | 397 |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
398 |
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
|
399 |
sset (flat s) = (\<Union>xs \<in> sset s. set xs)" (is "?P \<Longrightarrow> ?L = ?R") |
51462 | 400 |
proof safe |
401 |
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
|
402 |
then obtain m where "x = flat s !! m" by (metis image_iff sset_range) |
51462 | 403 |
with `?P` obtain n m' where "x = s !! n ! m'" "m' < length (s !! n)" |
404 |
proof (atomize_elim, induct m arbitrary: s rule: less_induct) |
|
405 |
case (less y) |
|
406 |
thus ?case |
|
407 |
proof (cases "y < length (shd s)") |
|
408 |
case True thus ?thesis by (metis flat_snth less(2,3) snth.simps(1)) |
|
409 |
next |
|
410 |
case False |
|
411 |
hence "x = flat (stl s) !! (y - length (shd s))" by (metis less(2,3) flat_snth) |
|
412 |
moreover |
|
53374
a14d2a854c02
tuned proofs -- clarified flow of facts wrt. calculation;
wenzelm
parents:
53290
diff
changeset
|
413 |
{ 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
|
414 |
with False have "y > 0" by (cases y) simp_all |
a14d2a854c02
tuned proofs -- clarified flow of facts wrt. calculation;
wenzelm
parents:
53290
diff
changeset
|
415 |
with * have "y - length (shd s) < y" by simp |
51462 | 416 |
} |
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
417 |
moreover have "\<forall>xs \<in> sset (stl s). xs \<noteq> []" using less(2) by (cases s) auto |
51462 | 418 |
ultimately have "\<exists>n m'. x = stl s !! n ! m' \<and> m' < length (stl s !! n)" by (intro less(1)) auto |
419 |
thus ?thesis by (metis snth.simps(2)) |
|
420 |
qed |
|
421 |
qed |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
422 |
thus "x \<in> ?R" by (auto simp: sset_range dest!: nth_mem) |
51462 | 423 |
next |
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
424 |
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
|
425 |
by (induct rule: sset_induct1) |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
426 |
(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
|
427 |
metis UnI2 flat_unfold shd_sset stl_sset sset_shift) |
51462 | 428 |
qed |
429 |
||
430 |
||
431 |
subsection {* merge a stream of streams *} |
|
432 |
||
433 |
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
|
434 |
"smerge ss = flat (smap (\<lambda>n. map (\<lambda>s. s !! n) (stake (Suc n) ss) @ stake n (ss !! n)) nats)" |
51462 | 435 |
|
436 |
lemma stake_nth[simp]: "m < n \<Longrightarrow> stake n s ! m = s !! m" |
|
437 |
by (induct n arbitrary: s m) (auto simp: nth_Cons', metis Suc_pred snth.simps(2)) |
|
438 |
||
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
439 |
lemma snth_sset_smerge: "ss !! n !! m \<in> sset (smerge ss)" |
51462 | 440 |
proof (cases "n \<le> m") |
441 |
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
|
442 |
by (subst sset_flat) |
53290 | 443 |
(auto simp: stream.set_map in_set_conv_nth simp del: stake.simps |
51462 | 444 |
intro!: exI[of _ n, OF disjI2] exI[of _ m, OF mp]) |
445 |
next |
|
446 |
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
|
447 |
by (subst sset_flat) |
53290 | 448 |
(auto simp: stream.set_map in_set_conv_nth image_iff simp del: stake.simps snth.simps |
51462 | 449 |
intro!: exI[of _ m, OF disjI1] bexI[of _ "ss !! n"] exI[of _ n, OF mp]) |
450 |
qed |
|
451 |
||
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
452 |
lemma sset_smerge: "sset (smerge ss) = UNION (sset ss) sset" |
51462 | 453 |
proof safe |
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
454 |
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
|
455 |
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
|
456 |
unfolding smerge_def by (subst (asm) sset_flat) |
53290 | 457 |
(auto simp: stream.set_map in_set_conv_nth sset_range simp del: stake.simps, fast+) |
51462 | 458 |
next |
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
459 |
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
|
460 |
thus "x \<in> sset (smerge ss)" using snth_sset_smerge by (auto simp: sset_range) |
51462 | 461 |
qed |
462 |
||
463 |
||
464 |
subsection {* product of two streams *} |
|
465 |
||
466 |
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
|
467 |
"sproduct s1 s2 = smerge (smap (\<lambda>x. smap (Pair x) s2) s1)" |
51462 | 468 |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
469 |
lemma sset_sproduct: "sset (sproduct s1 s2) = sset s1 \<times> sset s2" |
53290 | 470 |
unfolding sproduct_def sset_smerge by (auto simp: stream.set_map) |
51462 | 471 |
|
472 |
||
473 |
subsection {* interleave two streams *} |
|
474 |
||
54027
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
475 |
primcorec sinterleave where |
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
476 |
"shd (sinterleave s1 s2) = shd s1" |
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
477 |
| "stl (sinterleave s1 s2) = sinterleave s2 (stl s1)" |
51462 | 478 |
|
479 |
lemma sinterleave_code[code]: |
|
480 |
"sinterleave (x ## s1) s2 = x ## sinterleave s2 s1" |
|
54027
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
481 |
by (subst sinterleave.ctr) simp |
51462 | 482 |
|
483 |
lemma sinterleave_snth[simp]: |
|
484 |
"even n \<Longrightarrow> sinterleave s1 s2 !! n = s1 !! (n div 2)" |
|
485 |
"odd n \<Longrightarrow> sinterleave s1 s2 !! n = s2 !! (n div 2)" |
|
486 |
by (induct n arbitrary: s1 s2) |
|
487 |
(auto dest: even_nat_Suc_div_2 odd_nat_plus_one_div_two[folded nat_2]) |
|
488 |
||
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
489 |
lemma sset_sinterleave: "sset (sinterleave s1 s2) = sset s1 \<union> sset s2" |
51462 | 490 |
proof (intro equalityI subsetI) |
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
491 |
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
|
492 |
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
|
493 |
thus "x \<in> sset s1 \<union> sset s2" by (cases "even n") auto |
51462 | 494 |
next |
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
495 |
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
|
496 |
thus "x \<in> sset (sinterleave s1 s2)" |
51462 | 497 |
proof |
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
498 |
assume "x \<in> sset s1" |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
499 |
then obtain n where "x = s1 !! n" unfolding sset_range by blast |
51462 | 500 |
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
|
501 |
thus ?thesis unfolding sset_range by blast |
51462 | 502 |
next |
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
503 |
assume "x \<in> sset s2" |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
504 |
then obtain n where "x = s2 !! n" unfolding sset_range by blast |
51462 | 505 |
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
|
506 |
thus ?thesis unfolding sset_range by blast |
51462 | 507 |
qed |
508 |
qed |
|
509 |
||
510 |
||
51141 | 511 |
subsection {* zip *} |
512 |
||
54027
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
513 |
primcorec szip where |
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
514 |
"shd (szip s1 s2) = (shd s1, shd s2)" |
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
515 |
| "stl (szip s1 s2) = szip (stl s1) (stl s2)" |
51141 | 516 |
|
51409 | 517 |
lemma szip_unfold[code]: "szip (Stream a s1) (Stream b s2) = Stream (a, b) (szip s1 s2)" |
54027
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
518 |
by (subst szip.ctr) simp |
51409 | 519 |
|
51141 | 520 |
lemma snth_szip[simp]: "szip s1 s2 !! n = (s1 !! n, s2 !! n)" |
521 |
by (induct n arbitrary: s1 s2) auto |
|
522 |
||
523 |
||
524 |
subsection {* zip via function *} |
|
525 |
||
54027
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
526 |
primcorec smap2 where |
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
527 |
"shd (smap2 f s1 s2) = f (shd s1) (shd s2)" |
54027
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
528 |
| "stl (smap2 f s1 s2) = smap2 f (stl s1) (stl s2)" |
51141 | 529 |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
530 |
lemma smap2_unfold[code]: |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
531 |
"smap2 f (Stream a s1) (Stream b s2) = Stream (f a b) (smap2 f s1 s2)" |
54027
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
532 |
by (subst smap2.ctr) simp |
51409 | 533 |
|
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
534 |
lemma smap2_szip: |
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
535 |
"smap2 f s1 s2 = smap (split f) (szip s1 s2)" |
54027
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
536 |
by (coinduction arbitrary: s1 s2) auto |
50518 | 537 |
|
51462 | 538 |
|
539 |
subsection {* iterated application of a function *} |
|
540 |
||
54027
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
541 |
primcorec siterate where |
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
542 |
"shd (siterate f x) = x" |
e5853a648b59
use new coinduction method and primcorec in examples
traytel
parents:
53808
diff
changeset
|
543 |
| "stl (siterate f x) = siterate f (f x)" |
51462 | 544 |
|
545 |
lemma stake_Suc: "stake (Suc n) s = stake n s @ [s !! n]" |
|
546 |
by (induct n arbitrary: s) auto |
|
547 |
||
548 |
lemma snth_siterate[simp]: "siterate f x !! n = (f^^n) x" |
|
549 |
by (induct n arbitrary: x) (auto simp: funpow_swap1) |
|
550 |
||
551 |
lemma sdrop_siterate[simp]: "sdrop n (siterate f x) = siterate f ((f^^n) x)" |
|
552 |
by (induct n arbitrary: x) (auto simp: funpow_swap1) |
|
553 |
||
554 |
lemma stake_siterate[simp]: "stake n (siterate f x) = map (\<lambda>n. (f^^n) x) [0 ..< n]" |
|
555 |
by (induct n arbitrary: x) (auto simp del: stake.simps(2) simp: stake_Suc) |
|
556 |
||
51772
d2b265ebc1fa
specify nicer names for map, set and rel in the stream library
traytel
parents:
51766
diff
changeset
|
557 |
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
|
558 |
by (auto simp: sset_range) |
51462 | 559 |
|
50518 | 560 |
end |