diff -r 07a269d9642b -r 9f46a9571e37 Derivatives.thy --- a/Derivatives.thy Wed Aug 03 17:08:31 2011 +0000 +++ b/Derivatives.thy Fri Aug 05 05:34:11 2011 +0000 @@ -21,35 +21,15 @@ where "Ders s A \ {s'. s @ s' \ A}" -definition - Ders_set :: "'a lang \ 'a lang \ 'a lang" -where - "Ders_set A B \ {s' | s s'. s @ s' \ B \ s \ A}" - -lemma Ders_set_Ders: - shows "Ders_set A B = (\s \ A. Ders s B)" -unfolding Ders_set_def Ders_def -by auto - -lemma Der_zero [simp]: - shows "Der c {} = {}" -unfolding Der_def -by auto +abbreviation + "Derss s A \ \ (Ders s) ` A" -lemma Der_one [simp]: - shows "Der c {[]} = {}" -unfolding Der_def -by auto - -lemma Der_atom [simp]: - shows "Der c {[d]} = (if c = d then {[]} else {})" -unfolding Der_def -by auto - -lemma Der_union [simp]: - shows "Der c (A \ B) = Der c A \ Der c B" -unfolding Der_def -by auto +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 Der_conc [simp]: shows "Der c (A \ B) = (Der c A) \ B \ (Delta A \ Der c B)" @@ -60,7 +40,7 @@ shows "Der c (A\) = (Der c A) \ A\" proof - have incl: "Delta A \ Der c (A\) \ (Der c A) \ A\" - unfolding Der_def Delta_def + unfolding Der_def Delta_def conc_def apply(auto) apply(drule star_decom) apply(auto simp add: Cons_eq_append_conv) @@ -69,7 +49,7 @@ have "Der c (A\) = Der c (A \ A\ \ {[]})" by (simp only: star_unfold_left[symmetric]) also have "... = Der c (A \ A\)" - by (simp only: Der_union Der_one) (simp) + by (simp only: Der_simps) (simp) also have "... = (Der c A) \ A\ \ (Delta A \ Der c (A\))" by simp also have "... = (Der c A) \ A\" @@ -77,19 +57,12 @@ finally show "Der c (A\) = (Der c A) \ A\" . qed -lemma Ders_nil [simp]: +lemma Ders_simps [simp]: shows "Ders [] A = A" -unfolding Ders_def by simp - -lemma Ders_cons [simp]: - shows "Ders (c # s) A = Ders s (Der c 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 Ders_append [simp]: - shows "Ders (s1 @ s2) A = Ders s2 (Ders s1 A)" -unfolding Ders_def by simp - - subsection {* Brozowsky's derivatives of regular expressions *} fun @@ -137,7 +110,7 @@ subsection {* Antimirov's Partial Derivatives *} abbreviation - "Times_set rs r \ {Times r' r | r'. r' \ rs}" + "Timess rs r \ {Times r' r | r'. r' \ rs}" fun pder :: "'a \ 'a rexp \ ('a rexp) set" @@ -147,11 +120,11 @@ | "pder c (Atom c') = (if c = c' then {One} else {Zero})" | "pder c (Plus r1 r2) = (pder c r1) \ (pder c r2)" | "pder c (Times r1 r2) = - (if nullable r1 then Times_set (pder c r1) r2 \ pder c r2 else Times_set (pder c r1) r2)" -| "pder c (Star r) = Times_set (pder c r) (Star r)" + (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 \ \r \ rs. pder c r" + "pder_set c rs \ \ pder c ` rs" fun pders :: "'a list \ 'a rexp \ ('a rexp) set" @@ -160,7 +133,7 @@ | "pders (c # s) r = \ (pders s) ` (pder c r)" abbreviation - "pders_set A r \ \s \ A. pders s r" + "pderss s A \ \ (pders s) ` A" lemma pders_append: "pders (s1 @ s2) r = \ (pders s2) ` (pders s1 r)" @@ -170,85 +143,113 @@ shows "pders (s @ [c]) r = pder_set c (pders s r)" by (simp add: pders_append) -lemma pders_set_lang: - shows "(\ (lang ` pder_set c rs)) = (\r \ rs. (\lang ` (pder c r)))" -unfolding image_def -by auto - -lemma pders_Zero [simp]: +lemma pders_simps [simp]: shows "pders s Zero = {Zero}" -by (induct s) (simp_all) - -lemma pders_One [simp]: - shows "pders s One = (if s = [] then {One} else {Zero})" + and "pders s One = (if s = [] then {One} else {Zero})" + and "pders s (Atom c) = (if s = [] then {Atom c} else (if s = [c] then {One} else {Zero}))" + and "pders s (Plus r1 r2) = (if s = [] then {Plus r1 r2} else (pders s r1) \ (pders s r2))" by (induct s) (auto) -lemma pders_Atom [simp]: - shows "pders s (Atom c) = (if s = [] then {Atom c} else (if s = [c] then {One} else {Zero}))" -by (induct s) (auto) +subsection {* Relating left-quotients and partial derivatives *} + +lemma Der_pder: + shows "Der c (lang r) = \ lang ` (pder c r)" +by (induct r) (auto simp add: Delta_nullable conc_UNION_distrib) -lemma pders_Plus [simp]: - shows "pders s (Plus r1 r2) = (if s = [] then {Plus r1 r2} else (pders s r1) \ (pders s r2))" -by (induct s) (auto) +lemma Ders_pders: + shows "Ders s (lang r) = \ lang ` (pders 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))" + 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) + +subsection {* Relating derivatives and partial derivatives *} + +lemma + shows "(\ lang ` (pder c r)) = lang (der c r)" +unfolding Der_der[symmetric] Der_pder by simp + +lemma + shows "(\ lang ` (pders s r)) = lang (ders s r)" +unfolding Ders_ders[symmetric] Ders_pders by simp + + +subsection {* There are only finitely many partial derivatives for a language *} + +abbreviation + "pders_set A r \ \s \ A. pders s r" text {* Non-empty suffixes of a string *} definition "Suf s \ {v. v \ [] \ (\u. u @ v = s)}" -lemma Suf: +lemma Suf_snoc: shows "Suf (s @ [c]) = (Suf s) \ {[c]} \ {[c]}" unfolding Suf_def conc_def by (auto simp add: append_eq_append_conv2 append_eq_Cons_conv) lemma Suf_Union: - shows "(\v \ Suf s \ {[c]}. P v) = (\v \ Suf s. P (v @ [c]))" + shows "(\v \ Suf s \ {[c]}. f v) = (\v \ Suf s. f (v @ [c]))" by (auto simp add: conc_def) +lemma pders_set_snoc: + shows "pders_set (Suf s \ {[c]}) r = (pder_set c (pders_set (Suf s) r))" +by (simp add: Suf_Union pders_snoc) + lemma pders_Times: - shows "pders s (Times r1 r2) \ Times_set (pders s r1) r2 \ (\v \ Suf s. pders v r2)" + shows "pders s (Times r1 r2) \ Timess (pders s r1) r2 \ (pders_set (Suf s) r2)" proof (induct s rule: rev_induct) case (snoc c s) - have ih: "pders s (Times r1 r2) \ Times_set (pders s r1) r2 \ (\v \ Suf s. pders v r2)" + have ih: "pders s (Times r1 r2) \ Timess (pders s r1) r2 \ (pders_set (Suf 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 (Times_set (pders s r1) r2 \ (\v \ Suf s. pders v r2))" + also have "\ \ pder_set c (Timess (pders s r1) r2 \ (pders_set (Suf s) r2))" using ih by (auto) (blast) - also have "\ = pder_set c (Times_set (pders s r1) r2) \ pder_set c (\v \ Suf s. pders v r2)" - by (simp) - also have "\ = pder_set c (Times_set (pders s r1) r2) \ (\v \ Suf s. pder_set c (pders v r2))" + also have "\ = pder_set c (Timess (pders s r1) r2) \ pder_set c (pders_set (Suf s) r2)" by (simp) - also have "\ \ pder_set c (Times_set (pders s r1) r2) \ (pder c r2) \ (\v \ Suf s. pders (v @ [c]) r2)" - by (auto simp add: pders_snoc) - also have "\ \ Times_set (pder_set c (pders s r1)) r2 \ (pder c r2) \ (\v \ Suf s. pders (v @ [c]) r2)" - by (auto simp add: if_splits) (blast) - also have "\ = Times_set (pders (s @ [c]) r1) r2 \ (\v \ Suf (s @ [c]). pders v r2)" - by (auto simp add: pders_snoc Suf Suf_Union) + also have "\ = pder_set c (Timess (pders s r1) r2) \ pders_set (Suf s \ {[c]}) r2" + by (simp add: pders_set_snoc) + also have "\ \ pder_set c (Timess (pders s r1) r2) \ pder c r2 \ pders_set (Suf s \ {[c]}) r2" + by auto + also have "\ \ Timess (pders (s @ [c]) r1) r2 \ pder c r2 \ pders_set (Suf s \ {[c]}) r2" + by (auto simp add: if_splits pders_snoc) (blast) + also have "\ = Timess (pders (s @ [c]) r1) r2 \ pders_set (Suf (s @ [c])) r2" + by (auto simp add: Suf_snoc) finally show ?case . -qed (simp) +qed (simp) + lemma pders_Star: assumes a: "s \ []" - shows "pders s (Star r) \ (\v \ Suf s. Times_set (pders v r) (Star r))" + shows "pders s (Star r) \ (\v \ Suf s. Timess (pders v r) (Star r))" using a proof (induct s rule: rev_induct) case (snoc c s) - have ih: "s \ [] \ pders s (Star r) \ (\v\Suf s. Times_set (pders v r) (Star r))" by fact + have ih: "s \ [] \ pders s (Star r) \ (\v\Suf s. Timess (pders v 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 (\v\Suf s. Times_set (pders v r) (Star r)))" - using ih[OF asm] by blast - also have "\ = (\v\Suf s. pder_set c (Times_set (pders v r) (Star r)))" + also have "\ \ (pder_set c (\v\Suf s. Timess (pders v r) (Star r)))" + using ih[OF asm] by (auto) (blast) + also have "\ = (\v\Suf s. pder_set c (Timess (pders v r) (Star r)))" by simp - also have "\ \ (\v\Suf s. (Times_set (pder_set c (pders v r)) (Star r) \ pder c (Star r)))" + also have "\ \ (\v\Suf s. (Timess (pder_set c (pders v r)) (Star r) \ pder c (Star r)))" by (auto split: if_splits) - also have "\ = (\v\Suf s. (Times_set (pder_set c (pders v r)) (Star r))) \ pder c (Star r)" + also have "\ = (\v\Suf s. (Timess (pder_set c (pders v r)) (Star r))) \ pder c (Star r)" using asm by (auto simp add: Suf_def) - also have "\ = (\v\Suf s. (Times_set (pders (v @ [c]) r) (Star r))) \ (Times_set (pder c r) (Star r))" + also have "\ = (\v\Suf s. (Timess (pders (v @ [c]) r) (Star r))) \ (Timess (pder c r) (Star r))" by (simp add: pders_snoc) - also have "\ = (\v\Suf (s @ [c]). (Times_set (pders v r) (Star r)))" - by (auto simp add: Suf Suf_Union pders_snoc) + also have "\ = (\v\Suf (s @ [c]). (Timess (pders v r) (Star r)))" + by (auto simp add: Suf_snoc Suf_Union pders_snoc) finally have ?case . } moreover @@ -284,7 +285,7 @@ using a unfolding UNIV1_def Suf_def by (auto) lemma pders_set_Times: - shows "pders_set UNIV1 (Times r1 r2) \ Times_set (pders_set UNIV1 r1) r2 \ pders_set UNIV1 r2" + shows "pders_set UNIV1 (Times r1 r2) \ Timess (pders_set UNIV1 r1) r2 \ pders_set UNIV1 r2" unfolding UNIV1_def apply(rule UN_least) apply(rule subset_trans) @@ -298,7 +299,7 @@ done lemma pders_set_Star: - shows "pders_set UNIV1 (Star r) \ Times_set (pders_set UNIV1 r) (Star r)" + shows "pders_set UNIV1 (Star r) \ Timess (pders_set UNIV1 r) (Star r)" unfolding UNIV1_def apply(rule UN_least) apply(rule subset_trans) @@ -308,9 +309,9 @@ apply(auto) done -lemma finite_Times_set: +lemma finite_Timess: assumes a: "finite A" - shows "finite (Times_set A r)" + shows "finite (Timess A r)" using a by (auto) lemma finite_pders_set_UNIV1: @@ -326,11 +327,11 @@ apply(simp) apply(rule finite_subset) apply(rule pders_set_Times) -apply(simp only: finite_Times_set finite_Un) +apply(simp only: finite_Timess finite_Un) apply(simp) apply(rule finite_subset) apply(rule pders_set_Star) -apply(simp only: finite_Times_set) +apply(simp only: finite_Timess) done lemma pders_set_UNIV_UNIV1: @@ -371,48 +372,6 @@ qed -subsection {* Relating left-quotients and partial derivatives *} - -lemma Der_pder: - shows "Der c (lang r) = \ lang ` (pder c r)" -by (induct r) (auto simp add: Delta_nullable conc_UNION_distrib) - -lemma Ders_pders: - shows "Ders s (lang r) = \ lang ` (pders s r)" -proof (induct s rule: rev_induct) - case (snoc c s) - have ih: "Ders s (lang r) = \ lang ` (pders s r)" by fact - have "Ders (s @ [c]) (lang r) = Ders [c] (Ders s (lang r))" - by (simp add: Ders_append) - also have "\ = Der c (\ lang ` (pders s r))" using ih - by (simp) - also have "\ = (\r\pders s r. Der c (lang r))" - unfolding Der_def image_def by auto - also have "\ = (\r\pders s r. (\ lang ` (pder c r)))" - by (simp add: Der_pder) - also have "\ = (\lang ` (pder_set c (pders s r)))" - by (simp add: pders_set_lang) - also have "\ = (\lang ` (pders (s @ [c]) r))" - by (simp add: pders_snoc) - finally show "Ders (s @ [c]) (lang r) = \ lang ` pders (s @ [c]) r" . -qed (simp add: Ders_def) - -lemma Ders_set_pders_set: - shows "Ders_set A (lang r) = (\ lang ` (pders_set A r))" -by (simp add: Ders_set_Ders Ders_pders) - - -subsection {* Relating derivatives and partial derivatives *} - -lemma - shows "(\ lang ` (pder c r)) = lang (der c r)" -unfolding Der_der[symmetric] Der_pder by simp - -lemma - shows "(\ lang ` (pders s r)) = lang (ders s r)" -unfolding Ders_ders[symmetric] Ders_pders by simp - - text {* Relating the Myhill-Nerode relation with left-quotients. *} lemma MN_Rel_Ders: