src/HOL/BNF/Examples/Stream.thy
author traytel
Fri Feb 15 11:31:59 2013 +0100 (2013-02-15)
changeset 51141 cc7423ce6774
parent 51023 550f265864e3
child 51352 fdecc2cd5649
permissions -rw-r--r--
extended stream library
traytel@50518
     1
(*  Title:      HOL/BNF/Examples/Stream.thy
traytel@50518
     2
    Author:     Dmitriy Traytel, TU Muenchen
traytel@50518
     3
    Author:     Andrei Popescu, TU Muenchen
traytel@50518
     4
    Copyright   2012
traytel@50518
     5
traytel@50518
     6
Infinite streams.
traytel@50518
     7
*)
traytel@50518
     8
traytel@50518
     9
header {* Infinite Streams *}
traytel@50518
    10
traytel@50518
    11
theory Stream
traytel@50518
    12
imports "../BNF"
traytel@50518
    13
begin
traytel@50518
    14
traytel@51023
    15
codata 'a stream = Stream (shd: 'a) (stl: "'a stream") (infixr "##" 65)
traytel@50518
    16
traytel@50518
    17
(* TODO: Provide by the package*)
traytel@50518
    18
theorem stream_set_induct:
traytel@51141
    19
  "\<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>
traytel@51141
    20
    \<forall>y \<in> stream_set s. P y s"
traytel@51141
    21
  by (rule stream.dtor_set_induct)
traytel@51141
    22
    (auto simp add:  shd_def stl_def stream_case_def fsts_def snds_def split_beta)
traytel@51141
    23
traytel@51141
    24
lemma stream_map_simps[simp]:
traytel@51141
    25
  "shd (stream_map f s) = f (shd s)" "stl (stream_map f s) = stream_map f (stl s)"
traytel@51141
    26
  unfolding shd_def stl_def stream_case_def stream_map_def stream.dtor_unfold
traytel@51141
    27
  by (case_tac [!] s) (auto simp: Stream_def stream.dtor_ctor)
traytel@51141
    28
traytel@51141
    29
lemma stream_map_Stream[simp]: "stream_map f (x ## s) = f x ## stream_map f s"
traytel@51141
    30
  by (metis stream.exhaust stream.sels stream_map_simps)
traytel@50518
    31
traytel@50518
    32
theorem shd_stream_set: "shd s \<in> stream_set s"
traytel@51141
    33
  by (auto simp add: shd_def stl_def stream_case_def fsts_def snds_def split_beta)
traytel@51141
    34
    (metis UnCI fsts_def insertI1 stream.dtor_set)
traytel@50518
    35
traytel@50518
    36
theorem stl_stream_set: "y \<in> stream_set (stl s) \<Longrightarrow> y \<in> stream_set s"
traytel@51141
    37
  by (auto simp add: shd_def stl_def stream_case_def fsts_def snds_def split_beta)
traytel@51141
    38
    (metis insertI1 set_mp snds_def stream.dtor_set_set_incl)
traytel@50518
    39
traytel@50518
    40
(* only for the non-mutual case: *)
traytel@50518
    41
theorem stream_set_induct1[consumes 1, case_names shd stl, induct set: "stream_set"]:
traytel@50518
    42
  assumes "y \<in> stream_set s" and "\<And>s. P (shd s) s"
traytel@50518
    43
  and "\<And>s y. \<lbrakk>y \<in> stream_set (stl s); P y (stl s)\<rbrakk> \<Longrightarrow> P y s"
traytel@50518
    44
  shows "P y s"
traytel@51141
    45
  using assms stream_set_induct by blast
traytel@50518
    46
(* end TODO *)
traytel@50518
    47
traytel@50518
    48
traytel@50518
    49
subsection {* prepend list to stream *}
traytel@50518
    50
traytel@50518
    51
primrec shift :: "'a list \<Rightarrow> 'a stream \<Rightarrow> 'a stream" (infixr "@-" 65) where
traytel@50518
    52
  "shift [] s = s"
traytel@51023
    53
| "shift (x # xs) s = x ## shift xs s"
traytel@50518
    54
traytel@50518
    55
lemma shift_append[simp]: "(xs @ ys) @- s = xs @- ys @- s"
traytel@51141
    56
  by (induct xs) auto
traytel@50518
    57
traytel@50518
    58
lemma shift_simps[simp]:
traytel@50518
    59
   "shd (xs @- s) = (if xs = [] then shd s else hd xs)"
traytel@50518
    60
   "stl (xs @- s) = (if xs = [] then stl s else tl xs @- s)"
traytel@51141
    61
  by (induct xs) auto
traytel@50518
    62
traytel@51141
    63
lemma stream_set_shift[simp]: "stream_set (xs @- s) = set xs \<union> stream_set s"
traytel@51141
    64
  by (induct xs) auto
traytel@50518
    65
traytel@50518
    66
traytel@51141
    67
subsection {* set of streams with elements in some fixes set *}
traytel@50518
    68
traytel@50518
    69
coinductive_set
traytel@50518
    70
  streams :: "'a set => 'a stream set"
traytel@50518
    71
  for A :: "'a set"
traytel@50518
    72
where
traytel@51023
    73
  Stream[intro!, simp, no_atp]: "\<lbrakk>a \<in> A; s \<in> streams A\<rbrakk> \<Longrightarrow> a ## s \<in> streams A"
traytel@50518
    74
traytel@50518
    75
lemma shift_streams: "\<lbrakk>w \<in> lists A; s \<in> streams A\<rbrakk> \<Longrightarrow> w @- s \<in> streams A"
traytel@51141
    76
  by (induct w) auto
traytel@50518
    77
traytel@50518
    78
lemma stream_set_streams:
traytel@50518
    79
  assumes "stream_set s \<subseteq> A"
traytel@50518
    80
  shows "s \<in> streams A"
traytel@51023
    81
proof (coinduct rule: streams.coinduct[of "\<lambda>s'. \<exists>a s. s' = a ## s \<and> a \<in> A \<and> stream_set s \<subseteq> A"])
traytel@50518
    82
  case streams from assms show ?case by (cases s) auto
traytel@50518
    83
next
traytel@51023
    84
  fix s' assume "\<exists>a s. s' = a ## s \<and> a \<in> A \<and> stream_set s \<subseteq> A"
traytel@50518
    85
  then guess a s by (elim exE)
traytel@51023
    86
  with assms show "\<exists>a l. s' = a ## l \<and>
traytel@51023
    87
    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)"
traytel@50518
    88
    by (cases s) auto
traytel@50518
    89
qed
traytel@50518
    90
traytel@50518
    91
traytel@50518
    92
subsection {* flatten a stream of lists *}
traytel@50518
    93
traytel@50518
    94
definition flat where
traytel@51023
    95
  "flat \<equiv> stream_unfold (hd o shd) (\<lambda>s. if tl (shd s) = [] then stl s else tl (shd s) ## stl s)"
traytel@50518
    96
traytel@50518
    97
lemma flat_simps[simp]:
traytel@50518
    98
  "shd (flat ws) = hd (shd ws)"
traytel@51023
    99
  "stl (flat ws) = flat (if tl (shd ws) = [] then stl ws else tl (shd ws) ## stl ws)"
traytel@51141
   100
  unfolding flat_def by auto
traytel@50518
   101
traytel@51023
   102
lemma flat_Cons[simp]: "flat ((x # xs) ## ws) = x ## flat (if xs = [] then ws else xs ## ws)"
traytel@51141
   103
  unfolding flat_def using stream.unfold[of "hd o shd" _ "(x # xs) ## ws"] by auto
traytel@50518
   104
traytel@51023
   105
lemma flat_Stream[simp]: "xs \<noteq> [] \<Longrightarrow> flat (xs ## ws) = xs @- flat ws"
traytel@51141
   106
  by (induct xs) auto
traytel@50518
   107
traytel@50518
   108
lemma flat_unfold: "shd ws \<noteq> [] \<Longrightarrow> flat ws = shd ws @- flat (stl ws)"
traytel@51141
   109
  by (cases ws) auto
traytel@50518
   110
traytel@50518
   111
traytel@51141
   112
subsection {* nth, take, drop for streams *}
traytel@51141
   113
traytel@51141
   114
primrec snth :: "'a stream \<Rightarrow> nat \<Rightarrow> 'a" (infixl "!!" 100) where
traytel@51141
   115
  "s !! 0 = shd s"
traytel@51141
   116
| "s !! Suc n = stl s !! n"
traytel@51141
   117
traytel@51141
   118
lemma snth_stream_map[simp]: "stream_map f s !! n = f (s !! n)"
traytel@51141
   119
  by (induct n arbitrary: s) auto
traytel@51141
   120
traytel@51141
   121
lemma shift_snth_less[simp]: "p < length xs \<Longrightarrow> (xs @- s) !! p = xs ! p"
traytel@51141
   122
  by (induct p arbitrary: xs) (auto simp: hd_conv_nth nth_tl)
traytel@51141
   123
traytel@51141
   124
lemma shift_snth_ge[simp]: "p \<ge> length xs \<Longrightarrow> (xs @- s) !! p = s !! (p - length xs)"
traytel@51141
   125
  by (induct p arbitrary: xs) (auto simp: Suc_diff_eq_diff_pred)
traytel@51141
   126
traytel@51141
   127
lemma snth_stream_set[simp]: "s !! n \<in> stream_set s"
traytel@51141
   128
  by (induct n arbitrary: s) (auto intro: shd_stream_set stl_stream_set)
traytel@51141
   129
traytel@51141
   130
lemma stream_set_range: "stream_set s = range (snth s)"
traytel@51141
   131
proof (intro equalityI subsetI)
traytel@51141
   132
  fix x assume "x \<in> stream_set s"
traytel@51141
   133
  thus "x \<in> range (snth s)"
traytel@51141
   134
  proof (induct s)
traytel@51141
   135
    case (stl s x)
traytel@51141
   136
    then obtain n where "x = stl s !! n" by auto
traytel@51141
   137
    thus ?case by (auto intro: range_eqI[of _ _ "Suc n"])
traytel@51141
   138
  qed (auto intro: range_eqI[of _ _ 0])
traytel@51141
   139
qed auto
traytel@50518
   140
traytel@50518
   141
primrec stake :: "nat \<Rightarrow> 'a stream \<Rightarrow> 'a list" where
traytel@50518
   142
  "stake 0 s = []"
traytel@50518
   143
| "stake (Suc n) s = shd s # stake n (stl s)"
traytel@50518
   144
traytel@51141
   145
lemma length_stake[simp]: "length (stake n s) = n"
traytel@51141
   146
  by (induct n arbitrary: s) auto
traytel@51141
   147
traytel@51141
   148
lemma stake_stream_map[simp]: "stake n (stream_map f s) = map f (stake n s)"
traytel@51141
   149
  by (induct n arbitrary: s) auto
traytel@51141
   150
traytel@50518
   151
primrec sdrop :: "nat \<Rightarrow> 'a stream \<Rightarrow> 'a stream" where
traytel@50518
   152
  "sdrop 0 s = s"
traytel@50518
   153
| "sdrop (Suc n) s = sdrop n (stl s)"
traytel@50518
   154
traytel@51141
   155
lemma sdrop_simps[simp]:
traytel@51141
   156
  "shd (sdrop n s) = s !! n" "stl (sdrop n s) = sdrop (Suc n) s"
traytel@51141
   157
  by (induct n arbitrary: s)  auto
traytel@51141
   158
traytel@51141
   159
lemma sdrop_stream_map[simp]: "sdrop n (stream_map f s) = stream_map f (sdrop n s)"
traytel@51141
   160
  by (induct n arbitrary: s) auto
traytel@50518
   161
traytel@50518
   162
lemma stake_sdrop: "stake n s @- sdrop n s = s"
traytel@51141
   163
  by (induct n arbitrary: s) auto
traytel@51141
   164
traytel@51141
   165
lemma id_stake_snth_sdrop:
traytel@51141
   166
  "s = stake i s @- s !! i ## sdrop (Suc i) s"
traytel@51141
   167
  by (subst stake_sdrop[symmetric, of _ i]) (metis sdrop_simps stream.collapse)
traytel@50518
   168
traytel@51141
   169
lemma stream_map_alt: "stream_map f s = s' \<longleftrightarrow> (\<forall>n. f (s !! n) = s' !! n)" (is "?L = ?R")
traytel@51141
   170
proof
traytel@51141
   171
  assume ?R
traytel@51141
   172
  thus ?L 
traytel@51141
   173
    by (coinduct rule: stream.coinduct[of "\<lambda>s1 s2. \<exists>n. s1 = stream_map f (sdrop n s) \<and> s2 = sdrop n s'"])
traytel@51141
   174
      (auto intro: exI[of _ 0] simp del: sdrop.simps(2))
traytel@51141
   175
qed auto
traytel@51141
   176
traytel@51141
   177
lemma stake_invert_Nil[iff]: "stake n s = [] \<longleftrightarrow> n = 0"
traytel@51141
   178
  by (induct n) auto
traytel@50518
   179
traytel@50518
   180
lemma sdrop_shift: "\<lbrakk>s = w @- s'; length w = n\<rbrakk> \<Longrightarrow> sdrop n s = s'"
traytel@51141
   181
  by (induct n arbitrary: w s) auto
traytel@50518
   182
traytel@50518
   183
lemma stake_shift: "\<lbrakk>s = w @- s'; length w = n\<rbrakk> \<Longrightarrow> stake n s = w"
traytel@51141
   184
  by (induct n arbitrary: w s) auto
traytel@50518
   185
traytel@50518
   186
lemma stake_add[simp]: "stake m s @ stake n (sdrop m s) = stake (m + n) s"
traytel@51141
   187
  by (induct m arbitrary: s) auto
traytel@50518
   188
traytel@50518
   189
lemma sdrop_add[simp]: "sdrop n (sdrop m s) = sdrop (m + n) s"
traytel@51141
   190
  by (induct m arbitrary: s) auto
traytel@51141
   191
traytel@51141
   192
traytel@51141
   193
subsection {* unary predicates lifted to streams *}
traytel@51141
   194
traytel@51141
   195
definition "stream_all P s = (\<forall>p. P (s !! p))"
traytel@51141
   196
traytel@51141
   197
lemma stream_all_iff[iff]: "stream_all P s \<longleftrightarrow> Ball (stream_set s) P"
traytel@51141
   198
  unfolding stream_all_def stream_set_range by auto
traytel@51141
   199
traytel@51141
   200
lemma stream_all_shift[simp]: "stream_all P (xs @- s) = (list_all P xs \<and> stream_all P s)"
traytel@51141
   201
  unfolding stream_all_iff list_all_iff by auto
traytel@51141
   202
traytel@51141
   203
traytel@51141
   204
subsection {* recurring stream out of a list *}
traytel@51141
   205
traytel@51141
   206
definition cycle :: "'a list \<Rightarrow> 'a stream" where
traytel@51141
   207
  "cycle = stream_unfold hd (\<lambda>xs. tl xs @ [hd xs])"
traytel@51141
   208
traytel@51141
   209
lemma cycle_simps[simp]:
traytel@51141
   210
  "shd (cycle u) = hd u"
traytel@51141
   211
  "stl (cycle u) = cycle (tl u @ [hd u])"
traytel@51141
   212
  by (auto simp: cycle_def)
traytel@51141
   213
traytel@51141
   214
lemma cycle_decomp: "u \<noteq> [] \<Longrightarrow> cycle u = u @- cycle u"
traytel@51141
   215
proof (coinduct rule: stream.coinduct[of "\<lambda>s1 s2. \<exists>u. s1 = cycle u \<and> s2 = u @- cycle u \<and> u \<noteq> []"])
traytel@51141
   216
  case (2 s1 s2)
traytel@51141
   217
  then obtain u where "s1 = cycle u \<and> s2 = u @- cycle u \<and> u \<noteq> []" by blast
traytel@51141
   218
  thus ?case using stream.unfold[of hd "\<lambda>xs. tl xs @ [hd xs]" u] by (auto simp: cycle_def)
traytel@51141
   219
qed auto
traytel@51141
   220
traytel@51141
   221
lemma cycle_Cons: "cycle (x # xs) = x ## cycle (xs @ [x])"
traytel@51141
   222
proof (coinduct rule: stream.coinduct[of "\<lambda>s1 s2. \<exists>x xs. s1 = cycle (x # xs) \<and> s2 = x ## cycle (xs @ [x])"])
traytel@51141
   223
  case (2 s1 s2)
traytel@51141
   224
  then obtain x xs where "s1 = cycle (x # xs) \<and> s2 = x ## cycle (xs @ [x])" by blast
traytel@51141
   225
  thus ?case
traytel@51141
   226
    by (auto simp: cycle_def intro!: exI[of _ "hd (xs @ [x])"] exI[of _ "tl (xs @ [x])"] stream.unfold)
traytel@51141
   227
qed auto
traytel@50518
   228
traytel@50518
   229
lemma cycle_rotated: "\<lbrakk>v \<noteq> []; cycle u = v @- s\<rbrakk> \<Longrightarrow> cycle (tl u @ [hd u]) = tl v @- s"
traytel@51141
   230
  by (auto dest: arg_cong[of _ _ stl])
traytel@50518
   231
traytel@50518
   232
lemma stake_append: "stake n (u @- s) = take (min (length u) n) u @ stake (n - length u) s"
traytel@50518
   233
proof (induct n arbitrary: u)
traytel@50518
   234
  case (Suc n) thus ?case by (cases u) auto
traytel@50518
   235
qed auto
traytel@50518
   236
traytel@50518
   237
lemma stake_cycle_le[simp]:
traytel@50518
   238
  assumes "u \<noteq> []" "n < length u"
traytel@50518
   239
  shows "stake n (cycle u) = take n u"
traytel@50518
   240
using min_absorb2[OF less_imp_le_nat[OF assms(2)]]
traytel@51141
   241
  by (subst cycle_decomp[OF assms(1)], subst stake_append) auto
traytel@50518
   242
traytel@50518
   243
lemma stake_cycle_eq[simp]: "u \<noteq> [] \<Longrightarrow> stake (length u) (cycle u) = u"
traytel@51141
   244
  by (metis cycle_decomp stake_shift)
traytel@50518
   245
traytel@50518
   246
lemma sdrop_cycle_eq[simp]: "u \<noteq> [] \<Longrightarrow> sdrop (length u) (cycle u) = cycle u"
traytel@51141
   247
  by (metis cycle_decomp sdrop_shift)
traytel@50518
   248
traytel@50518
   249
lemma stake_cycle_eq_mod_0[simp]: "\<lbrakk>u \<noteq> []; n mod length u = 0\<rbrakk> \<Longrightarrow>
traytel@50518
   250
   stake n (cycle u) = concat (replicate (n div length u) u)"
traytel@51141
   251
  by (induct "n div length u" arbitrary: n u) (auto simp: stake_add[symmetric])
traytel@50518
   252
traytel@50518
   253
lemma sdrop_cycle_eq_mod_0[simp]: "\<lbrakk>u \<noteq> []; n mod length u = 0\<rbrakk> \<Longrightarrow>
traytel@50518
   254
   sdrop n (cycle u) = cycle u"
traytel@51141
   255
  by (induct "n div length u" arbitrary: n u) (auto simp: sdrop_add[symmetric])
traytel@50518
   256
traytel@50518
   257
lemma stake_cycle: "u \<noteq> [] \<Longrightarrow>
traytel@50518
   258
   stake n (cycle u) = concat (replicate (n div length u) u) @ take (n mod length u) u"
traytel@51141
   259
  by (subst mod_div_equality[of n "length u", symmetric], unfold stake_add[symmetric]) auto
traytel@50518
   260
traytel@50518
   261
lemma sdrop_cycle: "u \<noteq> [] \<Longrightarrow> sdrop n (cycle u) = cycle (rotate (n mod length u) u)"
traytel@51141
   262
  by (induct n arbitrary: u) (auto simp: rotate1_rotate_swap rotate1_hd_tl rotate_conv_mod[symmetric])
traytel@51141
   263
traytel@51141
   264
traytel@51141
   265
subsection {* stream repeating a single element *}
traytel@51141
   266
traytel@51141
   267
definition "same x = stream_unfold (\<lambda>_. x) id ()"
traytel@51141
   268
traytel@51141
   269
lemma same_simps[simp]: "shd (same x) = x" "stl (same x) = same x"
traytel@51141
   270
  unfolding same_def by auto
traytel@51141
   271
traytel@51141
   272
lemma same_unfold: "same x = Stream x (same x)"
traytel@51141
   273
  by (metis same_simps stream.collapse)
traytel@51141
   274
traytel@51141
   275
lemma snth_same[simp]: "same x !! n = x"
traytel@51141
   276
  unfolding same_def by (induct n) auto
traytel@51141
   277
traytel@51141
   278
lemma stake_same[simp]: "stake n (same x) = replicate n x"
traytel@51141
   279
  unfolding same_def by (induct n) (auto simp: upt_rec)
traytel@51141
   280
traytel@51141
   281
lemma sdrop_same[simp]: "sdrop n (same x) = same x"
traytel@51141
   282
  unfolding same_def by (induct n) auto
traytel@51141
   283
traytel@51141
   284
lemma shift_replicate_same[simp]: "replicate n x @- same x = same x"
traytel@51141
   285
  by (metis sdrop_same stake_same stake_sdrop)
traytel@51141
   286
traytel@51141
   287
lemma stream_all_same[simp]: "stream_all P (same x) \<longleftrightarrow> P x"
traytel@51141
   288
  unfolding stream_all_def by auto
traytel@51141
   289
traytel@51141
   290
lemma same_cycle: "same x = cycle [x]"
traytel@51141
   291
  by (coinduct rule: stream.coinduct[of "\<lambda>s1 s2. s1 = same x \<and> s2 = cycle [x]"]) auto
traytel@51141
   292
traytel@51141
   293
traytel@51141
   294
subsection {* stream of natural numbers *}
traytel@51141
   295
traytel@51141
   296
definition "fromN n = stream_unfold id Suc n"
traytel@51141
   297
traytel@51141
   298
lemma fromN_simps[simp]: "shd (fromN n) = n" "stl (fromN n) = fromN (Suc n)"
traytel@51141
   299
  unfolding fromN_def by auto
traytel@51141
   300
traytel@51141
   301
lemma snth_fromN[simp]: "fromN n !! m = n + m"
traytel@51141
   302
  unfolding fromN_def by (induct m arbitrary: n) auto
traytel@51141
   303
traytel@51141
   304
lemma stake_fromN[simp]: "stake m (fromN n) = [n ..< m + n]"
traytel@51141
   305
  unfolding fromN_def by (induct m arbitrary: n) (auto simp: upt_rec)
traytel@51141
   306
traytel@51141
   307
lemma sdrop_fromN[simp]: "sdrop m (fromN n) = fromN (n + m)"
traytel@51141
   308
  unfolding fromN_def by (induct m arbitrary: n) auto
traytel@51141
   309
traytel@51141
   310
abbreviation "nats \<equiv> fromN 0"
traytel@51141
   311
traytel@51141
   312
traytel@51141
   313
subsection {* zip *}
traytel@51141
   314
traytel@51141
   315
definition "szip s1 s2 =
traytel@51141
   316
  stream_unfold (map_pair shd shd) (map_pair stl stl) (s1, s2)"
traytel@51141
   317
traytel@51141
   318
lemma szip_simps[simp]:
traytel@51141
   319
  "shd (szip s1 s2) = (shd s1, shd s2)" "stl (szip s1 s2) = szip (stl s1) (stl s2)"
traytel@51141
   320
  unfolding szip_def by auto
traytel@51141
   321
traytel@51141
   322
lemma snth_szip[simp]: "szip s1 s2 !! n = (s1 !! n, s2 !! n)"
traytel@51141
   323
  by (induct n arbitrary: s1 s2) auto
traytel@51141
   324
traytel@51141
   325
traytel@51141
   326
subsection {* zip via function *}
traytel@51141
   327
traytel@51141
   328
definition "stream_map2 f s1 s2 =
traytel@51141
   329
  stream_unfold (\<lambda>(s1,s2). f (shd s1) (shd s2)) (map_pair stl stl) (s1, s2)"
traytel@51141
   330
traytel@51141
   331
lemma stream_map2_simps[simp]:
traytel@51141
   332
 "shd (stream_map2 f s1 s2) = f (shd s1) (shd s2)"
traytel@51141
   333
 "stl (stream_map2 f s1 s2) = stream_map2 f (stl s1) (stl s2)"
traytel@51141
   334
  unfolding stream_map2_def by auto
traytel@51141
   335
traytel@51141
   336
lemma stream_map2_szip:
traytel@51141
   337
  "stream_map2 f s1 s2 = stream_map (split f) (szip s1 s2)"
traytel@51141
   338
  by (coinduct rule: stream.coinduct[of
traytel@51141
   339
    "\<lambda>s1 s2. \<exists>s1' s2'. s1 = stream_map2 f s1' s2' \<and> s2 = stream_map (split f) (szip s1' s2')"])
traytel@51141
   340
    fastforce+
traytel@50518
   341
traytel@50518
   342
end