# HG changeset patch # User wu # Date 1290080357 0 # Node ID e31b733ace44f4054380ea5d63c1999a585b2a1b # Parent 0792821035b6c267e910660073ee61d91ee396cf All cases of the Other direction finished diff -r 0792821035b6 -r e31b733ace44 MyhillNerode.thy --- a/MyhillNerode.thy Wed Nov 10 11:59:29 2010 +0000 +++ b/MyhillNerode.thy Thu Nov 18 11:39:17 2010 +0000 @@ -1,5 +1,5 @@ theory MyhillNerode - imports "Main" + imports "Main" "List_Prefix" begin text {* sequential composition of languages *} @@ -281,8 +281,9 @@ where "L1 Quo L2 \ { \x\L2 | x. x \ L1}" + lemma lang_eqs_union_of_eqcls: - "Lang = (\ {X. X \ (UNIV Quo Lang) \ (\ x \ X. x \ Lang)})" + "Lang = \ {X. X \ (UNIV Quo Lang) \ (\ x \ X. x \ Lang)}" proof show "Lang \ \{X \ UNIV Quo Lang. \x\X. x \ Lang}" proof @@ -304,7 +305,6 @@ by auto qed - lemma empty_notin_CS: "{} \ UNIV Quo Lang" apply (clarsimp simp:quot_def equiv_class_def) by (rule_tac x = x in exI, auto simp:equiv_str_def) @@ -317,7 +317,7 @@ definition CT :: "string set \ char \ string set \ bool" ("_-_\_" [99,99]99) where - "X-c\Y \ ( X; {[c]} \ Y)" + "X-c\Y \ ((X;{[c]}) \ Y)" types t_equa_rhs = "(string set \ rexp) set" @@ -345,7 +345,7 @@ equation_rhs :: "(string set) set \ string set \ t_equa_rhs" where "equation_rhs CS X \ if (X = {[]}) then {({[]}, EMPTY)} - else {(S, folds ALT NULL {CHAR c| c. S-c\X} )| S. S \ CS} \ empty_rhs X" + else {(S, folds ALT NULL {CHAR c| c. S-c\X} )| S. S \ CS} \ empty_rhs X" definition equations :: "(string set) set \ t_equas" @@ -498,14 +498,14 @@ qed text {* - merge_rhs {(X1, r1), (x2, r2}, (x4, r4), \} {(x1, r1'), (x3, r3'), \} = + merge_rhs {(x1, r1), (x2, r2}, (x4, r4), \} {(x1, r1'), (x3, r3'), \} = {(x1, ALT r1 r1'}, (x2, r2), (x3, r3'), (x4, r4), \} *} definition merge_rhs :: "t_equa_rhs \ t_equa_rhs \ t_equa_rhs" where "merge_rhs rhs rhs' \ {(X, r). (\ r1 r2. ((X,r1) \ rhs \ (X, r2) \ rhs') \ r = ALT r1 r2) \ (\ r1. (X, r1) \ rhs \ (\ (\ r2. (X, r2) \ rhs')) \ r = r1) \ - (\ r2. (X, r2) \ rhs' \ (\ (\ r1. (X, r1) \ rhs)) \ r = r2) }" + (\ r2. (X, r2) \ rhs' \ (\ (\ r1. (X, r1) \ rhs)) \ r = r2) }" text {* rhs_subst rhs X=xrhs r: substitude all occurence of X in rhs((X,r) \ rhs) with xrhs *} @@ -631,8 +631,7 @@ definition Inv :: "string set \ t_equas \ bool" where "Inv X ES \ finite ES \ (\ rhs. (X, rhs) \ ES) \ distinct_equas ES \ - (\ X xrhs. (X, xrhs) \ ES \ ardenable (X, xrhs) \ X \ {} \ rhs_eq_cls xrhs - \ insert {[]} (left_eq_cls ES))" + (\ X xrhs. (X, xrhs) \ ES \ ardenable (X, xrhs) \ X \ {} \ rhs_eq_cls xrhs \ insert {[]} (left_eq_cls ES))" text {* TCon: Termination Condition of the equation-system decreasion. @@ -644,14 +643,11 @@ text {* The following is a iteration principle, and is the main framework for the proof: + 1: We can form the initial equation-system using "equations" defined above, and prove it has invariance Inv by lemma "init_ES_satisfy_Inv"; + 2: We can decrease the number of the equation-system using ardens_lemma_revised and substitution ("equas_subst", defined above), + and prove it holds the property "step" in "wf_iter" by lemma "iteration_step" + and finally using property Inv and TCon to prove the myhill-nerode theorem - 1: We can form the initial equation-system using "equations" defined above, - and prove it has invariance Inv by lemma "init_ES_satisfy_Inv"; - - 2: We can decrease the number of the equation-system using ardens_lemma_revised - and substitution ("equas_subst", defined above), - and prove it holds the property "step" in "wf_iter" by lemma "iteration_step" - and finally using property Inv and TCon to prove the myhill-nerode theorem *} lemma wf_iter [rule_format]: fixes f @@ -806,8 +802,7 @@ "(X, xrhs) \ equations CS \ no_EMPTY_rhs xrhs" apply (clarsimp simp add:equations_def equation_rhs_def) apply (simp add:no_EMPTY_rhs_def empty_rhs_def, auto) -apply (subgoal_tac "finite {CHAR c |c. Xa-c\X}", - drule_tac x = "[]" in fold_alt_null_eqs, clarsimp, rule finite_charset_rS)+ +apply (subgoal_tac "finite {CHAR c |c. Xa-c\X}", drule_tac x = "[]" in fold_alt_null_eqs, clarsimp, rule finite_charset_rS)+ done lemma init_ES_satisfy_ardenable: @@ -894,8 +889,7 @@ lemma ardenable_prop: assumes not_lambda: "Y \ {[]}" and ardable: "ardenable (Y, yrhs)" - shows "\ yrhs'. Y = L yrhs' \ distinct_rhs yrhs' \ rhs_eq_cls yrhs' = rhs_eq_cls yrhs - {Y}" - (is "\ yrhs'. ?P yrhs'") + shows "\ yrhs'. Y = L yrhs' \ distinct_rhs yrhs' \ rhs_eq_cls yrhs' = rhs_eq_cls yrhs - {Y}" (is "\ yrhs'. ?P yrhs'") proof (cases "(\ reg. (Y, reg) \ yrhs)") case True thus ?thesis @@ -1312,59 +1306,26 @@ text {* tests by Christian *} -lemma temp_set_ext[no_atp]: "(\x. (x:A) = (x:B)) \ (A = B)" -by(auto intro:set_eqI) - -fun - MNRel -where - "MNRel Lang (x, y) = (x \Lang\ y)" - -lemma - "equiv UNIV (MNRel Lang)" -unfolding equiv_def -unfolding refl_on_def sym_def trans_def -apply(auto simp add: mem_def equiv_str_def) -done - -lemma - "(MNRel Lang)``{x} = \x\Lang" -unfolding equiv_class_def Image_def mem_def -by (simp) - -lemma tt: "\A = B; C \ B\ \ C \ A" by simp - -lemma - "UNIV//(MNRel (L1 \ L2)) \ (UNIV//(MNRel L1)) \ (UNIV//(MNRel L2))" -unfolding quotient_def -unfolding UNION_eq_Union_image -apply(rule tt) -apply(rule Un_Union_image[symmetric]) -apply(simp) -apply(rule UN_mono) -apply(simp) -apply(simp) -unfolding Image_def -unfolding mem_def -unfolding MNRel.simps -apply(simp) -oops - - - -text {* Alternative definition for Quo *} +(* Alternative definition for Quo *) definition QUOT :: "string set \ (string set) set" where "QUOT Lang \ (\x. {\x\Lang})" -lemma test_01: - "Lang \ (\ QUOT Lang)" -unfolding QUOT_def equiv_class_def equiv_str_def -by (blast) +lemma test: + "UNIV Quo Lang = QUOT Lang" +by (auto simp add: quot_def QUOT_def) +lemma test1: + assumes finite_CS: "finite (QUOT Lang)" + shows "reg Lang" +using finite_CS +unfolding test[symmetric] +by (auto dest: myhill_nerode) -(* by chunhan *) +lemma cons_one: "x @ y \ {z} \ x @ y = z" +by simp + lemma quot_lambda: "QUOT {[]} = {{[]}, UNIV - {[]}}" proof show "QUOT {[]} \ {{[]}, UNIV - {[]}}" @@ -1446,7 +1407,7 @@ proof - have "xa = [c] \ {y. xa \{[c]}\ y} = {[c]}" using in_eqiv apply (simp add:equiv_str_def) - apply (rule temp_set_ext, rule iffI, simp) + apply (rule set_ext, rule iffI, simp) apply (drule_tac x = "[]" in spec, auto) done thus "xa = [c] \ x = {[c]}" using in_eqiv by simp @@ -1455,7 +1416,7 @@ proof - have "\xa \ []; xa \ [c]\ \ {y. xa \{[c]}\ y} = UNIV - {[],[c]}" apply (clarsimp simp add:equiv_str_def) - apply (rule temp_set_ext, rule iffI, simp) + apply (rule set_ext, rule iffI, simp) apply (rule conjI) apply (drule_tac x = "[c]" in spec, simp) apply (drule_tac x = "[]" in spec, simp) @@ -1481,13 +1442,13 @@ moreover have "x = {[c]} \ x \ QUOT {[c]}" apply (simp add:QUOT_def equiv_class_def equiv_str_def) apply (rule_tac x = "[c]" in exI, simp) - apply (rule temp_set_ext, rule iffI, simp+) + apply (rule set_ext, rule iffI, simp+) by (drule_tac x = "[]" in spec, simp) moreover have "x = UNIV - {[],[c]} \ x \ QUOT {[c]}" using exist_another apply (clarsimp simp add:QUOT_def equiv_class_def equiv_str_def) apply (rule_tac x = "[a]" in exI, simp) - apply (rule temp_set_ext, rule iffI, simp) + apply (rule set_ext, rule iffI, simp) apply (clarsimp simp:quot_single_aux, simp) apply (rule conjI) apply (drule_tac x = "[c]" in spec, simp) @@ -1498,53 +1459,18 @@ qed qed -lemma quot_seq: - assumes finite1: "finite (QUOT L\<^isub>1)" - and finite2: "finite (QUOT L\<^isub>2)" - shows "finite (QUOT (L\<^isub>1;L\<^isub>2))" -apply (simp add:QUOT_def equiv_class_def equiv_str_def) -sorry - - -lemma a: - "\x \L1\ y \ x \L2\ y\ \ x \(L1 \ L2)\ y" -apply(simp add: equiv_str_def) -done - - -(* -lemma quot_star: - assumes finite1: "finite (QUOT L\<^isub>1)" - shows "finite (QUOT (L\<^isub>1\))" -sorry - - -lemma other_direction: - "Lang = L (r::rexp) \ finite (QUOT Lang)" -apply (induct arbitrary:Lang rule:rexp.induct) -apply (simp add:QUOT_def equiv_class_def equiv_str_def) -by (simp_all add:quot_lambda quot_single quot_seq quot_alt quot_star) - -lemma test: - "UNIV Quo Lang = QUOT Lang" -by (auto simp add: quot_def QUOT_def) -*) - - -(* by chunhan *) - +lemma eq_class_imp_eq_str: + "\x\lang = \y\lang \ x \lang\ y" +by (auto simp:equiv_class_def equiv_str_def) lemma finite_tag_image: "finite (range tag) \ finite (((op `) tag) ` S)" apply (rule_tac B = "Pow (tag ` UNIV)" in finite_subset) by (auto simp add:image_def Pow_def) -term image -term "(op `) tag" - lemma str_inj_imps: assumes str_inj: "\ m n. tag m = tag (n::string) \ m \lang\ n" - shows "inj_on (image tag) (QUOT lang)" + shows "inj_on ((op `) tag) (QUOT lang)" proof (clarsimp simp add:inj_on_def QUOT_def) fix x y assume eq_tag: "tag ` \x\lang = tag ` \y\lang" @@ -1563,24 +1489,17 @@ qed qed -definition - tag_str_ALT :: "string set \ string set \ string \ (string set \ string set)" +definition tag_str_ALT :: "string set \ string set \ string \ (string set \ string set)" where "tag_str_ALT L\<^isub>1 L\<^isub>2 x \ (\x\L\<^isub>1, \x\L\<^isub>2)" -lemma - "{(\x\L\<^isub>1, \x\L\<^isub>2) | x. True} \ (QUOT L\<^isub>1) \ (QUOT L\<^isub>2)" -unfolding QUOT_def -by (auto) - lemma tag_str_alt_range_finite: assumes finite1: "finite (QUOT L\<^isub>1)" and finite2: "finite (QUOT L\<^isub>2)" shows "finite (range (tag_str_ALT L\<^isub>1 L\<^isub>2))" proof - have "{y. \x. y = (\x\L\<^isub>1, \x\L\<^isub>2)} \ (QUOT L\<^isub>1) \ (QUOT L\<^isub>2)" - unfolding QUOT_def - by auto + by (auto simp:QUOT_def) thus ?thesis using finite1 finite2 by (auto simp: image_def tag_str_ALT_def UNION_def intro: finite_subset[where B = "(QUOT L\<^isub>1) \ (QUOT L\<^isub>2)"]) @@ -1595,111 +1514,16 @@ assumes finite1: "finite (QUOT L\<^isub>1)" and finite2: "finite (QUOT L\<^isub>2)" shows "finite (QUOT (L\<^isub>1 \ L\<^isub>2))" -proof - - have "finite (op ` (tag_str_ALT L\<^isub>1 L\<^isub>2) ` QUOT (L\<^isub>1 \ L\<^isub>2))" +proof (rule_tac f = "(op `) (tag_str_ALT L\<^isub>1 L\<^isub>2)" in finite_imageD) + show "finite (op ` (tag_str_ALT L\<^isub>1 L\<^isub>2) ` QUOT (L\<^isub>1 \ L\<^isub>2))" using finite_tag_image tag_str_alt_range_finite finite1 finite2 by auto - moreover - have "inj_on (op ` (tag_str_ALT L\<^isub>1 L\<^isub>2)) (QUOT (L\<^isub>1 \ L\<^isub>2))" +next + show "inj_on (op ` (tag_str_ALT L\<^isub>1 L\<^isub>2)) (QUOT (L\<^isub>1 \ L\<^isub>2))" apply (rule_tac str_inj_imps) by (erule_tac tag_str_alt_inj) - ultimately - show "finite (QUOT (L\<^isub>1 \ L\<^isub>2))" by (rule finite_imageD) qed - -(*by cu *) - - -definition - str_eq ("_ \_ _") -where - "x \Lang y \ (\z. x @ z \ Lang \ y @ z \ Lang)" - -definition - str_eq_rel ("\_") -where - "\Lang \ {(x, y). x \Lang y}" - -lemma [simp]: - "(x, y) \ {(x, y). P x y} \ P x y" -by simp - -lemma inj_image_lang: - fixes f::"string \ 'a" - assumes str_inj: "\x y. f x = f y \ x \Lang y" - shows "inj_on (image f) (UNIV // (\Lang))" -proof - - { fix x y::string - assume eq_tag: "f ` {z. x \Lang z} = f ` {z. y \Lang z}" - moreover - have "{z. x \Lang z} \ {}" unfolding str_eq_def by auto - ultimately obtain a b where "x \Lang a" "y \Lang b" "f a = f b" by blast - then have "x \Lang a" "y \Lang b" "a \Lang b" using str_inj by auto - then have "x \Lang y" unfolding str_eq_def by simp - then have "{z. x \Lang z} = {z. y \Lang z}" unfolding str_eq_def by simp - } - then have "\x\UNIV // \Lang. \y\UNIV // \Lang. f ` x = f ` y \ x = y" - unfolding quotient_def Image_def str_eq_rel_def by simp - then show "inj_on (image f) (UNIV // (\Lang))" - unfolding inj_on_def by simp -qed - - -lemma finite_range_image: - assumes fin: "finite (range f)" - shows "finite ((image f) ` X)" -proof - - from fin have "finite (Pow (f ` UNIV))" by auto - moreover - have "(image f) ` X \ Pow (f ` UNIV)" by auto - ultimately show "finite ((image f) ` X)" using finite_subset by auto -qed - -definition - tag1 :: "string set \ string set \ string \ (string set \ string set)" -where - "tag1 L\<^isub>1 L\<^isub>2 \ \x. ((\L\<^isub>1) `` {x}, (\L\<^isub>2) `` {x})" - -lemma tag1_range_finite: - assumes finite1: "finite (UNIV // \L\<^isub>1)" - and finite2: "finite (UNIV // \L\<^isub>2)" - shows "finite (range (tag1 L\<^isub>1 L\<^isub>2))" -proof - - have "finite (UNIV // \L\<^isub>1 \ UNIV // \L\<^isub>2)" using finite1 finite2 by auto - moreover - have "range (tag1 L\<^isub>1 L\<^isub>2) \ (UNIV // \L\<^isub>1) \ (UNIV // \L\<^isub>2)" - unfolding tag1_def quotient_def by auto - ultimately show "finite (range (tag1 L\<^isub>1 L\<^isub>2))" - using finite_subset by blast -qed - -lemma tag1_inj: - "tag1 L\<^isub>1 L\<^isub>2 x = tag1 L\<^isub>1 L\<^isub>2 y \ x \(L\<^isub>1 \ L\<^isub>2) y" -unfolding tag1_def Image_def str_eq_rel_def str_eq_def -by auto - -lemma quot_alt_cu: - fixes L\<^isub>1 L\<^isub>2::"string set" - assumes fin1: "finite (UNIV // \L\<^isub>1)" - and fin2: "finite (UNIV // \L\<^isub>2)" - shows "finite (UNIV // \(L\<^isub>1 \ L\<^isub>2))" -proof - - have "finite (range (tag1 L\<^isub>1 L\<^isub>2))" - using fin1 fin2 tag1_range_finite by simp - then have "finite (image (tag1 L\<^isub>1 L\<^isub>2) ` (UNIV // \(L\<^isub>1 \ L\<^isub>2)))" - using finite_range_image by blast - moreover - have "\x y. tag1 L\<^isub>1 L\<^isub>2 x = tag1 L\<^isub>1 L\<^isub>2 y \ x \(L\<^isub>1 \ L\<^isub>2) y" - using tag1_inj by simp - then have "inj_on (image (tag1 L\<^isub>1 L\<^isub>2)) (UNIV // \(L\<^isub>1 \ L\<^isub>2))" - using inj_image_lang by blast - ultimately - show "finite (UNIV // \(L\<^isub>1 \ L\<^isub>2))" by (rule finite_imageD) -qed - -(* by chunhan *) - (* list_diff:: list substract, once different return tailer *) fun list_diff :: "'a list \ 'a list \ 'a list" (infix "-" 51) where @@ -1707,76 +1531,108 @@ "list_diff (x#xs) [] = x#xs" | "list_diff (x#xs) (y#ys) = (if x = y then list_diff xs ys else (x#xs))" -definition tag_str_SEQ:: "string set \ string set \ string \ (string set) set" +lemma [simp]: "(x @ y) - x = y" +apply (induct x) +by (case_tac y, simp+) + +lemma [simp]: "x - x = []" +by (induct x, auto) + +lemma [simp]: "x = xa @ y \ x - xa = y " +by (induct x, auto) + +lemma [simp]: "x - [] = x" +by (induct x, auto) + +lemma [simp]: "xa \ x \ (x @ y) - xa = (x - xa) @ y" +by (auto elim:prefixE) + +definition tag_str_SEQ:: "string set \ string set \ string \ (string set \ string set set)" where - "tag_str_SEQ L\<^isub>1 L\<^isub>2 x \ if (\ y. y \ x \ y \ L\<^isub>1) - then {(\(x - y)\L\<^isub>2) | y. y \ x \ y \ L\<^isub>1} - else { \x\L\<^isub>1 }" + "tag_str_SEQ L\<^isub>1 L\<^isub>2 x \ if (\ xa \ x. xa \ L\<^isub>1) + then (\x\L\<^isub>1, {\(x - xa)\L\<^isub>2 | xa. xa \ x \ xa \ L\<^isub>1}) + else (\x\L\<^isub>1, {})" + +lemma tag_seq_eq_E: + "tag_str_SEQ L\<^isub>1 L\<^isub>2 x = tag_str_SEQ L\<^isub>1 L\<^isub>2 y \ + ((\ xa \ x. xa \ L\<^isub>1) \ \x\L\<^isub>1 = \y\L\<^isub>1 \ + {\(x - xa)\L\<^isub>2 | xa. xa \ x \ xa \ L\<^isub>1} = {\(y - ya)\L\<^isub>2 | ya. ya \ y \ ya \ L\<^isub>1} ) \ + ((\ xa \ x. xa \ L\<^isub>1) \ \x\L\<^isub>1 = \y\L\<^isub>1)" +by (simp add:tag_str_SEQ_def split:if_splits, blast) lemma tag_str_seq_range_finite: assumes finite1: "finite (QUOT L\<^isub>1)" and finite2: "finite (QUOT L\<^isub>2)" shows "finite (range (tag_str_SEQ L\<^isub>1 L\<^isub>2))" proof - - have "(range (tag_str_SEQ L\<^isub>1 L\<^isub>2)) \ Pow ((QUOT L\<^isub>1) \ (QUOT L\<^isub>2))" + have "(range (tag_str_SEQ L\<^isub>1 L\<^isub>2)) \ (QUOT L\<^isub>1) \ (Pow (QUOT L\<^isub>2))" by (auto simp:image_def tag_str_SEQ_def QUOT_def) thus ?thesis using finite1 finite2 - by (rule_tac B = "Pow ((QUOT L\<^isub>1) \ (QUOT L\<^isub>2))" in finite_subset, auto) + by (rule_tac B = "(QUOT L\<^isub>1) \ (Pow (QUOT L\<^isub>2))" in finite_subset, auto) qed +lemma app_in_seq_decom[rule_format]: + "\ x. x @ z \ L\<^isub>1 ; L\<^isub>2 \ (\ xa \ x. xa \ L\<^isub>1 \ (x - xa) @ z \ L\<^isub>2) \ + (\ za \ z. (x @ za) \ L\<^isub>1 \ (z - za) \ L\<^isub>2)" +apply (induct z) +apply (simp, rule allI, rule impI, rule disjI1) +apply (clarsimp simp add:lang_seq_def) +apply (rule_tac x = s1 in exI, simp) +apply (rule allI | rule impI)+ +apply (drule_tac x = "x @ [a]" in spec, simp) +apply (erule exE | erule conjE | erule disjE)+ +apply (rule disjI2, rule_tac x = "[a]" in exI, simp) +apply (rule disjI1, rule_tac x = xa in exI, simp) +apply (erule exE | erule conjE)+ +apply (rule disjI2, rule_tac x = "a # za" in exI, simp) +done + lemma tag_str_seq_inj: assumes tag_eq: "tag_str_SEQ L\<^isub>1 L\<^isub>2 x = tag_str_SEQ L\<^isub>1 L\<^isub>2 y" shows "(x::string) \(L\<^isub>1 ; L\<^isub>2)\ y" -proof (cases "\ xa. xa \ x \ xa \ L\<^isub>1") - have equiv_str_sym: "\ x y lang. (x::string) \lang\ y \ y \lang\ x" - by (auto simp:equiv_str_def) - have set_equ_D: "\ A a B b. \A = B; A \ {}\ \ \ a b. a \ A \ b \ B \ a = b " by auto - have eqset_equ_D: "\ x y lang. {y. x \lang\ y} = {ya. y \lang\ ya} \ x \lang\ y" - by (drule set_equ_D, auto simp:equiv_str_def) - assume x_left_l1: "\xa\x. xa \ L\<^isub>1" - show "x \L\<^isub>1 ; L\<^isub>2\ y" - proof (cases "\ ya. ya \ y \ ya \ L\<^isub>1") - assume y_left_l1: "\ya\y. ya \ L\<^isub>1" - with tag_eq x_left_l1 - show "x \L\<^isub>1 ; L\<^isub>2\ y" - apply (simp add:tag_str_SEQ_def) - apply (drule set_equ_D) - apply (auto simp:equiv_class_def equiv_str_def)[1] - apply (clarsimp simp:equiv_str_def) - apply (rule iffI) - apply - apply ( +proof - + have aux: "\ x y z. \tag_str_SEQ L\<^isub>1 L\<^isub>2 x = tag_str_SEQ L\<^isub>1 L\<^isub>2 y; x @ z \ L\<^isub>1 ; L\<^isub>2\ + \ y @ z \ L\<^isub>1 ; L\<^isub>2" + proof (drule app_in_seq_decom, erule disjE) + fix x y z + assume tag_eq: "tag_str_SEQ L\<^isub>1 L\<^isub>2 x = tag_str_SEQ L\<^isub>1 L\<^isub>2 y" + and x_gets_l2: "\xa\x. xa \ L\<^isub>1 \ (x - xa) @ z \ L\<^isub>2" + from x_gets_l2 have "\ xa \ x. xa \ L\<^isub>1" by blast + hence xy_l2:"{\(x - xa)\L\<^isub>2 | xa. xa \ x \ xa \ L\<^isub>1} = {\(y - ya)\L\<^isub>2 | ya. ya \ y \ ya \ L\<^isub>1}" + using tag_eq tag_seq_eq_E by blast + from x_gets_l2 obtain xa where xa_le_x: "xa \ x" + and xa_in_l1: "xa \ L\<^isub>1" + and rest_in_l2: "(x - xa) @ z \ L\<^isub>2" by blast + hence "\ ya. \(x - xa)\L\<^isub>2 = \(y - ya)\L\<^isub>2 \ ya \ y \ ya \ L\<^isub>1" using xy_l2 by auto + then obtain ya where ya_le_x: "ya \ y" + and ya_in_l1: "ya \ L\<^isub>1" + and rest_eq: "\(x - xa)\L\<^isub>2 = \(y - ya)\L\<^isub>2" by blast + from rest_eq rest_in_l2 have "(y - ya) @ z \ L\<^isub>2" + by (auto simp:equiv_class_def equiv_str_def) + hence "ya @ ((y - ya) @ z) \ L\<^isub>1 ; L\<^isub>2" using ya_in_l1 + by (auto simp:lang_seq_def) + thus "y @ z \ L\<^isub>1 ; L\<^isub>2" using ya_le_x + by (erule_tac prefixE, simp) next - assume y_in_l1: "\ (\ya\y. ya \ L\<^isub>1)" - show "x \L\<^isub>1 ; L\<^isub>2\ y" - sorry + fix x y z + assume tag_eq: "tag_str_SEQ L\<^isub>1 L\<^isub>2 x = tag_str_SEQ L\<^isub>1 L\<^isub>2 y" + and x_gets_l1: "\za\z. x @ za \ L\<^isub>1 \ z - za \ L\<^isub>2" + from tag_eq tag_seq_eq_E have x_y_eq: "\x\L\<^isub>1 = \y\L\<^isub>1" by blast + from x_gets_l1 obtain za where za_le_z: "za \ z" + and x_za_in_l1: "(x @ za) \ L\<^isub>1" + and rest_in_l2: "z - za \ L\<^isub>2" by blast + from x_y_eq x_za_in_l1 have y_za_in_l1: "y @ za \ L\<^isub>1" + by (auto simp:equiv_class_def equiv_str_def) + hence "(y @ za) @ (z - za) \ L\<^isub>1 ; L\<^isub>2" using rest_in_l2 + apply (simp add:lang_seq_def) + by (rule_tac x = "y @ za" in exI, rule_tac x = "z - za" in exI, simp) + thus "y @ z \ L\<^isub>1 ; L\<^isub>2" using za_le_z + by (erule_tac prefixE, simp) qed -next - assume x_in_l1: "\ (\xa\x. xa \ L\<^isub>1)" - show "x \L\<^isub>1 ; L\<^isub>2\ y" - proof (cases "\ ya. ya \ y \ ya \ L\<^isub>1") - assume y_left_l1: "\ya\y. ya \ L\<^isub>1" - show "x \L\<^isub>1 ; L\<^isub>2\ y" - sorry - next - assume y_in_l1: "\ (\ya\y. ya \ L\<^isub>1)" - with tag_eq x_in_l1 - have "\x\(L\<^isub>1;L\<^isub>2) = \y\(L\<^isub>1;L\<^isub>2)" - sorry - thus "x \L\<^isub>1 ; L\<^isub>2\ y" - by (auto simp:equiv_class_def equiv_str_def) - qed + show ?thesis using tag_eq + apply (simp add:equiv_str_def) + by (auto intro:aux) qed - -apply (simp add:tag_str_SEQ_def split:if_splits) -prefer 4 -apply (clarsimp simp add:equiv_str_def) -apply (rule iffI) -apply (simp add:lang_seq_def equiv_class_def equiv_str_def) -apply blast -apply ( -sorry - lemma quot_seq: assumes finite1: "finite (QUOT L\<^isub>1)" @@ -1792,9 +1648,20 @@ by (erule_tac tag_str_seq_inj) qed -definition tag_str_STAR:: "string set \ string \ (string set) set" +(****************** the STAR case ************************) + +lemma app_eq_elim[rule_format]: + "\ a. \ b x y. a @ b = x @ y \ (\ aa ab. a = aa @ ab \ x = aa \ y = ab @ b) \ + (\ ba bb. b = ba @ bb \ x = a @ ba \ y = bb \ ba \ [])" + apply (induct_tac a rule:List.induct, simp) + apply (rule allI | rule impI)+ + by (case_tac x, auto) + +definition tag_str_STAR:: "string set \ string \ string set set" where - "tag_str_STAR L\<^isub>1 x = {\y\L\<^isub>1 | y. y \ x}" + "tag_str_STAR L\<^isub>1 x \ if (x = []) + then {} + else {\x\<^isub>2\L\<^isub>1 | x\<^isub>1 x\<^isub>2. x = x\<^isub>1 @ x\<^isub>2 \ x\<^isub>1 \ L\<^isub>1\ \ x\<^isub>2 \ []}" lemma tag_str_star_range_finite: assumes finite1: "finite (QUOT L\<^isub>1)" @@ -1806,52 +1673,126 @@ by (rule_tac B = "Pow (QUOT L\<^isub>1)" in finite_subset, auto) qed +lemma star_prop[rule_format]: "x \ lang\ \ \ y. y \ lang\ \ x @ y \ lang\" +by (erule Star.induct, auto) + +lemma star_prop2: "y \ lang \ y \ lang\" +by (drule step[of y lang "[]"], auto simp:start) + +lemma star_prop3[rule_format]: "x \ lang\ \ \y . y \ lang \ x @ y \ lang\" +by (erule Star.induct, auto intro:star_prop2) + +lemma postfix_prop: "y >>= (x @ y) \ x = []" +by (erule postfixE, induct x arbitrary:y, auto) + +lemma inj_aux: + "\(m @ z) \ L\<^isub>1\; m \L\<^isub>1\ yb; xa @ m = x; xa \ L\<^isub>1\; m \ []; + \ xa xb. x = xa @ xb \ xa \ L\<^isub>1\ \ xb \ [] \ xb @ z \ L\<^isub>1\ \ xb >>= m\ + \ (yb @ z) \ L\<^isub>1\" +proof- + have "\s. s \ L\<^isub>1\ \ \ m z yb. (s = m @ z \ m \L\<^isub>1\ yb \ x = xa @ m \ xa \ L\<^isub>1\ \ m \ [] \ + (\ xa xb. x = xa @ xb \ xa \ L\<^isub>1\ \ xb \ [] \ xb @ z \ L\<^isub>1\ \ xb >>= m) \ (yb @ z) \ L\<^isub>1\)" + apply (erule Star.induct, simp) + apply (rule allI | rule impI | erule conjE)+ + apply (drule app_eq_elim) + apply (erule disjE | erule exE | erule conjE)+ + apply simp + apply (simp (no_asm) only:append_assoc[THEN sym]) + apply (rule step) + apply (simp add:equiv_str_def) + apply simp + + apply (erule exE | erule conjE)+ + apply (rotate_tac 3) + apply (frule_tac x = "xa @ s1" in spec) + apply (rotate_tac 12) + apply (drule_tac x = ba in spec) + apply (erule impE) + apply ( simp add:star_prop3) + apply (simp) + apply (drule postfix_prop) + apply simp + done + thus "\(m @ z) \ L\<^isub>1\; m \L\<^isub>1\ yb; xa @ m = x; xa \ L\<^isub>1\; m \ []; + \ xa xb. x = xa @ xb \ xa \ L\<^isub>1\ \ xb \ [] \ xb @ z \ L\<^isub>1\ \ xb >>= m\ + \ (yb @ z) \ L\<^isub>1\" by blast +qed + + +lemma min_postfix_exists[rule_format]: + "finite A \ A \ {} \ (\ a \ A. \ b \ A. ((b >>= a) \ (a >>= b))) + \ (\ min. (min \ A \ (\ a \ A. a >>= min)))" +apply (erule finite.induct) +apply simp +apply simp +apply (case_tac "A = {}") +apply simp +apply clarsimp +apply (case_tac "a >>= min") +apply (rule_tac x = min in exI, simp) +apply (rule_tac x = a in exI, simp) +apply clarify +apply (rotate_tac 5) +apply (erule_tac x = aa in ballE) defer apply simp +apply (erule_tac ys = min in postfix_trans) +apply (erule_tac x = min in ballE) +by simp+ + lemma tag_str_star_inj: "tag_str_STAR L\<^isub>1 x = tag_str_STAR L\<^isub>1 (y::string) \ x \L\<^isub>1\\ y" proof - - have "\ x lang. (x = []) = (tag_str_STAR lang x = {\[]\lang})" - proof (rule_tac allI, rule_tac allI, rule_tac iffI) - fix x lang - show "x = [] \ tag_str_STAR lang x = {\[]\lang}" - by (simp add:tag_str_STAR_def) - next - fix x lang - show "tag_str_STAR lang x = {\[]\lang} \ x = []" - apply (simp add:tag_str_STAR_def) - apply (drule equalityD1) - apply (case_tac x) - apply simp - thm in_mono - apply (drule_tac x = "\[a]\lang" in in_mono) - apply simp - apply auto - - apply (erule subsetCE) - - apply (case_tac y) - - sorry - next + have aux: "\ x y z. \tag_str_STAR L\<^isub>1 x = tag_str_STAR L\<^isub>1 y; x @ z \ L\<^isub>1\\ \ y @ z \ L\<^isub>1\" + proof- + fix x y z + assume tag_eq: "tag_str_STAR L\<^isub>1 x = tag_str_STAR L\<^isub>1 y" + and x_z: "x @ z \ L\<^isub>1\" + show "y @ z \ L\<^isub>1\" + proof (cases "x = []") + case True + with tag_eq have "y = []" by (simp add:tag_str_STAR_def split:if_splits, blast) + thus ?thesis using x_z True by simp + next + case False + hence not_empty: "{xb. \ xa. x = xa @ xb \ xa \ L\<^isub>1\ \ xb \ [] \ xb @ z \ L\<^isub>1\} \ {}" using x_z + by (simp, rule_tac x = x in exI, rule_tac x = "[]" in exI, simp add:start) + have finite_set: "finite {xb. \ xa. x = xa @ xb \ xa \ L\<^isub>1\ \ xb \ [] \ xb @ z \ L\<^isub>1\}" + apply (rule_tac B = "{xb. \ xa. x = xa @ xb}" in finite_subset) + apply auto + apply (induct x, simp) + apply (subgoal_tac "{xb. \xa. a # x = xa @ xb} = insert (a # x) {xb. \xa. x = xa @ xb}") + apply auto + by (case_tac xaa, simp+) + have comparable: "\ a \ {xb. \ xa. x = xa @ xb \ xa \ L\<^isub>1\ \ xb \ [] \ xb @ z \ L\<^isub>1\}. + \ b \ {xb. \ xa. x = xa @ xb \ xa \ L\<^isub>1\ \ xb \ [] \ xb @ z \ L\<^isub>1\}. + ((b >>= a) \ (a >>= b))" + by (auto simp:postfix_def, drule app_eq_elim, blast) + hence "\ min. min \ {xb. \ xa. x = xa @ xb \ xa \ L\<^isub>1\ \ xb \ [] \ xb @ z \ L\<^isub>1\} + \ (\ xa xb. x = xa @ xb \ xa \ L\<^isub>1\ \ xb \ [] \ xb @ z \ L\<^isub>1\ \ xb >>= min)" + using finite_set not_empty comparable + apply (drule_tac min_postfix_exists, simp) + by (erule exE, rule_tac x = min in exI, auto) + then obtain min xa where x_decom: "x = xa @ min \ xa \ L\<^isub>1\" + and min_not_empty: "min \ []" + and min_z_in_star: "min @ z \ L\<^isub>1\" + and is_min: "\ xa xb. x = xa @ xb \ xa \ L\<^isub>1\ \ xb \ [] \ xb @ z \ L\<^isub>1\ \ xb >>= min" by blast + from x_decom min_not_empty have "\min\L\<^isub>1 \ tag_str_STAR L\<^isub>1 x" by (auto simp:tag_str_STAR_def) + hence "\ yb. \yb\L\<^isub>1 \ tag_str_STAR L\<^isub>1 y \ \min\L\<^isub>1 = \yb\L\<^isub>1" using tag_eq by auto + hence "\ ya yb. y = ya @ yb \ ya \ L\<^isub>1\ \ min \L\<^isub>1\ yb \ yb \ [] " + by (simp add:tag_str_STAR_def equiv_class_def equiv_str_def split:if_splits, blast) + then obtain ya yb where y_decom: "y = ya @ yb" + and ya_in_star: "ya \ L\<^isub>1\" + and yb_not_empty: "yb \ []" + and min_yb_eq: "min \L\<^isub>1\ yb" by blast + from min_z_in_star min_yb_eq min_not_empty is_min x_decom + have "yb @ z \ L\<^isub>1\" + by (rule_tac x = x and xa = xa in inj_aux, simp+) + thus ?thesis using ya_in_star y_decom + by (auto dest:star_prop) + qed qed - apply (simp add:tag_str_STAR_def equiv_class_def equiv_str_def) - apply (rule iffI) - - apply (auto simp:tag_str_STAR_def equiv_class_def equiv_str_def) - have "\ x y z xstr. xstr \ L\<^isub>1\ \ - xstr = x @ z \ tag_str_STAR L\<^isub>1 x = tag_str_STAR L\<^isub>1 y \ y @ z \ L\<^isub>1\ " - proof (erule Star.induct) - fix x y z xstr - show "[] = x @ z \ tag_str_STAR L\<^isub>1 x = tag_str_STAR L\<^isub>1 y \ y @ z \ L\<^isub>1\" - apply (clarsimp simp add:tag_str_STAR_def equiv_str_def equiv_class_def) - apply (blast) -apply (simp add:tag_str_STAR_def equiv_class_def QUOT_def) -apply (simp add:equiv_str_def) -apply (rule allI, rule_tac iffI) -apply (erule_tac star.induct) -apply blast - -sorry - + show "tag_str_STAR L\<^isub>1 x = tag_str_STAR L\<^isub>1 (y::string) \ x \L\<^isub>1\\ y" + by (auto intro:aux simp:equiv_str_def) +qed lemma quot_star: assumes finite1: "finite (QUOT L\<^isub>1)" @@ -1872,7 +1813,4 @@ apply (simp add:QUOT_def equiv_class_def equiv_str_def) by (simp_all add:quot_lambda quot_single quot_seq quot_alt quot_star) - - - -end \ No newline at end of file +end