src/HOLCF/FOCUS/Buffer.ML
author skalberg
Thu Aug 28 01:56:40 2003 +0200 (2003-08-28)
changeset 14171 0cab06e3bbd0
parent 13454 01e2496dee05
child 14981 e73f8140af78
permissions -rw-r--r--
Extended the notion of letter and digit, such that now one may use greek,
gothic, euler, or calligraphic letters as normal letters.
     1 (*  Title: 	HOLCF/FOCUS/Buffer.ML
     2     ID:         $Id$
     3     Author: 	David von Oheimb, TU Muenchen
     4     License:    GPL (GNU GENERAL PUBLIC LICENSE)
     5 *)
     6 
     7 val set_cong = prove_goal Set.thy "!!X. A = B ==> (x:A) = (x:B)" (K [
     8 	etac subst 1, rtac refl 1]);
     9 
    10 fun B_prover s tac eqs = prove_goal thy s (fn prems => [cut_facts_tac prems 1, 
    11 	tac 1, auto_tac (claset(), simpset() addsimps eqs)]);
    12 
    13 fun prove_forw  s thm     = B_prover s (dtac (thm RS iffD1)) [];
    14 fun prove_backw s thm eqs = B_prover s (rtac (thm RS iffD2)) eqs;
    15 
    16 
    17 (**** BufEq *******************************************************************)
    18 
    19 val mono_BufEq_F = prove_goalw thy [mono_def, BufEq_F_def] 
    20 		"mono BufEq_F" (K [Fast_tac 1]);
    21 
    22 val BufEq_fix = mono_BufEq_F RS (BufEq_def RS def_gfp_unfold);
    23 
    24 val BufEq_unfold = prove_goal thy "(f:BufEq) = (!d. f\\<cdot>(Md d\\<leadsto><>) = <> & \
    25 		\(!x. ? ff:BufEq. f\\<cdot>(Md d\\<leadsto>\\<bullet>\\<leadsto>x) = d\\<leadsto>(ff\\<cdot>x)))" (K [
    26 	stac (BufEq_fix RS set_cong) 1,
    27 	rewtac BufEq_F_def,
    28 	Asm_full_simp_tac 1]);
    29 
    30 val Buf_f_empty = prove_forw "f:BufEq \\<Longrightarrow> f\\<cdot><> = <>" BufEq_unfold;
    31 val Buf_f_d     = prove_forw "f:BufEq \\<Longrightarrow> f\\<cdot>(Md d\\<leadsto><>) = <>" BufEq_unfold;
    32 val Buf_f_d_req = prove_forw 
    33 	"f:BufEq \\<Longrightarrow> \\<exists>ff. ff:BufEq \\<and> f\\<cdot>(Md d\\<leadsto>\\<bullet>\\<leadsto>x) = d\\<leadsto>ff\\<cdot>x" BufEq_unfold;
    34 
    35 
    36 (**** BufAC_Asm ***************************************************************)
    37 
    38 val mono_BufAC_Asm_F = prove_goalw thy [mono_def, BufAC_Asm_F_def]
    39 		"mono BufAC_Asm_F" (K [Fast_tac 1]);
    40 
    41 val BufAC_Asm_fix = mono_BufAC_Asm_F RS (BufAC_Asm_def RS def_gfp_unfold);
    42 
    43 val BufAC_Asm_unfold = prove_goal thy "(s:BufAC_Asm) = (s = <> | (? d x. \
    44 \       s = Md d\\<leadsto>x & (x = <> | (ft\\<cdot>x = Def \\<bullet> & (rt\\<cdot>x):BufAC_Asm))))" (K [
    45 				stac (BufAC_Asm_fix RS set_cong) 1,
    46 				rewtac BufAC_Asm_F_def,
    47 				Asm_full_simp_tac 1]);
    48 
    49 val BufAC_Asm_empty = prove_backw "<>     :BufAC_Asm" BufAC_Asm_unfold [];
    50 val BufAC_Asm_d     = prove_backw "Md d\\<leadsto><>:BufAC_Asm" BufAC_Asm_unfold [];
    51 val BufAC_Asm_d_req = prove_backw "x:BufAC_Asm ==> Md d\\<leadsto>\\<bullet>\\<leadsto>x:BufAC_Asm"
    52 							   BufAC_Asm_unfold [];
    53 val BufAC_Asm_prefix2 = prove_forw "a\\<leadsto>b\\<leadsto>s:BufAC_Asm ==> s:BufAC_Asm"
    54 							 BufAC_Asm_unfold;
    55 
    56 
    57 (**** BBufAC_Cmt **************************************************************)
    58 
    59 val mono_BufAC_Cmt_F = prove_goalw thy [mono_def, BufAC_Cmt_F_def] 
    60 		"mono BufAC_Cmt_F" (K [Fast_tac 1]);
    61 
    62 val BufAC_Cmt_fix = mono_BufAC_Cmt_F RS (BufAC_Cmt_def RS def_gfp_unfold);
    63 
    64 val BufAC_Cmt_unfold = prove_goal thy "((s,t):BufAC_Cmt) = (!d x. \
    65     \(s = <>       -->      t = <>) & \
    66     \(s = Md d\\<leadsto><>  -->      t = <>) & \
    67     \(s = Md d\\<leadsto>\\<bullet>\\<leadsto>x --> ft\\<cdot>t = Def d & (x, rt\\<cdot>t):BufAC_Cmt))" (K [
    68 	stac (BufAC_Cmt_fix RS set_cong) 1,
    69 	rewtac BufAC_Cmt_F_def,
    70 	Asm_full_simp_tac 1]);
    71 
    72 val BufAC_Cmt_empty = prove_backw "f:BufEq ==> (<>, f\\<cdot><>):BufAC_Cmt"
    73 				BufAC_Cmt_unfold [Buf_f_empty];
    74 
    75 val BufAC_Cmt_d = prove_backw "f:BufEq ==> (a\\<leadsto>\\<bottom>, f\\<cdot>(a\\<leadsto>\\<bottom>)):BufAC_Cmt" 
    76 				BufAC_Cmt_unfold [Buf_f_d];
    77 
    78 val BufAC_Cmt_d2 = prove_forw 
    79  "(Md d\\<leadsto>\\<bottom>, f\\<cdot>(Md d\\<leadsto>\\<bottom>)):BufAC_Cmt ==> f\\<cdot>(Md d\\<leadsto>\\<bottom>) = \\<bottom>" BufAC_Cmt_unfold;
    80 val BufAC_Cmt_d3 = prove_forw 
    81 "(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"
    82 							BufAC_Cmt_unfold;
    83 
    84 val BufAC_Cmt_d32 = prove_forw 
    85 "(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"
    86 							BufAC_Cmt_unfold;
    87 
    88 (**** BufAC *******************************************************************)
    89 
    90 Goalw [BufAC_def] "f \\<in> BufAC \\<Longrightarrow> f\\<cdot>(Md d\\<leadsto>\\<bottom>) = \\<bottom>";
    91 by (fast_tac (claset() addIs [BufAC_Cmt_d2, BufAC_Asm_d]) 1);
    92 qed "BufAC_f_d";
    93 
    94 Goal "(? ff:B. (!x. f\\<cdot>(a\\<leadsto>b\\<leadsto>x) = d\\<leadsto>ff\\<cdot>x)) = \
    95    \((!x. ft\\<cdot>(f\\<cdot>(a\\<leadsto>b\\<leadsto>x)) = Def d) & (LAM x. rt\\<cdot>(f\\<cdot>(a\\<leadsto>b\\<leadsto>x))):B)";
    96 (*  this is an instance (though unification cannot handle this) of
    97 Goal "(? ff:B. (!x. f\\<cdot>x = d\\<leadsto>ff\\<cdot>x)) = \
    98    \((!x. ft\\<cdot>(f\\<cdot>x) = Def d) & (LAM x. rt\\<cdot>(f\\<cdot>x)):B)";*)
    99 by Safe_tac;
   100 by (  res_inst_tac [("P","(%x. x:B)")] ssubst 2);
   101 by (   atac 3);
   102 by (  rtac ext_cfun 2);
   103 by (  dtac spec 2);
   104 by (  dres_inst_tac [("f","rt")] cfun_arg_cong 2);
   105 by (  Asm_full_simp_tac 2);
   106 by ( Full_simp_tac 2);
   107 by (rtac bexI 2);
   108 by Auto_tac;
   109 by (dtac spec 1);
   110 by (etac exE 1);;
   111 by (etac ssubst 1);
   112 by (Simp_tac 1);
   113 qed "ex_elim_lemma";
   114 
   115 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";
   116 by (rtac (ex_elim_lemma RS iffD2) 1);
   117 by Safe_tac;
   118 by  (fast_tac (claset() addIs [BufAC_Cmt_d32 RS Def_maximal, 
   119              monofun_cfun_arg,	BufAC_Asm_empty RS BufAC_Asm_d_req]) 1);
   120 by (auto_tac (claset() addIs [BufAC_Cmt_d3, BufAC_Asm_d_req],simpset()));
   121 qed "BufAC_f_d_req";
   122 
   123 
   124 (**** BufSt *******************************************************************)
   125 
   126 val mono_BufSt_F = prove_goalw thy [mono_def, BufSt_F_def] 
   127 		"mono BufSt_F" (K [Fast_tac 1]);
   128 
   129 val BufSt_P_fix = mono_BufSt_F RS (BufSt_P_def RS def_gfp_unfold);
   130 
   131 val BufSt_P_unfold = prove_goal thy "(h:BufSt_P) = (!s. h s\\<cdot><> = <> & \
   132 	 \ (!d x. h \\<currency>     \\<cdot>(Md d\\<leadsto>x)   =    h (Sd d)\\<cdot>x & \
   133   \   (? hh:BufSt_P. h (Sd d)\\<cdot>(\\<bullet>\\<leadsto>x)   = d\\<leadsto>(hh \\<currency>    \\<cdot>x))))" (K [
   134 	stac (BufSt_P_fix RS set_cong) 1,
   135 	rewtac BufSt_F_def,
   136 	Asm_full_simp_tac 1]);
   137 
   138 val BufSt_P_empty = prove_forw "h:BufSt_P ==> h s     \\<cdot> <>       = <>" 
   139 			BufSt_P_unfold;
   140 val BufSt_P_d     = prove_forw "h:BufSt_P ==> h  \\<currency>    \\<cdot>(Md d\\<leadsto>x) = h (Sd d)\\<cdot>x"
   141 			BufSt_P_unfold;
   142 val BufSt_P_d_req = prove_forw "h:BufSt_P ==> \\<exists>hh\\<in>BufSt_P. \
   143 				         \ h (Sd d)\\<cdot>(\\<bullet>   \\<leadsto>x) = d\\<leadsto>(hh \\<currency>    \\<cdot>x)"
   144 			BufSt_P_unfold;
   145 
   146 
   147 (**** Buf_AC_imp_Eq ***********************************************************)
   148 
   149 Goalw [BufEq_def] "BufAC \\<subseteq> BufEq";
   150 by (rtac gfp_upperbound 1);
   151 by (rewtac BufEq_F_def);
   152 by Safe_tac;
   153 by  (etac BufAC_f_d 1);
   154 by (dtac BufAC_f_d_req 1);
   155 by (Fast_tac 1);
   156 qed "Buf_AC_imp_Eq";
   157 
   158 
   159 (**** Buf_Eq_imp_AC by coinduction ********************************************)
   160 
   161 Goal "\\<forall>s f ff. f\\<in>BufEq \\<longrightarrow> ff\\<in>BufEq \\<longrightarrow> \
   162 \ s\\<in>BufAC_Asm \\<longrightarrow> stream_take n\\<cdot>(f\\<cdot>s) = stream_take n\\<cdot>(ff\\<cdot>s)";
   163 by (induct_tac "n" 1);
   164 by  (Simp_tac 1);
   165 by (strip_tac 1);
   166 by (dtac (BufAC_Asm_unfold RS iffD1) 1);
   167 by Safe_tac;
   168 by   (asm_simp_tac (simpset() addsimps [Buf_f_empty]) 1);
   169 by  (asm_simp_tac (simpset() addsimps [Buf_f_d]) 1);
   170 by (dtac (ft_eq RS iffD1) 1);
   171 by (Clarsimp_tac 1);
   172 by (REPEAT(dtac Buf_f_d_req 1));
   173 by Safe_tac;
   174 by (REPEAT(etac ssubst 1));
   175 by (Simp_tac 1);
   176 by (Fast_tac 1);
   177 qed_spec_mp "BufAC_Asm_cong_lemma";
   178 Goal "\\<lbrakk>f \\<in> BufEq; ff \\<in> BufEq; s \\<in> BufAC_Asm\\<rbrakk> \\<Longrightarrow> f\\<cdot>s = ff\\<cdot>s";
   179 by (resolve_tac stream.take_lemmas 1);
   180 by (eatac BufAC_Asm_cong_lemma 2 1);
   181 qed "BufAC_Asm_cong";
   182 
   183 Goalw [BufAC_Cmt_def] "\\<lbrakk>f \\<in> BufEq; x \\<in> BufAC_Asm\\<rbrakk> \\<Longrightarrow> (x, f\\<cdot>x) \\<in> BufAC_Cmt";
   184 by (rotate_tac ~1 1);
   185 by (etac weak_coinduct_image 1);
   186 by (rewtac BufAC_Cmt_F_def);
   187 by Safe_tac;
   188 by    (etac Buf_f_empty 1);
   189 by   (etac Buf_f_d 1);
   190 by  (dtac Buf_f_d_req 1);
   191 by  (Clarsimp_tac 1);
   192 by  (etac exI 1);
   193 by (dtac BufAC_Asm_prefix2 1);
   194 by (ftac Buf_f_d_req 1);
   195 by (Clarsimp_tac 1);
   196 by (etac ssubst 1);
   197 by (Simp_tac 1);
   198 by (datac BufAC_Asm_cong 2 1);
   199 by (etac subst 1);
   200 by (etac imageI 1);
   201 qed "Buf_Eq_imp_AC_lemma";
   202 Goalw [BufAC_def] "BufEq \\<subseteq> BufAC";
   203 by (Clarify_tac 1);
   204 by (eatac Buf_Eq_imp_AC_lemma 1 1);
   205 qed "Buf_Eq_imp_AC";
   206 
   207 (**** Buf_Eq_eq_AC ************************************************************)
   208 
   209 val Buf_Eq_eq_AC = Buf_AC_imp_Eq RS (Buf_Eq_imp_AC RS subset_antisym);
   210 
   211 
   212 (**** alternative (not strictly) stronger version of Buf_Eq *******************)
   213 
   214 val Buf_Eq_alt_imp_Eq = prove_goalw thy [BufEq_def,BufEq_alt_def] 
   215 	"BufEq_alt \\<subseteq> BufEq" (K [
   216 	rtac gfp_mono 1,
   217 	rewtac BufEq_F_def,
   218 	Fast_tac 1]);
   219 
   220 (* direct proof of "BufEq \\<subseteq> BufEq_alt" seems impossible *)
   221 
   222 
   223 Goalw [BufEq_alt_def] "BufAC <= BufEq_alt";
   224 by (rtac gfp_upperbound 1);
   225 by (fast_tac (claset() addEs [BufAC_f_d, BufAC_f_d_req]) 1);
   226 qed "Buf_AC_imp_Eq_alt";
   227 
   228 bind_thm ("Buf_Eq_imp_Eq_alt", 
   229   subset_trans OF [Buf_Eq_imp_AC, Buf_AC_imp_Eq_alt]);
   230 
   231 bind_thm ("Buf_Eq_alt_eq", 
   232  subset_antisym OF [Buf_Eq_alt_imp_Eq, Buf_Eq_imp_Eq_alt]);
   233 
   234 
   235 (**** Buf_Eq_eq_St ************************************************************)
   236 
   237 Goalw [BufSt_def, BufEq_def] "BufSt <= BufEq";
   238 by (rtac gfp_upperbound 1);
   239 by (rewtac BufEq_F_def);
   240 by Safe_tac;
   241 by ( asm_simp_tac (simpset() addsimps [BufSt_P_d, BufSt_P_empty]) 1);
   242 by (asm_simp_tac (simpset() addsimps [BufSt_P_d]) 1);
   243 by (dtac BufSt_P_d_req 1);
   244 by (Force_tac 1);
   245 qed "Buf_St_imp_Eq";
   246 
   247 Goalw [BufSt_def, BufSt_P_def] "BufEq <= BufSt";
   248 by Safe_tac;
   249 by (EVERY'[rename_tac "f", res_inst_tac 
   250         [("x","\\<lambda>s. case s of Sd d => \\<Lambda> x. f\\<cdot>(Md d\\<leadsto>x)| \\<currency> => f")] bexI] 1);
   251 by ( Simp_tac 1);
   252 by (etac weak_coinduct_image 1);
   253 by (rewtac BufSt_F_def); 
   254 by (Simp_tac 1);
   255 by Safe_tac;
   256 by (  EVERY'[rename_tac "s", induct_tac "s"] 1);
   257 by (   asm_simp_tac (simpset() addsimps [Buf_f_d]) 1);
   258 by (  asm_simp_tac (simpset() addsimps [Buf_f_empty]) 1);
   259 by ( Simp_tac 1);
   260 by (Simp_tac 1);
   261 by (EVERY'[rename_tac"f d x",dres_inst_tac[("d","d"),("x","x")] Buf_f_d_req] 1);
   262 by Auto_tac;
   263 qed "Buf_Eq_imp_St";
   264 
   265 bind_thm ("Buf_Eq_eq_St", Buf_St_imp_Eq RS (Buf_Eq_imp_St RS subset_antisym));
   266 
   267 
   268