diff -r 09e6f3719cbc -r 5d724fe0e096 Derivatives.thy --- a/Derivatives.thy Fri Aug 19 20:39:07 2011 +0000 +++ b/Derivatives.thy Mon Aug 22 12:49:27 2011 +0000 @@ -1,67 +1,81 @@ theory Derivatives -imports Myhill_2 +imports Regular_Exp begin -section {* Left-Quotients and Derivatives *} - -subsection {* Left-Quotients *} +section {* Leftquotients, Derivatives and Partial Derivatives *} -definition - Delta :: "'a lang \ 'a lang" -where - "Delta A = (if [] \ A then {[]} else {})" +text{* This theory is based on work by Brozowski \cite{Brzozowski64} and Antimirov \cite{Antimirov95}. *} + +subsection {* Left-Quotients of languages *} -definition - Der :: "'a \ 'a lang \ 'a lang" -where - "Der c A \ {s'. [c] @ s' \ A}" +definition Deriv :: "'a \ 'a lang \ 'a lang" +where "Deriv x A = { xs. x#xs \ A }" -definition - Ders :: "'a list \ 'a lang \ 'a lang" -where - "Ders s A \ {s'. s @ s' \ A}" +definition Derivs :: "'a list \ 'a lang \ 'a lang" +where "Derivs xs A = { ys. xs @ ys \ A }" abbreviation - "Derss s A \ \ (Ders s) ` A" + Derivss :: "'a list \ 'a lang set \ 'a lang" +where + "Derivss s As \ \ (Derivs s) ` As" + + +lemma Deriv_empty[simp]: "Deriv a {} = {}" + and Deriv_epsilon[simp]: "Deriv a {[]} = {}" + and Deriv_char[simp]: "Deriv a {[b]} = (if a = b then {[]} else {})" + and Deriv_union[simp]: "Deriv a (A \ B) = Deriv a A \ Deriv a B" +by (auto simp: Deriv_def) -lemma Der_simps [simp]: - shows "Der c {} = {}" - and "Der c {[]} = {}" - and "Der c {[d]} = (if c = d then {[]} else {})" - and "Der c (A \ B) = Der c A \ Der c B" -unfolding Der_def by auto +lemma Deriv_conc_subset: +"Deriv a A @@ B \ Deriv a (A @@ B)" (is "?L \ ?R") +proof + fix w assume "w \ ?L" + then obtain u v where "w = u @ v" "a # u \ A" "v \ B" + by (auto simp: Deriv_def) + then have "a # w \ A @@ B" + by (auto intro: concI[of "a # u", simplified]) + thus "w \ ?R" by (auto simp: Deriv_def) +qed lemma Der_conc [simp]: - shows "Der c (A \ B) = (Der c A) \ B \ (Delta A \ Der c B)" -unfolding Der_def Delta_def conc_def + shows "Deriv c (A @@ B) = (Deriv c A) @@ B \ (if [] \ A then Deriv c B else {})" +unfolding Deriv_def conc_def by (auto simp add: Cons_eq_append_conv) -lemma Der_star [simp]: - shows "Der c (A\) = (Der c A) \ A\" +lemma Deriv_star [simp]: + shows "Deriv c (star A) = (Deriv c A) @@ star A" proof - - have incl: "Delta A \ Der c (A\) \ (Der c A) \ A\" - unfolding Der_def Delta_def conc_def - apply(auto) + have incl: "[] \ A \ Deriv c (star A) \ (Deriv c A) @@ star A" + unfolding Deriv_def conc_def + apply(auto simp add: Cons_eq_append_conv) apply(drule star_decom) apply(auto simp add: Cons_eq_append_conv) done - - have "Der c (A\) = Der c (A \ A\ \ {[]})" + + have "Deriv c (star A) = Deriv c (A @@ star A \ {[]})" by (simp only: star_unfold_left[symmetric]) - also have "... = Der c (A \ A\)" - by (simp only: Der_simps) (simp) - also have "... = (Der c A) \ A\ \ (Delta A \ Der c (A\))" + also have "... = Deriv c (A @@ star A)" + by (simp only: Deriv_union) (simp) + also have "... = (Deriv c A) @@ (star A) \ (if [] \ A then Deriv c (star A) else {})" by simp - also have "... = (Der c A) \ A\" + also have "... = (Deriv c A) @@ star A" using incl by auto - finally show "Der c (A\) = (Der c A) \ A\" . + finally show "Deriv c (star A) = (Deriv c A) @@ star A" . qed -lemma Ders_simps [simp]: - shows "Ders [] A = A" - and "Ders (c # s) A = Ders s (Der c A)" - and "Ders (s1 @ s2) A = Ders s2 (Ders s1 A)" -unfolding Ders_def Der_def by auto +lemma Derivs_simps [simp]: + shows "Derivs [] A = A" + and "Derivs (c # s) A = Derivs s (Deriv c A)" + and "Derivs (s1 @ s2) A = Derivs s2 (Derivs s1 A)" +unfolding Derivs_def Deriv_def by auto + +(* +lemma Deriv_insert_eps[simp]: +"Deriv a (insert [] A) = Deriv a A" +by (auto simp: Deriv_def) +*) + + subsection {* Brozowsky's derivatives of regular expressions *} @@ -76,247 +90,254 @@ | "nullable (Star r) = True" fun - der :: "'a \ 'a rexp \ 'a rexp" + deriv :: "'a \ 'a rexp \ 'a rexp" where - "der c (Zero) = Zero" -| "der c (One) = Zero" -| "der c (Atom c') = (if c = c' then One else Zero)" -| "der c (Plus r1 r2) = Plus (der c r1) (der c r2)" -| "der c (Times r1 r2) = - (if nullable r1 then Plus (Times (der c r1) r2) (der c r2) else Times (der c r1) r2)" -| "der c (Star r) = Times (der c r) (Star r)" + "deriv c (Zero) = Zero" +| "deriv c (One) = Zero" +| "deriv c (Atom c') = (if c = c' then One else Zero)" +| "deriv c (Plus r1 r2) = Plus (deriv c r1) (deriv c r2)" +| "deriv c (Times r1 r2) = + (if nullable r1 then Plus (Times (deriv c r1) r2) (deriv c r2) else Times (deriv c r1) r2)" +| "deriv c (Star r) = Times (deriv c r) (Star r)" fun - ders :: "'a list \ 'a rexp \ 'a rexp" + derivs :: "'a list \ 'a rexp \ 'a rexp" where - "ders [] r = r" -| "ders (c # s) r = ders s (der c r)" + "derivs [] r = r" +| "derivs (c # s) r = derivs s (deriv c r)" -lemma Delta_nullable: - shows "Delta (lang r) = (if nullable r then {[]} else {})" -unfolding Delta_def +lemma nullable_iff: + shows "nullable r \ [] \ lang r" by (induct r) (auto simp add: conc_def split: if_splits) -lemma Der_der: - shows "Der c (lang r) = lang (der c r)" -by (induct r) (simp_all add: Delta_nullable) +lemma Deriv_deriv: + shows "Deriv c (lang r) = lang (deriv c r)" +by (induct r) (simp_all add: nullable_iff) -lemma Ders_ders: - shows "Ders s (lang r) = lang (ders s r)" -by (induct s arbitrary: r) (simp_all add: Der_der) +lemma Derivs_derivs: + shows "Derivs s (lang r) = lang (derivs s r)" +by (induct s arbitrary: r) (simp_all add: Deriv_deriv) -subsection {* Antimirov's Partial Derivatives *} +subsection {* Antimirov's partial derivivatives *} abbreviation "Timess rs r \ {Times r' r | r'. r' \ rs}" fun - pder :: "'a \ 'a rexp \ ('a rexp) set" + pderiv :: "'a \ 'a rexp \ 'a rexp set" where - "pder c Zero = {}" -| "pder c One = {}" -| "pder c (Atom c') = (if c = c' then {One} else {})" -| "pder c (Plus r1 r2) = (pder c r1) \ (pder c r2)" -| "pder c (Times r1 r2) = - (if nullable r1 then Timess (pder c r1) r2 \ pder c r2 else Timess (pder c r1) r2)" -| "pder c (Star r) = Timess (pder c r) (Star r)" - -abbreviation - "pder_set c rs \ \ pder c ` rs" + "pderiv c Zero = {}" +| "pderiv c One = {}" +| "pderiv c (Atom c') = (if c = c' then {One} else {})" +| "pderiv c (Plus r1 r2) = (pderiv c r1) \ (pderiv c r2)" +| "pderiv c (Times r1 r2) = + (if nullable r1 then Timess (pderiv c r1) r2 \ pderiv c r2 else Timess (pderiv c r1) r2)" +| "pderiv c (Star r) = Timess (pderiv c r) (Star r)" fun - pders :: "'a list \ 'a rexp \ ('a rexp) set" + pderivs :: "'a list \ 'a rexp \ ('a rexp) set" where - "pders [] r = {r}" -| "pders (c # s) r = \ (pders s) ` (pder c r)" + "pderivs [] r = {r}" +| "pderivs (c # s) r = \ (pderivs s) ` (pderiv c r)" abbreviation - "pderss s A \ \ (pders s) ` A" + pderiv_set :: "'a \ 'a rexp set \ 'a rexp set" +where + "pderiv_set c rs \ \ pderiv c ` rs" -lemma pders_append: - "pders (s1 @ s2) r = \ (pders s2) ` (pders s1 r)" +abbreviation + pderivs_set :: "'a list \ 'a rexp set \ 'a rexp set" +where + "pderivs_set s rs \ \ (pderivs s) ` rs" + +lemma pderivs_append: + "pderivs (s1 @ s2) r = \ (pderivs s2) ` (pderivs s1 r)" by (induct s1 arbitrary: r) (simp_all) -lemma pders_snoc: - shows "pders (s @ [c]) r = pder_set c (pders s r)" -by (simp add: pders_append) +lemma pderivs_snoc: + shows "pderivs (s @ [c]) r = pderiv_set c (pderivs s r)" +by (simp add: pderivs_append) -lemma pders_simps [simp]: - shows "pders s Zero = (if s= [] then {Zero} else {})" - and "pders s One = (if s = [] then {One} else {})" - and "pders s (Plus r1 r2) = (if s = [] then {Plus r1 r2} else (pders s r1) \ (pders s r2))" +lemma pderivs_simps [simp]: + shows "pderivs s Zero = (if s = [] then {Zero} else {})" + and "pderivs s One = (if s = [] then {One} else {})" + and "pderivs s (Plus r1 r2) = (if s = [] then {Plus r1 r2} else (pderivs s r1) \ (pderivs s r2))" by (induct s) (simp_all) -lemma pders_Atom [intro]: - shows "pders s (Atom c) \ {Atom c, One}" +lemma pderivs_Atom: + shows "pderivs s (Atom c) \ {Atom c, One}" by (induct s) (simp_all) -subsection {* Relating left-quotients and partial derivatives *} +subsection {* Relating left-quotients and partial derivivatives *} -lemma Der_pder: - shows "Der c (lang r) = \ lang ` (pder c r)" -by (induct r) (auto simp add: Delta_nullable conc_UNION_distrib) +lemma Deriv_pderiv: + shows "Deriv c (lang r) = \ lang ` (pderiv c r)" +by (induct r) (auto simp add: nullable_iff conc_UNION_distrib) -lemma Ders_pders: - shows "Ders s (lang r) = \ lang ` (pders s r)" +lemma Derivs_pderivs: + shows "Derivs s (lang r) = \ lang ` (pderivs s r)" proof (induct s arbitrary: r) case (Cons c s) - have ih: "\r. Ders s (lang r) = \ lang ` (pders s r)" by fact - have "Ders (c # s) (lang r) = Ders s (Der c (lang r))" by simp - also have "\ = Ders s (\ lang ` (pder c r))" by (simp add: Der_pder) - also have "\ = Derss s (lang ` (pder c r))" - by (auto simp add: Ders_def) - also have "\ = \ lang ` (pderss s (pder c r))" + have ih: "\r. Derivs s (lang r) = \ lang ` (pderivs s r)" by fact + have "Derivs (c # s) (lang r) = Derivs s (Deriv c (lang r))" by simp + also have "\ = Derivs s (\ lang ` (pderiv c r))" by (simp add: Deriv_pderiv) + also have "\ = Derivss s (lang ` (pderiv c r))" + by (auto simp add: Derivs_def) + also have "\ = \ lang ` (pderivs_set s (pderiv c r))" using ih by auto - also have "\ = \ lang ` (pders (c # s) r)" by simp - finally show "Ders (c # s) (lang r) = \ lang ` pders (c # s) r" . -qed (simp add: Ders_def) + also have "\ = \ lang ` (pderivs (c # s) r)" by simp + finally show "Derivs (c # s) (lang r) = \ lang ` pderivs (c # s) r" . +qed (simp add: Derivs_def) -subsection {* Relating derivatives and partial derivatives *} +subsection {* Relating derivivatives and partial derivivatives *} -lemma der_pder: - shows "(\ lang ` (pder c r)) = lang (der c r)" -unfolding Der_der[symmetric] Der_pder by simp +lemma deriv_pderiv: + shows "(\ lang ` (pderiv c r)) = lang (deriv c r)" +unfolding Deriv_deriv[symmetric] Deriv_pderiv by simp -lemma ders_pders: - shows "(\ lang ` (pders s r)) = lang (ders s r)" -unfolding Ders_ders[symmetric] Ders_pders by simp +lemma derivs_pderivs: + shows "(\ lang ` (pderivs s r)) = lang (derivs s r)" +unfolding Derivs_derivs[symmetric] Derivs_pderivs by simp -subsection {* There are only finitely many partial derivatives for a language *} +subsection {* Finiteness property of partial derivivatives *} definition - "pders_lang A r \ \x \ A. pders x r" - -lemma pders_lang_subsetI [intro]: - assumes "\s. s \ A \ pders s r \ C" - shows "pders_lang A r \ C" -using assms unfolding pders_lang_def by (rule UN_least) + pderivs_lang :: "'a lang \ 'a rexp \ 'a rexp set" +where + "pderivs_lang A r \ \x \ A. pderivs x r" -lemma pders_lang_union: - shows "pders_lang (A \ B) r = (pders_lang A r \ pders_lang B r)" -by (simp add: pders_lang_def) +lemma pderivs_lang_subsetI: + assumes "\s. s \ A \ pderivs s r \ C" + shows "pderivs_lang A r \ C" +using assms unfolding pderivs_lang_def by (rule UN_least) -lemma pders_lang_subset: - shows "A \ B \ pders_lang A r \ pders_lang B r" -by (auto simp add: pders_lang_def) +lemma pderivs_lang_union: + shows "pderivs_lang (A \ B) r = (pderivs_lang A r \ pderivs_lang B r)" +by (simp add: pderivs_lang_def) + +lemma pderivs_lang_subset: + shows "A \ B \ pderivs_lang A r \ pderivs_lang B r" +by (auto simp add: pderivs_lang_def) definition "UNIV1 \ UNIV - {[]}" -lemma pders_lang_Zero [simp]: - shows "pders_lang UNIV1 Zero = {}" -unfolding UNIV1_def pders_lang_def by auto +lemma pderivs_lang_Zero [simp]: + shows "pderivs_lang UNIV1 Zero = {}" +unfolding UNIV1_def pderivs_lang_def by auto -lemma pders_lang_One [simp]: - shows "pders_lang UNIV1 One = {}" -unfolding UNIV1_def pders_lang_def by (auto split: if_splits) +lemma pderivs_lang_One [simp]: + shows "pderivs_lang UNIV1 One = {}" +unfolding UNIV1_def pderivs_lang_def by (auto split: if_splits) -lemma pders_lang_Atom [simp]: - shows "pders_lang UNIV1 (Atom c) = {One}" -unfolding UNIV1_def pders_lang_def +lemma pderivs_lang_Atom [simp]: + shows "pderivs_lang UNIV1 (Atom c) = {One}" +unfolding UNIV1_def pderivs_lang_def apply(auto) apply(frule rev_subsetD) -apply(rule pders_Atom) +apply(rule pderivs_Atom) apply(simp) apply(case_tac xa) apply(auto split: if_splits) done -lemma pders_lang_Plus [simp]: - shows "pders_lang UNIV1 (Plus r1 r2) = pders_lang UNIV1 r1 \ pders_lang UNIV1 r2" -unfolding UNIV1_def pders_lang_def by auto +lemma pderivs_lang_Plus [simp]: + shows "pderivs_lang UNIV1 (Plus r1 r2) = pderivs_lang UNIV1 r1 \ pderivs_lang UNIV1 r2" +unfolding UNIV1_def pderivs_lang_def by auto text {* Non-empty suffixes of a string (needed for teh cases of @{const Times} and @{const Star} *} definition - "Suf s \ {v. v \ [] \ (\u. u @ v = s)}" + "PSuf s \ {v. v \ [] \ (\u. u @ v = s)}" -lemma Suf_snoc: - shows "Suf (s @ [c]) = (Suf s) \ {[c]} \ {[c]}" -unfolding Suf_def conc_def +lemma PSuf_snoc: + shows "PSuf (s @ [c]) = (PSuf s) @@ {[c]} \ {[c]}" +unfolding PSuf_def conc_def by (auto simp add: append_eq_append_conv2 append_eq_Cons_conv) -lemma Suf_Union: - shows "(\v \ Suf s \ {[c]}. f v) = (\v \ Suf s. f (v @ [c]))" +lemma PSuf_Union: + shows "(\v \ PSuf s @@ {[c]}. f v) = (\v \ PSuf s. f (v @ [c]))" by (auto simp add: conc_def) -lemma pders_lang_snoc: - shows "pders_lang (Suf s \ {[c]}) r = (pder_set c (pders_lang (Suf s) r))" -unfolding pders_lang_def -by (simp add: Suf_Union pders_snoc) +lemma pderivs_lang_snoc: + shows "pderivs_lang (PSuf s @@ {[c]}) r = (pderiv_set c (pderivs_lang (PSuf s) r))" +unfolding pderivs_lang_def +by (simp add: PSuf_Union pderivs_snoc) -lemma pders_Times: - shows "pders s (Times r1 r2) \ Timess (pders s r1) r2 \ (pders_lang (Suf s) r2)" +lemma pderivs_Times: + shows "pderivs s (Times r1 r2) \ Timess (pderivs s r1) r2 \ (pderivs_lang (PSuf s) r2)" proof (induct s rule: rev_induct) case (snoc c s) - have ih: "pders s (Times r1 r2) \ Timess (pders s r1) r2 \ (pders_lang (Suf s) r2)" + have ih: "pderivs s (Times r1 r2) \ Timess (pderivs s r1) r2 \ (pderivs_lang (PSuf s) r2)" by fact - have "pders (s @ [c]) (Times r1 r2) = pder_set c (pders s (Times r1 r2))" - by (simp add: pders_snoc) - also have "\ \ pder_set c (Timess (pders s r1) r2 \ (pders_lang (Suf s) r2))" + have "pderivs (s @ [c]) (Times r1 r2) = pderiv_set c (pderivs s (Times r1 r2))" + by (simp add: pderivs_snoc) + also have "\ \ pderiv_set c (Timess (pderivs s r1) r2 \ (pderivs_lang (PSuf s) r2))" using ih by (auto) (blast) - also have "\ = pder_set c (Timess (pders s r1) r2) \ pder_set c (pders_lang (Suf s) r2)" + also have "\ = pderiv_set c (Timess (pderivs s r1) r2) \ pderiv_set c (pderivs_lang (PSuf s) r2)" by (simp) - also have "\ = pder_set c (Timess (pders s r1) r2) \ pders_lang (Suf s \ {[c]}) r2" - by (simp add: pders_lang_snoc) - also have "\ \ pder_set c (Timess (pders s r1) r2) \ pder c r2 \ pders_lang (Suf s \ {[c]}) r2" + also have "\ = pderiv_set c (Timess (pderivs s r1) r2) \ pderivs_lang (PSuf s @@ {[c]}) r2" + by (simp add: pderivs_lang_snoc) + also + have "\ \ pderiv_set c (Timess (pderivs s r1) r2) \ pderiv c r2 \ pderivs_lang (PSuf s @@ {[c]}) r2" by auto - also have "\ \ Timess (pder_set c (pders s r1)) r2 \ pder c r2 \ pders_lang (Suf s \ {[c]}) r2" + also + have "\ \ Timess (pderiv_set c (pderivs s r1)) r2 \ pderiv c r2 \ pderivs_lang (PSuf s @@ {[c]}) r2" by (auto simp add: if_splits) (blast) - also have "\ = Timess (pders (s @ [c]) r1) r2 \ pder c r2 \ pders_lang (Suf s \ {[c]}) r2" - by (simp add: pders_snoc) - also have "\ = Timess (pders (s @ [c]) r1) r2 \ pders_lang (Suf (s @ [c])) r2" - unfolding pders_lang_def by (auto simp add: Suf_snoc) + also have "\ = Timess (pderivs (s @ [c]) r1) r2 \ pderiv c r2 \ pderivs_lang (PSuf s @@ {[c]}) r2" + by (simp add: pderivs_snoc) + also have "\ \ Timess (pderivs (s @ [c]) r1) r2 \ pderivs_lang (PSuf (s @ [c])) r2" + unfolding pderivs_lang_def by (auto simp add: PSuf_snoc) finally show ?case . qed (simp) -lemma pders_lang_Times_aux1: +lemma pderivs_lang_Times_aux1: assumes a: "s \ UNIV1" - shows "pders_lang (Suf s) r \ pders_lang UNIV1 r" -using a unfolding UNIV1_def Suf_def pders_lang_def by auto + shows "pderivs_lang (PSuf s) r \ pderivs_lang UNIV1 r" +using a unfolding UNIV1_def PSuf_def pderivs_lang_def by auto -lemma pders_lang_Times_aux2: +lemma pderivs_lang_Times_aux2: assumes a: "s \ UNIV1" - shows "Timess (pders s r1) r2 \ Timess (pders_lang UNIV1 r1) r2" -using a unfolding pders_lang_def by auto + shows "Timess (pderivs s r1) r2 \ Timess (pderivs_lang UNIV1 r1) r2" +using a unfolding pderivs_lang_def by auto -lemma pders_lang_Times [intro]: - shows "pders_lang UNIV1 (Times r1 r2) \ Timess (pders_lang UNIV1 r1) r2 \ pders_lang UNIV1 r2" -apply(rule pders_lang_subsetI) +lemma pderivs_lang_Times: + shows "pderivs_lang UNIV1 (Times r1 r2) \ Timess (pderivs_lang UNIV1 r1) r2 \ pderivs_lang UNIV1 r2" +apply(rule pderivs_lang_subsetI) apply(rule subset_trans) -apply(rule pders_Times) -using pders_lang_Times_aux1 pders_lang_Times_aux2 +apply(rule pderivs_Times) +using pderivs_lang_Times_aux1 pderivs_lang_Times_aux2 apply(blast) done -lemma pders_Star: +lemma pderivs_Star: assumes a: "s \ []" - shows "pders s (Star r) \ Timess (pders_lang (Suf s) r) (Star r)" + shows "pderivs s (Star r) \ Timess (pderivs_lang (PSuf s) r) (Star r)" using a proof (induct s rule: rev_induct) case (snoc c s) - have ih: "s \ [] \ pders s (Star r) \ Timess (pders_lang (Suf s) r) (Star r)" by fact + have ih: "s \ [] \ pderivs s (Star r) \ Timess (pderivs_lang (PSuf s) r) (Star r)" by fact { assume asm: "s \ []" - have "pders (s @ [c]) (Star r) = pder_set c (pders s (Star r))" by (simp add: pders_snoc) - also have "\ \ pder_set c (Timess (pders_lang (Suf s) r) (Star r))" + have "pderivs (s @ [c]) (Star r) = pderiv_set c (pderivs s (Star r))" by (simp add: pderivs_snoc) + also have "\ \ pderiv_set c (Timess (pderivs_lang (PSuf s) r) (Star r))" using ih[OF asm] by (auto) (blast) - also have "\ \ Timess (pder_set c (pders_lang (Suf s) r)) (Star r) \ pder c (Star r)" + also have "\ \ Timess (pderiv_set c (pderivs_lang (PSuf s) r)) (Star r) \ pderiv c (Star r)" by (auto split: if_splits) (blast)+ - also have "\ \ Timess (pders_lang (Suf (s @ [c])) r) (Star r) \ (Timess (pder c r) (Star r))" - by (simp only: Suf_snoc pders_lang_snoc pders_lang_union) - (auto simp add: pders_lang_def) - also have "\ = Timess (pders_lang (Suf (s @ [c])) r) (Star r)" - by (auto simp add: Suf_snoc Suf_Union pders_snoc pders_lang_def) + also have "\ \ Timess (pderivs_lang (PSuf (s @ [c])) r) (Star r) \ (Timess (pderiv c r) (Star r))" + by (simp only: PSuf_snoc pderivs_lang_snoc pderivs_lang_union) + (auto simp add: pderivs_lang_def) + also have "\ = Timess (pderivs_lang (PSuf (s @ [c])) r) (Star r)" + by (auto simp add: PSuf_snoc PSuf_Union pderivs_snoc pderivs_lang_def) finally have ?case . } moreover { assume asm: "s = []" then have ?case - apply (auto simp add: pders_lang_def pders_snoc Suf_def) + apply (auto simp add: pderivs_lang_def pderivs_snoc PSuf_def) apply(rule_tac x = "[c]" in exI) apply(auto) done @@ -324,14 +345,14 @@ ultimately show ?case by blast qed (simp) -lemma pders_lang_Star [intro]: - shows "pders_lang UNIV1 (Star r) \ Timess (pders_lang UNIV1 r) (Star r)" -apply(rule pders_lang_subsetI) +lemma pderivs_lang_Star: + shows "pderivs_lang UNIV1 (Star r) \ Timess (pderivs_lang UNIV1 r) (Star r)" +apply(rule pderivs_lang_subsetI) apply(rule subset_trans) -apply(rule pders_Star) +apply(rule pderivs_Star) apply(simp add: UNIV1_def) -apply(simp add: UNIV1_def Suf_def) -apply(auto simp add: pders_lang_def) +apply(simp add: UNIV1_def PSuf_def) +apply(auto simp add: pderivs_lang_def) done lemma finite_Timess [simp]: @@ -339,72 +360,27 @@ shows "finite (Timess A r)" using a by auto -lemma finite_pders_lang_UNIV1: - shows "finite (pders_lang UNIV1 r)" +lemma finite_pderivs_lang_UNIV1: + shows "finite (pderivs_lang UNIV1 r)" apply(induct r) apply(simp_all add: - finite_subset[OF pders_lang_Times] - finite_subset[OF pders_lang_Star]) + finite_subset[OF pderivs_lang_Times] + finite_subset[OF pderivs_lang_Star]) done -lemma pders_lang_UNIV: - shows "pders_lang UNIV r = pders [] r \ pders_lang UNIV1 r" -unfolding UNIV1_def pders_lang_def +lemma pderivs_lang_UNIV: + shows "pderivs_lang UNIV r = pderivs [] r \ pderivs_lang UNIV1 r" +unfolding UNIV1_def pderivs_lang_def by blast -lemma finite_pders_lang_UNIV: - shows "finite (pders_lang UNIV r)" -unfolding pders_lang_UNIV -by (simp add: finite_pders_lang_UNIV1) - -lemma finite_pders_lang: - shows "finite (pders_lang A r)" -apply(rule rev_finite_subset[OF finite_pders_lang_UNIV]) -apply(rule pders_lang_subset) -apply(simp) -done - -text {* Relating the Myhill-Nerode relation with left-quotients. *} - -lemma MN_Rel_Ders: - shows "x \A y \ Ders x A = Ders y A" -unfolding Ders_def str_eq_def -by auto - -subsection {* - The second direction of the Myhill-Nerode theorem using - partial derivatives. -*} +lemma finite_pderivs_lang_UNIV: + shows "finite (pderivs_lang UNIV r)" +unfolding pderivs_lang_UNIV +by (simp add: finite_pderivs_lang_UNIV1) -lemma Myhill_Nerode3: - fixes r::"'a rexp" - shows "finite (UNIV // \(lang r))" -proof - - have "finite (UNIV // =(\x. pders x r)=)" - proof - - have "range (\x. pders x r) \ Pow (pders_lang UNIV r)" - unfolding pders_lang_def by auto - moreover - have "finite (Pow (pders_lang UNIV r))" by (simp add: finite_pders_lang) - ultimately - have "finite (range (\x. pders x r))" - by (simp add: finite_subset) - then show "finite (UNIV // =(\x. pders x r)=)" - by (rule finite_eq_tag_rel) - qed - moreover - have "=(\x. pders x r)= \ \(lang r)" - unfolding tag_eq_def - by (auto simp add: MN_Rel_Ders Ders_pders) - moreover - have "equiv UNIV =(\x. pders x r)=" - and "equiv UNIV (\(lang r))" - unfolding equiv_def refl_on_def sym_def trans_def - unfolding tag_eq_def str_eq_def - by auto - ultimately show "finite (UNIV // \(lang r))" - by (rule refined_partition_finite) -qed +lemma finite_pderivs_lang: + shows "finite (pderivs_lang A r)" +by (metis finite_pderivs_lang_UNIV pderivs_lang_subset rev_finite_subset subset_UNIV) end \ No newline at end of file