diff -r 97b783438316 -r 37ab56205097 Myhill_1.thy --- a/Myhill_1.thy Wed Feb 09 09:46:59 2011 +0000 +++ b/Myhill_1.thy Wed Feb 09 12:34:30 2011 +0000 @@ -1,5 +1,5 @@ theory Myhill_1 -imports Main Folds +imports Main Folds While_Combinator begin section {* Preliminary definitions *} @@ -442,47 +442,43 @@ "subst_op_all ES X xrhs \ {(Y, subst_op yrhs X xrhs) | Y yrhs. (Y, yrhs) \ ES}" -section {* Well-founded iteration *} +section {* While-combinator *} text {* - The computation of regular expressions for equivalence classes is accomplished - using a iteration principle given by the following lemma. + The following term @{text "remove ES Y yrhs"} removes the equation + @{text "Y = yrhs"} from equational system @{text "ES"} by replacing + all occurences of @{text "Y"} by its definition (using @{text "eqs_subst"}). + The @{text "Y"}-definition is made non-recursive using Arden's transformation + @{text "arden_variate Y yrhs"}. + *} + +definition + "remove_op ES Y yrhs \ + subst_op_all (ES - {(Y, yrhs)}) Y (arden_op Y yrhs)" + +text {* + The following term @{text "iterm X ES"} represents one iteration in the while loop. + It arbitrarily chooses a @{text "Y"} different from @{text "X"} to remove. *} -lemma wf_iter [rule_format]: - fixes f - assumes step: "\ e. \P e; \ Q e\ \ (\ e'. P e' \ (f(e'), f(e)) \ less_than)" - shows pe: "P e \ (\ e'. P e' \ Q e')" -proof(induct e rule: wf_induct - [OF wf_inv_image[OF wf_less_than, where f = "f"]], clarify) - fix x - assume h [rule_format]: - "\y. (y, x) \ inv_image less_than f \ P y \ (\e'. P e' \ Q e')" - and px: "P x" - show "\e'. P e' \ Q e'" - proof(cases "Q x") - assume "Q x" with px show ?thesis by blast - next - assume nq: "\ Q x" - from step [OF px nq] - obtain e' where pe': "P e'" and ltf: "(f e', f x) \ less_than" by auto - show ?thesis - proof(rule h) - from ltf show "(e', x) \ inv_image less_than f" - by (simp add:inv_image_def) - next - from pe' show "P e'" . - qed - qed -qed +definition + "iter X ES \ (let (Y, yrhs) = SOME (Y, yrhs). (Y, yrhs) \ ES \ (X \ Y) + in remove_op ES Y yrhs)" text {* - The @{text "P"} in lemma @{text "wf_iter"} is an invariant kept throughout the iteration procedure. - The particular invariant used to solve our problem is defined by function @{text "Inv(ES)"}, - an invariant over equal system @{text "ES"}. - Every definition starting next till @{text "Inv"} stipulates a property to be satisfied by @{text "ES"}. + The following term @{text "reduce X ES"} repeatedly removes characteriztion equations + for unknowns other than @{text "X"} until one is left. *} +definition + "reduce X ES \ while (\ ES. card ES \ 1) (iter X) ES" + +text {* + Since the @{text "while"} combinator from HOL library is used to implement @{text "reduce X ES"}, + the induction principle @{thm [source] while_rule} is used to proved the desired properties + of @{text "reduce X ES"}. For this purpose, an invariant predicate @{text "invariant"} is defined + in terms of a series of auxilliary predicates: +*} section {* Invariants *} @@ -757,14 +753,11 @@ ultimately show ?thesis by (simp add:invariant_def) qed -subsubsection {* - Interation step - *} +subsubsection {* Interation step *} text {* - From this point until @{text "iteration_step"}, it is proved - that there exists iteration steps which keep @{text "invariant(ES)"} while - decreasing the size of @{text "ES"}. + From this point until @{text "iteration_step"}, + the correctness of the iteration step @{text "iter X ES"} is proved. *} lemma arden_op_keeps_eq: @@ -1019,66 +1012,118 @@ thus "(\e'. e' \ S \ e \ e' \ thesis) \ thesis" by auto qed -lemma iteration_step: - assumes invariant_ES: "invariant ES" +lemma iteration_step: + assumes Inv_ES: "invariant ES" and X_in_ES: "(X, xrhs) \ ES" and not_T: "card ES \ 1" - shows "\ ES'. (invariant ES' \ (\ xrhs'.(X, xrhs') \ ES')) \ - (card ES', card ES) \ less_than" (is "\ ES'. ?P ES'") + shows "(invariant (iter X ES) \ (\ xrhs'.(X, xrhs') \ (iter X ES)) \ + (iter X ES, ES) \ measure card)" proof - - have finite_ES: "finite ES" using invariant_ES by (simp add:invariant_def) + have finite_ES: "finite ES" using Inv_ES by (simp add: invariant_def) then obtain Y yrhs where Y_in_ES: "(Y, yrhs) \ ES" and not_eq: "(X, xrhs) \ (Y, yrhs)" using not_T X_in_ES by (drule_tac card_noteq_1_has_more, auto) - def ES' == "ES - {(Y, yrhs)}" - let ?ES'' = "subst_op_all ES' Y (arden_op Y yrhs)" - have "?P ?ES''" - proof - - have "invariant ?ES''" using Y_in_ES invariant_ES - by (rule_tac subst_op_all_satisfy_invariant, simp add:ES'_def insert_absorb) - moreover have "\xrhs'. (X, xrhs') \ ?ES''" using not_eq X_in_ES - by (rule_tac ES = ES' in subst_op_all_cls_remains, auto simp add:ES'_def) - moreover have "(card ?ES'', card ES) \ less_than" - proof - - have "finite ES'" using finite_ES ES'_def by auto - moreover have "card ES' < card ES" using finite_ES Y_in_ES - by (auto simp:ES'_def card_gt_0_iff intro:diff_Suc_less) - ultimately show ?thesis - by (auto dest:subst_op_all_card_le elim:le_less_trans) + let ?ES' = "iter X ES" + show ?thesis + proof(unfold iter_def remove_op_def, rule someI2 [where a = "(Y, yrhs)"], clarsimp) + from X_in_ES Y_in_ES and not_eq and Inv_ES + show "(Y, yrhs) \ ES \ X \ Y" + by (auto simp: invariant_def distinct_equas_def) + next + fix x + let ?ES' = "let (Y, yrhs) = x in subst_op_all (ES - {(Y, yrhs)}) Y (arden_op Y yrhs)" + assume prem: "case x of (Y, yrhs) \ (Y, yrhs) \ ES \ (X \ Y)" + thus "invariant (?ES') \ (\xrhs'. (X, xrhs') \ ?ES') \ (?ES', ES) \ measure card" + proof(cases "x", simp) + fix Y yrhs + assume h: "(Y, yrhs) \ ES \ X \ Y" + show "invariant (subst_op_all (ES - {(Y, yrhs)}) Y (arden_op Y yrhs)) \ + (\xrhs'. (X, xrhs') \ subst_op_all (ES - {(Y, yrhs)}) Y (arden_op Y yrhs)) \ + card (subst_op_all (ES - {(Y, yrhs)}) Y (arden_op Y yrhs)) < card ES" + proof - + have "invariant (subst_op_all (ES - {(Y, yrhs)}) Y (arden_op Y yrhs))" + proof(rule subst_op_all_satisfy_invariant) + from h have "(Y, yrhs) \ ES" by simp + hence "ES - {(Y, yrhs)} \ {(Y, yrhs)} = ES" by auto + with Inv_ES show "invariant (ES - {(Y, yrhs)} \ {(Y, yrhs)})" by auto + qed + moreover have + "(\xrhs'. (X, xrhs') \ subst_op_all (ES - {(Y, yrhs)}) Y (arden_op Y yrhs))" + proof(rule subst_op_all_cls_remains) + from X_in_ES and h + show "(X, xrhs) \ ES - {(Y, yrhs)}" by auto + qed + moreover have + "card (subst_op_all (ES - {(Y, yrhs)}) Y (arden_op Y yrhs)) < card ES" + proof(rule le_less_trans) + show + "card (subst_op_all (ES - {(Y, yrhs)}) Y (arden_op Y yrhs)) \ + card (ES - {(Y, yrhs)})" + proof(rule subst_op_all_card_le) + show "finite (ES - {(Y, yrhs)})" using finite_ES by auto + qed + next + show "card (ES - {(Y, yrhs)}) < card ES" using finite_ES h + by (auto simp:card_gt_0_iff intro:diff_Suc_less) + qed + ultimately show ?thesis + by (auto dest: subst_op_all_card_le elim:le_less_trans) + qed qed - ultimately show ?thesis by simp qed - thus ?thesis by blast qed -subsubsection {* - Conclusion of the proof - *} + +subsubsection {* Conclusion of the proof *} text {* From this point until @{text "hard_direction"}, the hard direction is proved through a simple application of the iteration principle. *} -lemma iteration_conc: - assumes history: "invariant ES" - and X_in_ES: "\ xrhs. (X, xrhs) \ ES" - shows - "\ ES'. (invariant ES' \ (\ xrhs'. (X, xrhs') \ ES')) \ card ES' = 1" - (is "\ ES'. ?P ES'") -proof (cases "card ES = 1") - case True - thus ?thesis using history X_in_ES - by blast -next - case False - thus ?thesis using history iteration_step X_in_ES - by (rule_tac f = card in wf_iter, auto) +lemma reduce_x: + assumes inv: "invariant ES" + and contain_x: "(X, xrhs) \ ES" + shows "\ xrhs'. reduce X ES = {(X, xrhs')} \ invariant(reduce X ES)" +proof - + let ?Inv = "\ ES. (invariant ES \ (\ xrhs. (X, xrhs) \ ES))" + show ?thesis + proof (unfold reduce_def, + rule while_rule [where P = ?Inv and r = "measure card"]) + from inv and contain_x show "?Inv ES" by auto + next + show "wf (measure card)" by simp + next + fix ES + assume inv: "?Inv ES" and crd: "card ES \ 1" + show "(iter X ES, ES) \ measure card" + proof - + from inv obtain xrhs where x_in: "(X, xrhs) \ ES" by auto + from inv have "invariant ES" by simp + from iteration_step [OF this x_in crd] + show ?thesis by auto + qed + next + fix ES + assume inv: "?Inv ES" and crd: "card ES \ 1" + thus "?Inv (iter X ES)" + proof - + from inv obtain xrhs where x_in: "(X, xrhs) \ ES" by auto + from inv have "invariant ES" by simp + from iteration_step [OF this x_in crd] + show ?thesis by auto + qed + next + fix ES + assume "?Inv ES" and "\ card ES \ 1" + thus "\xrhs'. ES = {(X, xrhs')} \ invariant ES" + apply (auto, rule_tac x = xrhs in exI) + by (auto simp: invariant_def dest!:card_Suc_Diff1 simp:card_eq_0_iff) + qed qed - + lemma last_cl_exists_rexp: - assumes ES_single: "ES = {(X, xrhs)}" - and invariant_ES: "invariant ES" + assumes Inv_ES: "invariant {(X, xrhs)}" shows "\ (r::rexp). L r = X" (is "\ r. ?P r") proof- def A \ "arden_op X xrhs" @@ -1088,7 +1133,7 @@ proof(rule rexp_of_lam_eq_lam_set) show "finite A" unfolding A_def - using invariant_ES ES_single + using Inv_ES by (rule_tac arden_op_keeps_finite) (auto simp add: invariant_def finite_rhs_def) qed @@ -1096,7 +1141,7 @@ proof- have "{Lam r | r. Lam r \ A} = A" proof- - have "classes_of A = {}" using invariant_ES ES_single + have "classes_of A = {}" using Inv_ES unfolding A_def by (simp add:arden_op_removes_cl self_contained_def invariant_def lefts_of_def) @@ -1109,38 +1154,37 @@ also have "\ = X" unfolding A_def proof(rule arden_op_keeps_eq [THEN sym]) - show "X = L xrhs" using invariant_ES ES_single - by (auto simp only:invariant_def valid_eqns_def) + show "X = L xrhs" using Inv_ES + by (auto simp only: invariant_def valid_eqns_def) next - from invariant_ES ES_single show "[] \ L (\{r. Trn X r \ xrhs})" - by(simp add:invariant_def ardenable_def rexp_of_empty finite_rhs_def) + from Inv_ES show "[] \ L (\{r. Trn X r \ xrhs})" + by(simp add: invariant_def ardenable_def rexp_of_empty finite_rhs_def) next - from invariant_ES ES_single show "finite xrhs" - by (simp add:invariant_def finite_rhs_def) + from Inv_ES show "finite xrhs" + by (simp add: invariant_def finite_rhs_def) qed finally show ?thesis by simp qed thus ?thesis by auto qed - + lemma every_eqcl_has_reg: assumes finite_CS: "finite (UNIV // (\Lang))" and X_in_CS: "X \ (UNIV // (\Lang))" shows "\ (reg::rexp). L reg = X" (is "\ r. ?E r") proof - - from X_in_CS have "\ xrhs. (X, xrhs) \ (eqs (UNIV // (\Lang)))" + let ?ES = " eqs (UNIV // \Lang)" + from X_in_CS + obtain xrhs where "(X, xrhs) \ ?ES" by (auto simp:eqs_def init_rhs_def) - then obtain ES xrhs where invariant_ES: "invariant ES" - and X_in_ES: "(X, xrhs) \ ES" - and card_ES: "card ES = 1" - using finite_CS X_in_CS init_ES_satisfy_invariant iteration_conc - by blast - hence ES_single_equa: "ES = {(X, xrhs)}" - by (auto simp:invariant_def dest!:card_Suc_Diff1 simp:card_eq_0_iff) - thus ?thesis using invariant_ES - by (rule last_cl_exists_rexp) + from reduce_x [OF init_ES_satisfy_invariant [OF finite_CS] this] + have "\xrhs'. reduce X ?ES = {(X, xrhs')} \ invariant (reduce X ?ES)" . + then obtain xrhs' where "invariant {(X, xrhs')}" by auto + from last_cl_exists_rexp [OF this] + show ?thesis . qed + theorem hard_direction: assumes finite_CS: "finite (UNIV // \A)" shows "\r::rexp. A = L r"