thys/Spec.thy
changeset 267 32b222d77fa0
parent 266 fff2e1b40dfc
child 268 6746f5e1f1f8
equal deleted inserted replaced
266:fff2e1b40dfc 267:32b222d77fa0
     1    
     1    
     2 theory Spec
     2 theory Spec
     3   imports Main 
     3   imports Main "~~/src/HOL/Library/Sublist"
     4 begin
     4 begin
     5 
       
     6 
     5 
     7 section {* Sequential Composition of Languages *}
     6 section {* Sequential Composition of Languages *}
     8 
     7 
     9 definition
     8 definition
    10   Sequ :: "string set \<Rightarrow> string set \<Rightarrow> string set" ("_ ;; _" [100,100] 100)
     9   Sequ :: "string set \<Rightarrow> string set \<Rightarrow> string set" ("_ ;; _" [100,100] 100)
   170   shows "L (der c r) = Der c (L r)"
   169   shows "L (der c r) = Der c (L r)"
   171 by (induct r) (simp_all add: nullable_correctness)
   170 by (induct r) (simp_all add: nullable_correctness)
   172 
   171 
   173 lemma ders_correctness:
   172 lemma ders_correctness:
   174   shows "L (ders s r) = Ders s (L r)"
   173   shows "L (ders s r) = Ders s (L r)"
   175 apply(induct s arbitrary: r)
   174 by (induct s arbitrary: r)
   176 apply(simp_all add: Ders_def der_correctness Der_def)
   175    (simp_all add: Ders_def der_correctness Der_def)
   177 done
   176 
   178 
   177 
   179 
   178 
   180 section {* Lemmas about ders *}
   179 section {* Lemmas about ders *}
       
   180 
       
   181 (* not really needed *)
   181 
   182 
   182 lemma ders_ZERO:
   183 lemma ders_ZERO:
   183   shows "ders s (ZERO) = ZERO"
   184   shows "ders s (ZERO) = ZERO"
   184 apply(induct s)
   185 apply(induct s)
   185 apply(simp_all)
   186 apply(simp_all)
   199 apply(simp_all add: ders_ZERO ders_ONE)
   200 apply(simp_all add: ders_ZERO ders_ONE)
   200 done
   201 done
   201 
   202 
   202 lemma  ders_ALT:
   203 lemma  ders_ALT:
   203   shows "ders s (ALT r1 r2) = ALT (ders s r1) (ders s r2)"
   204   shows "ders s (ALT r1 r2) = ALT (ders s r1) (ders s r2)"
   204 apply(induct s arbitrary: r1 r2)
   205 by (induct s arbitrary: r1 r2)(simp_all)
   205 apply(simp_all)
   206 
   206 done
       
   207 
   207 
   208 section {* Values *}
   208 section {* Values *}
   209 
   209 
   210 datatype val = 
   210 datatype val = 
   211   Void
   211   Void
   227 | "flat (Right v) = flat v"
   227 | "flat (Right v) = flat v"
   228 | "flat (Seq v1 v2) = (flat v1) @ (flat v2)"
   228 | "flat (Seq v1 v2) = (flat v1) @ (flat v2)"
   229 | "flat (Stars []) = []"
   229 | "flat (Stars []) = []"
   230 | "flat (Stars (v#vs)) = (flat v) @ (flat (Stars vs))" 
   230 | "flat (Stars (v#vs)) = (flat v) @ (flat (Stars vs))" 
   231 
   231 
       
   232 abbreviation
       
   233   "flats vs \<equiv> concat (map flat vs)"
       
   234 
   232 lemma flat_Stars [simp]:
   235 lemma flat_Stars [simp]:
   233  "flat (Stars vs) = concat (map flat vs)"
   236  "flat (Stars vs) = flats vs"
   234 by (induct vs) (auto)
   237 by (induct vs) (auto)
   235 
   238 
   236 
   239 
   237 section {* Relation between values and regular expressions *}
   240 section {* Relation between values and regular expressions *}
   238 
   241 
   271 apply(simp)
   274 apply(simp)
   272 done
   275 done
   273 
   276 
   274 lemma Star_val:
   277 lemma Star_val:
   275   assumes "\<forall>s\<in>set ss. \<exists>v. s = flat v \<and> \<turnstile> v : r"
   278   assumes "\<forall>s\<in>set ss. \<exists>v. s = flat v \<and> \<turnstile> v : r"
   276   shows "\<exists>vs. concat (map flat vs) = concat ss \<and> (\<forall>v\<in>set vs. \<turnstile> v : r)"
   279   shows "\<exists>vs. flats vs = concat ss \<and> (\<forall>v\<in>set vs. \<turnstile> v : r)"
   277 using assms
   280 using assms
   278 apply(induct ss)
   281 apply(induct ss)
   279 apply(auto)
   282 apply(auto)
   280 apply(rule_tac x="[]" in exI)
   283 apply(rule_tac x="[]" in exI)
   281 apply(simp)
   284 apply(simp)
   311   case (STAR r s)
   314   case (STAR r s)
   312   have IH: "\<And>s. s \<in> L r \<Longrightarrow> \<exists>v. \<turnstile> v : r \<and> flat v = s" by fact
   315   have IH: "\<And>s. s \<in> L r \<Longrightarrow> \<exists>v. \<turnstile> v : r \<and> flat v = s" by fact
   313   have "s \<in> L (STAR r)" by fact
   316   have "s \<in> L (STAR r)" by fact
   314   then obtain ss where "concat ss = s" "\<forall>s \<in> set ss. s \<in> L r"
   317   then obtain ss where "concat ss = s" "\<forall>s \<in> set ss. s \<in> L r"
   315   using Star_string by auto
   318   using Star_string by auto
   316   then obtain vs where "concat (map flat vs) = s" "\<forall>v\<in>set vs. \<turnstile> v : r"
   319   then obtain vs where "flats vs = s" "\<forall>v\<in>set vs. \<turnstile> v : r"
   317   using IH Star_val by blast
   320   using IH Star_val by blast
   318   then show "\<exists>v. \<turnstile> v : STAR r \<and> flat v = s"
   321   then show "\<exists>v. \<turnstile> v : STAR r \<and> flat v = s"
   319   using Prf.intros(6) flat_Stars by blast
   322   using Prf.intros(6) flat_Stars by blast
   320 next 
   323 next 
   321   case (SEQ r1 r2 s)
   324   case (SEQ r1 r2 s)
   329 
   332 
   330 lemma L_flat_Prf:
   333 lemma L_flat_Prf:
   331   shows "L(r) = {flat v | v. \<turnstile> v : r}"
   334   shows "L(r) = {flat v | v. \<turnstile> v : r}"
   332 using L_flat_Prf1 L_flat_Prf2 by blast
   335 using L_flat_Prf1 L_flat_Prf2 by blast
   333 
   336 
   334 section {* CPT and CPTpre *}
   337 
   335 
   338 section {* Canonical Values *}
   336 
   339 
   337 inductive 
   340 inductive 
   338   CPrf :: "val \<Rightarrow> rexp \<Rightarrow> bool" ("\<Turnstile> _ : _" [100, 100] 100)
   341   CPrf :: "val \<Rightarrow> rexp \<Rightarrow> bool" ("\<Turnstile> _ : _" [100, 100] 100)
   339 where
   342 where
   340  "\<lbrakk>\<Turnstile> v1 : r1; \<Turnstile> v2 : r2\<rbrakk> \<Longrightarrow> \<Turnstile>  Seq v1 v2 : SEQ r1 r2"
   343  "\<lbrakk>\<Turnstile> v1 : r1; \<Turnstile> v2 : r2\<rbrakk> \<Longrightarrow> \<Turnstile>  Seq v1 v2 : SEQ r1 r2"
   348   assumes "\<Turnstile> v : r"
   351   assumes "\<Turnstile> v : r"
   349   shows "\<turnstile> v : r"
   352   shows "\<turnstile> v : r"
   350 using assms
   353 using assms
   351 by (induct)(auto intro: Prf.intros)
   354 by (induct)(auto intro: Prf.intros)
   352 
   355 
   353 lemma CPrf_stars:
       
   354   assumes "\<Turnstile> Stars vs : STAR r"
       
   355   shows "\<forall>v \<in> set vs. flat v \<noteq> [] \<and> \<Turnstile> v : r"
       
   356 using assms
       
   357 apply(erule_tac CPrf.cases)
       
   358 apply(simp_all)
       
   359 done
       
   360 
       
   361 lemma CPrf_Stars_appendE:
   356 lemma CPrf_Stars_appendE:
   362   assumes "\<Turnstile> Stars (vs1 @ vs2) : STAR r"
   357   assumes "\<Turnstile> Stars (vs1 @ vs2) : STAR r"
   363   shows "\<Turnstile> Stars vs1 : STAR r \<and> \<Turnstile> Stars vs2 : STAR r" 
   358   shows "\<Turnstile> Stars vs1 : STAR r \<and> \<Turnstile> Stars vs2 : STAR r" 
   364 using assms
   359 using assms
   365 apply(erule_tac CPrf.cases)
   360 apply(erule_tac CPrf.cases)
   366 apply(auto intro: CPrf.intros elim: Prf.cases)
   361 apply(auto intro: CPrf.intros)
   367 done
   362 done
   368 
   363 
   369 definition PT :: "rexp \<Rightarrow> string \<Rightarrow> val set"
   364 
   370 where "PT r s \<equiv> {v. flat v = s \<and> \<turnstile> v : r}"
   365 section {* Sets of Lexical and Canonical Values *}
       
   366 
       
   367 definition 
       
   368   LV :: "rexp \<Rightarrow> string \<Rightarrow> val set"
       
   369 where "LV r s \<equiv> {v.  \<turnstile> v : r \<and> flat v = s}"
   371 
   370 
   372 definition
   371 definition
   373   "CPT r s = {v. flat v = s \<and> \<Turnstile> v : r}"
   372   CV :: "rexp \<Rightarrow> string \<Rightarrow> val set"
   374 
   373 where  "CV r s \<equiv> {v. \<Turnstile> v : r \<and> flat v = s}"
   375 definition
   374 
   376   "CPTpre r s = {v. \<exists>s'. flat v @ s' = s \<and> \<Turnstile> v : r}"
   375 lemma LV_CV_subset:
   377 
   376   shows "CV r s \<subseteq> LV r s"
   378 lemma CPT_CPTpre_subset:
   377 unfolding CV_def LV_def by(auto simp add: Prf_CPrf)
   379   shows "CPT r s \<subseteq> CPTpre r s"
   378 
   380 by(auto simp add: CPT_def CPTpre_def)
   379 abbreviation
   381 
   380   "Prefixes s \<equiv> {s'. prefixeq s' s}"
   382 lemma CPT_simps:
   381 
   383   shows "CPT ZERO s = {}"
   382 abbreviation
   384   and   "CPT ONE s = (if s = [] then {Void} else {})"
   383   "Suffixes s \<equiv> {s'. suffixeq s' s}"
   385   and   "CPT (CHAR c) s = (if s = [c] then {Char c} else {})"
   384 
   386   and   "CPT (ALT r1 r2) s = Left ` CPT r1 s \<union> Right ` CPT r2 s"
   385 abbreviation
   387   and   "CPT (SEQ r1 r2) s = 
   386   "SSuffixes s \<equiv> {s'. suffix s' s}"
   388           {Seq v1 v2 | v1 v2. flat v1 @ flat v2 = s \<and> v1 \<in> CPT r1 (flat v1) \<and> v2 \<in> CPT r2 (flat v2)}"
   387 
   389   and   "CPT (STAR r) s = 
   388 lemma Suffixes_cons [simp]:
   390           Stars ` {vs. concat (map flat vs) = s \<and> (\<forall>v \<in> set vs. v \<in> CPT r (flat v) \<and> flat v \<noteq> [])}"
   389   shows "Suffixes (c # s) = Suffixes s \<union> {c # s}"
   391 apply -
   390 by (auto simp add: suffixeq_def Cons_eq_append_conv)
   392 apply(auto simp add: CPT_def intro: CPrf.intros)[1]
   391 
       
   392 lemma CV_simps:
       
   393   shows "CV ZERO s = {}"
       
   394   and   "CV ONE s = (if s = [] then {Void} else {})"
       
   395   and   "CV (CHAR c) s = (if s = [c] then {Char c} else {})"
       
   396   and   "CV (ALT r1 r2) s = Left ` CV r1 s \<union> Right ` CV r2 s"
       
   397 unfolding CV_def
       
   398 by (auto intro: CPrf.intros elim: CPrf.cases)
       
   399 
       
   400 lemma finite_Suffixes: 
       
   401   shows "finite (Suffixes s)"
       
   402 by (induct s) (simp_all)
       
   403 
       
   404 lemma finite_SSuffixes: 
       
   405   shows "finite (SSuffixes s)"
       
   406 proof -
       
   407   have "SSuffixes s \<subseteq> Suffixes s"
       
   408    unfolding suffix_def suffixeq_def by auto
       
   409   then show "finite (SSuffixes s)"
       
   410    using finite_Suffixes finite_subset by blast
       
   411 qed
       
   412 
       
   413 lemma finite_Prefixes: 
       
   414   shows "finite (Prefixes s)"
       
   415 proof -
       
   416   have "finite (Suffixes (rev s))" 
       
   417     by (rule finite_Suffixes)
       
   418   then have "finite (rev ` Suffixes (rev s))" by simp
       
   419   moreover
       
   420   have "rev ` (Suffixes (rev s)) = Prefixes s"
       
   421   unfolding suffixeq_def prefixeq_def image_def
       
   422    by (auto)(metis rev_append rev_rev_ident)+
       
   423   ultimately show "finite (Prefixes s)" by simp
       
   424 qed
       
   425 
       
   426 lemma CV_SEQ_subset:
       
   427   "CV (SEQ r1 r2) s \<subseteq> (\<lambda>(v1,v2). Seq v1 v2) ` ((\<Union>s' \<in> Prefixes s. CV r1 s') \<times> (\<Union>s' \<in> Suffixes s. CV r2 s'))"
       
   428 unfolding image_def CV_def prefixeq_def suffixeq_def
       
   429 by (auto elim: CPrf.cases)
       
   430 
       
   431 lemma CV_STAR_subset:
       
   432   "CV (STAR r) s \<subseteq> {Stars []} \<union>
       
   433       (\<lambda>(v,vs). Stars (v#vs)) ` ((\<Union>s' \<in> Prefixes s. CV r s') \<times> (\<Union>s2 \<in> SSuffixes s. Stars -` (CV (STAR r) s2)))"
       
   434 unfolding image_def CV_def prefixeq_def suffix_def
       
   435 apply(auto)
   393 apply(erule CPrf.cases)
   436 apply(erule CPrf.cases)
   394 apply(simp_all)[6]
   437 apply(auto)
   395 apply(auto simp add: CPT_def intro: CPrf.intros)[1]
   438 apply(case_tac vs)
   396 apply(erule CPrf.cases)
   439 apply(auto intro: CPrf.intros)
   397 apply(simp_all)[6]
   440 done
   398 apply(erule CPrf.cases)
   441 
   399 apply(simp_all)[6]
   442 
   400 apply(auto simp add: CPT_def intro: CPrf.intros)[1]
   443 lemma CV_STAR_finite:
   401 apply(erule CPrf.cases)
   444   assumes "\<forall>s. finite (CV r s)"
   402 apply(simp_all)[6]
   445   shows "finite (CV (STAR r) s)"
   403 apply(erule CPrf.cases)
   446 proof(induct s rule: length_induct)
   404 apply(simp_all)[6]
   447   fix s::"char list"
   405 apply(auto simp add: CPT_def intro: CPrf.intros)[1]
   448   assume "\<forall>s'. length s' < length s \<longrightarrow> finite (CV (STAR r) s')"
   406 apply(erule CPrf.cases)
   449   then have IH: "\<forall>s' \<in> SSuffixes s. finite (CV (STAR r) s')"
   407 apply(simp_all)[6]
   450     by (auto simp add: suffix_def) 
   408 apply(auto simp add: CPT_def intro: CPrf.intros)[1]
   451   def f \<equiv> "\<lambda>(v, vs). Stars (v # vs)"
   409 apply(erule CPrf.cases)
   452   def S1 \<equiv> "\<Union>s' \<in> Prefixes s. CV r s'"
   410 apply(simp_all)[6]
   453   def S2 \<equiv> "\<Union>s2 \<in> SSuffixes s. Stars -` (CV (STAR r) s2)"
   411 (* STAR case *)
   454   have "finite S1" using assms
   412 apply(auto simp add: CPT_def intro: CPrf.intros)[1]
   455     unfolding S1_def by (simp_all add: finite_Prefixes)
   413 apply(erule CPrf.cases)
   456   moreover 
   414 apply(simp_all)[6]
   457   with IH have "finite S2" unfolding S2_def
   415 done
   458     by (auto simp add: finite_SSuffixes inj_on_def finite_vimageI)
       
   459   ultimately 
       
   460   have "finite ({Stars []} \<union> f ` (S1 \<times> S2))" by simp
       
   461   moreover 
       
   462   have "CV (STAR r) s \<subseteq> {Stars []} \<union> f ` (S1 \<times> S2)" unfolding S1_def S2_def f_def
       
   463      by (rule CV_STAR_subset)
       
   464   ultimately
       
   465   show "finite (CV (STAR r) s)" by (simp add: finite_subset)
       
   466 qed  
       
   467     
       
   468 
       
   469 lemma CV_finite:
       
   470   shows "finite (CV r s)"
       
   471 proof(induct r arbitrary: s)
       
   472   case (ZERO s) 
       
   473   show "finite (CV ZERO s)" by (simp add: CV_simps)
       
   474 next
       
   475   case (ONE s)
       
   476   show "finite (CV ONE s)" by (simp add: CV_simps)
       
   477 next
       
   478   case (CHAR c s)
       
   479   show "finite (CV (CHAR c) s)" by (simp add: CV_simps)
       
   480 next 
       
   481   case (ALT r1 r2 s)
       
   482   then show "finite (CV (ALT r1 r2) s)" by (simp add: CV_simps)
       
   483 next 
       
   484   case (SEQ r1 r2 s)
       
   485   def f \<equiv> "\<lambda>(v1, v2). Seq v1 v2"
       
   486   def S1 \<equiv> "\<Union>s' \<in> Prefixes s. CV r1 s'"
       
   487   def S2 \<equiv> "\<Union>s' \<in> Suffixes s. CV r2 s'"
       
   488   have IHs: "\<And>s. finite (CV r1 s)" "\<And>s. finite (CV r2 s)" by fact+
       
   489   then have "finite S1" "finite S2" unfolding S1_def S2_def
       
   490     by (simp_all add: finite_Prefixes finite_Suffixes)
       
   491   moreover
       
   492   have "CV (SEQ r1 r2) s \<subseteq> f ` (S1 \<times> S2)"
       
   493     unfolding f_def S1_def S2_def by (auto simp add: CV_SEQ_subset)
       
   494   ultimately 
       
   495   show "finite (CV (SEQ r1 r2) s)"
       
   496     by (simp add: finite_subset)
       
   497 next
       
   498   case (STAR r s)
       
   499   then show "finite (CV (STAR r) s)" by (simp add: CV_STAR_finite)
       
   500 qed
   416 
   501 
   417 
   502 
   418 
   503 
   419 section {* Our POSIX Definition *}
   504 section {* Our POSIX Definition *}
   420 
   505 
   529 
   614 
   530 text {*
   615 text {*
   531   Our POSIX value is a canonical value.
   616   Our POSIX value is a canonical value.
   532 *}
   617 *}
   533 
   618 
   534 lemma Posix_CPT:
   619 lemma Posix_CV:
   535   assumes "s \<in> r \<rightarrow> v"
   620   assumes "s \<in> r \<rightarrow> v"
   536   shows "v \<in> CPT r s"
   621   shows "v \<in> CV r s"
   537 using assms
   622 using assms
   538 apply(induct rule: Posix.induct)
   623 apply(induct rule: Posix.induct)
   539 apply(auto simp add: CPT_def intro: CPrf.intros elim: CPrf.cases)
   624 apply(auto simp add: CV_def intro: CPrf.intros elim: CPrf.cases)
   540 apply(rotate_tac 5)
   625 apply(rotate_tac 5)
   541 apply(erule CPrf.cases)
   626 apply(erule CPrf.cases)
   542 apply(simp_all)
   627 apply(simp_all)
   543 apply(rule CPrf.intros)
   628 apply(rule CPrf.intros)
   544 apply(simp_all)
   629 apply(simp_all)
   545 done
   630 done
   546 
   631 
   547 
       
   548 
       
   549 (*
       
   550 lemma CPTpre_STAR_finite:
       
   551   assumes "\<And>s. finite (CPT r s)"
       
   552   shows "finite (CPT (STAR r) s)"
       
   553 apply(induct s rule: length_induct)
       
   554 apply(case_tac xs)
       
   555 apply(simp)
       
   556 apply(simp add: CPT_simps)
       
   557 apply(auto)
       
   558 apply(rule finite_imageI)
       
   559 using assms
       
   560 thm finite_Un
       
   561 prefer 2
       
   562 apply(simp add: CPT_simps)
       
   563 apply(rule finite_imageI)
       
   564 apply(rule finite_subset)
       
   565 apply(rule CPTpre_subsets)
       
   566 apply(simp)
       
   567 apply(rule_tac B="(\<lambda>(v, vs). Stars (v#vs)) ` {(v, vs). v \<in> CPTpre r (a#list) \<and> flat v \<noteq> [] \<and> Stars vs \<in> CPTpre (STAR r) (drop (length (flat v)) (a#list))}" in finite_subset)
       
   568 apply(auto)[1]
       
   569 apply(rule finite_imageI)
       
   570 apply(simp add: Collect_case_prod_Sigma)
       
   571 apply(rule finite_SigmaI)
       
   572 apply(rule assms)
       
   573 apply(case_tac "flat v = []")
       
   574 apply(simp)
       
   575 apply(drule_tac x="drop (length (flat v)) (a # list)" in spec)
       
   576 apply(simp)
       
   577 apply(auto)[1]
       
   578 apply(rule test)
       
   579 apply(simp)
       
   580 done
       
   581 
       
   582 lemma CPTpre_subsets:
       
   583   "CPTpre ZERO s = {}"
       
   584   "CPTpre ONE s \<subseteq> {Void}"
       
   585   "CPTpre (CHAR c) s \<subseteq> {Char c}"
       
   586   "CPTpre (ALT r1 r2) s \<subseteq> Left ` CPTpre r1 s \<union> Right ` CPTpre r2 s"
       
   587   "CPTpre (SEQ r1 r2) s \<subseteq> {Seq v1 v2 | v1 v2. v1 \<in> CPTpre r1 s \<and> v2 \<in> CPTpre r2 (drop (length (flat v1)) s)}"
       
   588   "CPTpre (STAR r) s \<subseteq> {Stars []} \<union>
       
   589     {Stars (v#vs) | v vs. v \<in> CPTpre r s \<and> flat v \<noteq> [] \<and> Stars vs \<in> CPTpre (STAR r) (drop (length (flat v)) s)}"
       
   590   "CPTpre (STAR r) [] = {Stars []}"
       
   591 apply(auto simp add: CPTpre_def)
       
   592 apply(erule CPrf.cases)
       
   593 apply(simp_all)
       
   594 apply(erule CPrf.cases)
       
   595 apply(simp_all)
       
   596 apply(erule CPrf.cases)
       
   597 apply(simp_all)
       
   598 apply(erule CPrf.cases)
       
   599 apply(simp_all)
       
   600 apply(erule CPrf.cases)
       
   601 apply(simp_all)
       
   602 
       
   603 apply(erule CPrf.cases)
       
   604 apply(simp_all)
       
   605 apply(erule CPrf.cases)
       
   606 apply(simp_all)
       
   607 apply(rule CPrf.intros)
       
   608 done
       
   609 
       
   610 
       
   611 lemma CPTpre_simps:
       
   612   shows "CPTpre ONE s = {Void}"
       
   613   and   "CPTpre (CHAR c) (d#s) = (if c = d then {Char c} else {})"
       
   614   and   "CPTpre (ALT r1 r2) s = Left ` CPTpre r1 s \<union> Right ` CPTpre r2 s"
       
   615   and   "CPTpre (SEQ r1 r2) s = 
       
   616           {Seq v1 v2 | v1 v2. v1 \<in> CPTpre r1 s \<and> v2 \<in> CPTpre r2 (drop (length (flat v1)) s)}"
       
   617 apply -
       
   618 apply(rule subset_antisym)
       
   619 apply(rule CPTpre_subsets)
       
   620 apply(auto simp add: CPTpre_def intro: "CPrf.intros")[1]
       
   621 apply(case_tac "c = d")
       
   622 apply(simp)
       
   623 apply(rule subset_antisym)
       
   624 apply(rule CPTpre_subsets)
       
   625 apply(auto simp add: CPTpre_def intro: CPrf.intros)[1]
       
   626 apply(simp)
       
   627 apply(auto simp add: CPTpre_def intro: CPrf.intros)[1]
       
   628 apply(erule CPrf.cases)
       
   629 apply(simp_all)
       
   630 apply(rule subset_antisym)
       
   631 apply(rule CPTpre_subsets)
       
   632 apply(auto simp add: CPTpre_def intro: CPrf.intros)[1]
       
   633 apply(rule subset_antisym)
       
   634 apply(rule CPTpre_subsets)
       
   635 apply(auto simp add: CPTpre_def intro: CPrf.intros)[1]
       
   636 done
       
   637 
       
   638 lemma CPT_simps:
       
   639   shows "CPT ONE s = (if s = [] then {Void} else {})"
       
   640   and   "CPT (CHAR c) [d] = (if c = d then {Char c} else {})"
       
   641   and   "CPT (ALT r1 r2) s = Left ` CPT r1 s \<union> Right ` CPT r2 s"
       
   642   and   "CPT (SEQ r1 r2) s = 
       
   643           {Seq v1 v2 | v1 v2 s1 s2. s1 @ s2 = s \<and> v1 \<in> CPT r1 s1 \<and> v2 \<in> CPT r2 s2}"
       
   644 apply -
       
   645 apply(rule subset_antisym)
       
   646 apply(auto simp add: CPT_def)[1]
       
   647 apply(erule CPrf.cases)
       
   648 apply(simp_all)[7]
       
   649 apply(erule CPrf.cases)
       
   650 apply(simp_all)[7]
       
   651 apply(auto simp add: CPT_def intro: CPrf.intros)[1]
       
   652 apply(auto simp add: CPT_def intro: CPrf.intros)[1]
       
   653 apply(erule CPrf.cases)
       
   654 apply(simp_all)[7]
       
   655 apply(erule CPrf.cases)
       
   656 apply(simp_all)[7]
       
   657 apply(auto simp add: CPT_def image_def intro: CPrf.intros)[1]
       
   658 apply(erule CPrf.cases)
       
   659 apply(simp_all)[7]
       
   660 apply(clarify)
       
   661 apply blast
       
   662 apply(auto simp add: CPT_def image_def intro: CPrf.intros)[1]
       
   663 apply(erule CPrf.cases)
       
   664 apply(simp_all)[7]
       
   665 done
       
   666 
       
   667 lemma test: 
       
   668   assumes "finite A"
       
   669   shows "finite {vs. Stars vs \<in> A}"
       
   670 using assms
       
   671 apply(induct A)
       
   672 apply(simp)
       
   673 apply(auto)
       
   674 apply(case_tac x)
       
   675 apply(simp_all)
       
   676 done
       
   677 
       
   678 lemma CPTpre_STAR_finite:
       
   679   assumes "\<And>s. finite (CPTpre r s)"
       
   680   shows "finite (CPTpre (STAR r) s)"
       
   681 apply(induct s rule: length_induct)
       
   682 apply(case_tac xs)
       
   683 apply(simp)
       
   684 apply(simp add: CPTpre_subsets)
       
   685 apply(rule finite_subset)
       
   686 apply(rule CPTpre_subsets)
       
   687 apply(simp)
       
   688 apply(rule_tac B="(\<lambda>(v, vs). Stars (v#vs)) ` {(v, vs). v \<in> CPTpre r (a#list) \<and> flat v \<noteq> [] \<and> Stars vs \<in> CPTpre (STAR r) (drop (length (flat v)) (a#list))}" in finite_subset)
       
   689 apply(auto)[1]
       
   690 apply(rule finite_imageI)
       
   691 apply(simp add: Collect_case_prod_Sigma)
       
   692 apply(rule finite_SigmaI)
       
   693 apply(rule assms)
       
   694 apply(case_tac "flat v = []")
       
   695 apply(simp)
       
   696 apply(drule_tac x="drop (length (flat v)) (a # list)" in spec)
       
   697 apply(simp)
       
   698 apply(auto)[1]
       
   699 apply(rule test)
       
   700 apply(simp)
       
   701 done
       
   702 
       
   703 lemma CPTpre_finite:
       
   704   shows "finite (CPTpre r s)"
       
   705 apply(induct r arbitrary: s)
       
   706 apply(simp add: CPTpre_subsets)
       
   707 apply(rule finite_subset)
       
   708 apply(rule CPTpre_subsets)
       
   709 apply(simp)
       
   710 apply(rule finite_subset)
       
   711 apply(rule CPTpre_subsets)
       
   712 apply(simp)
       
   713 apply(rule finite_subset)
       
   714 apply(rule CPTpre_subsets)
       
   715 apply(rule_tac B="(\<lambda>(v1, v2). Seq v1 v2) ` {(v1, v2).  v1 \<in> CPTpre r1 s \<and> v2 \<in> CPTpre r2 (drop (length (flat v1)) s)}" in finite_subset)
       
   716 apply(auto)[1]
       
   717 apply(rule finite_imageI)
       
   718 apply(simp add: Collect_case_prod_Sigma)
       
   719 apply(rule finite_subset)
       
   720 apply(rule CPTpre_subsets)
       
   721 apply(simp)
       
   722 by (simp add: CPTpre_STAR_finite)
       
   723 
       
   724 
       
   725 lemma CPT_finite:
       
   726   shows "finite (CPT r s)"
       
   727 apply(rule finite_subset)
       
   728 apply(rule CPT_CPTpre_subset)
       
   729 apply(rule CPTpre_finite)
       
   730 done
       
   731 *)
       
   732 
       
   733 lemma test2: 
   632 lemma test2: 
   734   assumes "\<forall>v \<in> set vs. flat v \<in> r \<rightarrow> v \<and> flat v \<noteq> []"
   633   assumes "\<forall>v \<in> set vs. flat v \<in> r \<rightarrow> v \<and> flat v \<noteq> []"
   735   shows "(Stars vs) \<in> CPT (STAR r) (flat (Stars vs))" 
   634   shows "(Stars vs) \<in> CV (STAR r) (flat (Stars vs))" 
   736 using assms
   635 using assms
   737 apply(induct vs)
   636 apply(induct vs)
   738 apply(auto simp add: CPT_def)
   637 apply(auto simp add: CV_def)
   739 apply(rule CPrf.intros)
   638 apply(rule CPrf.intros)
   740 apply(simp)
   639 apply(simp)
   741 apply(rule CPrf.intros)
   640 apply(rule CPrf.intros)
   742 apply(simp_all)
   641 apply(simp_all)
   743 by (metis (no_types, lifting) CPT_def Posix_CPT mem_Collect_eq)
   642 by (metis (no_types, lifting) CV_def Posix_CV mem_Collect_eq)
   744 
   643 
   745 
   644 
   746 end
   645 end