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