Myhill_1.thy
changeset 75 d63baacbdb16
parent 71 426070e68b21
child 76 1589bf5c1ad8
equal deleted inserted replaced
74:2335fcb96052 75:d63baacbdb16
     1 theory Myhill_1
     1 theory Myhill_1
     2   imports Main List_Prefix Prefix_subtract Prelude
     2   imports Main 
     3 begin
     3 begin
     4 
     4 
     5 (*
     5 (*
     6 text {*
     6 text {*
     7      \begin{figure}
     7      \begin{figure}
   332   *}
   332   *}
   333 
   333 
   334 lemma folds_alt_simp [simp]:
   334 lemma folds_alt_simp [simp]:
   335   assumes a: "finite rs"
   335   assumes a: "finite rs"
   336   shows "L (folds ALT NULL rs) = \<Union> (L ` rs)"
   336   shows "L (folds ALT NULL rs) = \<Union> (L ` rs)"
   337 apply(rule set_eq_intro)
   337 apply(rule set_eqI)
   338 apply(simp add: folds_def)
   338 apply(simp add: folds_def)
   339 apply(rule someI2_ex)
   339 apply(rule someI2_ex)
   340 apply(rule_tac finite_imp_fold_graph[OF a])
   340 apply(rule_tac finite_imp_fold_graph[OF a])
   341 apply(erule fold_graph.induct)
   341 apply(erule fold_graph.induct)
   342 apply(auto)
   342 apply(auto)
   343 done
   343 done
   344 
   344 
   345 
   345 
   346 text {* Just a technical lemma for collections and pairs *}
   346 text {* Just a technical lemma for collections and pairs *}
   347 
   347 
   348 lemma [simp]:
   348 lemma Pair_Collect[simp]:
   349   shows "(x, y) \<in> {(x, y). P x y} \<longleftrightarrow> P x y"
   349   shows "(x, y) \<in> {(x, y). P x y} \<longleftrightarrow> P x y"
   350 by simp
   350 by simp
   351 
   351 
   352 text {*
   352 text {*
   353   @{text "\<approx>A"} is an equivalence class defined by language @{text "A"}.
   353   @{text "\<approx>A"} is an equivalence class defined by language @{text "A"}.
   469   the equation describing the formation of @{text "X"}. The definition of @{text "init_rhs"}
   469   the equation describing the formation of @{text "X"}. The definition of @{text "init_rhs"}
   470   is:
   470   is:
   471 *}
   471 *}
   472 
   472 
   473 definition 
   473 definition 
   474   transition :: "lang \<Rightarrow> char \<Rightarrow> lang \<Rightarrow> bool" ("_ \<Turnstile>_\<Rightarrow>_" [100,100,100] 100)
   474   transition :: "lang \<Rightarrow> rexp \<Rightarrow> lang \<Rightarrow> bool" ("_ \<Turnstile>_\<Rightarrow>_" [100,100,100] 100)
   475 where
   475 where
   476   "Y \<Turnstile>c\<Rightarrow> X \<equiv> Y ;; {[c]} \<subseteq> X"
   476   "Y \<Turnstile>r\<Rightarrow> X \<equiv> Y ;; (L r) \<subseteq> X"
   477 
   477 
   478 definition
   478 definition
   479   "init_rhs CS X \<equiv>  
   479   "init_rhs CS X \<equiv>  
   480       if ([] \<in> X) then 
   480       if ([] \<in> X) then 
   481           {Lam EMPTY} \<union> {Trn Y (CHAR c) | Y c. Y \<in> CS \<and> Y \<Turnstile>c\<Rightarrow> X}
   481           {Lam EMPTY} \<union> {Trn Y (CHAR c) | Y c. Y \<in> CS \<and> Y \<Turnstile>(CHAR c)\<Rightarrow> X}
   482       else 
   482       else 
   483           {Trn Y (CHAR c)| Y c. Y \<in> CS \<and> Y \<Turnstile>c\<Rightarrow> X}"
   483           {Trn Y (CHAR c)| Y c. Y \<in> CS \<and> Y \<Turnstile>(CHAR c)\<Rightarrow> X}"
   484 
   484 
   485 text {*
   485 text {*
   486   In the definition of @{text "init_rhs"}, the term 
   486   In the definition of @{text "init_rhs"}, the term 
   487   @{text "{Trn Y (CHAR c)| Y c. Y \<in> CS \<and> Y ;; {[c]} \<subseteq> X}"} appearing on both branches
   487   @{text "{Trn Y (CHAR c)| Y c. Y \<in> CS \<and> Y ;; {[c]} \<subseteq> X}"} appearing on both branches
   488   describes the formation of strings in @{text "X"} out of transitions, while 
   488   describes the formation of strings in @{text "X"} out of transitions, while 
   494   equivalent class inside @{text "CS"} is given by the following @{text "eqs(CS)"}.
   494   equivalent class inside @{text "CS"} is given by the following @{text "eqs(CS)"}.
   495 *}
   495 *}
   496 
   496 
   497 
   497 
   498 definition "eqs CS \<equiv> {(X, init_rhs CS X) | X.  X \<in> CS}"
   498 definition "eqs CS \<equiv> {(X, init_rhs CS X) | X.  X \<in> CS}"
       
   499 
       
   500 
       
   501 
   499 (************ arden's lemma variation ********************)
   502 (************ arden's lemma variation ********************)
   500 
   503 
   501 text {* 
   504 text {* 
   502   The following @{text "items_of rhs X"} returns all @{text "X"}-items in @{text "rhs"}.
   505   The following @{text "items_of rhs X"} returns all @{text "X"}-items in @{text "rhs"}.
   503   *}
   506   *}
   514 definition 
   517 definition 
   515   "rexp_of rhs X \<equiv> folds ALT NULL ((snd o the_Trn) ` items_of rhs X)"
   518   "rexp_of rhs X \<equiv> folds ALT NULL ((snd o the_Trn) ` items_of rhs X)"
   516 
   519 
   517 text {* 
   520 text {* 
   518   The following @{text "lam_of rhs"} returns all pure regular expression items in @{text "rhs"}.
   521   The following @{text "lam_of rhs"} returns all pure regular expression items in @{text "rhs"}.
   519   *}
   522 *}
   520 
   523 
   521 definition
   524 definition
   522   "lam_of rhs \<equiv> {Lam r | r. Lam r \<in> rhs}"
   525   "lam_of rhs \<equiv> {Lam r | r. Lam r \<in> rhs}"
   523 
   526 
   524 text {*
   527 text {*
   525   The following @{text "rexp_of_lam rhs"} combines pure regular expression items in @{text "rhs"}
   528   The following @{text "rexp_of_lam rhs"} combines pure regular expression items in @{text "rhs"}
   526   using @{text "ALT"} to form a single regular expression. 
   529   using @{text "ALT"} to form a single regular expression. 
   527   When all variables inside @{text "rhs"} are eliminated, @{text "rexp_of_lam rhs"}
   530   When all variables inside @{text "rhs"} are eliminated, @{text "rexp_of_lam rhs"}
   528   is used to compute compute the regular expression corresponds to @{text "rhs"}.
   531   is used to compute compute the regular expression corresponds to @{text "rhs"}.
   529   *}
   532 *}
   530 
   533 
   531 definition
   534 definition
   532   "rexp_of_lam rhs \<equiv> folds ALT NULL (the_r ` lam_of rhs)"
   535   "rexp_of_lam rhs \<equiv> folds ALT NULL (the_r ` lam_of rhs)"
   533 
   536 
   534 text {*
   537 text {*
   535   The following @{text "attach_rexp rexp' itm"} attach 
   538   The following @{text "attach_rexp rexp' itm"} attach 
   536   the regular expression @{text "rexp'"} to
   539   the regular expression @{text "rexp'"} to
   537   the right of right hand side item @{text "itm"}.
   540   the right of right hand side item @{text "itm"}.
   538   *}
   541 *}
   539 
   542 
   540 fun 
   543 fun 
   541   attach_rexp :: "rexp \<Rightarrow> rhs_item \<Rightarrow> rhs_item"
   544   attach_rexp :: "rexp \<Rightarrow> rhs_item \<Rightarrow> rhs_item"
   542 where
   545 where
   543   "attach_rexp rexp' (Lam rexp)   = Lam (SEQ rexp rexp')"
   546   "attach_rexp rexp' (Lam rexp)   = Lam (SEQ rexp rexp')"
   544 | "attach_rexp rexp' (Trn X rexp) = Trn X (SEQ rexp rexp')"
   547 | "attach_rexp rexp' (Trn X rexp) = Trn X (SEQ rexp rexp')"
   545 
   548 
   546 text {* 
   549 text {* 
   547   The following @{text "append_rhs_rexp rhs rexp"} attaches 
   550   The following @{text "append_rhs_rexp rhs rexp"} attaches 
   548   @{text "rexp"} to every item in @{text "rhs"}.
   551   @{text "rexp"} to every item in @{text "rhs"}.
   549   *}
   552 *}
   550 
   553 
   551 definition
   554 definition
   552   "append_rhs_rexp rhs rexp \<equiv> (attach_rexp rexp) ` rhs"
   555   "append_rhs_rexp rhs rexp \<equiv> (attach_rexp rexp) ` rhs"
   553 
   556 
   554 text {*
   557 text {*
   620     qed
   623     qed
   621   qed
   624   qed
   622 qed
   625 qed
   623 
   626 
   624 text {*
   627 text {*
   625   The @{text "P"} in lemma @{text "wf_iter"} is an invaiant kept throughout the iteration procedure.
   628   The @{text "P"} in lemma @{text "wf_iter"} is an invariant kept throughout the iteration procedure.
   626   The particular invariant used to solve our problem is defined by function @{text "Inv(ES)"},
   629   The particular invariant used to solve our problem is defined by function @{text "Inv(ES)"},
   627   an invariant over equal system @{text "ES"}.
   630   an invariant over equal system @{text "ES"}.
   628   Every definition starting next till @{text "Inv"} stipulates a property to be satisfied by @{text "ES"}.
   631   Every definition starting next till @{text "Inv"} stipulates a property to be satisfied by @{text "ES"}.
   629 *}
   632 *}
   630 
   633 
   631 text {* 
   634 text {* 
   632   Every variable is defined at most onece in @{text "ES"}.
   635   Every variable is defined at most onece in @{text "ES"}.
   633   *}
   636   *}
       
   637 
   634 definition 
   638 definition 
   635   "distinct_equas ES \<equiv> 
   639   "distinct_equas ES \<equiv> 
   636             \<forall> X rhs rhs'. (X, rhs) \<in> ES \<and> (X, rhs') \<in> ES \<longrightarrow> rhs = rhs'"
   640             \<forall> X rhs rhs'. (X, rhs) \<in> ES \<and> (X, rhs') \<in> ES \<longrightarrow> rhs = rhs'"
   637 
   641 
   638 text {* 
   642 text {* 
   832         where "Y \<in> UNIV // (\<approx>Lang)" 
   836         where "Y \<in> UNIV // (\<approx>Lang)" 
   833         and "Y ;; {[c]} \<subseteq> X"
   837         and "Y ;; {[c]} \<subseteq> X"
   834         and "clist \<in> Y"
   838         and "clist \<in> Y"
   835         using decom "(1)" every_eqclass_has_transition by blast
   839         using decom "(1)" every_eqclass_has_transition by blast
   836       hence 
   840       hence 
   837         "x \<in> L {Trn Y (CHAR c)| Y c. Y \<in> UNIV // (\<approx>Lang) \<and> Y \<Turnstile>c\<Rightarrow> X}"
   841         "x \<in> L {Trn Y (CHAR c)| Y c. Y \<in> UNIV // (\<approx>Lang) \<and> Y \<Turnstile>(CHAR c)\<Rightarrow> X}"
   838         unfolding transition_def
   842         unfolding transition_def
   839 	using "(1)" decom
   843 	using "(1)" decom
   840         by (simp, rule_tac x = "Trn Y (CHAR c)" in exI, simp add:Seq_def)
   844         by (simp, rule_tac x = "Trn Y (CHAR c)" in exI, simp add:Seq_def)
   841       thus ?thesis using X_in_eqs "(1)"	
   845       thus ?thesis using X_in_eqs "(1)"	
   842         by (simp add: eqs_def init_rhs_def)
   846         by (simp add: eqs_def init_rhs_def)