1 (* Title: HOLCF/FOCUS/Buffer.ML |
1 (* Title: HOLCF/FOCUS/Buffer.ML |
2 ID: $Id$ |
2 ID: $Id$ |
3 Author: David von Oheimb, TU Muenchen |
3 Author: David von Oheimb, TU Muenchen |
4 *) |
4 *) |
5 |
5 |
6 val set_cong = prove_goal Set.thy "!!X. A = B ==> (x:A) = (x:B)" (K [ |
6 val set_cong = prove_goal (theory "Set") "!!X. A = B ==> (x:A) = (x:B)" (K [ |
7 etac subst 1, rtac refl 1]); |
7 etac subst 1, rtac refl 1]); |
8 |
8 |
9 fun B_prover s tac eqs = prove_goal thy s (fn prems => [cut_facts_tac prems 1, |
9 fun B_prover s tac eqs = prove_goal (the_context ()) s (fn prems => [cut_facts_tac prems 1, |
10 tac 1, auto_tac (claset(), simpset() addsimps eqs)]); |
10 tac 1, auto_tac (claset(), simpset() addsimps eqs)]); |
11 |
11 |
12 fun prove_forw s thm = B_prover s (dtac (thm RS iffD1)) []; |
12 fun prove_forw s thm = B_prover s (dtac (thm RS iffD1)) []; |
13 fun prove_backw s thm eqs = B_prover s (rtac (thm RS iffD2)) eqs; |
13 fun prove_backw s thm eqs = B_prover s (rtac (thm RS iffD2)) eqs; |
14 |
14 |
15 |
15 |
16 (**** BufEq *******************************************************************) |
16 (**** BufEq *******************************************************************) |
17 |
17 |
18 val mono_BufEq_F = prove_goalw thy [mono_def, BufEq_F_def] |
18 val mono_BufEq_F = prove_goalw (the_context ()) [mono_def, BufEq_F_def] |
19 "mono BufEq_F" (K [Fast_tac 1]); |
19 "mono BufEq_F" (K [Fast_tac 1]); |
20 |
20 |
21 val BufEq_fix = mono_BufEq_F RS (BufEq_def RS def_gfp_unfold); |
21 val BufEq_fix = mono_BufEq_F RS (BufEq_def RS def_gfp_unfold); |
22 |
22 |
23 val BufEq_unfold = prove_goal thy "(f:BufEq) = (!d. f\\<cdot>(Md d\\<leadsto><>) = <> & \ |
23 val BufEq_unfold = prove_goal (the_context ()) "(f:BufEq) = (!d. f\\<cdot>(Md d\\<leadsto><>) = <> & \ |
24 \(!x. ? ff:BufEq. f\\<cdot>(Md d\\<leadsto>\\<bullet>\\<leadsto>x) = d\\<leadsto>(ff\\<cdot>x)))" (K [ |
24 \(!x. ? ff:BufEq. f\\<cdot>(Md d\\<leadsto>\\<bullet>\\<leadsto>x) = d\\<leadsto>(ff\\<cdot>x)))" (K [ |
25 stac (BufEq_fix RS set_cong) 1, |
25 stac (BufEq_fix RS set_cong) 1, |
26 rewtac BufEq_F_def, |
26 rewtac BufEq_F_def, |
27 Asm_full_simp_tac 1]); |
27 Asm_full_simp_tac 1]); |
28 |
28 |
29 val Buf_f_empty = prove_forw "f:BufEq \\<Longrightarrow> f\\<cdot><> = <>" BufEq_unfold; |
29 val Buf_f_empty = prove_forw "f:BufEq \\<Longrightarrow> f\\<cdot><> = <>" BufEq_unfold; |
30 val Buf_f_d = prove_forw "f:BufEq \\<Longrightarrow> f\\<cdot>(Md d\\<leadsto><>) = <>" BufEq_unfold; |
30 val Buf_f_d = prove_forw "f:BufEq \\<Longrightarrow> f\\<cdot>(Md d\\<leadsto><>) = <>" BufEq_unfold; |
31 val Buf_f_d_req = prove_forw |
31 val Buf_f_d_req = prove_forw |
32 "f:BufEq \\<Longrightarrow> \\<exists>ff. ff:BufEq \\<and> f\\<cdot>(Md d\\<leadsto>\\<bullet>\\<leadsto>x) = d\\<leadsto>ff\\<cdot>x" BufEq_unfold; |
32 "f:BufEq \\<Longrightarrow> \\<exists>ff. ff:BufEq \\<and> f\\<cdot>(Md d\\<leadsto>\\<bullet>\\<leadsto>x) = d\\<leadsto>ff\\<cdot>x" BufEq_unfold; |
33 |
33 |
34 |
34 |
35 (**** BufAC_Asm ***************************************************************) |
35 (**** BufAC_Asm ***************************************************************) |
36 |
36 |
37 val mono_BufAC_Asm_F = prove_goalw thy [mono_def, BufAC_Asm_F_def] |
37 val mono_BufAC_Asm_F = prove_goalw (the_context ()) [mono_def, BufAC_Asm_F_def] |
38 "mono BufAC_Asm_F" (K [Fast_tac 1]); |
38 "mono BufAC_Asm_F" (K [Fast_tac 1]); |
39 |
39 |
40 val BufAC_Asm_fix = mono_BufAC_Asm_F RS (BufAC_Asm_def RS def_gfp_unfold); |
40 val BufAC_Asm_fix = mono_BufAC_Asm_F RS (BufAC_Asm_def RS def_gfp_unfold); |
41 |
41 |
42 val BufAC_Asm_unfold = prove_goal thy "(s:BufAC_Asm) = (s = <> | (? d x. \ |
42 val BufAC_Asm_unfold = prove_goal (the_context ()) "(s:BufAC_Asm) = (s = <> | (? d x. \ |
43 \ s = Md d\\<leadsto>x & (x = <> | (ft\\<cdot>x = Def \\<bullet> & (rt\\<cdot>x):BufAC_Asm))))" (K [ |
43 \ s = Md d\\<leadsto>x & (x = <> | (ft\\<cdot>x = Def \\<bullet> & (rt\\<cdot>x):BufAC_Asm))))" (K [ |
44 stac (BufAC_Asm_fix RS set_cong) 1, |
44 stac (BufAC_Asm_fix RS set_cong) 1, |
45 rewtac BufAC_Asm_F_def, |
45 rewtac BufAC_Asm_F_def, |
46 Asm_full_simp_tac 1]); |
46 Asm_full_simp_tac 1]); |
47 |
47 |
48 val BufAC_Asm_empty = prove_backw "<> :BufAC_Asm" BufAC_Asm_unfold []; |
48 val BufAC_Asm_empty = prove_backw "<> :BufAC_Asm" BufAC_Asm_unfold []; |
49 val BufAC_Asm_d = prove_backw "Md d\\<leadsto><>:BufAC_Asm" BufAC_Asm_unfold []; |
49 val BufAC_Asm_d = prove_backw "Md d\\<leadsto><>:BufAC_Asm" BufAC_Asm_unfold []; |
50 val BufAC_Asm_d_req = prove_backw "x:BufAC_Asm ==> Md d\\<leadsto>\\<bullet>\\<leadsto>x:BufAC_Asm" |
50 val BufAC_Asm_d_req = prove_backw "x:BufAC_Asm ==> Md d\\<leadsto>\\<bullet>\\<leadsto>x:BufAC_Asm" |
51 BufAC_Asm_unfold []; |
51 BufAC_Asm_unfold []; |
52 val BufAC_Asm_prefix2 = prove_forw "a\\<leadsto>b\\<leadsto>s:BufAC_Asm ==> s:BufAC_Asm" |
52 val BufAC_Asm_prefix2 = prove_forw "a\\<leadsto>b\\<leadsto>s:BufAC_Asm ==> s:BufAC_Asm" |
53 BufAC_Asm_unfold; |
53 BufAC_Asm_unfold; |
54 |
54 |
55 |
55 |
56 (**** BBufAC_Cmt **************************************************************) |
56 (**** BBufAC_Cmt **************************************************************) |
57 |
57 |
58 val mono_BufAC_Cmt_F = prove_goalw thy [mono_def, BufAC_Cmt_F_def] |
58 val mono_BufAC_Cmt_F = prove_goalw (the_context ()) [mono_def, BufAC_Cmt_F_def] |
59 "mono BufAC_Cmt_F" (K [Fast_tac 1]); |
59 "mono BufAC_Cmt_F" (K [Fast_tac 1]); |
60 |
60 |
61 val BufAC_Cmt_fix = mono_BufAC_Cmt_F RS (BufAC_Cmt_def RS def_gfp_unfold); |
61 val BufAC_Cmt_fix = mono_BufAC_Cmt_F RS (BufAC_Cmt_def RS def_gfp_unfold); |
62 |
62 |
63 val BufAC_Cmt_unfold = prove_goal thy "((s,t):BufAC_Cmt) = (!d x. \ |
63 val BufAC_Cmt_unfold = prove_goal (the_context ()) "((s,t):BufAC_Cmt) = (!d x. \ |
64 \(s = <> --> t = <>) & \ |
64 \(s = <> --> t = <>) & \ |
65 \(s = Md d\\<leadsto><> --> t = <>) & \ |
65 \(s = Md d\\<leadsto><> --> t = <>) & \ |
66 \(s = Md d\\<leadsto>\\<bullet>\\<leadsto>x --> ft\\<cdot>t = Def d & (x, rt\\<cdot>t):BufAC_Cmt))" (K [ |
66 \(s = Md d\\<leadsto>\\<bullet>\\<leadsto>x --> ft\\<cdot>t = Def d & (x, rt\\<cdot>t):BufAC_Cmt))" (K [ |
67 stac (BufAC_Cmt_fix RS set_cong) 1, |
67 stac (BufAC_Cmt_fix RS set_cong) 1, |
68 rewtac BufAC_Cmt_F_def, |
68 rewtac BufAC_Cmt_F_def, |
69 Asm_full_simp_tac 1]); |
69 Asm_full_simp_tac 1]); |
70 |
70 |
71 val BufAC_Cmt_empty = prove_backw "f:BufEq ==> (<>, f\\<cdot><>):BufAC_Cmt" |
71 val BufAC_Cmt_empty = prove_backw "f:BufEq ==> (<>, f\\<cdot><>):BufAC_Cmt" |
72 BufAC_Cmt_unfold [Buf_f_empty]; |
72 BufAC_Cmt_unfold [Buf_f_empty]; |
73 |
73 |
74 val BufAC_Cmt_d = prove_backw "f:BufEq ==> (a\\<leadsto>\\<bottom>, f\\<cdot>(a\\<leadsto>\\<bottom>)):BufAC_Cmt" |
74 val BufAC_Cmt_d = prove_backw "f:BufEq ==> (a\\<leadsto>\\<bottom>, f\\<cdot>(a\\<leadsto>\\<bottom>)):BufAC_Cmt" |
75 BufAC_Cmt_unfold [Buf_f_d]; |
75 BufAC_Cmt_unfold [Buf_f_d]; |
76 |
76 |
77 val BufAC_Cmt_d2 = prove_forw |
77 val BufAC_Cmt_d2 = prove_forw |
78 "(Md d\\<leadsto>\\<bottom>, f\\<cdot>(Md d\\<leadsto>\\<bottom>)):BufAC_Cmt ==> f\\<cdot>(Md d\\<leadsto>\\<bottom>) = \\<bottom>" BufAC_Cmt_unfold; |
78 "(Md d\\<leadsto>\\<bottom>, f\\<cdot>(Md d\\<leadsto>\\<bottom>)):BufAC_Cmt ==> f\\<cdot>(Md d\\<leadsto>\\<bottom>) = \\<bottom>" BufAC_Cmt_unfold; |
79 val BufAC_Cmt_d3 = prove_forw |
79 val BufAC_Cmt_d3 = prove_forw |
80 "(Md d\\<leadsto>\\<bullet>\\<leadsto>x, f\\<cdot>(Md d\\<leadsto>\\<bullet>\\<leadsto>x)):BufAC_Cmt ==> (x, rt\\<cdot>(f\\<cdot>(Md d\\<leadsto>\\<bullet>\\<leadsto>x))):BufAC_Cmt" |
80 "(Md d\\<leadsto>\\<bullet>\\<leadsto>x, f\\<cdot>(Md d\\<leadsto>\\<bullet>\\<leadsto>x)):BufAC_Cmt ==> (x, rt\\<cdot>(f\\<cdot>(Md d\\<leadsto>\\<bullet>\\<leadsto>x))):BufAC_Cmt" |
81 BufAC_Cmt_unfold; |
81 BufAC_Cmt_unfold; |
82 |
82 |
83 val BufAC_Cmt_d32 = prove_forw |
83 val BufAC_Cmt_d32 = prove_forw |
84 "(Md d\\<leadsto>\\<bullet>\\<leadsto>x, f\\<cdot>(Md d\\<leadsto>\\<bullet>\\<leadsto>x)):BufAC_Cmt ==> ft\\<cdot>(f\\<cdot>(Md d\\<leadsto>\\<bullet>\\<leadsto>x)) = Def d" |
84 "(Md d\\<leadsto>\\<bullet>\\<leadsto>x, f\\<cdot>(Md d\\<leadsto>\\<bullet>\\<leadsto>x)):BufAC_Cmt ==> ft\\<cdot>(f\\<cdot>(Md d\\<leadsto>\\<bullet>\\<leadsto>x)) = Def d" |
85 BufAC_Cmt_unfold; |
85 BufAC_Cmt_unfold; |
86 |
86 |
87 (**** BufAC *******************************************************************) |
87 (**** BufAC *******************************************************************) |
88 |
88 |
89 Goalw [BufAC_def] "f \\<in> BufAC \\<Longrightarrow> f\\<cdot>(Md d\\<leadsto>\\<bottom>) = \\<bottom>"; |
89 Goalw [BufAC_def] "f \\<in> BufAC \\<Longrightarrow> f\\<cdot>(Md d\\<leadsto>\\<bottom>) = \\<bottom>"; |
90 by (fast_tac (claset() addIs [BufAC_Cmt_d2, BufAC_Asm_d]) 1); |
90 by (fast_tac (claset() addIs [BufAC_Cmt_d2, BufAC_Asm_d]) 1); |
112 qed "ex_elim_lemma"; |
112 qed "ex_elim_lemma"; |
113 |
113 |
114 Goalw [BufAC_def] "f\\<in>BufAC \\<Longrightarrow> \\<exists>ff\\<in>BufAC. \\<forall>x. f\\<cdot>(Md d\\<leadsto>\\<bullet>\\<leadsto>x) = d\\<leadsto>ff\\<cdot>x"; |
114 Goalw [BufAC_def] "f\\<in>BufAC \\<Longrightarrow> \\<exists>ff\\<in>BufAC. \\<forall>x. f\\<cdot>(Md d\\<leadsto>\\<bullet>\\<leadsto>x) = d\\<leadsto>ff\\<cdot>x"; |
115 by (rtac (ex_elim_lemma RS iffD2) 1); |
115 by (rtac (ex_elim_lemma RS iffD2) 1); |
116 by Safe_tac; |
116 by Safe_tac; |
117 by (fast_tac (claset() addIs [BufAC_Cmt_d32 RS Def_maximal, |
117 by (fast_tac (claset() addIs [BufAC_Cmt_d32 RS Def_maximal, |
118 monofun_cfun_arg, BufAC_Asm_empty RS BufAC_Asm_d_req]) 1); |
118 monofun_cfun_arg, BufAC_Asm_empty RS BufAC_Asm_d_req]) 1); |
119 by (auto_tac (claset() addIs [BufAC_Cmt_d3, BufAC_Asm_d_req],simpset())); |
119 by (auto_tac (claset() addIs [BufAC_Cmt_d3, BufAC_Asm_d_req],simpset())); |
120 qed "BufAC_f_d_req"; |
120 qed "BufAC_f_d_req"; |
121 |
121 |
122 |
122 |
123 (**** BufSt *******************************************************************) |
123 (**** BufSt *******************************************************************) |
124 |
124 |
125 val mono_BufSt_F = prove_goalw thy [mono_def, BufSt_F_def] |
125 val mono_BufSt_F = prove_goalw (the_context ()) [mono_def, BufSt_F_def] |
126 "mono BufSt_F" (K [Fast_tac 1]); |
126 "mono BufSt_F" (K [Fast_tac 1]); |
127 |
127 |
128 val BufSt_P_fix = mono_BufSt_F RS (BufSt_P_def RS def_gfp_unfold); |
128 val BufSt_P_fix = mono_BufSt_F RS (BufSt_P_def RS def_gfp_unfold); |
129 |
129 |
130 val BufSt_P_unfold = prove_goal thy "(h:BufSt_P) = (!s. h s\\<cdot><> = <> & \ |
130 val BufSt_P_unfold = prove_goal (the_context ()) "(h:BufSt_P) = (!s. h s\\<cdot><> = <> & \ |
131 \ (!d x. h \\<currency> \\<cdot>(Md d\\<leadsto>x) = h (Sd d)\\<cdot>x & \ |
131 \ (!d x. h \\<currency> \\<cdot>(Md d\\<leadsto>x) = h (Sd d)\\<cdot>x & \ |
132 \ (? hh:BufSt_P. h (Sd d)\\<cdot>(\\<bullet>\\<leadsto>x) = d\\<leadsto>(hh \\<currency> \\<cdot>x))))" (K [ |
132 \ (? hh:BufSt_P. h (Sd d)\\<cdot>(\\<bullet>\\<leadsto>x) = d\\<leadsto>(hh \\<currency> \\<cdot>x))))" (K [ |
133 stac (BufSt_P_fix RS set_cong) 1, |
133 stac (BufSt_P_fix RS set_cong) 1, |
134 rewtac BufSt_F_def, |
134 rewtac BufSt_F_def, |
135 Asm_full_simp_tac 1]); |
135 Asm_full_simp_tac 1]); |
136 |
136 |
137 val BufSt_P_empty = prove_forw "h:BufSt_P ==> h s \\<cdot> <> = <>" |
137 val BufSt_P_empty = prove_forw "h:BufSt_P ==> h s \\<cdot> <> = <>" |
138 BufSt_P_unfold; |
138 BufSt_P_unfold; |
139 val BufSt_P_d = prove_forw "h:BufSt_P ==> h \\<currency> \\<cdot>(Md d\\<leadsto>x) = h (Sd d)\\<cdot>x" |
139 val BufSt_P_d = prove_forw "h:BufSt_P ==> h \\<currency> \\<cdot>(Md d\\<leadsto>x) = h (Sd d)\\<cdot>x" |
140 BufSt_P_unfold; |
140 BufSt_P_unfold; |
141 val BufSt_P_d_req = prove_forw "h:BufSt_P ==> \\<exists>hh\\<in>BufSt_P. \ |
141 val BufSt_P_d_req = prove_forw "h:BufSt_P ==> \\<exists>hh\\<in>BufSt_P. \ |
142 \ h (Sd d)\\<cdot>(\\<bullet> \\<leadsto>x) = d\\<leadsto>(hh \\<currency> \\<cdot>x)" |
142 \ h (Sd d)\\<cdot>(\\<bullet> \\<leadsto>x) = d\\<leadsto>(hh \\<currency> \\<cdot>x)" |
143 BufSt_P_unfold; |
143 BufSt_P_unfold; |
144 |
144 |
145 |
145 |
146 (**** Buf_AC_imp_Eq ***********************************************************) |
146 (**** Buf_AC_imp_Eq ***********************************************************) |
147 |
147 |
148 Goalw [BufEq_def] "BufAC \\<subseteq> BufEq"; |
148 Goalw [BufEq_def] "BufAC \\<subseteq> BufEq"; |
208 val Buf_Eq_eq_AC = Buf_AC_imp_Eq RS (Buf_Eq_imp_AC RS subset_antisym); |
208 val Buf_Eq_eq_AC = Buf_AC_imp_Eq RS (Buf_Eq_imp_AC RS subset_antisym); |
209 |
209 |
210 |
210 |
211 (**** alternative (not strictly) stronger version of Buf_Eq *******************) |
211 (**** alternative (not strictly) stronger version of Buf_Eq *******************) |
212 |
212 |
213 val Buf_Eq_alt_imp_Eq = prove_goalw thy [BufEq_def,BufEq_alt_def] |
213 val Buf_Eq_alt_imp_Eq = prove_goalw (the_context ()) [BufEq_def,BufEq_alt_def] |
214 "BufEq_alt \\<subseteq> BufEq" (K [ |
214 "BufEq_alt \\<subseteq> BufEq" (K [ |
215 rtac gfp_mono 1, |
215 rtac gfp_mono 1, |
216 rewtac BufEq_F_def, |
216 rewtac BufEq_F_def, |
217 Fast_tac 1]); |
217 Fast_tac 1]); |
218 |
218 |
219 (* direct proof of "BufEq \\<subseteq> BufEq_alt" seems impossible *) |
219 (* direct proof of "BufEq \\<subseteq> BufEq_alt" seems impossible *) |
220 |
220 |
221 |
221 |
222 Goalw [BufEq_alt_def] "BufAC <= BufEq_alt"; |
222 Goalw [BufEq_alt_def] "BufAC <= BufEq_alt"; |
223 by (rtac gfp_upperbound 1); |
223 by (rtac gfp_upperbound 1); |
224 by (fast_tac (claset() addEs [BufAC_f_d, BufAC_f_d_req]) 1); |
224 by (fast_tac (claset() addEs [BufAC_f_d, BufAC_f_d_req]) 1); |
225 qed "Buf_AC_imp_Eq_alt"; |
225 qed "Buf_AC_imp_Eq_alt"; |
226 |
226 |
227 bind_thm ("Buf_Eq_imp_Eq_alt", |
227 bind_thm ("Buf_Eq_imp_Eq_alt", |
228 subset_trans OF [Buf_Eq_imp_AC, Buf_AC_imp_Eq_alt]); |
228 subset_trans OF [Buf_Eq_imp_AC, Buf_AC_imp_Eq_alt]); |
229 |
229 |
230 bind_thm ("Buf_Eq_alt_eq", |
230 bind_thm ("Buf_Eq_alt_eq", |
231 subset_antisym OF [Buf_Eq_alt_imp_Eq, Buf_Eq_imp_Eq_alt]); |
231 subset_antisym OF [Buf_Eq_alt_imp_Eq, Buf_Eq_imp_Eq_alt]); |
232 |
232 |
233 |
233 |
234 (**** Buf_Eq_eq_St ************************************************************) |
234 (**** Buf_Eq_eq_St ************************************************************) |
235 |
235 |