| author | haftmann | 
| Tue, 10 Jul 2007 17:30:50 +0200 | |
| changeset 23709 | fd31da8f752a | 
| parent 21404 | eb85850d3eb7 | 
| child 24107 | fecafd71e758 | 
| permissions | -rw-r--r-- | 
| 17293 | 1  | 
(* Title: HOLCF/FOCUS/Fstream.thy  | 
| 11355 | 2  | 
ID: $Id$  | 
| 17293 | 3  | 
Author: David von Oheimb, TU Muenchen  | 
| 
11350
 
4c55b020d6ee
added FOCUS including the One-Element Buffer by Manfred Broy
 
oheimb 
parents:  
diff
changeset
 | 
4  | 
|
| 
 
4c55b020d6ee
added FOCUS including the One-Element Buffer by Manfred Broy
 
oheimb 
parents:  
diff
changeset
 | 
5  | 
FOCUS streams (with lifted elements)  | 
| 
15188
 
9d57263faf9e
integrated Streams with ex/Stream.*; added FOCUS/Fstreams.thy
 
oheimb 
parents: 
14981 
diff
changeset
 | 
6  | 
###TODO: integrate Fstreams.thy  | 
| 
11350
 
4c55b020d6ee
added FOCUS including the One-Element Buffer by Manfred Broy
 
oheimb 
parents:  
diff
changeset
 | 
7  | 
*)  | 
| 
 
4c55b020d6ee
added FOCUS including the One-Element Buffer by Manfred Broy
 
oheimb 
parents:  
diff
changeset
 | 
8  | 
|
| 17293 | 9  | 
header {* FOCUS flat streams *}
 | 
| 
11350
 
4c55b020d6ee
added FOCUS including the One-Element Buffer by Manfred Broy
 
oheimb 
parents:  
diff
changeset
 | 
10  | 
|
| 17293 | 11  | 
theory Fstream  | 
12  | 
imports Stream  | 
|
13  | 
begin  | 
|
| 
11350
 
4c55b020d6ee
added FOCUS including the One-Element Buffer by Manfred Broy
 
oheimb 
parents:  
diff
changeset
 | 
14  | 
|
| 17293 | 15  | 
defaultsort type  | 
16  | 
||
17  | 
types 'a fstream = "'a lift stream"  | 
|
| 
11350
 
4c55b020d6ee
added FOCUS including the One-Element Buffer by Manfred Broy
 
oheimb 
parents:  
diff
changeset
 | 
18  | 
|
| 19763 | 19  | 
definition  | 
| 
21404
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
21210 
diff
changeset
 | 
20  | 
fscons :: "'a \<Rightarrow> 'a fstream \<rightarrow> 'a fstream" where  | 
| 19763 | 21  | 
"fscons a = (\<Lambda> s. Def a && s)"  | 
| 
11350
 
4c55b020d6ee
added FOCUS including the One-Element Buffer by Manfred Broy
 
oheimb 
parents:  
diff
changeset
 | 
22  | 
|
| 
21404
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
21210 
diff
changeset
 | 
23  | 
definition  | 
| 
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
21210 
diff
changeset
 | 
24  | 
fsfilter :: "'a set \<Rightarrow> 'a fstream \<rightarrow> 'a fstream" where  | 
| 19763 | 25  | 
"fsfilter A = (sfilter\<cdot>(flift2 (\<lambda>x. x\<in>A)))"  | 
| 
11350
 
4c55b020d6ee
added FOCUS including the One-Element Buffer by Manfred Broy
 
oheimb 
parents:  
diff
changeset
 | 
26  | 
|
| 19763 | 27  | 
abbreviation  | 
| 
21404
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
21210 
diff
changeset
 | 
28  | 
  emptystream   :: "'a fstream"                          ("<>") where
 | 
| 19763 | 29  | 
"<> == \<bottom>"  | 
| 
11350
 
4c55b020d6ee
added FOCUS including the One-Element Buffer by Manfred Broy
 
oheimb 
parents:  
diff
changeset
 | 
30  | 
|
| 
21404
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
21210 
diff
changeset
 | 
31  | 
abbreviation  | 
| 
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
21210 
diff
changeset
 | 
32  | 
  fscons'       :: "'a \<Rightarrow> 'a fstream \<Rightarrow> 'a fstream"       ("(_~>_)"    [66,65] 65) where
 | 
| 19763 | 33  | 
"a~>s == fscons a\<cdot>s"  | 
| 
11350
 
4c55b020d6ee
added FOCUS including the One-Element Buffer by Manfred Broy
 
oheimb 
parents:  
diff
changeset
 | 
34  | 
|
| 
21404
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
21210 
diff
changeset
 | 
35  | 
abbreviation  | 
| 
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
21210 
diff
changeset
 | 
36  | 
  fsfilter'     :: "'a set \<Rightarrow> 'a fstream \<Rightarrow> 'a fstream"   ("(_'(C')_)" [64,63] 63) where
 | 
| 19763 | 37  | 
"A(C)s == fsfilter A\<cdot>s"  | 
| 
11350
 
4c55b020d6ee
added FOCUS including the One-Element Buffer by Manfred Broy
 
oheimb 
parents:  
diff
changeset
 | 
38  | 
|
| 21210 | 39  | 
notation (xsymbols)  | 
| 
21404
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
21210 
diff
changeset
 | 
40  | 
  fscons'  ("(_\<leadsto>_)"                                                 [66,65] 65) and
 | 
| 19763 | 41  | 
  fsfilter'  ("(_\<copyright>_)"                                               [64,63] 63)
 | 
| 
11350
 
4c55b020d6ee
added FOCUS including the One-Element Buffer by Manfred Broy
 
oheimb 
parents:  
diff
changeset
 | 
42  | 
|
| 
 
4c55b020d6ee
added FOCUS including the One-Element Buffer by Manfred Broy
 
oheimb 
parents:  
diff
changeset
 | 
43  | 
|
| 19759 | 44  | 
lemma Def_maximal: "a = Def d \<Longrightarrow> a\<sqsubseteq>b \<Longrightarrow> b = Def d"  | 
45  | 
apply (rule flat_eq [THEN iffD1, symmetric])  | 
|
46  | 
apply (rule Def_not_UU)  | 
|
47  | 
apply (drule antisym_less_inverse)  | 
|
48  | 
apply (erule (1) conjunct2 [THEN trans_less])  | 
|
49  | 
done  | 
|
50  | 
||
51  | 
||
52  | 
section "fscons"  | 
|
53  | 
||
54  | 
lemma fscons_def2: "a~>s = Def a && s"  | 
|
55  | 
apply (unfold fscons_def)  | 
|
56  | 
apply (simp)  | 
|
57  | 
done  | 
|
58  | 
||
59  | 
lemma fstream_exhaust: "x = UU | (? a y. x = a~> y)"  | 
|
60  | 
apply (simp add: fscons_def2)  | 
|
61  | 
apply (cut_tac stream.exhaust)  | 
|
62  | 
apply (fast dest: not_Undef_is_Def [THEN iffD1])  | 
|
63  | 
done  | 
|
64  | 
||
65  | 
lemma fstream_cases: "[| x = UU ==> P; !!a y. x = a~> y ==> P |] ==> P"  | 
|
66  | 
apply (cut_tac fstream_exhaust)  | 
|
67  | 
apply (erule disjE)  | 
|
68  | 
apply fast  | 
|
69  | 
apply fast  | 
|
70  | 
done  | 
|
71  | 
(*  | 
|
72  | 
fun fstream_case_tac s i = res_inst_tac [("x",s)] fstream_cases i
 | 
|
73  | 
THEN hyp_subst_tac i THEN hyp_subst_tac (i+1);  | 
|
74  | 
*)  | 
|
75  | 
lemma fstream_exhaust_eq: "(x ~= UU) = (? a y. x = a~> y)"  | 
|
76  | 
apply (simp add: fscons_def2 stream_exhaust_eq)  | 
|
77  | 
apply (fast dest: not_Undef_is_Def [THEN iffD1] elim: DefE)  | 
|
78  | 
done  | 
|
79  | 
||
80  | 
||
81  | 
lemma fscons_not_empty [simp]: "a~> s ~= <>"  | 
|
82  | 
by (simp add: fscons_def2)  | 
|
83  | 
||
84  | 
||
85  | 
lemma fscons_inject [simp]: "(a~> s = b~> t) = (a = b & s = t)"  | 
|
86  | 
by (simp add: fscons_def2)  | 
|
87  | 
||
88  | 
lemma fstream_prefix: "a~> s << t ==> ? tt. t = a~> tt & s << tt"  | 
|
89  | 
apply (rule_tac x="t" in stream.casedist)  | 
|
90  | 
apply (cut_tac fscons_not_empty)  | 
|
91  | 
apply (fast dest: eq_UU_iff [THEN iffD2])  | 
|
92  | 
apply (simp add: fscons_def2)  | 
|
93  | 
apply (drule stream_flat_prefix)  | 
|
94  | 
apply (rule Def_not_UU)  | 
|
95  | 
apply (fast)  | 
|
96  | 
done  | 
|
97  | 
||
98  | 
lemma fstream_prefix' [simp]:  | 
|
99  | 
"x << a~> z = (x = <> | (? y. x = a~> y & y << z))"  | 
|
100  | 
apply (simp add: fscons_def2 Def_not_UU [THEN stream_prefix'])  | 
|
101  | 
apply (safe)  | 
|
102  | 
apply (erule_tac [!] contrapos_np)  | 
|
103  | 
prefer 2 apply (fast elim: DefE)  | 
|
104  | 
apply (rule Lift_cases)  | 
|
105  | 
apply (erule (1) notE)  | 
|
106  | 
apply (safe)  | 
|
107  | 
apply (drule Def_inject_less_eq [THEN iffD1])  | 
|
108  | 
apply fast  | 
|
109  | 
done  | 
|
110  | 
||
111  | 
(* ------------------------------------------------------------------------- *)  | 
|
112  | 
||
113  | 
section "ft & rt"  | 
|
114  | 
||
115  | 
lemmas ft_empty = stream.sel_rews (1)  | 
|
116  | 
lemma ft_fscons [simp]: "ft\<cdot>(m~> s) = Def m"  | 
|
117  | 
by (simp add: fscons_def)  | 
|
118  | 
||
119  | 
lemmas rt_empty = stream.sel_rews (2)  | 
|
120  | 
lemma rt_fscons [simp]: "rt\<cdot>(m~> s) = s"  | 
|
121  | 
by (simp add: fscons_def)  | 
|
122  | 
||
123  | 
lemma ft_eq [simp]: "(ft\<cdot>s = Def a) = (? t. s = a~> t)"  | 
|
124  | 
apply (unfold fscons_def)  | 
|
125  | 
apply (simp)  | 
|
126  | 
apply (safe)  | 
|
127  | 
apply (erule subst)  | 
|
128  | 
apply (rule exI)  | 
|
129  | 
apply (rule surjectiv_scons [symmetric])  | 
|
130  | 
apply (simp)  | 
|
131  | 
done  | 
|
132  | 
||
133  | 
lemma surjective_fscons_lemma: "(d\<leadsto>y = x) = (ft\<cdot>x = Def d & rt\<cdot>x = y)"  | 
|
134  | 
by auto  | 
|
135  | 
||
136  | 
lemma surjective_fscons: "ft\<cdot>x = Def d \<Longrightarrow> d\<leadsto>rt\<cdot>x = x"  | 
|
137  | 
by (simp add: surjective_fscons_lemma)  | 
|
138  | 
||
139  | 
||
140  | 
(* ------------------------------------------------------------------------- *)  | 
|
141  | 
||
142  | 
section "take"  | 
|
143  | 
||
144  | 
lemma fstream_take_Suc [simp]:  | 
|
145  | 
"stream_take (Suc n)\<cdot>(a~> s) = a~> stream_take n\<cdot>s"  | 
|
146  | 
by (simp add: fscons_def)  | 
|
147  | 
||
148  | 
||
149  | 
(* ------------------------------------------------------------------------- *)  | 
|
150  | 
||
151  | 
section "slen"  | 
|
152  | 
||
153  | 
(*bind_thm("slen_empty", slen_empty);*)
 | 
|
154  | 
||
155  | 
lemma slen_fscons: "#(m~> s) = iSuc (#s)"  | 
|
156  | 
by (simp add: fscons_def)  | 
|
157  | 
||
158  | 
lemma slen_fscons_eq:  | 
|
159  | 
"(Fin (Suc n) < #x) = (? a y. x = a~> y & Fin n < #y)"  | 
|
160  | 
apply (simp add: fscons_def2 slen_scons_eq)  | 
|
161  | 
apply (fast dest: not_Undef_is_Def [THEN iffD1] elim: DefE)  | 
|
162  | 
done  | 
|
163  | 
||
164  | 
lemma slen_fscons_eq_rev:  | 
|
165  | 
"(#x < Fin (Suc (Suc n))) = (!a y. x ~= a~> y | #y < Fin (Suc n))"  | 
|
166  | 
apply (simp add: fscons_def2 slen_scons_eq_rev)  | 
|
| 19764 | 167  | 
apply (tactic {* step_tac (HOL_cs addSEs [thm "DefE"]) 1 *})
 | 
168  | 
apply (tactic {* step_tac (HOL_cs addSEs [thm "DefE"]) 1 *})
 | 
|
169  | 
apply (tactic {* step_tac (HOL_cs addSEs [thm "DefE"]) 1 *})
 | 
|
170  | 
apply (tactic {* step_tac (HOL_cs addSEs [thm "DefE"]) 1 *})
 | 
|
171  | 
apply (tactic {* step_tac (HOL_cs addSEs [thm "DefE"]) 1 *})
 | 
|
172  | 
apply (tactic {* step_tac (HOL_cs addSEs [thm "DefE"]) 1 *})
 | 
|
| 19759 | 173  | 
apply (erule contrapos_np)  | 
174  | 
apply (fast dest: not_Undef_is_Def [THEN iffD1] elim: DefE)  | 
|
175  | 
done  | 
|
176  | 
||
177  | 
lemma slen_fscons_less_eq:  | 
|
178  | 
"(#(a~> y) < Fin (Suc (Suc n))) = (#y < Fin (Suc n))"  | 
|
179  | 
apply (subst slen_fscons_eq_rev)  | 
|
180  | 
apply (fast dest!: fscons_inject [THEN iffD1])  | 
|
181  | 
done  | 
|
182  | 
||
183  | 
||
184  | 
(* ------------------------------------------------------------------------- *)  | 
|
185  | 
||
186  | 
section "induction"  | 
|
187  | 
||
188  | 
lemma fstream_ind:  | 
|
189  | 
"[| adm P; P <>; !!a s. P s ==> P (a~> s) |] ==> P x"  | 
|
190  | 
apply (erule stream.ind)  | 
|
191  | 
apply (assumption)  | 
|
192  | 
apply (unfold fscons_def2)  | 
|
193  | 
apply (fast dest: not_Undef_is_Def [THEN iffD1])  | 
|
194  | 
done  | 
|
195  | 
||
196  | 
lemma fstream_ind2:  | 
|
197  | 
"[| adm P; P UU; !!a. P (a~> UU); !!a b s. P s ==> P (a~> b~> s) |] ==> P x"  | 
|
198  | 
apply (erule stream_ind2)  | 
|
199  | 
apply (assumption)  | 
|
200  | 
apply (unfold fscons_def2)  | 
|
201  | 
apply (fast dest: not_Undef_is_Def [THEN iffD1])  | 
|
202  | 
apply (fast dest: not_Undef_is_Def [THEN iffD1])  | 
|
203  | 
done  | 
|
204  | 
||
205  | 
||
206  | 
(* ------------------------------------------------------------------------- *)  | 
|
207  | 
||
208  | 
section "fsfilter"  | 
|
209  | 
||
210  | 
lemma fsfilter_empty: "A(C)UU = UU"  | 
|
211  | 
apply (unfold fsfilter_def)  | 
|
212  | 
apply (rule sfilter_empty)  | 
|
213  | 
done  | 
|
214  | 
||
215  | 
lemma fsfilter_fscons:  | 
|
216  | 
"A(C)x~> xs = (if x:A then x~> (A(C)xs) else A(C)xs)"  | 
|
217  | 
apply (unfold fsfilter_def)  | 
|
218  | 
apply (simp add: fscons_def2 sfilter_scons If_and_if)  | 
|
219  | 
done  | 
|
220  | 
||
221  | 
lemma fsfilter_emptys: "{}(C)x = UU"
 | 
|
222  | 
apply (rule_tac x="x" in fstream_ind)  | 
|
223  | 
apply (simp)  | 
|
224  | 
apply (rule fsfilter_empty)  | 
|
225  | 
apply (simp add: fsfilter_fscons)  | 
|
226  | 
done  | 
|
227  | 
||
228  | 
lemma fsfilter_insert: "(insert a A)(C)a~> x = a~> ((insert a A)(C)x)"  | 
|
229  | 
by (simp add: fsfilter_fscons)  | 
|
230  | 
||
231  | 
lemma fsfilter_single_in: "{a}(C)a~> x = a~> ({a}(C)x)"
 | 
|
232  | 
by (rule fsfilter_insert)  | 
|
233  | 
||
234  | 
lemma fsfilter_single_out: "b ~= a ==> {a}(C)b~> x = ({a}(C)x)"
 | 
|
235  | 
by (simp add: fsfilter_fscons)  | 
|
236  | 
||
237  | 
lemma fstream_lub_lemma1:  | 
|
238  | 
"\<lbrakk>chain Y; lub (range Y) = a\<leadsto>s\<rbrakk> \<Longrightarrow> \<exists>j t. Y j = a\<leadsto>t"  | 
|
239  | 
apply (case_tac "max_in_chain i Y")  | 
|
240  | 
apply (drule (1) lub_finch1 [THEN thelubI, THEN sym])  | 
|
241  | 
apply (force)  | 
|
242  | 
apply (unfold max_in_chain_def)  | 
|
243  | 
apply auto  | 
|
244  | 
apply (frule (1) chain_mono3)  | 
|
245  | 
apply (rule_tac x="Y j" in fstream_cases)  | 
|
246  | 
apply (force)  | 
|
247  | 
apply (drule_tac x="j" in is_ub_thelub)  | 
|
248  | 
apply (force)  | 
|
249  | 
done  | 
|
250  | 
||
251  | 
lemma fstream_lub_lemma:  | 
|
252  | 
"\<lbrakk>chain Y; lub (range Y) = a\<leadsto>s\<rbrakk> \<Longrightarrow> (\<exists>j t. Y j = a\<leadsto>t) & (\<exists>X. chain X & (!i. ? j. Y j = a\<leadsto>X i) & lub (range X) = s)"  | 
|
253  | 
apply (frule (1) fstream_lub_lemma1)  | 
|
254  | 
apply (clarsimp)  | 
|
255  | 
apply (rule_tac x="%i. rt\<cdot>(Y(i+j))" in exI)  | 
|
256  | 
apply (rule conjI)  | 
|
257  | 
apply (erule chain_shift [THEN chain_monofun])  | 
|
258  | 
apply safe  | 
|
259  | 
apply (drule_tac x="j" and y="i+j" in chain_mono3)  | 
|
260  | 
apply (simp)  | 
|
261  | 
apply (simp)  | 
|
262  | 
apply (rule_tac x="i+j" in exI)  | 
|
263  | 
apply (drule fstream_prefix)  | 
|
264  | 
apply (clarsimp)  | 
|
265  | 
apply (subst contlub_cfun [symmetric])  | 
|
266  | 
apply (rule chainI)  | 
|
267  | 
apply (fast)  | 
|
268  | 
apply (erule chain_shift)  | 
|
269  | 
apply (subst lub_const [THEN thelubI])  | 
|
270  | 
apply (subst lub_range_shift)  | 
|
271  | 
apply (assumption)  | 
|
272  | 
apply (simp)  | 
|
273  | 
done  | 
|
274  | 
||
| 
11350
 
4c55b020d6ee
added FOCUS including the One-Element Buffer by Manfred Broy
 
oheimb 
parents:  
diff
changeset
 | 
275  | 
end  |