diff -r b794db0b79db -r b1258b7d2789 Myhill_2.thy --- a/Myhill_2.thy Fri Jun 03 13:59:21 2011 +0000 +++ b/Myhill_2.thy Mon Jul 25 13:33:38 2011 +0000 @@ -6,7 +6,7 @@ section {* Direction @{text "regular language \ finite partition"} *} definition - str_eq :: "string \ lang \ string \ bool" ("_ \_ _") + str_eq :: "'a list \ 'a lang \ 'a list \ bool" ("_ \_ _") where "x \A y \ (x, y) \ (\A)" @@ -16,7 +16,7 @@ by simp definition - tag_eq_rel :: "(string \ 'b) \ (string \ string) set" ("=_=") + tag_eq_rel :: "('a list \ 'b) \ ('a list \ 'a list) set" ("=_=") where "=tag= \ {(x, y). tag x = tag y}" @@ -116,20 +116,20 @@ subsection {* The proof *} -subsubsection {* The base case for @{const "NULL"} *} +subsubsection {* The base case for @{const "Zero"} *} -lemma quot_null_eq: +lemma quot_zero_eq: shows "UNIV // \{} = {UNIV}" unfolding quotient_def Image_def str_eq_rel_def by auto -lemma quot_null_finiteI [intro]: +lemma quot_zero_finiteI [intro]: shows "finite (UNIV // \{})" -unfolding quot_null_eq by simp +unfolding quot_zero_eq by simp -subsubsection {* The base case for @{const "EMPTY"} *} +subsubsection {* The base case for @{const "One"} *} -lemma quot_empty_subset: +lemma quot_one_subset: shows "UNIV // \{[]} \ {{[]}, UNIV - {[]}}" proof fix x @@ -148,14 +148,14 @@ qed qed -lemma quot_empty_finiteI [intro]: +lemma quot_one_finiteI [intro]: shows "finite (UNIV // \{[]})" -by (rule finite_subset[OF quot_empty_subset]) (simp) +by (rule finite_subset[OF quot_one_subset]) (simp) -subsubsection {* The base case for @{const "CHAR"} *} +subsubsection {* The base case for @{const "Atom"} *} -lemma quot_char_subset: +lemma quot_atom_subset: "UNIV // (\{[c]}) \ {{[]},{[c]}, UNIV - {[], [c]}}" proof fix x @@ -181,43 +181,43 @@ qed qed -lemma quot_char_finiteI [intro]: +lemma quot_atom_finiteI [intro]: shows "finite (UNIV // \{[c]})" -by (rule finite_subset[OF quot_char_subset]) (simp) +by (rule finite_subset[OF quot_atom_subset]) (simp) -subsubsection {* The inductive case for @{const ALT} *} +subsubsection {* The inductive case for @{const Plus} *} definition - tag_str_ALT :: "lang \ lang \ string \ (lang \ lang)" + tag_str_Plus :: "'a lang \ 'a lang \ 'a list \ ('a lang \ 'a lang)" where - "tag_str_ALT A B \ (\x. (\A `` {x}, \B `` {x}))" + "tag_str_Plus A B \ (\x. (\A `` {x}, \B `` {x}))" lemma quot_union_finiteI [intro]: assumes finite1: "finite (UNIV // \A)" and finite2: "finite (UNIV // \B)" shows "finite (UNIV // \(A \ B))" -proof (rule_tac tag = "tag_str_ALT A B" in tag_finite_imageD) +proof (rule_tac tag = "tag_str_Plus A B" in tag_finite_imageD) have "finite ((UNIV // \A) \ (UNIV // \B))" using finite1 finite2 by auto - then show "finite (range (tag_str_ALT A B))" - unfolding tag_str_ALT_def quotient_def + then show "finite (range (tag_str_Plus A B))" + unfolding tag_str_Plus_def quotient_def by (rule rev_finite_subset) (auto) next - show "\x y. tag_str_ALT A B x = tag_str_ALT A B y \ x \(A \ B) y" - unfolding tag_str_ALT_def + show "\x y. tag_str_Plus A B x = tag_str_Plus A B y \ x \(A \ B) y" + unfolding tag_str_Plus_def unfolding str_eq_def unfolding str_eq_rel_def by auto qed -subsubsection {* The inductive case for @{text "SEQ"}*} +subsubsection {* The inductive case for @{text "Times"}*} definition - tag_str_SEQ :: "lang \ lang \ string \ (lang \ lang set)" + tag_str_Times :: "'a lang \ 'a lang \ 'a list \ ('a lang \ 'a lang set)" where - "tag_str_SEQ L1 L2 \ + "tag_str_Times L1 L2 \ (\x. (\L1 `` {x}, {(\L2 `` {x - xa}) | xa. xa \ x \ xa \ L1}))" lemma Seq_in_cases: @@ -225,16 +225,16 @@ shows "(\ x' \ x. x' \ A \ (x - x') @ z \ B) \ (\ z' \ z. (x @ z') \ A \ (z - z') \ B)" using assms -unfolding Seq_def prefix_def +unfolding conc_def prefix_def by (auto simp add: append_eq_append_conv2) -lemma tag_str_SEQ_injI: - assumes eq_tag: "tag_str_SEQ A B x = tag_str_SEQ A B y" +lemma tag_str_Times_injI: + assumes eq_tag: "tag_str_Times A B x = tag_str_Times A B y" shows "x \(A \ B) y" proof - { fix x y z assume xz_in_seq: "x @ z \ A \ B" - and tag_xy: "tag_str_SEQ A B x = tag_str_SEQ A B y" + and tag_xy: "tag_str_Times A B x = tag_str_Times A B y" have"y @ z \ A \ B" proof - { (* first case with x' in A and (x - x') @ z in B *) @@ -247,7 +247,7 @@ proof - have "{\B `` {x - x'} |x'. x' \ x \ x' \ A} = {\B `` {y - y'} |y'. y' \ y \ y' \ A}" (is "?Left = ?Right") - using tag_xy unfolding tag_str_SEQ_def by simp + using tag_xy unfolding tag_str_Times_def by simp moreover have "\B `` {x - x'} \ ?Left" using h1 h2 by auto ultimately @@ -271,11 +271,11 @@ fix z' assume h1: "z' \ z" and h2: "(x @ z') \ A" and h3: "z - z' \ B" have "\A `` {x} = \A `` {y}" - using tag_xy unfolding tag_str_SEQ_def by simp + using tag_xy unfolding tag_str_Times_def by simp with h2 have "y @ z' \ A" unfolding Image_def str_eq_rel_def str_eq_def by auto with h1 h3 have "y @ z \ A \ B" - unfolding prefix_def Seq_def + unfolding prefix_def conc_def by (auto) (metis append_assoc) } ultimately show "y @ z \ A \ B" @@ -287,30 +287,30 @@ qed lemma quot_seq_finiteI [intro]: - fixes L1 L2::"lang" + fixes L1 L2::"'a lang" assumes fin1: "finite (UNIV // \L1)" and fin2: "finite (UNIV // \L2)" shows "finite (UNIV // \(L1 \ L2))" -proof (rule_tac tag = "tag_str_SEQ L1 L2" in tag_finite_imageD) - show "\x y. tag_str_SEQ L1 L2 x = tag_str_SEQ L1 L2 y \ x \(L1 \ L2) y" - by (rule tag_str_SEQ_injI) +proof (rule_tac tag = "tag_str_Times L1 L2" in tag_finite_imageD) + show "\x y. tag_str_Times L1 L2 x = tag_str_Times L1 L2 y \ x \(L1 \ L2) y" + by (rule tag_str_Times_injI) next have *: "finite ((UNIV // \L1) \ (Pow (UNIV // \L2)))" using fin1 fin2 by auto - show "finite (range (tag_str_SEQ L1 L2))" - unfolding tag_str_SEQ_def + show "finite (range (tag_str_Times L1 L2))" + unfolding tag_str_Times_def apply(rule finite_subset[OF _ *]) unfolding quotient_def by auto qed -subsubsection {* The inductive case for @{const "STAR"} *} +subsubsection {* The inductive case for @{const "Star"} *} definition - tag_str_STAR :: "lang \ string \ lang set" + tag_str_Star :: "'a lang \ 'a list \ ('a lang) set" where - "tag_str_STAR L1 \ (\x. {\L1 `` {x - xa} | xa. xa < x \ xa \ L1\})" + "tag_str_Star L1 \ (\x. {\L1 `` {x - xa} | xa. xa < x \ xa \ L1\})" text {* A technical lemma. *} lemma finite_set_has_max: "\finite A; A \ {}\ \ @@ -342,31 +342,33 @@ text {* The following is a technical lemma, which helps to show the range finiteness of tag function. *} -lemma finite_strict_prefix_set: "finite {xa. xa < (x::string)}" +lemma finite_strict_prefix_set: + shows "finite {xa. xa < (x::'a list)}" apply (induct x rule:rev_induct, simp) apply (subgoal_tac "{xa. xa < xs @ [x]} = {xa. xa < xs} \ {xs}") by (auto simp:strict_prefix_def) -lemma tag_str_STAR_injI: - assumes eq_tag: "tag_str_STAR L\<^isub>1 v = tag_str_STAR L\<^isub>1 w" +lemma tag_str_Star_injI: + fixes L\<^isub>1::"('a::finite) lang" + assumes eq_tag: "tag_str_Star L\<^isub>1 v = tag_str_Star L\<^isub>1 w" shows "v \(L\<^isub>1\) w" proof- { fix x y z assume xz_in_star: "x @ z \ L\<^isub>1\" - and tag_xy: "tag_str_STAR L\<^isub>1 x = tag_str_STAR L\<^isub>1 y" + and tag_xy: "tag_str_Star L\<^isub>1 x = tag_str_Star L\<^isub>1 y" have "y @ z \ L\<^isub>1\" proof(cases "x = []") case True with tag_xy have "y = []" - by (auto simp add: tag_str_STAR_def strict_prefix_def) + by (auto simp add: tag_str_Star_def strict_prefix_def) thus ?thesis using xz_in_star True by simp next case False - let ?S = "{xa. xa < x \ xa \ L\<^isub>1\ \ (x - xa) @ z \ L\<^isub>1\}" + let ?S = "{xa::('a::finite) list. xa < x \ xa \ L\<^isub>1\ \ (x - xa) @ z \ L\<^isub>1\}" have "finite ?S" - by (rule_tac B = "{xa. xa < x}" in finite_subset, - auto simp:finite_strict_prefix_set) + by (rule_tac B = "{xa. xa < x}" in finite_subset) + (auto simp: finite_strict_prefix_set) moreover have "?S \ {}" using False xz_in_star by (simp, rule_tac x = "[]" in exI, auto simp:strict_prefix_def) ultimately have "\ xa_max \ ?S. \ xa \ ?S. length xa \ length xa_max" @@ -384,7 +386,7 @@ proof- from tag_xy have "{\L\<^isub>1 `` {x - xa} |xa. xa < x \ xa \ L\<^isub>1\} = {\L\<^isub>1 `` {y - xa} |xa. xa < y \ xa \ L\<^isub>1\}" (is "?left = ?right") - by (auto simp:tag_str_STAR_def) + by (auto simp:tag_str_Star_def) moreover have "\L\<^isub>1 `` {x - xa_max} \ ?left" using h1 h2 by auto ultimately have "\L\<^isub>1 `` {x - xa_max} \ ?right" by simp thus ?thesis using that @@ -417,7 +419,7 @@ have "?xa_max' < x" using np h1 by (clarsimp simp:strict_prefix_def diff_prefix) moreover have "?xa_max' \ L\<^isub>1\" - using a_in h2 by (simp add:star_intro3) + using a_in h2 by (auto) moreover have "(x - ?xa_max') @ z \ L\<^isub>1\" using b_eqs b_in np h1 by (simp add:diff_diff_append) moreover have "\ (length ?xa_max' \ length xa_max)" @@ -432,11 +434,12 @@ with eq_z and b_in show ?thesis using that by blast qed - have "((y - ya) @ za) @ zb \ L\<^isub>1\" using l_za ls_zb by blast + have "((y - ya) @ za) @ zb \ L\<^isub>1\" using l_za ls_zb + by (rule_tac append_in_starI) (auto) with eq_zab show ?thesis by simp qed - with h5 h6 show ?thesis - by (drule_tac star_intro1) (auto simp:strict_prefix_def elim: prefixE) + with h5 h6 show ?thesis + by (auto simp:strict_prefix_def elim: prefixE) qed } from this [OF _ eq_tag] and this [OF _ eq_tag [THEN sym]] @@ -444,16 +447,17 @@ qed lemma quot_star_finiteI [intro]: + fixes A::"('a::finite) lang" assumes finite1: "finite (UNIV // \A)" shows "finite (UNIV // \(A\))" -proof (rule_tac tag = "tag_str_STAR A" in tag_finite_imageD) - show "\x y. tag_str_STAR A x = tag_str_STAR A y \ x \(A\) y" - by (rule tag_str_STAR_injI) +proof (rule_tac tag = "tag_str_Star A" in tag_finite_imageD) + show "\x y. tag_str_Star A x = tag_str_Star A y \ x \(A\) y" + by (rule tag_str_Star_injI) next have *: "finite (Pow (UNIV // \A))" using finite1 by auto - show "finite (range (tag_str_STAR A))" - unfolding tag_str_STAR_def + show "finite (range (tag_str_Star A))" + unfolding tag_str_Star_def apply(rule finite_subset[OF _ *]) unfolding quotient_def by auto @@ -462,12 +466,13 @@ subsubsection{* The conclusion *} lemma Myhill_Nerode2: - shows "finite (UNIV // \(L_rexp r))" + fixes r::"('a::finite) rexp" + shows "finite (UNIV // \(lang r))" by (induct r) (auto) - theorem Myhill_Nerode: - shows "(\r. A = L_rexp r) \ finite (UNIV // \A)" + fixes A::"('a::finite) lang" + shows "(\r. A = lang r) \ finite (UNIV // \A)" using Myhill_Nerode1 Myhill_Nerode2 by auto end