diff -r b794db0b79db -r b1258b7d2789 More_Regular_Set.thy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/More_Regular_Set.thy Mon Jul 25 13:33:38 2011 +0000 @@ -0,0 +1,170 @@ +(* Author: Christian Urban, Xingyuan Zhang, Chunhan Wu *) +theory More_Regular_Set +imports "Regular_Exp" "Folds" +begin + +text {* Some properties of operator @{text "@@"}. *} + +notation + conc (infixr "\" 100) and + star ("_\" [101] 102) + +lemma conc_add_left: + assumes a: "A = B" + shows "C \ A = C \ B" +using a by simp + +lemma star_cases: + shows "A\ = {[]} \ A \ A\" +proof + { fix x + have "x \ A\ \ x \ {[]} \ A \ A\" + unfolding conc_def + by (induct rule: star_induct) (auto) + } + then show "A\ \ {[]} \ A \ A\" by auto +next + show "{[]} \ A \ A\ \ A\" + unfolding conc_def by auto +qed + +lemma star_decom: + assumes a: "x \ A\" "x \ []" + shows "\a b. x = a @ b \ a \ [] \ a \ A \ b \ A\" +using a +by (induct rule: star_induct) (blast)+ + +lemma seq_pow_comm: + shows "A \ (A ^^ n) = (A ^^ n) \ A" +by (induct n) (simp_all add: conc_assoc[symmetric]) + +lemma seq_star_comm: + shows "A \ A\ = A\ \ A" +unfolding star_def seq_pow_comm conc_UNION_distrib +by simp + + +text {* Two lemmas about the length of strings in @{text "A \ n"} *} + +lemma pow_length: + assumes a: "[] \ A" + and b: "s \ A ^^ Suc n" + shows "n < length s" +using b +proof (induct n arbitrary: s) + case 0 + have "s \ A ^^ Suc 0" by fact + with a have "s \ []" by auto + then show "0 < length s" by auto +next + case (Suc n) + have ih: "\s. s \ A ^^ Suc n \ n < length s" by fact + have "s \ A ^^ Suc (Suc n)" by fact + then obtain s1 s2 where eq: "s = s1 @ s2" and *: "s1 \ A" and **: "s2 \ A ^^ Suc n" + by (auto simp add: conc_def) + from ih ** have "n < length s2" by simp + moreover have "0 < length s1" using * a by auto + ultimately show "Suc n < length s" unfolding eq + by (simp only: length_append) +qed + +lemma seq_pow_length: + assumes a: "[] \ A" + and b: "s \ B \ (A ^^ Suc n)" + shows "n < length s" +proof - + from b obtain s1 s2 where eq: "s = s1 @ s2" and *: "s2 \ A ^^ Suc n" + unfolding Seq_def by auto + from * have " n < length s2" by (rule pow_length[OF a]) + then show "n < length s" using eq by simp +qed + + +section {* A modified version of Arden's lemma *} + +text {* A helper lemma for Arden *} + +lemma arden_helper: + assumes eq: "X = X \ A \ B" + shows "X = X \ (A ^^ Suc n) \ (\m\{0..n}. B \ (A ^^ m))" +proof (induct n) + case 0 + show "X = X \ (A ^^ Suc 0) \ (\(m::nat)\{0..0}. B \ (A ^^ m))" + using eq by simp +next + case (Suc n) + have ih: "X = X \ (A ^^ Suc n) \ (\m\{0..n}. B \ (A ^^ m))" by fact + also have "\ = (X \ A \ B) \ (A ^^ Suc n) \ (\m\{0..n}. B \ (A ^^ m))" using eq by simp + also have "\ = X \ (A ^^ Suc (Suc n)) \ (B \ (A ^^ Suc n)) \ (\m\{0..n}. B \ (A ^^ m))" + by (simp add: conc_Un_distrib conc_assoc) + also have "\ = X \ (A ^^ Suc (Suc n)) \ (\m\{0..Suc n}. B \ (A ^^ m))" + by (auto simp add: le_Suc_eq) + finally show "X = X \ (A ^^ Suc (Suc n)) \ (\m\{0..Suc n}. B \ (A ^^ m))" . +qed + +theorem arden: + assumes nemp: "[] \ A" + shows "X = X \ A \ B \ X = B \ A\" +proof + assume eq: "X = B \ A\" + have "A\ = {[]} \ A\ \ A" + unfolding seq_star_comm[symmetric] + by (rule star_cases) + then have "B \ A\ = B \ ({[]} \ A\ \ A)" + by (rule conc_add_left) + also have "\ = B \ B \ (A\ \ A)" + unfolding conc_Un_distrib by simp + also have "\ = B \ (B \ A\) \ A" + by (simp only: conc_assoc) + finally show "X = X \ A \ B" + using eq by blast +next + assume eq: "X = X \ A \ B" + { fix n::nat + have "B \ (A ^^ n) \ X" using arden_helper[OF eq, of "n"] by auto } + then have "B \ A\ \ X" + unfolding conc_def star_def UNION_def by auto + moreover + { fix s::"'a list" + obtain k where "k = length s" by auto + then have not_in: "s \ X \ (A ^^ Suc k)" + using seq_pow_length[OF nemp] by blast + assume "s \ X" + then have "s \ X \ (A ^^ Suc k) \ (\m\{0..k}. B \ (A ^^ m))" + using arden_helper[OF eq, of "k"] by auto + then have "s \ (\m\{0..k}. B \ (A ^^ m))" using not_in by auto + moreover + have "(\m\{0..k}. B \ (A ^^ m)) \ (\n. B \ (A ^^ n))" by auto + ultimately + have "s \ B \ A\" + unfolding conc_Un_distrib star_def by auto } + then have "X \ B \ A\" by auto + ultimately + show "X = B \ A\" by simp +qed + + +text {* Plus-combination for a set of regular expressions *} + +abbreviation + Setalt ("\_" [1000] 999) +where + "\A \ folds Plus Zero A" + +text {* + For finite sets, @{term Setalt} is preserved under @{term lang}. +*} + +lemma folds_alt_simp [simp]: + fixes rs::"('a rexp) set" + assumes a: "finite rs" + shows "lang (\rs) = \ (lang ` rs)" +unfolding folds_def +apply(rule set_eqI) +apply(rule someI2_ex) +apply(rule_tac finite_imp_fold_graph[OF a]) +apply(erule fold_graph.induct) +apply(auto) +done + +end \ No newline at end of file