src/HOLCF/Library/Stream.thy
author huffman
Tue Oct 12 06:20:05 2010 -0700 (2010-10-12)
changeset 40006 116e94f9543b
parent 40002 c5b5f7a3a3b1
child 40025 876689e6bbdf
permissions -rw-r--r--
remove unneeded lemmas from Fun_Cpo.thy
wenzelm@17291
     1
(*  Title:      HOLCF/ex/Stream.thy
wenzelm@17291
     2
    Author:     Franz Regensburger, David von Oheimb, Borislav Gajanovic
oheimb@2570
     3
*)
oheimb@2570
     4
wenzelm@17291
     5
header {* General Stream domain *}
wenzelm@17291
     6
wenzelm@17291
     7
theory Stream
wenzelm@17291
     8
imports HOLCF Nat_Infinity
wenzelm@17291
     9
begin
oheimb@2570
    10
wenzelm@22808
    11
domain 'a stream = scons (ft::'a) (lazy rt::"'a stream") (infixr "&&" 65)
oheimb@2570
    12
wenzelm@19763
    13
definition
wenzelm@21404
    14
  smap :: "('a \<rightarrow> 'b) \<rightarrow> 'a stream \<rightarrow> 'b stream" where
wenzelm@19763
    15
  "smap = fix\<cdot>(\<Lambda> h f s. case s of x && xs \<Rightarrow> f\<cdot>x && h\<cdot>f\<cdot>xs)"
oheimb@11348
    16
wenzelm@21404
    17
definition
wenzelm@21404
    18
  sfilter :: "('a \<rightarrow> tr) \<rightarrow> 'a stream \<rightarrow> 'a stream" where
wenzelm@19763
    19
  "sfilter = fix\<cdot>(\<Lambda> h p s. case s of x && xs \<Rightarrow>
wenzelm@19763
    20
                                     If p\<cdot>x then x && h\<cdot>p\<cdot>xs else h\<cdot>p\<cdot>xs fi)"
oheimb@11348
    21
wenzelm@21404
    22
definition
wenzelm@21404
    23
  slen :: "'a stream \<Rightarrow> inat"  ("#_" [1000] 1000) where
wenzelm@19763
    24
  "#s = (if stream_finite s then Fin (LEAST n. stream_take n\<cdot>s = s) else \<infinity>)"
wenzelm@19763
    25
oheimb@15188
    26
oheimb@15188
    27
(* concatenation *)
oheimb@15188
    28
wenzelm@19763
    29
definition
wenzelm@21404
    30
  i_rt :: "nat => 'a stream => 'a stream" where (* chops the first i elements *)
wenzelm@19763
    31
  "i_rt = (%i s. iterate i$rt$s)"
wenzelm@17291
    32
wenzelm@21404
    33
definition
wenzelm@21404
    34
  i_th :: "nat => 'a stream => 'a" where (* the i-th element *)
wenzelm@19763
    35
  "i_th = (%i s. ft$(i_rt i s))"
oheimb@15188
    36
wenzelm@21404
    37
definition
wenzelm@21404
    38
  sconc :: "'a stream => 'a stream => 'a stream"  (infixr "ooo" 65) where
wenzelm@19763
    39
  "s1 ooo s2 = (case #s1 of
wenzelm@19763
    40
                  Fin n \<Rightarrow> (SOME s. (stream_take n$s=s1) & (i_rt n s = s2))
wenzelm@19763
    41
               | \<infinity>     \<Rightarrow> s1)"
oheimb@15188
    42
wenzelm@27361
    43
primrec constr_sconc' :: "nat => 'a stream => 'a stream => 'a stream"
wenzelm@27361
    44
where
oheimb@15188
    45
  constr_sconc'_0:   "constr_sconc' 0 s1 s2 = s2"
wenzelm@27361
    46
| constr_sconc'_Suc: "constr_sconc' (Suc n) s1 s2 = ft$s1 &&
oheimb@15188
    47
                                                    constr_sconc' n (rt$s1) s2"
oheimb@15188
    48
wenzelm@19763
    49
definition
wenzelm@21404
    50
  constr_sconc  :: "'a stream => 'a stream => 'a stream" where (* constructive *)
wenzelm@19763
    51
  "constr_sconc s1 s2 = (case #s1 of
wenzelm@19763
    52
                          Fin n \<Rightarrow> constr_sconc' n s1 s2
wenzelm@19763
    53
                        | \<infinity>    \<Rightarrow> s1)"
wenzelm@19763
    54
oheimb@15188
    55
oheimb@15188
    56
(* ----------------------------------------------------------------------- *)
oheimb@15188
    57
(* theorems about scons                                                    *)
oheimb@15188
    58
(* ----------------------------------------------------------------------- *)
oheimb@15188
    59
oheimb@15188
    60
oheimb@15188
    61
section "scons"
oheimb@15188
    62
oheimb@15188
    63
lemma scons_eq_UU: "(a && s = UU) = (a = UU)"
huffman@30913
    64
by simp
oheimb@15188
    65
oheimb@15188
    66
lemma scons_not_empty: "[| a && x = UU; a ~= UU |] ==> R"
huffman@30913
    67
by simp
oheimb@15188
    68
oheimb@15188
    69
lemma stream_exhaust_eq: "(x ~= UU) = (EX a y. a ~= UU &  x = a && y)"
huffman@35781
    70
by (cases x, auto)
oheimb@15188
    71
wenzelm@18109
    72
lemma stream_neq_UU: "x~=UU ==> EX a a_s. x=a&&a_s & a~=UU"
oheimb@15188
    73
by (simp add: stream_exhaust_eq,auto)
oheimb@15188
    74
wenzelm@17291
    75
lemma stream_prefix:
oheimb@15188
    76
  "[| a && s << t; a ~= UU  |] ==> EX b tt. t = b && tt &  b ~= UU &  s << tt"
huffman@35781
    77
by (cases t, auto)
oheimb@15188
    78
wenzelm@17291
    79
lemma stream_prefix':
wenzelm@17291
    80
  "b ~= UU ==> x << b && z =
oheimb@15188
    81
   (x = UU |  (EX a y. x = a && y &  a ~= UU &  a << b &  y << z))"
huffman@35781
    82
by (cases x, auto)
huffman@19550
    83
oheimb@15188
    84
oheimb@15188
    85
(*
oheimb@15188
    86
lemma stream_prefix1: "[| x<<y; xs<<ys |] ==> x&&xs << y&&ys"
oheimb@15188
    87
by (insert stream_prefix' [of y "x&&xs" ys],force)
oheimb@15188
    88
*)
oheimb@15188
    89
wenzelm@17291
    90
lemma stream_flat_prefix:
oheimb@15188
    91
  "[| x && xs << y && ys; (x::'a::flat) ~= UU|] ==> x = y & xs << ys"
oheimb@15188
    92
apply (case_tac "y=UU",auto)
huffman@25920
    93
by (drule ax_flat,simp)
huffman@19550
    94
oheimb@15188
    95
oheimb@15188
    96
oheimb@15188
    97
oheimb@15188
    98
(* ----------------------------------------------------------------------- *)
oheimb@15188
    99
(* theorems about stream_when                                              *)
oheimb@15188
   100
(* ----------------------------------------------------------------------- *)
oheimb@15188
   101
oheimb@15188
   102
section "stream_when"
oheimb@15188
   103
oheimb@15188
   104
oheimb@15188
   105
lemma stream_when_strictf: "stream_when$UU$s=UU"
huffman@35781
   106
by (cases s, auto)
oheimb@15188
   107
oheimb@15188
   108
oheimb@15188
   109
oheimb@15188
   110
(* ----------------------------------------------------------------------- *)
oheimb@15188
   111
(* theorems about ft and rt                                                *)
oheimb@15188
   112
(* ----------------------------------------------------------------------- *)
oheimb@15188
   113
oheimb@15188
   114
oheimb@15188
   115
section "ft & rt"
oheimb@15188
   116
oheimb@15188
   117
oheimb@15188
   118
lemma ft_defin: "s~=UU ==> ft$s~=UU"
huffman@35781
   119
by simp
oheimb@15188
   120
oheimb@15188
   121
lemma rt_strict_rev: "rt$s~=UU ==> s~=UU"
oheimb@15188
   122
by auto
oheimb@15188
   123
oheimb@15188
   124
lemma surjectiv_scons: "(ft$s)&&(rt$s)=s"
huffman@35781
   125
by (cases s, auto)
oheimb@15188
   126
huffman@18075
   127
lemma monofun_rt_mult: "x << s ==> iterate i$rt$x << iterate i$rt$s"
huffman@18075
   128
by (rule monofun_cfun_arg)
oheimb@15188
   129
oheimb@15188
   130
oheimb@15188
   131
oheimb@15188
   132
(* ----------------------------------------------------------------------- *)
oheimb@15188
   133
(* theorems about stream_take                                              *)
oheimb@15188
   134
(* ----------------------------------------------------------------------- *)
oheimb@15188
   135
oheimb@15188
   136
wenzelm@17291
   137
section "stream_take"
oheimb@15188
   138
oheimb@15188
   139
oheimb@15188
   140
lemma stream_reach2: "(LUB i. stream_take i$s) = s"
huffman@35494
   141
by (rule stream.reach)
oheimb@15188
   142
oheimb@15188
   143
lemma chain_stream_take: "chain (%i. stream_take i$s)"
huffman@35781
   144
by simp
oheimb@15188
   145
oheimb@15188
   146
lemma stream_take_prefix [simp]: "stream_take n$s << s"
oheimb@15188
   147
apply (insert stream_reach2 [of s])
oheimb@15188
   148
apply (erule subst) back
oheimb@15188
   149
apply (rule is_ub_thelub)
oheimb@15188
   150
by (simp only: chain_stream_take)
oheimb@15188
   151
wenzelm@17291
   152
lemma stream_take_more [rule_format]:
oheimb@15188
   153
  "ALL x. stream_take n$x = x --> stream_take (Suc n)$x = x"
oheimb@15188
   154
apply (induct_tac n,auto)
oheimb@15188
   155
apply (case_tac "x=UU",auto)
oheimb@15188
   156
by (drule stream_exhaust_eq [THEN iffD1],auto)
oheimb@15188
   157
wenzelm@17291
   158
lemma stream_take_lemma3 [rule_format]:
oheimb@15188
   159
  "ALL x xs. x~=UU --> stream_take n$(x && xs) = x && xs --> stream_take n$xs=xs"
oheimb@15188
   160
apply (induct_tac n,clarsimp)
huffman@16745
   161
(*apply (drule sym, erule scons_not_empty, simp)*)
oheimb@15188
   162
apply (clarify, rule stream_take_more)
oheimb@15188
   163
apply (erule_tac x="x" in allE)
oheimb@15188
   164
by (erule_tac x="xs" in allE,simp)
oheimb@15188
   165
wenzelm@17291
   166
lemma stream_take_lemma4:
oheimb@15188
   167
  "ALL x xs. stream_take n$xs=xs --> stream_take (Suc n)$(x && xs) = x && xs"
oheimb@15188
   168
by auto
oheimb@15188
   169
wenzelm@17291
   170
lemma stream_take_idempotent [rule_format, simp]:
oheimb@15188
   171
 "ALL s. stream_take n$(stream_take n$s) = stream_take n$s"
oheimb@15188
   172
apply (induct_tac n, auto)
oheimb@15188
   173
apply (case_tac "s=UU", auto)
oheimb@15188
   174
by (drule stream_exhaust_eq [THEN iffD1], auto)
oheimb@15188
   175
wenzelm@17291
   176
lemma stream_take_take_Suc [rule_format, simp]:
wenzelm@17291
   177
  "ALL s. stream_take n$(stream_take (Suc n)$s) =
oheimb@15188
   178
                                    stream_take n$s"
oheimb@15188
   179
apply (induct_tac n, auto)
oheimb@15188
   180
apply (case_tac "s=UU", auto)
oheimb@15188
   181
by (drule stream_exhaust_eq [THEN iffD1], auto)
oheimb@15188
   182
wenzelm@17291
   183
lemma mono_stream_take_pred:
oheimb@15188
   184
  "stream_take (Suc n)$s1 << stream_take (Suc n)$s2 ==>
oheimb@15188
   185
                       stream_take n$s1 << stream_take n$s2"
wenzelm@17291
   186
by (insert monofun_cfun_arg [of "stream_take (Suc n)$s1"
oheimb@15188
   187
  "stream_take (Suc n)$s2" "stream_take n"], auto)
oheimb@15188
   188
(*
wenzelm@17291
   189
lemma mono_stream_take_pred:
oheimb@15188
   190
  "stream_take (Suc n)$s1 << stream_take (Suc n)$s2 ==>
oheimb@15188
   191
                       stream_take n$s1 << stream_take n$s2"
oheimb@15188
   192
by (drule mono_stream_take [of _ _ n],simp)
oheimb@15188
   193
*)
oheimb@15188
   194
oheimb@15188
   195
lemma stream_take_lemma10 [rule_format]:
wenzelm@17291
   196
  "ALL k<=n. stream_take n$s1 << stream_take n$s2
oheimb@15188
   197
                             --> stream_take k$s1 << stream_take k$s2"
oheimb@15188
   198
apply (induct_tac n,simp,clarsimp)
oheimb@15188
   199
apply (case_tac "k=Suc n",blast)
oheimb@15188
   200
apply (erule_tac x="k" in allE)
oheimb@15188
   201
by (drule mono_stream_take_pred,simp)
oheimb@15188
   202
oheimb@15188
   203
lemma stream_take_le_mono : "k<=n ==> stream_take k$s1 << stream_take n$s1"
oheimb@15188
   204
apply (insert chain_stream_take [of s1])
huffman@25922
   205
by (drule chain_mono,auto)
oheimb@15188
   206
oheimb@15188
   207
lemma mono_stream_take: "s1 << s2 ==> stream_take n$s1 << stream_take n$s2"
oheimb@15188
   208
by (simp add: monofun_cfun_arg)
oheimb@15188
   209
oheimb@15188
   210
(*
oheimb@15188
   211
lemma stream_take_prefix [simp]: "stream_take n$s << s"
oheimb@15188
   212
apply (subgoal_tac "s=(LUB n. stream_take n$s)")
oheimb@15188
   213
 apply (erule ssubst, rule is_ub_thelub)
oheimb@15188
   214
 apply (simp only: chain_stream_take)
oheimb@15188
   215
by (simp only: stream_reach2)
oheimb@15188
   216
*)
oheimb@15188
   217
oheimb@15188
   218
lemma stream_take_take_less:"stream_take k$(stream_take n$s) << stream_take k$s"
oheimb@15188
   219
by (rule monofun_cfun_arg,auto)
oheimb@15188
   220
oheimb@15188
   221
oheimb@15188
   222
(* ------------------------------------------------------------------------- *)
oheimb@15188
   223
(* special induction rules                                                   *)
oheimb@15188
   224
(* ------------------------------------------------------------------------- *)
oheimb@15188
   225
oheimb@15188
   226
oheimb@15188
   227
section "induction"
oheimb@15188
   228
wenzelm@17291
   229
lemma stream_finite_ind:
oheimb@15188
   230
 "[| stream_finite x; P UU; !!a s. [| a ~= UU; P s |] ==> P (a && s) |] ==> P x"
oheimb@15188
   231
apply (simp add: stream.finite_def,auto)
oheimb@15188
   232
apply (erule subst)
huffman@35781
   233
by (drule stream.finite_induct [of P _ x], auto)
oheimb@15188
   234
wenzelm@17291
   235
lemma stream_finite_ind2:
wenzelm@17291
   236
"[| P UU; !! x. x ~= UU ==> P (x && UU); !! y z s. [| y ~= UU; z ~= UU; P s |] ==> P (y && z && s )|] ==>
oheimb@15188
   237
                                 !s. P (stream_take n$s)"
paulson@29855
   238
apply (rule nat_less_induct [of _ n],auto)
paulson@29855
   239
apply (case_tac n, auto) 
paulson@29855
   240
apply (case_tac nat, auto) 
oheimb@15188
   241
apply (case_tac "s=UU",clarsimp)
oheimb@15188
   242
apply (drule stream_exhaust_eq [THEN iffD1],clarsimp)
oheimb@15188
   243
apply (case_tac "s=UU",clarsimp)
oheimb@15188
   244
apply (drule stream_exhaust_eq [THEN iffD1],clarsimp)
oheimb@15188
   245
apply (case_tac "y=UU",clarsimp)
oheimb@15188
   246
by (drule stream_exhaust_eq [THEN iffD1],clarsimp)
oheimb@15188
   247
wenzelm@17291
   248
lemma stream_ind2:
oheimb@15188
   249
"[| adm P; P UU; !!a. a ~= UU ==> P (a && UU); !!a b s. [| a ~= UU; b ~= UU; P s |] ==> P (a && b && s) |] ==> P x"
oheimb@15188
   250
apply (insert stream.reach [of x],erule subst)
huffman@35494
   251
apply (erule admD, rule chain_stream_take)
oheimb@15188
   252
apply (insert stream_finite_ind2 [of P])
huffman@35494
   253
by simp
oheimb@15188
   254
oheimb@15188
   255
oheimb@15188
   256
oheimb@15188
   257
(* ----------------------------------------------------------------------- *)
oheimb@15188
   258
(* simplify use of coinduction                                             *)
oheimb@15188
   259
(* ----------------------------------------------------------------------- *)
oheimb@15188
   260
oheimb@15188
   261
oheimb@15188
   262
section "coinduction"
oheimb@15188
   263
oheimb@15188
   264
lemma stream_coind_lemma2: "!s1 s2. R s1 s2 --> ft$s1 = ft$s2 &  R (rt$s1) (rt$s2) ==> stream_bisim R"
huffman@30807
   265
 apply (simp add: stream.bisim_def,clarsimp)
huffman@35497
   266
 apply (drule spec, drule spec, drule (1) mp)
huffman@35497
   267
 apply (case_tac "x", simp)
huffman@35497
   268
 apply (case_tac "x'", simp)
oheimb@15188
   269
by auto
oheimb@15188
   270
oheimb@15188
   271
oheimb@15188
   272
oheimb@15188
   273
(* ----------------------------------------------------------------------- *)
oheimb@15188
   274
(* theorems about stream_finite                                            *)
oheimb@15188
   275
(* ----------------------------------------------------------------------- *)
oheimb@15188
   276
oheimb@15188
   277
oheimb@15188
   278
section "stream_finite"
oheimb@15188
   279
oheimb@15188
   280
lemma stream_finite_UU [simp]: "stream_finite UU"
oheimb@15188
   281
by (simp add: stream.finite_def)
oheimb@15188
   282
oheimb@15188
   283
lemma stream_finite_UU_rev: "~  stream_finite s ==> s ~= UU"
oheimb@15188
   284
by (auto simp add: stream.finite_def)
oheimb@15188
   285
oheimb@15188
   286
lemma stream_finite_lemma1: "stream_finite xs ==> stream_finite (x && xs)"
oheimb@15188
   287
apply (simp add: stream.finite_def,auto)
huffman@35557
   288
apply (rule_tac x="Suc n" in exI)
oheimb@15188
   289
by (simp add: stream_take_lemma4)
oheimb@15188
   290
oheimb@15188
   291
lemma stream_finite_lemma2: "[| x ~= UU; stream_finite (x && xs) |] ==> stream_finite xs"
oheimb@15188
   292
apply (simp add: stream.finite_def, auto)
huffman@35557
   293
apply (rule_tac x="n" in exI)
oheimb@15188
   294
by (erule stream_take_lemma3,simp)
oheimb@15188
   295
oheimb@15188
   296
lemma stream_finite_rt_eq: "stream_finite (rt$s) = stream_finite s"
huffman@35781
   297
apply (cases s, auto)
oheimb@15188
   298
apply (rule stream_finite_lemma1, simp)
oheimb@15188
   299
by (rule stream_finite_lemma2,simp)
oheimb@15188
   300
oheimb@15188
   301
lemma stream_finite_less: "stream_finite s ==> !t. t<<s --> stream_finite t"
huffman@19440
   302
apply (erule stream_finite_ind [of s], auto)
oheimb@15188
   303
apply (case_tac "t=UU", auto)
oheimb@15188
   304
apply (drule stream_exhaust_eq [THEN iffD1],auto)
oheimb@15188
   305
apply (erule_tac x="y" in allE, simp)
oheimb@15188
   306
by (rule stream_finite_lemma1, simp)
oheimb@15188
   307
oheimb@15188
   308
lemma stream_take_finite [simp]: "stream_finite (stream_take n$s)"
oheimb@15188
   309
apply (simp add: stream.finite_def)
oheimb@15188
   310
by (rule_tac x="n" in exI,simp)
oheimb@15188
   311
oheimb@15188
   312
lemma adm_not_stream_finite: "adm (%x. ~ stream_finite x)"
huffman@25833
   313
apply (rule adm_upward)
huffman@25833
   314
apply (erule contrapos_nn)
huffman@25833
   315
apply (erule (1) stream_finite_less [rule_format])
huffman@25833
   316
done
oheimb@15188
   317
oheimb@15188
   318
oheimb@15188
   319
oheimb@15188
   320
(* ----------------------------------------------------------------------- *)
oheimb@15188
   321
(* theorems about stream length                                            *)
oheimb@15188
   322
(* ----------------------------------------------------------------------- *)
oheimb@15188
   323
oheimb@15188
   324
oheimb@15188
   325
section "slen"
oheimb@15188
   326
oheimb@15188
   327
lemma slen_empty [simp]: "#\<bottom> = 0"
haftmann@27111
   328
by (simp add: slen_def stream.finite_def zero_inat_def Least_equality)
oheimb@15188
   329
oheimb@15188
   330
lemma slen_scons [simp]: "x ~= \<bottom> ==> #(x&&xs) = iSuc (#xs)"
oheimb@15188
   331
apply (case_tac "stream_finite (x && xs)")
oheimb@15188
   332
apply (simp add: slen_def, auto)
haftmann@27111
   333
apply (simp add: stream.finite_def, auto simp add: iSuc_Fin)
haftmann@27111
   334
apply (rule Least_Suc2, auto)
huffman@16745
   335
(*apply (drule sym)*)
huffman@16745
   336
(*apply (drule sym scons_eq_UU [THEN iffD1],simp)*)
oheimb@15188
   337
apply (erule stream_finite_lemma2, simp)
oheimb@15188
   338
apply (simp add: slen_def, auto)
oheimb@15188
   339
by (drule stream_finite_lemma1,auto)
oheimb@15188
   340
oheimb@15188
   341
lemma slen_less_1_eq: "(#x < Fin (Suc 0)) = (x = \<bottom>)"
huffman@35781
   342
by (cases x, auto simp add: Fin_0 iSuc_Fin[THEN sym])
oheimb@15188
   343
oheimb@15188
   344
lemma slen_empty_eq: "(#x = 0) = (x = \<bottom>)"
huffman@35781
   345
by (cases x, auto)
oheimb@15188
   346
oheimb@15188
   347
lemma slen_scons_eq: "(Fin (Suc n) < #x) = (? a y. x = a && y &  a ~= \<bottom> &  Fin n < #y)"
oheimb@15188
   348
apply (auto, case_tac "x=UU",auto)
oheimb@15188
   349
apply (drule stream_exhaust_eq [THEN iffD1], auto)
haftmann@27111
   350
apply (case_tac "#y") apply simp_all
haftmann@27111
   351
apply (case_tac "#y") apply simp_all
haftmann@27111
   352
done
oheimb@15188
   353
oheimb@15188
   354
lemma slen_iSuc: "#x = iSuc n --> (? a y. x = a&&y &  a ~= \<bottom> &  #y = n)"
huffman@35781
   355
by (cases x, auto)
oheimb@15188
   356
oheimb@15188
   357
lemma slen_stream_take_finite [simp]: "#(stream_take n$s) ~= \<infinity>"
oheimb@15188
   358
by (simp add: slen_def)
oheimb@15188
   359
oheimb@15188
   360
lemma slen_scons_eq_rev: "(#x < Fin (Suc (Suc n))) = (!a y. x ~= a && y |  a = \<bottom> |  #y < Fin (Suc n))"
huffman@35781
   361
 apply (cases x, auto)
huffman@30807
   362
   apply (simp add: zero_inat_def)
huffman@35443
   363
  apply (case_tac "#stream") apply (simp_all add: iSuc_Fin)
huffman@35443
   364
 apply (case_tac "#stream") apply (simp_all add: iSuc_Fin)
haftmann@27111
   365
done
oheimb@15188
   366
wenzelm@17291
   367
lemma slen_take_lemma4 [rule_format]:
oheimb@15188
   368
  "!s. stream_take n$s ~= s --> #(stream_take n$s) = Fin n"
haftmann@27111
   369
apply (induct n, auto simp add: Fin_0)
haftmann@27111
   370
apply (case_tac "s=UU", simp)
haftmann@27111
   371
by (drule stream_exhaust_eq [THEN iffD1], auto simp add: iSuc_Fin)
oheimb@15188
   372
oheimb@15188
   373
(*
wenzelm@17291
   374
lemma stream_take_idempotent [simp]:
oheimb@15188
   375
 "stream_take n$(stream_take n$s) = stream_take n$s"
oheimb@15188
   376
apply (case_tac "stream_take n$s = s")
oheimb@15188
   377
apply (auto,insert slen_take_lemma4 [of n s]);
oheimb@15188
   378
by (auto,insert slen_take_lemma1 [of "stream_take n$s" n],simp)
oheimb@15188
   379
wenzelm@17291
   380
lemma stream_take_take_Suc [simp]: "stream_take n$(stream_take (Suc n)$s) =
oheimb@15188
   381
                                    stream_take n$s"
oheimb@15188
   382
apply (simp add: po_eq_conv,auto)
oheimb@15188
   383
 apply (simp add: stream_take_take_less)
oheimb@15188
   384
apply (subgoal_tac "stream_take n$s = stream_take n$(stream_take n$s)")
oheimb@15188
   385
 apply (erule ssubst)
oheimb@15188
   386
 apply (rule_tac monofun_cfun_arg)
oheimb@15188
   387
 apply (insert chain_stream_take [of s])
oheimb@15188
   388
by (simp add: chain_def,simp)
oheimb@15188
   389
*)
oheimb@15188
   390
oheimb@15188
   391
lemma slen_take_eq: "ALL x. (Fin n < #x) = (stream_take n\<cdot>x ~= x)"
oheimb@15188
   392
apply (induct_tac n, auto)
oheimb@15188
   393
apply (simp add: Fin_0, clarsimp)
oheimb@15188
   394
apply (drule not_sym)
oheimb@15188
   395
apply (drule slen_empty_eq [THEN iffD1], simp)
oheimb@15188
   396
apply (case_tac "x=UU", simp)
oheimb@15188
   397
apply (drule stream_exhaust_eq [THEN iffD1], clarsimp)
oheimb@15188
   398
apply (erule_tac x="y" in allE, auto)
haftmann@27111
   399
apply (simp_all add: not_less iSuc_Fin)
haftmann@27111
   400
apply (case_tac "#y") apply simp_all
oheimb@15188
   401
apply (case_tac "x=UU", simp)
oheimb@15188
   402
apply (drule stream_exhaust_eq [THEN iffD1], clarsimp)
oheimb@15188
   403
apply (erule_tac x="y" in allE, simp)
haftmann@27111
   404
apply (case_tac "#y") by simp_all
oheimb@15188
   405
oheimb@15188
   406
lemma slen_take_eq_rev: "(#x <= Fin n) = (stream_take n\<cdot>x = x)"
huffman@26102
   407
by (simp add: linorder_not_less [symmetric] slen_take_eq)
oheimb@15188
   408
oheimb@15188
   409
lemma slen_take_lemma1: "#x = Fin n ==> stream_take n\<cdot>x = x"
oheimb@15188
   410
by (rule slen_take_eq_rev [THEN iffD1], auto)
oheimb@15188
   411
oheimb@15188
   412
lemma slen_rt_mono: "#s2 <= #s1 ==> #(rt$s2) <= #(rt$s1)"
huffman@35781
   413
apply (cases s1)
huffman@35781
   414
 by (cases s2, simp+)+
oheimb@15188
   415
wenzelm@17291
   416
lemma slen_take_lemma5: "#(stream_take n$s) <= Fin n"
oheimb@15188
   417
apply (case_tac "stream_take n$s = s")
oheimb@15188
   418
 apply (simp add: slen_take_eq_rev)
oheimb@15188
   419
by (simp add: slen_take_lemma4)
oheimb@15188
   420
oheimb@15188
   421
lemma slen_take_lemma2: "!x. ~stream_finite x --> #(stream_take i\<cdot>x) = Fin i"
oheimb@15188
   422
apply (simp add: stream.finite_def, auto)
oheimb@15188
   423
by (simp add: slen_take_lemma4)
oheimb@15188
   424
oheimb@15188
   425
lemma slen_infinite: "stream_finite x = (#x ~= Infty)"
oheimb@15188
   426
by (simp add: slen_def)
oheimb@15188
   427
oheimb@15188
   428
lemma slen_mono_lemma: "stream_finite s ==> ALL t. s << t --> #s <= #t"
oheimb@15188
   429
apply (erule stream_finite_ind [of s], auto)
oheimb@15188
   430
apply (case_tac "t=UU", auto)
oheimb@15188
   431
apply (drule stream_exhaust_eq [THEN iffD1], auto)
huffman@30807
   432
done
oheimb@15188
   433
oheimb@15188
   434
lemma slen_mono: "s << t ==> #s <= #t"
oheimb@15188
   435
apply (case_tac "stream_finite t")
wenzelm@17291
   436
apply (frule stream_finite_less)
oheimb@15188
   437
apply (erule_tac x="s" in allE, simp)
oheimb@15188
   438
apply (drule slen_mono_lemma, auto)
oheimb@15188
   439
by (simp add: slen_def)
oheimb@15188
   440
huffman@18075
   441
lemma iterate_lemma: "F$(iterate n$F$x) = iterate n$F$(F$x)"
oheimb@15188
   442
by (insert iterate_Suc2 [of n F x], auto)
oheimb@15188
   443
huffman@18075
   444
lemma slen_rt_mult [rule_format]: "!x. Fin (i + j) <= #x --> Fin j <= #(iterate i$rt$x)"
haftmann@27111
   445
apply (induct i, auto)
haftmann@27111
   446
apply (case_tac "x=UU", auto simp add: zero_inat_def)
oheimb@15188
   447
apply (drule stream_exhaust_eq [THEN iffD1], auto)
oheimb@15188
   448
apply (erule_tac x="y" in allE, auto)
haftmann@27111
   449
apply (simp add: not_le) apply (case_tac "#y") apply (simp_all add: iSuc_Fin)
oheimb@15188
   450
by (simp add: iterate_lemma)
oheimb@15188
   451
wenzelm@17291
   452
lemma slen_take_lemma3 [rule_format]:
oheimb@15188
   453
  "!(x::'a::flat stream) y. Fin n <= #x --> x << y --> stream_take n\<cdot>x = stream_take n\<cdot>y"
oheimb@15188
   454
apply (induct_tac n, auto)
oheimb@15188
   455
apply (case_tac "x=UU", auto)
haftmann@27111
   456
apply (simp add: zero_inat_def)
oheimb@15188
   457
apply (simp add: Suc_ile_eq)
oheimb@15188
   458
apply (case_tac "y=UU", clarsimp)
oheimb@15188
   459
apply (drule stream_exhaust_eq [THEN iffD1], clarsimp)+
oheimb@15188
   460
apply (erule_tac x="ya" in allE, simp)
huffman@25920
   461
by (drule ax_flat, simp)
oheimb@15188
   462
wenzelm@17291
   463
lemma slen_strict_mono_lemma:
oheimb@15188
   464
  "stream_finite t ==> !s. #(s::'a::flat stream) = #t &  s << t --> s = t"
oheimb@15188
   465
apply (erule stream_finite_ind, auto)
oheimb@15188
   466
apply (case_tac "sa=UU", auto)
oheimb@15188
   467
apply (drule stream_exhaust_eq [THEN iffD1], clarsimp)
huffman@25920
   468
by (drule ax_flat, simp)
oheimb@15188
   469
oheimb@15188
   470
lemma slen_strict_mono: "[|stream_finite t; s ~= t; s << (t::'a::flat stream) |] ==> #s < #t"
haftmann@27111
   471
by (auto simp add: slen_mono less_le dest: slen_strict_mono_lemma)
oheimb@15188
   472
wenzelm@17291
   473
lemma stream_take_Suc_neq: "stream_take (Suc n)$s ~=s ==>
oheimb@15188
   474
                     stream_take n$s ~= stream_take (Suc n)$s"
oheimb@15188
   475
apply auto
oheimb@15188
   476
apply (subgoal_tac "stream_take n$s ~=s")
oheimb@15188
   477
 apply (insert slen_take_lemma4 [of n s],auto)
huffman@35781
   478
apply (cases s, simp)
haftmann@27111
   479
by (simp add: slen_take_lemma4 iSuc_Fin)
oheimb@15188
   480
oheimb@15188
   481
(* ----------------------------------------------------------------------- *)
oheimb@15188
   482
(* theorems about smap                                                     *)
oheimb@15188
   483
(* ----------------------------------------------------------------------- *)
oheimb@15188
   484
oheimb@15188
   485
oheimb@15188
   486
section "smap"
oheimb@15188
   487
oheimb@15188
   488
lemma smap_unfold: "smap = (\<Lambda> f t. case t of x&&xs \<Rightarrow> f$x && smap$f$xs)"
huffman@29530
   489
by (insert smap_def [where 'a='a and 'b='b, THEN eq_reflection, THEN fix_eq2], auto)
oheimb@15188
   490
oheimb@15188
   491
lemma smap_empty [simp]: "smap\<cdot>f\<cdot>\<bottom> = \<bottom>"
oheimb@15188
   492
by (subst smap_unfold, simp)
oheimb@15188
   493
oheimb@15188
   494
lemma smap_scons [simp]: "x~=\<bottom> ==> smap\<cdot>f\<cdot>(x&&xs) = (f\<cdot>x)&&(smap\<cdot>f\<cdot>xs)"
oheimb@15188
   495
by (subst smap_unfold, force)
oheimb@15188
   496
oheimb@15188
   497
oheimb@15188
   498
oheimb@15188
   499
(* ----------------------------------------------------------------------- *)
oheimb@15188
   500
(* theorems about sfilter                                                  *)
oheimb@15188
   501
(* ----------------------------------------------------------------------- *)
oheimb@15188
   502
oheimb@15188
   503
section "sfilter"
oheimb@15188
   504
wenzelm@17291
   505
lemma sfilter_unfold:
oheimb@15188
   506
 "sfilter = (\<Lambda> p s. case s of x && xs \<Rightarrow>
oheimb@15188
   507
  If p\<cdot>x then x && sfilter\<cdot>p\<cdot>xs else sfilter\<cdot>p\<cdot>xs fi)"
huffman@29530
   508
by (insert sfilter_def [where 'a='a, THEN eq_reflection, THEN fix_eq2], auto)
oheimb@15188
   509
oheimb@15188
   510
lemma strict_sfilter: "sfilter\<cdot>\<bottom> = \<bottom>"
huffman@40002
   511
apply (rule cfun_eqI)
oheimb@15188
   512
apply (subst sfilter_unfold, auto)
oheimb@15188
   513
apply (case_tac "x=UU", auto)
oheimb@15188
   514
by (drule stream_exhaust_eq [THEN iffD1], auto)
oheimb@15188
   515
oheimb@15188
   516
lemma sfilter_empty [simp]: "sfilter\<cdot>f\<cdot>\<bottom> = \<bottom>"
oheimb@15188
   517
by (subst sfilter_unfold, force)
oheimb@15188
   518
wenzelm@17291
   519
lemma sfilter_scons [simp]:
wenzelm@17291
   520
  "x ~= \<bottom> ==> sfilter\<cdot>f\<cdot>(x && xs) =
wenzelm@17291
   521
                           If f\<cdot>x then x && sfilter\<cdot>f\<cdot>xs else sfilter\<cdot>f\<cdot>xs fi"
oheimb@15188
   522
by (subst sfilter_unfold, force)
oheimb@15188
   523
oheimb@15188
   524
oheimb@15188
   525
(* ----------------------------------------------------------------------- *)
oheimb@15188
   526
   section "i_rt"
oheimb@15188
   527
(* ----------------------------------------------------------------------- *)
oheimb@15188
   528
oheimb@15188
   529
lemma i_rt_UU [simp]: "i_rt n UU = UU"
haftmann@34941
   530
  by (induct n) (simp_all add: i_rt_def)
oheimb@15188
   531
oheimb@15188
   532
lemma i_rt_0 [simp]: "i_rt 0 s = s"
oheimb@15188
   533
by (simp add: i_rt_def)
oheimb@15188
   534
oheimb@15188
   535
lemma i_rt_Suc [simp]: "a ~= UU ==> i_rt (Suc n) (a&&s) = i_rt n s"
oheimb@15188
   536
by (simp add: i_rt_def iterate_Suc2 del: iterate_Suc)
oheimb@15188
   537
oheimb@15188
   538
lemma i_rt_Suc_forw: "i_rt (Suc n) s = i_rt n (rt$s)"
oheimb@15188
   539
by (simp only: i_rt_def iterate_Suc2)
oheimb@15188
   540
oheimb@15188
   541
lemma i_rt_Suc_back:"i_rt (Suc n) s = rt$(i_rt n s)"
oheimb@15188
   542
by (simp only: i_rt_def,auto)
oheimb@15188
   543
oheimb@15188
   544
lemma i_rt_mono: "x << s ==> i_rt n x  << i_rt n s"
oheimb@15188
   545
by (simp add: i_rt_def monofun_rt_mult)
oheimb@15188
   546
oheimb@15188
   547
lemma i_rt_ij_lemma: "Fin (i + j) <= #x ==> Fin j <= #(i_rt i x)"
oheimb@15188
   548
by (simp add: i_rt_def slen_rt_mult)
oheimb@15188
   549
oheimb@15188
   550
lemma slen_i_rt_mono: "#s2 <= #s1 ==> #(i_rt n s2) <= #(i_rt n s1)"
oheimb@15188
   551
apply (induct_tac n,auto)
oheimb@15188
   552
apply (simp add: i_rt_Suc_back)
oheimb@15188
   553
by (drule slen_rt_mono,simp)
oheimb@15188
   554
oheimb@15188
   555
lemma i_rt_take_lemma1 [rule_format]: "ALL s. i_rt n (stream_take n$s) = UU"
wenzelm@17291
   556
apply (induct_tac n)
oheimb@15188
   557
 apply (simp add: i_rt_Suc_back,auto)
oheimb@15188
   558
apply (case_tac "s=UU",auto)
oheimb@15188
   559
by (drule stream_exhaust_eq [THEN iffD1],auto)
oheimb@15188
   560
oheimb@15188
   561
lemma i_rt_slen: "(i_rt n s = UU) = (stream_take n$s = s)"
oheimb@15188
   562
apply auto
wenzelm@17291
   563
 apply (insert i_rt_ij_lemma [of n "Suc 0" s])
oheimb@15188
   564
 apply (subgoal_tac "#(i_rt n s)=0")
oheimb@15188
   565
  apply (case_tac "stream_take n$s = s",simp+)
oheimb@15188
   566
  apply (insert slen_take_eq [rule_format,of n s],simp)
haftmann@27111
   567
  apply (cases "#s") apply (simp_all add: zero_inat_def)
haftmann@27111
   568
  apply (simp add: slen_take_eq)
haftmann@27111
   569
  apply (cases "#s")
haftmann@27111
   570
  using i_rt_take_lemma1 [of n s]
haftmann@27111
   571
  apply (simp_all add: zero_inat_def)
haftmann@27111
   572
  done
oheimb@15188
   573
oheimb@15188
   574
lemma i_rt_lemma_slen: "#s=Fin n ==> i_rt n s = UU"
oheimb@15188
   575
by (simp add: i_rt_slen slen_take_lemma1)
oheimb@15188
   576
oheimb@15188
   577
lemma stream_finite_i_rt [simp]: "stream_finite (i_rt n s) = stream_finite s"
oheimb@15188
   578
apply (induct_tac n, auto)
huffman@35781
   579
 apply (cases s, auto simp del: i_rt_Suc)
oheimb@15188
   580
by (simp add: i_rt_Suc_back stream_finite_rt_eq)+
oheimb@15188
   581
oheimb@15188
   582
lemma take_i_rt_len_lemma: "ALL sl x j t. Fin sl = #x & n <= sl &
wenzelm@17291
   583
                            #(stream_take n$x) = Fin t & #(i_rt n x)= Fin j
oheimb@15188
   584
                                              --> Fin (j + t) = #x"
haftmann@27111
   585
apply (induct n, auto)
haftmann@27111
   586
 apply (simp add: zero_inat_def)
oheimb@15188
   587
apply (case_tac "x=UU",auto)
haftmann@27111
   588
 apply (simp add: zero_inat_def)
oheimb@15188
   589
apply (drule stream_exhaust_eq [THEN iffD1],clarsimp)
oheimb@15188
   590
apply (subgoal_tac "EX k. Fin k = #y",clarify)
oheimb@15188
   591
 apply (erule_tac x="k" in allE)
oheimb@15188
   592
 apply (erule_tac x="y" in allE,auto)
oheimb@15188
   593
 apply (erule_tac x="THE p. Suc p = t" in allE,auto)
haftmann@27111
   594
   apply (simp add: iSuc_def split: inat.splits)
haftmann@27111
   595
  apply (simp add: iSuc_def split: inat.splits)
oheimb@15188
   596
  apply (simp only: the_equality)
haftmann@27111
   597
 apply (simp add: iSuc_def split: inat.splits)
oheimb@15188
   598
 apply force
haftmann@27111
   599
apply (simp add: iSuc_def split: inat.splits)
haftmann@27111
   600
done
oheimb@15188
   601
wenzelm@17291
   602
lemma take_i_rt_len:
oheimb@15188
   603
"[| Fin sl = #x; n <= sl; #(stream_take n$x) = Fin t; #(i_rt n x) = Fin j |] ==>
oheimb@15188
   604
    Fin (j + t) = #x"
oheimb@15188
   605
by (blast intro: take_i_rt_len_lemma [rule_format])
oheimb@15188
   606
oheimb@15188
   607
oheimb@15188
   608
(* ----------------------------------------------------------------------- *)
oheimb@15188
   609
   section "i_th"
oheimb@15188
   610
(* ----------------------------------------------------------------------- *)
oheimb@15188
   611
oheimb@15188
   612
lemma i_th_i_rt_step:
wenzelm@17291
   613
"[| i_th n s1 << i_th n s2; i_rt (Suc n) s1 << i_rt (Suc n) s2 |] ==>
oheimb@15188
   614
   i_rt n s1 << i_rt n s2"
oheimb@15188
   615
apply (simp add: i_th_def i_rt_Suc_back)
huffman@35781
   616
apply (cases "i_rt n s1", simp)
huffman@35781
   617
apply (cases "i_rt n s2", auto)
huffman@30807
   618
done
oheimb@15188
   619
wenzelm@17291
   620
lemma i_th_stream_take_Suc [rule_format]:
oheimb@15188
   621
 "ALL s. i_th n (stream_take (Suc n)$s) = i_th n s"
oheimb@15188
   622
apply (induct_tac n,auto)
oheimb@15188
   623
 apply (simp add: i_th_def)
oheimb@15188
   624
 apply (case_tac "s=UU",auto)
oheimb@15188
   625
 apply (drule stream_exhaust_eq [THEN iffD1],auto)
oheimb@15188
   626
apply (case_tac "s=UU",simp add: i_th_def)
oheimb@15188
   627
apply (drule stream_exhaust_eq [THEN iffD1],auto)
oheimb@15188
   628
by (simp add: i_th_def i_rt_Suc_forw)
oheimb@15188
   629
oheimb@15188
   630
lemma i_th_last: "i_th n s && UU = i_rt n (stream_take (Suc n)$s)"
oheimb@15188
   631
apply (insert surjectiv_scons [of "i_rt n (stream_take (Suc n)$s)"])
oheimb@15188
   632
apply (rule i_th_stream_take_Suc [THEN subst])
oheimb@15188
   633
apply (simp add: i_th_def  i_rt_Suc_back [symmetric])
oheimb@15188
   634
by (simp add: i_rt_take_lemma1)
oheimb@15188
   635
wenzelm@17291
   636
lemma i_th_last_eq:
oheimb@15188
   637
"i_th n s1 = i_th n s2 ==> i_rt n (stream_take (Suc n)$s1) = i_rt n (stream_take (Suc n)$s2)"
oheimb@15188
   638
apply (insert i_th_last [of n s1])
oheimb@15188
   639
apply (insert i_th_last [of n s2])
oheimb@15188
   640
by auto
oheimb@15188
   641
oheimb@15188
   642
lemma i_th_prefix_lemma:
wenzelm@17291
   643
"[| k <= n; stream_take (Suc n)$s1 << stream_take (Suc n)$s2 |] ==>
oheimb@15188
   644
    i_th k s1 << i_th k s2"
oheimb@15188
   645
apply (insert i_th_stream_take_Suc [of k s1, THEN sym])
oheimb@15188
   646
apply (insert i_th_stream_take_Suc [of k s2, THEN sym],auto)
oheimb@15188
   647
apply (simp add: i_th_def)
oheimb@15188
   648
apply (rule monofun_cfun, auto)
oheimb@15188
   649
apply (rule i_rt_mono)
oheimb@15188
   650
by (blast intro: stream_take_lemma10)
oheimb@15188
   651
wenzelm@17291
   652
lemma take_i_rt_prefix_lemma1:
oheimb@15188
   653
  "stream_take (Suc n)$s1 << stream_take (Suc n)$s2 ==>
wenzelm@17291
   654
   i_rt (Suc n) s1 << i_rt (Suc n) s2 ==>
oheimb@15188
   655
   i_rt n s1 << i_rt n s2 & stream_take n$s1 << stream_take n$s2"
oheimb@15188
   656
apply auto
oheimb@15188
   657
 apply (insert i_th_prefix_lemma [of n n s1 s2])
oheimb@15188
   658
 apply (rule i_th_i_rt_step,auto)
oheimb@15188
   659
by (drule mono_stream_take_pred,simp)
oheimb@15188
   660
wenzelm@17291
   661
lemma take_i_rt_prefix_lemma:
oheimb@15188
   662
"[| stream_take n$s1 << stream_take n$s2; i_rt n s1 << i_rt n s2 |] ==> s1 << s2"
oheimb@15188
   663
apply (case_tac "n=0",simp)
nipkow@25161
   664
apply (auto)
wenzelm@17291
   665
apply (subgoal_tac "stream_take 0$s1 << stream_take 0$s2 &
oheimb@15188
   666
                    i_rt 0 s1 << i_rt 0 s2")
oheimb@15188
   667
 defer 1
oheimb@15188
   668
 apply (rule zero_induct,blast)
oheimb@15188
   669
 apply (blast dest: take_i_rt_prefix_lemma1)
oheimb@15188
   670
by simp
oheimb@15188
   671
wenzelm@17291
   672
lemma streams_prefix_lemma: "(s1 << s2) =
wenzelm@17291
   673
  (stream_take n$s1 << stream_take n$s2 & i_rt n s1 << i_rt n s2)"
oheimb@15188
   674
apply auto
oheimb@15188
   675
  apply (simp add: monofun_cfun_arg)
oheimb@15188
   676
 apply (simp add: i_rt_mono)
oheimb@15188
   677
by (erule take_i_rt_prefix_lemma,simp)
oheimb@15188
   678
oheimb@15188
   679
lemma streams_prefix_lemma1:
oheimb@15188
   680
 "[| stream_take n$s1 = stream_take n$s2; i_rt n s1 = i_rt n s2 |] ==> s1 = s2"
oheimb@15188
   681
apply (simp add: po_eq_conv,auto)
oheimb@15188
   682
 apply (insert streams_prefix_lemma)
oheimb@15188
   683
 by blast+
oheimb@15188
   684
oheimb@15188
   685
oheimb@15188
   686
(* ----------------------------------------------------------------------- *)
oheimb@15188
   687
   section "sconc"
oheimb@15188
   688
(* ----------------------------------------------------------------------- *)
oheimb@15188
   689
oheimb@15188
   690
lemma UU_sconc [simp]: " UU ooo s = s "
haftmann@27111
   691
by (simp add: sconc_def zero_inat_def)
oheimb@15188
   692
oheimb@15188
   693
lemma scons_neq_UU: "a~=UU ==> a && s ~=UU"
oheimb@15188
   694
by auto
oheimb@15188
   695
oheimb@15188
   696
lemma singleton_sconc [rule_format, simp]: "x~=UU --> (x && UU) ooo y = x && y"
haftmann@27111
   697
apply (simp add: sconc_def zero_inat_def iSuc_def split: inat.splits, auto)
oheimb@15188
   698
apply (rule someI2_ex,auto)
oheimb@15188
   699
 apply (rule_tac x="x && y" in exI,auto)
oheimb@15188
   700
apply (simp add: i_rt_Suc_forw)
oheimb@15188
   701
apply (case_tac "xa=UU",simp)
oheimb@15188
   702
by (drule stream_exhaust_eq [THEN iffD1],auto)
oheimb@15188
   703
wenzelm@17291
   704
lemma ex_sconc [rule_format]:
oheimb@15188
   705
  "ALL k y. #x = Fin k --> (EX w. stream_take k$w = x & i_rt k w = y)"
oheimb@15188
   706
apply (case_tac "#x")
oheimb@15188
   707
 apply (rule stream_finite_ind [of x],auto)
oheimb@15188
   708
  apply (simp add: stream.finite_def)
oheimb@15188
   709
  apply (drule slen_take_lemma1,blast)
haftmann@27111
   710
 apply (simp_all add: zero_inat_def iSuc_def split: inat.splits)
oheimb@15188
   711
apply (erule_tac x="y" in allE,auto)
oheimb@15188
   712
by (rule_tac x="a && w" in exI,auto)
oheimb@15188
   713
wenzelm@17291
   714
lemma rt_sconc1: "Fin n = #x ==> i_rt n (x ooo y) = y"
haftmann@27111
   715
apply (simp add: sconc_def split: inat.splits, arith?,auto)
oheimb@15188
   716
apply (rule someI2_ex,auto)
oheimb@15188
   717
by (drule ex_sconc,simp)
oheimb@15188
   718
oheimb@15188
   719
lemma sconc_inj2: "\<lbrakk>Fin n = #x; x ooo y = x ooo z\<rbrakk> \<Longrightarrow> y = z"
oheimb@15188
   720
apply (frule_tac y=y in rt_sconc1)
oheimb@15188
   721
by (auto elim: rt_sconc1)
oheimb@15188
   722
oheimb@15188
   723
lemma sconc_UU [simp]:"s ooo UU = s"
oheimb@15188
   724
apply (case_tac "#s")
haftmann@27111
   725
 apply (simp add: sconc_def)
oheimb@15188
   726
 apply (rule someI2_ex)
oheimb@15188
   727
  apply (rule_tac x="s" in exI)
oheimb@15188
   728
  apply auto
oheimb@15188
   729
   apply (drule slen_take_lemma1,auto)
oheimb@15188
   730
  apply (simp add: i_rt_lemma_slen)
oheimb@15188
   731
 apply (drule slen_take_lemma1,auto)
oheimb@15188
   732
 apply (simp add: i_rt_slen)
haftmann@27111
   733
by (simp add: sconc_def)
oheimb@15188
   734
oheimb@15188
   735
lemma stream_take_sconc [simp]: "Fin n = #x ==> stream_take n$(x ooo y) = x"
oheimb@15188
   736
apply (simp add: sconc_def)
haftmann@27111
   737
apply (cases "#x")
haftmann@27111
   738
apply auto
haftmann@27111
   739
apply (rule someI2_ex, auto)
oheimb@15188
   740
by (drule ex_sconc,simp)
oheimb@15188
   741
oheimb@15188
   742
lemma scons_sconc [rule_format,simp]: "a~=UU --> (a && x) ooo y = a && x ooo y"
haftmann@27111
   743
apply (cases "#x",auto)
haftmann@27111
   744
 apply (simp add: sconc_def iSuc_Fin)
oheimb@15188
   745
 apply (rule someI2_ex)
haftmann@27111
   746
  apply (drule ex_sconc, simp)
haftmann@27111
   747
 apply (rule someI2_ex, auto)
oheimb@15188
   748
  apply (simp add: i_rt_Suc_forw)
haftmann@27111
   749
  apply (rule_tac x="a && x" in exI, auto)
oheimb@15188
   750
 apply (case_tac "xa=UU",auto)
oheimb@15188
   751
 apply (drule stream_exhaust_eq [THEN iffD1],auto)
oheimb@15188
   752
 apply (drule streams_prefix_lemma1,simp+)
oheimb@15188
   753
by (simp add: sconc_def)
oheimb@15188
   754
oheimb@15188
   755
lemma ft_sconc: "x ~= UU ==> ft$(x ooo y) = ft$x"
huffman@35781
   756
by (cases x, auto)
oheimb@15188
   757
oheimb@15188
   758
lemma sconc_assoc: "(x ooo y) ooo z = x ooo y ooo z"
oheimb@15188
   759
apply (case_tac "#x")
oheimb@15188
   760
 apply (rule stream_finite_ind [of x],auto simp del: scons_sconc)
oheimb@15188
   761
  apply (simp add: stream.finite_def del: scons_sconc)
oheimb@15188
   762
  apply (drule slen_take_lemma1,auto simp del: scons_sconc)
oheimb@15188
   763
 apply (case_tac "a = UU", auto)
oheimb@15188
   764
by (simp add: sconc_def)
oheimb@15188
   765
oheimb@15188
   766
oheimb@15188
   767
(* ----------------------------------------------------------------------- *)
oheimb@15188
   768
huffman@25833
   769
lemma cont_sconc_lemma1: "stream_finite x \<Longrightarrow> cont (\<lambda>y. x ooo y)"
huffman@25833
   770
by (erule stream_finite_ind, simp_all)
huffman@25833
   771
huffman@25833
   772
lemma cont_sconc_lemma2: "\<not> stream_finite x \<Longrightarrow> cont (\<lambda>y. x ooo y)"
huffman@25833
   773
by (simp add: sconc_def slen_def)
huffman@25833
   774
huffman@25833
   775
lemma cont_sconc: "cont (\<lambda>y. x ooo y)"
huffman@25833
   776
apply (cases "stream_finite x")
huffman@25833
   777
apply (erule cont_sconc_lemma1)
huffman@25833
   778
apply (erule cont_sconc_lemma2)
huffman@25833
   779
done
huffman@25833
   780
oheimb@15188
   781
lemma sconc_mono: "y << y' ==> x ooo y << x ooo y'"
huffman@25833
   782
by (rule cont_sconc [THEN cont2mono, THEN monofunE])
oheimb@15188
   783
oheimb@15188
   784
lemma sconc_mono1 [simp]: "x << x ooo y"
oheimb@15188
   785
by (rule sconc_mono [of UU, simplified])
oheimb@15188
   786
oheimb@15188
   787
(* ----------------------------------------------------------------------- *)
oheimb@15188
   788
oheimb@15188
   789
lemma empty_sconc [simp]: "(x ooo y = UU) = (x = UU & y = UU)"
oheimb@15188
   790
apply (case_tac "#x",auto)
wenzelm@17291
   791
   apply (insert sconc_mono1 [of x y])
huffman@19440
   792
   by auto
oheimb@15188
   793
oheimb@15188
   794
(* ----------------------------------------------------------------------- *)
oheimb@15188
   795
oheimb@15188
   796
lemma rt_sconc [rule_format, simp]: "s~=UU --> rt$(s ooo x) = rt$s ooo x"
huffman@35781
   797
by (cases s, auto)
oheimb@15188
   798
wenzelm@17291
   799
lemma i_th_sconc_lemma [rule_format]:
oheimb@15188
   800
  "ALL x y. Fin n < #x --> i_th n (x ooo y) = i_th n x"
oheimb@15188
   801
apply (induct_tac n, auto)
oheimb@15188
   802
apply (simp add: Fin_0 i_th_def)
oheimb@15188
   803
apply (simp add: slen_empty_eq ft_sconc)
oheimb@15188
   804
apply (simp add: i_th_def)
oheimb@15188
   805
apply (case_tac "x=UU",auto)
oheimb@15188
   806
apply (drule stream_exhaust_eq [THEN iffD1], auto)
oheimb@15188
   807
apply (erule_tac x="ya" in allE)
haftmann@27111
   808
apply (case_tac "#ya") by simp_all
oheimb@15188
   809
oheimb@15188
   810
oheimb@15188
   811
oheimb@15188
   812
(* ----------------------------------------------------------------------- *)
oheimb@15188
   813
oheimb@15188
   814
lemma sconc_lemma [rule_format, simp]: "ALL s. stream_take n$s ooo i_rt n s = s"
oheimb@15188
   815
apply (induct_tac n,auto)
oheimb@15188
   816
apply (case_tac "s=UU",auto)
oheimb@15188
   817
by (drule stream_exhaust_eq [THEN iffD1],auto)
oheimb@15188
   818
oheimb@15188
   819
(* ----------------------------------------------------------------------- *)
oheimb@15188
   820
   subsection "pointwise equality"
oheimb@15188
   821
(* ----------------------------------------------------------------------- *)
oheimb@15188
   822
wenzelm@17291
   823
lemma ex_last_stream_take_scons: "stream_take (Suc n)$s =
oheimb@15188
   824
                     stream_take n$s ooo i_rt n (stream_take (Suc n)$s)"
oheimb@15188
   825
by (insert sconc_lemma [of n "stream_take (Suc n)$s"],simp)
oheimb@15188
   826
wenzelm@17291
   827
lemma i_th_stream_take_eq:
oheimb@15188
   828
"!!n. ALL n. i_th n s1 = i_th n s2 ==> stream_take n$s1 = stream_take n$s2"
oheimb@15188
   829
apply (induct_tac n,auto)
oheimb@15188
   830
apply (subgoal_tac "stream_take (Suc na)$s1 =
oheimb@15188
   831
                    stream_take na$s1 ooo i_rt na (stream_take (Suc na)$s1)")
wenzelm@17291
   832
 apply (subgoal_tac "i_rt na (stream_take (Suc na)$s1) =
oheimb@15188
   833
                    i_rt na (stream_take (Suc na)$s2)")
wenzelm@17291
   834
  apply (subgoal_tac "stream_take (Suc na)$s2 =
oheimb@15188
   835
                    stream_take na$s2 ooo i_rt na (stream_take (Suc na)$s2)")
oheimb@15188
   836
   apply (insert ex_last_stream_take_scons,simp)
oheimb@15188
   837
  apply blast
oheimb@15188
   838
 apply (erule_tac x="na" in allE)
oheimb@15188
   839
 apply (insert i_th_last_eq [of _ s1 s2])
oheimb@15188
   840
by blast+
oheimb@15188
   841
oheimb@15188
   842
lemma pointwise_eq_lemma[rule_format]: "ALL n. i_th n s1 = i_th n s2 ==> s1 = s2"
huffman@35642
   843
by (insert i_th_stream_take_eq [THEN stream.take_lemma],blast)
oheimb@15188
   844
oheimb@15188
   845
(* ----------------------------------------------------------------------- *)
oheimb@15188
   846
   subsection "finiteness"
oheimb@15188
   847
(* ----------------------------------------------------------------------- *)
oheimb@15188
   848
oheimb@15188
   849
lemma slen_sconc_finite1:
oheimb@15188
   850
  "[| #(x ooo y) = Infty; Fin n = #x |] ==> #y = Infty"
oheimb@15188
   851
apply (case_tac "#y ~= Infty",auto)
oheimb@15188
   852
apply (drule_tac y=y in rt_sconc1)
oheimb@15188
   853
apply (insert stream_finite_i_rt [of n "x ooo y"])
oheimb@15188
   854
by (simp add: slen_infinite)
oheimb@15188
   855
oheimb@15188
   856
lemma slen_sconc_infinite1: "#x=Infty ==> #(x ooo y) = Infty"
oheimb@15188
   857
by (simp add: sconc_def)
oheimb@15188
   858
oheimb@15188
   859
lemma slen_sconc_infinite2: "#y=Infty ==> #(x ooo y) = Infty"
oheimb@15188
   860
apply (case_tac "#x")
oheimb@15188
   861
 apply (simp add: sconc_def)
oheimb@15188
   862
 apply (rule someI2_ex)
oheimb@15188
   863
  apply (drule ex_sconc,auto)
oheimb@15188
   864
 apply (erule contrapos_pp)
oheimb@15188
   865
 apply (insert stream_finite_i_rt)
nipkow@31084
   866
 apply (fastsimp simp add: slen_infinite,auto)
oheimb@15188
   867
by (simp add: sconc_def)
oheimb@15188
   868
oheimb@15188
   869
lemma sconc_finite: "(#x~=Infty & #y~=Infty) = (#(x ooo y)~=Infty)"
oheimb@15188
   870
apply auto
nipkow@31084
   871
  apply (metis not_Infty_eq slen_sconc_finite1)
nipkow@31084
   872
 apply (metis not_Infty_eq slen_sconc_infinite1)
nipkow@31084
   873
apply (metis not_Infty_eq slen_sconc_infinite2)
nipkow@31084
   874
done
oheimb@15188
   875
oheimb@15188
   876
(* ----------------------------------------------------------------------- *)
oheimb@15188
   877
oheimb@15188
   878
lemma slen_sconc_mono3: "[| Fin n = #x; Fin k = #(x ooo y) |] ==> n <= k"
oheimb@15188
   879
apply (insert slen_mono [of "x" "x ooo y"])
haftmann@27111
   880
apply (cases "#x") apply simp_all
haftmann@27111
   881
apply (cases "#(x ooo y)") apply simp_all
haftmann@27111
   882
done
oheimb@15188
   883
oheimb@15188
   884
(* ----------------------------------------------------------------------- *)
oheimb@15188
   885
   subsection "finite slen"
oheimb@15188
   886
(* ----------------------------------------------------------------------- *)
oheimb@15188
   887
oheimb@15188
   888
lemma slen_sconc: "[| Fin n = #x; Fin m = #y |] ==> #(x ooo y) = Fin (n + m)"
oheimb@15188
   889
apply (case_tac "#(x ooo y)")
oheimb@15188
   890
 apply (frule_tac y=y in rt_sconc1)
oheimb@15188
   891
 apply (insert take_i_rt_len [of "THE j. Fin j = #(x ooo y)" "x ooo y" n n m],simp)
oheimb@15188
   892
 apply (insert slen_sconc_mono3 [of n x _ y],simp)
oheimb@15188
   893
by (insert sconc_finite [of x y],auto)
oheimb@15188
   894
oheimb@15188
   895
(* ----------------------------------------------------------------------- *)
oheimb@15188
   896
   subsection "flat prefix"
oheimb@15188
   897
(* ----------------------------------------------------------------------- *)
oheimb@15188
   898
oheimb@15188
   899
lemma sconc_prefix: "(s1::'a::flat stream) << s2 ==> EX t. s1 ooo t = s2"
oheimb@15188
   900
apply (case_tac "#s1")
wenzelm@17291
   901
 apply (subgoal_tac "stream_take nat$s1 = stream_take nat$s2")
oheimb@15188
   902
  apply (rule_tac x="i_rt nat s2" in exI)
oheimb@15188
   903
  apply (simp add: sconc_def)
oheimb@15188
   904
  apply (rule someI2_ex)
oheimb@15188
   905
   apply (drule ex_sconc)
oheimb@15188
   906
   apply (simp,clarsimp,drule streams_prefix_lemma1)
wenzelm@17291
   907
   apply (simp+,rule slen_take_lemma3 [of _ s1 s2])
oheimb@15188
   908
  apply (simp+,rule_tac x="UU" in exI)
wenzelm@17291
   909
apply (insert slen_take_lemma3 [of _ s1 s2])
huffman@35642
   910
by (rule stream.take_lemma,simp)
oheimb@15188
   911
oheimb@15188
   912
(* ----------------------------------------------------------------------- *)
oheimb@15188
   913
   subsection "continuity"
oheimb@15188
   914
(* ----------------------------------------------------------------------- *)
oheimb@15188
   915
oheimb@15188
   916
lemma chain_sconc: "chain S ==> chain (%i. (x ooo S i))"
oheimb@15188
   917
by (simp add: chain_def,auto simp add: sconc_mono)
oheimb@15188
   918
oheimb@15188
   919
lemma chain_scons: "chain S ==> chain (%i. a && S i)"
oheimb@15188
   920
apply (simp add: chain_def,auto)
oheimb@15188
   921
by (rule monofun_cfun_arg,simp)
oheimb@15188
   922
oheimb@15188
   923
lemma contlub_scons_lemma: "chain S ==> (LUB i. a && S i) = a && (LUB i. S i)"
huffman@35914
   924
by (rule cont2contlubE [OF cont_Rep_CFun2, symmetric])
oheimb@15188
   925
wenzelm@17291
   926
lemma finite_lub_sconc: "chain Y ==> (stream_finite x) ==>
oheimb@15188
   927
                        (LUB i. x ooo Y i) = (x ooo (LUB i. Y i))"
oheimb@15188
   928
apply (rule stream_finite_ind [of x])
oheimb@15188
   929
 apply (auto)
oheimb@15188
   930
apply (subgoal_tac "(LUB i. a && (s ooo Y i)) = a && (LUB i. s ooo Y i)")
oheimb@15188
   931
 by (force,blast dest: contlub_scons_lemma chain_sconc)
oheimb@15188
   932
wenzelm@17291
   933
lemma contlub_sconc_lemma:
oheimb@15188
   934
  "chain Y ==> (LUB i. x ooo Y i) = (x ooo (LUB i. Y i))"
oheimb@15188
   935
apply (case_tac "#x=Infty")
oheimb@15188
   936
 apply (simp add: sconc_def)
huffman@18075
   937
apply (drule finite_lub_sconc,auto simp add: slen_infinite)
huffman@18075
   938
done
oheimb@15188
   939
oheimb@15188
   940
lemma monofun_sconc: "monofun (%y. x ooo y)"
huffman@16218
   941
by (simp add: monofun_def sconc_mono)
oheimb@15188
   942
oheimb@15188
   943
oheimb@15188
   944
(* ----------------------------------------------------------------------- *)
oheimb@15188
   945
   section "constr_sconc"
oheimb@15188
   946
(* ----------------------------------------------------------------------- *)
oheimb@15188
   947
oheimb@15188
   948
lemma constr_sconc_UUs [simp]: "constr_sconc UU s = s"
haftmann@27111
   949
by (simp add: constr_sconc_def zero_inat_def)
oheimb@15188
   950
oheimb@15188
   951
lemma "x ooo y = constr_sconc x y"
oheimb@15188
   952
apply (case_tac "#x")
oheimb@15188
   953
 apply (rule stream_finite_ind [of x],auto simp del: scons_sconc)
oheimb@15188
   954
  defer 1
oheimb@15188
   955
  apply (simp add: constr_sconc_def del: scons_sconc)
oheimb@15188
   956
  apply (case_tac "#s")
haftmann@27111
   957
   apply (simp add: iSuc_Fin)
oheimb@15188
   958
   apply (case_tac "a=UU",auto simp del: scons_sconc)
oheimb@15188
   959
   apply (simp)
oheimb@15188
   960
  apply (simp add: sconc_def)
oheimb@15188
   961
 apply (simp add: constr_sconc_def)
oheimb@15188
   962
apply (simp add: stream.finite_def)
oheimb@15188
   963
by (drule slen_take_lemma1,auto)
oheimb@15188
   964
oheimb@2570
   965
end