Myhill_1.thy
changeset 71 426070e68b21
parent 70 8ab3a06577cf
child 75 d63baacbdb16
equal deleted inserted replaced
70:8ab3a06577cf 71:426070e68b21
   131   assumes a: "x \<in> A\<star>"
   131   assumes a: "x \<in> A\<star>"
   132   and     b: "y \<in> A"
   132   and     b: "y \<in> A"
   133   shows "x @ y \<in> A\<star>"
   133   shows "x @ y \<in> A\<star>"
   134 using a b by (blast intro: star_intro1 star_intro2)
   134 using a b by (blast intro: star_intro1 star_intro2)
   135 
   135 
       
   136 lemma star_cases:
       
   137   shows "A\<star> =  {[]} \<union> A ;; A\<star>"
       
   138 proof
       
   139   { fix x
       
   140     have "x \<in> A\<star> \<Longrightarrow> x \<in> {[]} \<union> A ;; A\<star>"
       
   141       unfolding Seq_def
       
   142     by (induct rule: star_induct) (auto)
       
   143   }
       
   144   then show "A\<star> \<subseteq> {[]} \<union> A ;; A\<star>" by auto
       
   145 next
       
   146   show "{[]} \<union> A ;; A\<star> \<subseteq> A\<star>"
       
   147     unfolding Seq_def by auto
       
   148 qed
       
   149 
   136 lemma star_decom: 
   150 lemma star_decom: 
   137   "\<lbrakk>x \<in> A\<star>; x \<noteq> []\<rbrakk> \<Longrightarrow>(\<exists> a b. x = a @ b \<and> a \<noteq> [] \<and> a \<in> A \<and> b \<in> A\<star>)"
   151   assumes a: "x \<in> A\<star>" "x \<noteq> []"
       
   152   shows "\<exists>a b. x = a @ b \<and> a \<noteq> [] \<and> a \<in> A \<and> b \<in> A\<star>"
       
   153 using a
   138 apply(induct rule: star_induct)
   154 apply(induct rule: star_induct)
   139 apply(simp)
   155 apply(simp)
   140 apply(blast)
   156 apply(blast)
   141 done
   157 done
   142 
       
   143 lemma lang_star_cases:
       
   144   shows "L\<star> =  {[]} \<union> L ;; L\<star>"
       
   145 proof
       
   146   { fix x
       
   147     have "x \<in> L\<star> \<Longrightarrow> x \<in> {[]} \<union> L ;; L\<star>"
       
   148       unfolding Seq_def
       
   149     by (induct rule: star_induct) (auto)
       
   150   }
       
   151   then show "L\<star> \<subseteq> {[]} \<union> L ;; L\<star>" by auto
       
   152 next
       
   153   show "{[]} \<union> L ;; L\<star> \<subseteq> L\<star>"
       
   154     unfolding Seq_def by auto
       
   155 qed
       
   156 
   158 
   157 lemma
   159 lemma
   158   shows seq_Union_left:  "B ;; (\<Union>n. A \<up> n) = (\<Union>n. B ;; (A \<up> n))"
   160   shows seq_Union_left:  "B ;; (\<Union>n. A \<up> n) = (\<Union>n. B ;; (A \<up> n))"
   159   and   seq_Union_right: "(\<Union>n. A \<up> n) ;; B = (\<Union>n. (A \<up> n) ;; B)"
   161   and   seq_Union_right: "(\<Union>n. A \<up> n) ;; B = (\<Union>n. (A \<up> n) ;; B)"
   160 unfolding Seq_def by auto
   162 unfolding Seq_def by auto
   235   shows "X = X ;; A \<union> B \<longleftrightarrow> X = B ;; A\<star>"
   237   shows "X = X ;; A \<union> B \<longleftrightarrow> X = B ;; A\<star>"
   236 proof
   238 proof
   237   assume eq: "X = B ;; A\<star>"
   239   assume eq: "X = B ;; A\<star>"
   238   have "A\<star> = {[]} \<union> A\<star> ;; A" 
   240   have "A\<star> = {[]} \<union> A\<star> ;; A" 
   239     unfolding seq_star_comm[symmetric]
   241     unfolding seq_star_comm[symmetric]
   240     by (rule lang_star_cases)
   242     by (rule star_cases)
   241   then have "B ;; A\<star> = B ;; ({[]} \<union> A\<star> ;; A)"
   243   then have "B ;; A\<star> = B ;; ({[]} \<union> A\<star> ;; A)"
   242     by (rule seq_add_left)
   244     by (rule seq_add_left)
   243   also have "\<dots> = B \<union> B ;; (A\<star> ;; A)"
   245   also have "\<dots> = B \<union> B ;; (A\<star> ;; A)"
   244     unfolding seq_union_distrib_left by simp
   246     unfolding seq_union_distrib_left by simp
   245   also have "\<dots> = B \<union> (B ;; A\<star>) ;; A" 
   247   also have "\<dots> = B \<union> (B ;; A\<star>) ;; A" 
   349 
   351 
   350 text {*
   352 text {*
   351   @{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"}.
   352 *}
   354 *}
   353 definition
   355 definition
   354   str_eq_rel ("\<approx>_" [100] 100)
   356   str_eq_rel :: "lang \<Rightarrow> (string \<times> string) set" ("\<approx>_" [100] 100)
   355 where
   357 where
   356   "\<approx>A \<equiv> {(x, y).  (\<forall>z. x @ z \<in> A \<longleftrightarrow> y @ z \<in> A)}"
   358   "\<approx>A \<equiv> {(x, y).  (\<forall>z. x @ z \<in> A \<longleftrightarrow> y @ z \<in> A)}"
   357 
   359 
   358 text {* 
   360 text {* 
   359   Among the equivalence clases of @{text "\<approx>A"}, the set @{text "finals A"} singles out 
   361   Among the equivalence clases of @{text "\<approx>A"}, the set @{text "finals A"} singles out 
   360   those which contains the strings from @{text "A"}.
   362   those which contains the strings from @{text "A"}.
   361 *}
   363 *}
   362 
   364 
   363 definition 
   365 definition 
   364    "finals A \<equiv> {\<approx>A `` {x} | x . x \<in> A}"
   366   finals :: "lang \<Rightarrow> lang set"
       
   367 where
       
   368   "finals A \<equiv> {\<approx>A `` {x} | x . x \<in> A}"
   365 
   369 
   366 text {* 
   370 text {* 
   367   The following lemma establishes the relationshipt between 
   371   The following lemma establishes the relationshipt between 
   368   @{text "finals A"} and @{text "A"}.
   372   @{text "finals A"} and @{text "A"}.
   369 *}
   373 *}
   462 text {* 
   466 text {* 
   463   Given a set of equivalence classes @{text "CS"} and one equivalence class @{text "X"} among
   467   Given a set of equivalence classes @{text "CS"} and one equivalence class @{text "X"} among
   464   @{text "CS"}, the term @{text "init_rhs CS X"} is used to extract the right hand side of
   468   @{text "CS"}, the term @{text "init_rhs CS X"} is used to extract the right hand side of
   465   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"}
   466   is:
   470   is:
   467   *}
   471 *}
       
   472 
       
   473 definition 
       
   474   transition :: "lang \<Rightarrow> char \<Rightarrow> lang \<Rightarrow> bool" ("_ \<Turnstile>_\<Rightarrow>_" [100,100,100] 100)
       
   475 where
       
   476   "Y \<Turnstile>c\<Rightarrow> X \<equiv> Y ;; {[c]} \<subseteq> X"
   468 
   477 
   469 definition
   478 definition
   470   "init_rhs CS X \<equiv>  
   479   "init_rhs CS X \<equiv>  
   471       if ([] \<in> X) then 
   480       if ([] \<in> X) then 
   472           {Lam(EMPTY)} \<union> {Trn Y (CHAR c) | Y c. Y \<in> CS \<and> Y ;; {[c]} \<subseteq> X}
   481           {Lam EMPTY} \<union> {Trn Y (CHAR c) | Y c. Y \<in> CS \<and> Y \<Turnstile>c\<Rightarrow> X}
   473       else 
   482       else 
   474           {Trn Y (CHAR c)| Y c. Y \<in> CS \<and> Y ;; {[c]} \<subseteq> X}"
   483           {Trn Y (CHAR c)| Y c. Y \<in> CS \<and> Y \<Turnstile>c\<Rightarrow> X}"
   475 
   484 
   476 text {*
   485 text {*
   477   In the definition of @{text "init_rhs"}, the term 
   486   In the definition of @{text "init_rhs"}, the term 
   478   @{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
   479   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 
   481   @{text "X"} rather than by transition. This @{text "{Lam(EMPTY)}"} corresponds to 
   490   @{text "X"} rather than by transition. This @{text "{Lam(EMPTY)}"} corresponds to 
   482   the $\lambda$ in \eqref{example_eqns}.
   491   the $\lambda$ in \eqref{example_eqns}.
   483 
   492 
   484   With the help of @{text "init_rhs"}, the equitional system descrbing the formation of every
   493   With the help of @{text "init_rhs"}, the equitional system descrbing the formation of every
   485   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)"}.
   486   *}
   495 *}
   487 
   496 
   488 
   497 
   489 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}"
   490 (************ arden's lemma variation ********************)
   499 (************ arden's lemma variation ********************)
   491 
   500 
   544 
   553 
   545 text {*
   554 text {*
   546   With the help of the two functions immediately above, Ardens'
   555   With the help of the two functions immediately above, Ardens'
   547   transformation on right hand side @{text "rhs"} is implemented
   556   transformation on right hand side @{text "rhs"} is implemented
   548   by the following function @{text "arden_variate X rhs"}.
   557   by the following function @{text "arden_variate X rhs"}.
   549   After this transformation, the recursive occurent of @{text "X"}
   558   After this transformation, the recursive occurence of @{text "X"}
   550   in @{text "rhs"} will be eliminated, while the 
   559   in @{text "rhs"} will be eliminated, while the string set defined 
   551   string set defined by @{text "rhs"} is kept unchanged.
   560   by @{text "rhs"} is kept unchanged.
   552   *}
   561 *}
       
   562 
   553 definition 
   563 definition 
   554   "arden_variate X rhs \<equiv> 
   564   "arden_variate X rhs \<equiv> 
   555         append_rhs_rexp (rhs - items_of rhs X) (STAR (rexp_of rhs X))"
   565         append_rhs_rexp (rhs - items_of rhs X) (STAR (rexp_of rhs X))"
   556 
   566 
   557 
   567 
   578 
   588 
   579 definition
   589 definition
   580   "eqs_subst ES X xrhs \<equiv> {(Y, rhs_subst yrhs X xrhs) | Y yrhs. (Y, yrhs) \<in> ES}"
   590   "eqs_subst ES X xrhs \<equiv> {(Y, rhs_subst yrhs X xrhs) | Y yrhs. (Y, yrhs) \<in> ES}"
   581 
   591 
   582 text {*
   592 text {*
   583   The computation of regular expressions for equivalent classes is accomplished
   593   The computation of regular expressions for equivalence classes is accomplished
   584   using a iteration principle given by the following lemma.
   594   using a iteration principle given by the following lemma.
   585   *}
   595 *}
   586 
   596 
   587 lemma wf_iter [rule_format]: 
   597 lemma wf_iter [rule_format]: 
   588   fixes f
   598   fixes f
   589   assumes step: "\<And> e. \<lbrakk>P e; \<not> Q e\<rbrakk> \<Longrightarrow> (\<exists> e'. P e' \<and>  (f(e'), f(e)) \<in> less_than)"
   599   assumes step: "\<And> e. \<lbrakk>P e; \<not> Q e\<rbrakk> \<Longrightarrow> (\<exists> e'. P e' \<and>  (f(e'), f(e)) \<in> less_than)"
   590   shows pe:     "P e \<longrightarrow> (\<exists> e'. P e' \<and>  Q e')"
   600   shows pe:     "P e \<longrightarrow> (\<exists> e'. P e' \<and>  Q e')"
   771 subsubsection {* Intialization *}
   781 subsubsection {* Intialization *}
   772 
   782 
   773 text {*
   783 text {*
   774   The following several lemmas until @{text "init_ES_satisfy_Inv"} shows that
   784   The following several lemmas until @{text "init_ES_satisfy_Inv"} shows that
   775   the initial equational system satisfies invariant @{text "Inv"}.
   785   the initial equational system satisfies invariant @{text "Inv"}.
   776   *}
   786 *}
   777 
   787 
   778 lemma defined_by_str:
   788 lemma defined_by_str:
   779   "\<lbrakk>s \<in> X; X \<in> UNIV // (\<approx>Lang)\<rbrakk> \<Longrightarrow> X = (\<approx>Lang) `` {s}"
   789   "\<lbrakk>s \<in> X; X \<in> UNIV // (\<approx>Lang)\<rbrakk> \<Longrightarrow> X = (\<approx>Lang) `` {s}"
   780 by (auto simp:quotient_def Image_def str_eq_rel_def)
   790 by (auto simp:quotient_def Image_def str_eq_rel_def)
   781 
   791 
   822         where "Y \<in> UNIV // (\<approx>Lang)" 
   832         where "Y \<in> UNIV // (\<approx>Lang)" 
   823         and "Y ;; {[c]} \<subseteq> X"
   833         and "Y ;; {[c]} \<subseteq> X"
   824         and "clist \<in> Y"
   834         and "clist \<in> Y"
   825         using decom "(1)" every_eqclass_has_transition by blast
   835         using decom "(1)" every_eqclass_has_transition by blast
   826       hence 
   836       hence 
   827         "x \<in> L {Trn Y (CHAR c)| Y c. Y \<in> UNIV // (\<approx>Lang) \<and> Y ;; {[c]} \<subseteq> X}"
   837         "x \<in> L {Trn Y (CHAR c)| Y c. Y \<in> UNIV // (\<approx>Lang) \<and> Y \<Turnstile>c\<Rightarrow> X}"
   828         using "(1)" decom
   838         unfolding transition_def
       
   839 	using "(1)" decom
   829         by (simp, rule_tac x = "Trn Y (CHAR c)" in exI, simp add:Seq_def)
   840         by (simp, rule_tac x = "Trn Y (CHAR c)" in exI, simp add:Seq_def)
   830       thus ?thesis using X_in_eqs "(1)"
   841       thus ?thesis using X_in_eqs "(1)"	
   831         by (simp add:eqs_def init_rhs_def)
   842         by (simp add: eqs_def init_rhs_def)
   832     qed
   843     qed
   833   qed
   844   qed
   834 next
   845 next
   835   show "L xrhs \<subseteq> X" using X_in_eqs
   846   show "L xrhs \<subseteq> X" using X_in_eqs
   836     by (auto simp:eqs_def init_rhs_def) 
   847     by (auto simp:eqs_def init_rhs_def transition_def) 
   837 qed
   848 qed
   838 
   849 
   839 lemma finite_init_rhs: 
   850 lemma finite_init_rhs: 
   840   assumes finite: "finite CS"
   851   assumes finite: "finite CS"
   841   shows "finite (init_rhs CS X)"
   852   shows "finite (init_rhs CS X)"
   849       by (rule_tac B = "CS \<times> UNIV" in finite_subset, auto)
   860       by (rule_tac B = "CS \<times> UNIV" in finite_subset, auto)
   850     moreover have "?A = h ` S" by (auto simp: S_def h_def image_def)
   861     moreover have "?A = h ` S" by (auto simp: S_def h_def image_def)
   851     ultimately show ?thesis 
   862     ultimately show ?thesis 
   852       by auto
   863       by auto
   853   qed
   864   qed
   854   thus ?thesis by (simp add:init_rhs_def)
   865   thus ?thesis by (simp add:init_rhs_def transition_def)
   855 qed
   866 qed
   856 
   867 
   857 lemma init_ES_satisfy_Inv:
   868 lemma init_ES_satisfy_Inv:
   858   assumes finite_CS: "finite (UNIV // (\<approx>Lang))"
   869   assumes finite_CS: "finite (UNIV // (\<approx>Lang))"
   859   shows "Inv (eqs (UNIV // (\<approx>Lang)))"
   870   shows "Inv (eqs (UNIV // (\<approx>Lang)))"
   882 
   893 
   883 text {*
   894 text {*
   884   From this point until @{text "iteration_step"}, it is proved
   895   From this point until @{text "iteration_step"}, it is proved
   885   that there exists iteration steps which keep @{text "Inv(ES)"} while
   896   that there exists iteration steps which keep @{text "Inv(ES)"} while
   886   decreasing the size of @{text "ES"}.
   897   decreasing the size of @{text "ES"}.
   887   *}
   898 *}
       
   899 
   888 lemma arden_variate_keeps_eq:
   900 lemma arden_variate_keeps_eq:
   889   assumes l_eq_r: "X = L rhs"
   901   assumes l_eq_r: "X = L rhs"
   890   and not_empty: "[] \<notin> L (rexp_of rhs X)"
   902   and not_empty: "[] \<notin> L (rexp_of rhs X)"
   891   and finite: "finite rhs"
   903   and finite: "finite rhs"
   892   shows "X = L (arden_variate X rhs)"
   904   shows "X = L (arden_variate X rhs)"