1.1 --- a/src/HOL/BNF/Examples/Stream.thy Fri Feb 15 09:59:46 2013 +0100
1.2 +++ b/src/HOL/BNF/Examples/Stream.thy Fri Feb 15 11:31:59 2013 +0100
1.3 @@ -16,25 +16,33 @@
1.4
1.5 (* TODO: Provide by the package*)
1.6 theorem stream_set_induct:
1.7 - "\<lbrakk>\<And>s. P (shd s) s; \<And>s y. \<lbrakk>y \<in> stream_set (stl s); P y (stl s)\<rbrakk> \<Longrightarrow> P y s\<rbrakk> \<Longrightarrow>
1.8 - \<forall>y \<in> stream_set s. P y s"
1.9 -by (rule stream.dtor_set_induct)
1.10 - (auto simp add: shd_def stl_def stream_case_def fsts_def snds_def split_beta)
1.11 + "\<lbrakk>\<And>s. P (shd s) s; \<And>s y. \<lbrakk>y \<in> stream_set (stl s); P y (stl s)\<rbrakk> \<Longrightarrow> P y s\<rbrakk> \<Longrightarrow>
1.12 + \<forall>y \<in> stream_set s. P y s"
1.13 + by (rule stream.dtor_set_induct)
1.14 + (auto simp add: shd_def stl_def stream_case_def fsts_def snds_def split_beta)
1.15 +
1.16 +lemma stream_map_simps[simp]:
1.17 + "shd (stream_map f s) = f (shd s)" "stl (stream_map f s) = stream_map f (stl s)"
1.18 + unfolding shd_def stl_def stream_case_def stream_map_def stream.dtor_unfold
1.19 + by (case_tac [!] s) (auto simp: Stream_def stream.dtor_ctor)
1.20 +
1.21 +lemma stream_map_Stream[simp]: "stream_map f (x ## s) = f x ## stream_map f s"
1.22 + by (metis stream.exhaust stream.sels stream_map_simps)
1.23
1.24 theorem shd_stream_set: "shd s \<in> stream_set s"
1.25 -by (auto simp add: shd_def stl_def stream_case_def fsts_def snds_def split_beta)
1.26 - (metis UnCI fsts_def insertI1 stream.dtor_set)
1.27 + by (auto simp add: shd_def stl_def stream_case_def fsts_def snds_def split_beta)
1.28 + (metis UnCI fsts_def insertI1 stream.dtor_set)
1.29
1.30 theorem stl_stream_set: "y \<in> stream_set (stl s) \<Longrightarrow> y \<in> stream_set s"
1.31 -by (auto simp add: shd_def stl_def stream_case_def fsts_def snds_def split_beta)
1.32 - (metis insertI1 set_mp snds_def stream.dtor_set_set_incl)
1.33 + by (auto simp add: shd_def stl_def stream_case_def fsts_def snds_def split_beta)
1.34 + (metis insertI1 set_mp snds_def stream.dtor_set_set_incl)
1.35
1.36 (* only for the non-mutual case: *)
1.37 theorem stream_set_induct1[consumes 1, case_names shd stl, induct set: "stream_set"]:
1.38 assumes "y \<in> stream_set s" and "\<And>s. P (shd s) s"
1.39 and "\<And>s y. \<lbrakk>y \<in> stream_set (stl s); P y (stl s)\<rbrakk> \<Longrightarrow> P y s"
1.40 shows "P y s"
1.41 -using assms stream_set_induct by blast
1.42 + using assms stream_set_induct by blast
1.43 (* end TODO *)
1.44
1.45
1.46 @@ -45,12 +53,152 @@
1.47 | "shift (x # xs) s = x ## shift xs s"
1.48
1.49 lemma shift_append[simp]: "(xs @ ys) @- s = xs @- ys @- s"
1.50 -by (induct xs) auto
1.51 + by (induct xs) auto
1.52
1.53 lemma shift_simps[simp]:
1.54 "shd (xs @- s) = (if xs = [] then shd s else hd xs)"
1.55 "stl (xs @- s) = (if xs = [] then stl s else tl xs @- s)"
1.56 -by (induct xs) auto
1.57 + by (induct xs) auto
1.58 +
1.59 +lemma stream_set_shift[simp]: "stream_set (xs @- s) = set xs \<union> stream_set s"
1.60 + by (induct xs) auto
1.61 +
1.62 +
1.63 +subsection {* set of streams with elements in some fixes set *}
1.64 +
1.65 +coinductive_set
1.66 + streams :: "'a set => 'a stream set"
1.67 + for A :: "'a set"
1.68 +where
1.69 + Stream[intro!, simp, no_atp]: "\<lbrakk>a \<in> A; s \<in> streams A\<rbrakk> \<Longrightarrow> a ## s \<in> streams A"
1.70 +
1.71 +lemma shift_streams: "\<lbrakk>w \<in> lists A; s \<in> streams A\<rbrakk> \<Longrightarrow> w @- s \<in> streams A"
1.72 + by (induct w) auto
1.73 +
1.74 +lemma stream_set_streams:
1.75 + assumes "stream_set s \<subseteq> A"
1.76 + shows "s \<in> streams A"
1.77 +proof (coinduct rule: streams.coinduct[of "\<lambda>s'. \<exists>a s. s' = a ## s \<and> a \<in> A \<and> stream_set s \<subseteq> A"])
1.78 + case streams from assms show ?case by (cases s) auto
1.79 +next
1.80 + fix s' assume "\<exists>a s. s' = a ## s \<and> a \<in> A \<and> stream_set s \<subseteq> A"
1.81 + then guess a s by (elim exE)
1.82 + with assms show "\<exists>a l. s' = a ## l \<and>
1.83 + a \<in> A \<and> ((\<exists>a s. l = a ## s \<and> a \<in> A \<and> stream_set s \<subseteq> A) \<or> l \<in> streams A)"
1.84 + by (cases s) auto
1.85 +qed
1.86 +
1.87 +
1.88 +subsection {* flatten a stream of lists *}
1.89 +
1.90 +definition flat where
1.91 + "flat \<equiv> stream_unfold (hd o shd) (\<lambda>s. if tl (shd s) = [] then stl s else tl (shd s) ## stl s)"
1.92 +
1.93 +lemma flat_simps[simp]:
1.94 + "shd (flat ws) = hd (shd ws)"
1.95 + "stl (flat ws) = flat (if tl (shd ws) = [] then stl ws else tl (shd ws) ## stl ws)"
1.96 + unfolding flat_def by auto
1.97 +
1.98 +lemma flat_Cons[simp]: "flat ((x # xs) ## ws) = x ## flat (if xs = [] then ws else xs ## ws)"
1.99 + unfolding flat_def using stream.unfold[of "hd o shd" _ "(x # xs) ## ws"] by auto
1.100 +
1.101 +lemma flat_Stream[simp]: "xs \<noteq> [] \<Longrightarrow> flat (xs ## ws) = xs @- flat ws"
1.102 + by (induct xs) auto
1.103 +
1.104 +lemma flat_unfold: "shd ws \<noteq> [] \<Longrightarrow> flat ws = shd ws @- flat (stl ws)"
1.105 + by (cases ws) auto
1.106 +
1.107 +
1.108 +subsection {* nth, take, drop for streams *}
1.109 +
1.110 +primrec snth :: "'a stream \<Rightarrow> nat \<Rightarrow> 'a" (infixl "!!" 100) where
1.111 + "s !! 0 = shd s"
1.112 +| "s !! Suc n = stl s !! n"
1.113 +
1.114 +lemma snth_stream_map[simp]: "stream_map f s !! n = f (s !! n)"
1.115 + by (induct n arbitrary: s) auto
1.116 +
1.117 +lemma shift_snth_less[simp]: "p < length xs \<Longrightarrow> (xs @- s) !! p = xs ! p"
1.118 + by (induct p arbitrary: xs) (auto simp: hd_conv_nth nth_tl)
1.119 +
1.120 +lemma shift_snth_ge[simp]: "p \<ge> length xs \<Longrightarrow> (xs @- s) !! p = s !! (p - length xs)"
1.121 + by (induct p arbitrary: xs) (auto simp: Suc_diff_eq_diff_pred)
1.122 +
1.123 +lemma snth_stream_set[simp]: "s !! n \<in> stream_set s"
1.124 + by (induct n arbitrary: s) (auto intro: shd_stream_set stl_stream_set)
1.125 +
1.126 +lemma stream_set_range: "stream_set s = range (snth s)"
1.127 +proof (intro equalityI subsetI)
1.128 + fix x assume "x \<in> stream_set s"
1.129 + thus "x \<in> range (snth s)"
1.130 + proof (induct s)
1.131 + case (stl s x)
1.132 + then obtain n where "x = stl s !! n" by auto
1.133 + thus ?case by (auto intro: range_eqI[of _ _ "Suc n"])
1.134 + qed (auto intro: range_eqI[of _ _ 0])
1.135 +qed auto
1.136 +
1.137 +primrec stake :: "nat \<Rightarrow> 'a stream \<Rightarrow> 'a list" where
1.138 + "stake 0 s = []"
1.139 +| "stake (Suc n) s = shd s # stake n (stl s)"
1.140 +
1.141 +lemma length_stake[simp]: "length (stake n s) = n"
1.142 + by (induct n arbitrary: s) auto
1.143 +
1.144 +lemma stake_stream_map[simp]: "stake n (stream_map f s) = map f (stake n s)"
1.145 + by (induct n arbitrary: s) auto
1.146 +
1.147 +primrec sdrop :: "nat \<Rightarrow> 'a stream \<Rightarrow> 'a stream" where
1.148 + "sdrop 0 s = s"
1.149 +| "sdrop (Suc n) s = sdrop n (stl s)"
1.150 +
1.151 +lemma sdrop_simps[simp]:
1.152 + "shd (sdrop n s) = s !! n" "stl (sdrop n s) = sdrop (Suc n) s"
1.153 + by (induct n arbitrary: s) auto
1.154 +
1.155 +lemma sdrop_stream_map[simp]: "sdrop n (stream_map f s) = stream_map f (sdrop n s)"
1.156 + by (induct n arbitrary: s) auto
1.157 +
1.158 +lemma stake_sdrop: "stake n s @- sdrop n s = s"
1.159 + by (induct n arbitrary: s) auto
1.160 +
1.161 +lemma id_stake_snth_sdrop:
1.162 + "s = stake i s @- s !! i ## sdrop (Suc i) s"
1.163 + by (subst stake_sdrop[symmetric, of _ i]) (metis sdrop_simps stream.collapse)
1.164 +
1.165 +lemma stream_map_alt: "stream_map f s = s' \<longleftrightarrow> (\<forall>n. f (s !! n) = s' !! n)" (is "?L = ?R")
1.166 +proof
1.167 + assume ?R
1.168 + thus ?L
1.169 + by (coinduct rule: stream.coinduct[of "\<lambda>s1 s2. \<exists>n. s1 = stream_map f (sdrop n s) \<and> s2 = sdrop n s'"])
1.170 + (auto intro: exI[of _ 0] simp del: sdrop.simps(2))
1.171 +qed auto
1.172 +
1.173 +lemma stake_invert_Nil[iff]: "stake n s = [] \<longleftrightarrow> n = 0"
1.174 + by (induct n) auto
1.175 +
1.176 +lemma sdrop_shift: "\<lbrakk>s = w @- s'; length w = n\<rbrakk> \<Longrightarrow> sdrop n s = s'"
1.177 + by (induct n arbitrary: w s) auto
1.178 +
1.179 +lemma stake_shift: "\<lbrakk>s = w @- s'; length w = n\<rbrakk> \<Longrightarrow> stake n s = w"
1.180 + by (induct n arbitrary: w s) auto
1.181 +
1.182 +lemma stake_add[simp]: "stake m s @ stake n (sdrop m s) = stake (m + n) s"
1.183 + by (induct m arbitrary: s) auto
1.184 +
1.185 +lemma sdrop_add[simp]: "sdrop n (sdrop m s) = sdrop (m + n) s"
1.186 + by (induct m arbitrary: s) auto
1.187 +
1.188 +
1.189 +subsection {* unary predicates lifted to streams *}
1.190 +
1.191 +definition "stream_all P s = (\<forall>p. P (s !! p))"
1.192 +
1.193 +lemma stream_all_iff[iff]: "stream_all P s \<longleftrightarrow> Ball (stream_set s) P"
1.194 + unfolding stream_all_def stream_set_range by auto
1.195 +
1.196 +lemma stream_all_shift[simp]: "stream_all P (xs @- s) = (list_all P xs \<and> stream_all P s)"
1.197 + unfolding stream_all_iff list_all_iff by auto
1.198
1.199
1.200 subsection {* recurring stream out of a list *}
1.201 @@ -61,8 +209,7 @@
1.202 lemma cycle_simps[simp]:
1.203 "shd (cycle u) = hd u"
1.204 "stl (cycle u) = cycle (tl u @ [hd u])"
1.205 -by (auto simp: cycle_def)
1.206 -
1.207 + by (auto simp: cycle_def)
1.208
1.209 lemma cycle_decomp: "u \<noteq> [] \<Longrightarrow> cycle u = u @- cycle u"
1.210 proof (coinduct rule: stream.coinduct[of "\<lambda>s1 s2. \<exists>u. s1 = cycle u \<and> s2 = u @- cycle u \<and> u \<noteq> []"])
1.211 @@ -79,83 +226,8 @@
1.212 by (auto simp: cycle_def intro!: exI[of _ "hd (xs @ [x])"] exI[of _ "tl (xs @ [x])"] stream.unfold)
1.213 qed auto
1.214
1.215 -coinductive_set
1.216 - streams :: "'a set => 'a stream set"
1.217 - for A :: "'a set"
1.218 -where
1.219 - Stream[intro!, simp, no_atp]: "\<lbrakk>a \<in> A; s \<in> streams A\<rbrakk> \<Longrightarrow> a ## s \<in> streams A"
1.220 -
1.221 -lemma shift_streams: "\<lbrakk>w \<in> lists A; s \<in> streams A\<rbrakk> \<Longrightarrow> w @- s \<in> streams A"
1.222 -by (induct w) auto
1.223 -
1.224 -lemma stream_set_streams:
1.225 - assumes "stream_set s \<subseteq> A"
1.226 - shows "s \<in> streams A"
1.227 -proof (coinduct rule: streams.coinduct[of "\<lambda>s'. \<exists>a s. s' = a ## s \<and> a \<in> A \<and> stream_set s \<subseteq> A"])
1.228 - case streams from assms show ?case by (cases s) auto
1.229 -next
1.230 - fix s' assume "\<exists>a s. s' = a ## s \<and> a \<in> A \<and> stream_set s \<subseteq> A"
1.231 - then guess a s by (elim exE)
1.232 - with assms show "\<exists>a l. s' = a ## l \<and>
1.233 - a \<in> A \<and> ((\<exists>a s. l = a ## s \<and> a \<in> A \<and> stream_set s \<subseteq> A) \<or> l \<in> streams A)"
1.234 - by (cases s) auto
1.235 -qed
1.236 -
1.237 -
1.238 -subsection {* flatten a stream of lists *}
1.239 -
1.240 -definition flat where
1.241 - "flat \<equiv> stream_unfold (hd o shd) (\<lambda>s. if tl (shd s) = [] then stl s else tl (shd s) ## stl s)"
1.242 -
1.243 -lemma flat_simps[simp]:
1.244 - "shd (flat ws) = hd (shd ws)"
1.245 - "stl (flat ws) = flat (if tl (shd ws) = [] then stl ws else tl (shd ws) ## stl ws)"
1.246 -unfolding flat_def by auto
1.247 -
1.248 -lemma flat_Cons[simp]: "flat ((x # xs) ## ws) = x ## flat (if xs = [] then ws else xs ## ws)"
1.249 -unfolding flat_def using stream.unfold[of "hd o shd" _ "(x # xs) ## ws"] by auto
1.250 -
1.251 -lemma flat_Stream[simp]: "xs \<noteq> [] \<Longrightarrow> flat (xs ## ws) = xs @- flat ws"
1.252 -by (induct xs) auto
1.253 -
1.254 -lemma flat_unfold: "shd ws \<noteq> [] \<Longrightarrow> flat ws = shd ws @- flat (stl ws)"
1.255 -by (cases ws) auto
1.256 -
1.257 -
1.258 -subsection {* take, drop, nth for streams *}
1.259 -
1.260 -primrec stake :: "nat \<Rightarrow> 'a stream \<Rightarrow> 'a list" where
1.261 - "stake 0 s = []"
1.262 -| "stake (Suc n) s = shd s # stake n (stl s)"
1.263 -
1.264 -primrec sdrop :: "nat \<Rightarrow> 'a stream \<Rightarrow> 'a stream" where
1.265 - "sdrop 0 s = s"
1.266 -| "sdrop (Suc n) s = sdrop n (stl s)"
1.267 -
1.268 -primrec snth :: "'a stream \<Rightarrow> nat \<Rightarrow> 'a" (infixl "!!" 100) where
1.269 - "s !! 0 = shd s"
1.270 -| "s !! Suc n = stl s !! n"
1.271 -
1.272 -lemma stake_sdrop: "stake n s @- sdrop n s = s"
1.273 -by (induct n arbitrary: s) auto
1.274 -
1.275 -lemma stake_empty: "stake n s = [] \<longleftrightarrow> n = 0"
1.276 -by (cases n) auto
1.277 -
1.278 -lemma sdrop_shift: "\<lbrakk>s = w @- s'; length w = n\<rbrakk> \<Longrightarrow> sdrop n s = s'"
1.279 -by (induct n arbitrary: w s) auto
1.280 -
1.281 -lemma stake_shift: "\<lbrakk>s = w @- s'; length w = n\<rbrakk> \<Longrightarrow> stake n s = w"
1.282 -by (induct n arbitrary: w s) auto
1.283 -
1.284 -lemma stake_add[simp]: "stake m s @ stake n (sdrop m s) = stake (m + n) s"
1.285 -by (induct m arbitrary: s) auto
1.286 -
1.287 -lemma sdrop_add[simp]: "sdrop n (sdrop m s) = sdrop (m + n) s"
1.288 -by (induct m arbitrary: s) auto
1.289 -
1.290 lemma cycle_rotated: "\<lbrakk>v \<noteq> []; cycle u = v @- s\<rbrakk> \<Longrightarrow> cycle (tl u @ [hd u]) = tl v @- s"
1.291 -by (auto dest: arg_cong[of _ _ stl])
1.292 + by (auto dest: arg_cong[of _ _ stl])
1.293
1.294 lemma stake_append: "stake n (u @- s) = take (min (length u) n) u @ stake (n - length u) s"
1.295 proof (induct n arbitrary: u)
1.296 @@ -166,27 +238,105 @@
1.297 assumes "u \<noteq> []" "n < length u"
1.298 shows "stake n (cycle u) = take n u"
1.299 using min_absorb2[OF less_imp_le_nat[OF assms(2)]]
1.300 -by (subst cycle_decomp[OF assms(1)], subst stake_append) auto
1.301 + by (subst cycle_decomp[OF assms(1)], subst stake_append) auto
1.302
1.303 lemma stake_cycle_eq[simp]: "u \<noteq> [] \<Longrightarrow> stake (length u) (cycle u) = u"
1.304 -by (metis cycle_decomp stake_shift)
1.305 + by (metis cycle_decomp stake_shift)
1.306
1.307 lemma sdrop_cycle_eq[simp]: "u \<noteq> [] \<Longrightarrow> sdrop (length u) (cycle u) = cycle u"
1.308 -by (metis cycle_decomp sdrop_shift)
1.309 + by (metis cycle_decomp sdrop_shift)
1.310
1.311 lemma stake_cycle_eq_mod_0[simp]: "\<lbrakk>u \<noteq> []; n mod length u = 0\<rbrakk> \<Longrightarrow>
1.312 stake n (cycle u) = concat (replicate (n div length u) u)"
1.313 -by (induct "n div length u" arbitrary: n u) (auto simp: stake_add[symmetric])
1.314 + by (induct "n div length u" arbitrary: n u) (auto simp: stake_add[symmetric])
1.315
1.316 lemma sdrop_cycle_eq_mod_0[simp]: "\<lbrakk>u \<noteq> []; n mod length u = 0\<rbrakk> \<Longrightarrow>
1.317 sdrop n (cycle u) = cycle u"
1.318 -by (induct "n div length u" arbitrary: n u) (auto simp: sdrop_add[symmetric])
1.319 + by (induct "n div length u" arbitrary: n u) (auto simp: sdrop_add[symmetric])
1.320
1.321 lemma stake_cycle: "u \<noteq> [] \<Longrightarrow>
1.322 stake n (cycle u) = concat (replicate (n div length u) u) @ take (n mod length u) u"
1.323 -by (subst mod_div_equality[of n "length u", symmetric], unfold stake_add[symmetric]) auto
1.324 + by (subst mod_div_equality[of n "length u", symmetric], unfold stake_add[symmetric]) auto
1.325
1.326 lemma sdrop_cycle: "u \<noteq> [] \<Longrightarrow> sdrop n (cycle u) = cycle (rotate (n mod length u) u)"
1.327 -by (induct n arbitrary: u) (auto simp: rotate1_rotate_swap rotate1_hd_tl rotate_conv_mod[symmetric])
1.328 + by (induct n arbitrary: u) (auto simp: rotate1_rotate_swap rotate1_hd_tl rotate_conv_mod[symmetric])
1.329 +
1.330 +
1.331 +subsection {* stream repeating a single element *}
1.332 +
1.333 +definition "same x = stream_unfold (\<lambda>_. x) id ()"
1.334 +
1.335 +lemma same_simps[simp]: "shd (same x) = x" "stl (same x) = same x"
1.336 + unfolding same_def by auto
1.337 +
1.338 +lemma same_unfold: "same x = Stream x (same x)"
1.339 + by (metis same_simps stream.collapse)
1.340 +
1.341 +lemma snth_same[simp]: "same x !! n = x"
1.342 + unfolding same_def by (induct n) auto
1.343 +
1.344 +lemma stake_same[simp]: "stake n (same x) = replicate n x"
1.345 + unfolding same_def by (induct n) (auto simp: upt_rec)
1.346 +
1.347 +lemma sdrop_same[simp]: "sdrop n (same x) = same x"
1.348 + unfolding same_def by (induct n) auto
1.349 +
1.350 +lemma shift_replicate_same[simp]: "replicate n x @- same x = same x"
1.351 + by (metis sdrop_same stake_same stake_sdrop)
1.352 +
1.353 +lemma stream_all_same[simp]: "stream_all P (same x) \<longleftrightarrow> P x"
1.354 + unfolding stream_all_def by auto
1.355 +
1.356 +lemma same_cycle: "same x = cycle [x]"
1.357 + by (coinduct rule: stream.coinduct[of "\<lambda>s1 s2. s1 = same x \<and> s2 = cycle [x]"]) auto
1.358 +
1.359 +
1.360 +subsection {* stream of natural numbers *}
1.361 +
1.362 +definition "fromN n = stream_unfold id Suc n"
1.363 +
1.364 +lemma fromN_simps[simp]: "shd (fromN n) = n" "stl (fromN n) = fromN (Suc n)"
1.365 + unfolding fromN_def by auto
1.366 +
1.367 +lemma snth_fromN[simp]: "fromN n !! m = n + m"
1.368 + unfolding fromN_def by (induct m arbitrary: n) auto
1.369 +
1.370 +lemma stake_fromN[simp]: "stake m (fromN n) = [n ..< m + n]"
1.371 + unfolding fromN_def by (induct m arbitrary: n) (auto simp: upt_rec)
1.372 +
1.373 +lemma sdrop_fromN[simp]: "sdrop m (fromN n) = fromN (n + m)"
1.374 + unfolding fromN_def by (induct m arbitrary: n) auto
1.375 +
1.376 +abbreviation "nats \<equiv> fromN 0"
1.377 +
1.378 +
1.379 +subsection {* zip *}
1.380 +
1.381 +definition "szip s1 s2 =
1.382 + stream_unfold (map_pair shd shd) (map_pair stl stl) (s1, s2)"
1.383 +
1.384 +lemma szip_simps[simp]:
1.385 + "shd (szip s1 s2) = (shd s1, shd s2)" "stl (szip s1 s2) = szip (stl s1) (stl s2)"
1.386 + unfolding szip_def by auto
1.387 +
1.388 +lemma snth_szip[simp]: "szip s1 s2 !! n = (s1 !! n, s2 !! n)"
1.389 + by (induct n arbitrary: s1 s2) auto
1.390 +
1.391 +
1.392 +subsection {* zip via function *}
1.393 +
1.394 +definition "stream_map2 f s1 s2 =
1.395 + stream_unfold (\<lambda>(s1,s2). f (shd s1) (shd s2)) (map_pair stl stl) (s1, s2)"
1.396 +
1.397 +lemma stream_map2_simps[simp]:
1.398 + "shd (stream_map2 f s1 s2) = f (shd s1) (shd s2)"
1.399 + "stl (stream_map2 f s1 s2) = stream_map2 f (stl s1) (stl s2)"
1.400 + unfolding stream_map2_def by auto
1.401 +
1.402 +lemma stream_map2_szip:
1.403 + "stream_map2 f s1 s2 = stream_map (split f) (szip s1 s2)"
1.404 + by (coinduct rule: stream.coinduct[of
1.405 + "\<lambda>s1 s2. \<exists>s1' s2'. s1 = stream_map2 f s1' s2' \<and> s2 = stream_map (split f) (szip s1' s2')"])
1.406 + fastforce+
1.407
1.408 end