equal
deleted
inserted
replaced
11 theory Stream |
11 theory Stream |
12 imports Nat_Bijection |
12 imports Nat_Bijection |
13 begin |
13 begin |
14 |
14 |
15 codatatype (sset: 'a) stream = |
15 codatatype (sset: 'a) stream = |
16 SCons (shd: 'a) (stl: "'a stream") (infixr "##" 65) |
16 SCons (shd: 'a) (stl: "'a stream") (infixr \<open>##\<close> 65) |
17 for |
17 for |
18 map: smap |
18 map: smap |
19 rel: stream_all2 |
19 rel: stream_all2 |
20 |
20 |
21 context |
21 context |
42 lemma smap_ctr: "smap f s = x ## s' \<longleftrightarrow> f (shd s) = x \<and> smap f (stl s) = s'" |
42 lemma smap_ctr: "smap f s = x ## s' \<longleftrightarrow> f (shd s) = x \<and> smap f (stl s) = s'" |
43 by (cases s) simp |
43 by (cases s) simp |
44 |
44 |
45 subsection \<open>prepend list to stream\<close> |
45 subsection \<open>prepend list to stream\<close> |
46 |
46 |
47 primrec shift :: "'a list \<Rightarrow> 'a stream \<Rightarrow> 'a stream" (infixr "@-" 65) where |
47 primrec shift :: "'a list \<Rightarrow> 'a stream \<Rightarrow> 'a stream" (infixr \<open>@-\<close> 65) where |
48 "shift [] s = s" |
48 "shift [] s = s" |
49 | "shift (x # xs) s = x ## shift xs s" |
49 | "shift (x # xs) s = x ## shift xs s" |
50 |
50 |
51 lemma smap_shift[simp]: "smap f (xs @- s) = map f xs @- smap f s" |
51 lemma smap_shift[simp]: "smap f (xs @- s) = map f xs @- smap f s" |
52 by (induct xs) auto |
52 by (induct xs) auto |
134 lemma streams_UNIV[simp]: "streams UNIV = UNIV" |
134 lemma streams_UNIV[simp]: "streams UNIV = UNIV" |
135 by (auto simp: streams_iff_sset) |
135 by (auto simp: streams_iff_sset) |
136 |
136 |
137 subsection \<open>nth, take, drop for streams\<close> |
137 subsection \<open>nth, take, drop for streams\<close> |
138 |
138 |
139 primrec snth :: "'a stream \<Rightarrow> nat \<Rightarrow> 'a" (infixl "!!" 100) where |
139 primrec snth :: "'a stream \<Rightarrow> nat \<Rightarrow> 'a" (infixl \<open>!!\<close> 100) where |
140 "s !! 0 = shd s" |
140 "s !! 0 = shd s" |
141 | "s !! Suc n = stl s !! n" |
141 | "s !! Suc n = stl s !! n" |
142 |
142 |
143 lemma snth_Stream: "(x ## s) !! Suc i = s !! i" |
143 lemma snth_Stream: "(x ## s) !! Suc i = s !! i" |
144 by simp |
144 by simp |