diff -r 91e3e906034c -r 68e28debe995 Closures2.thy --- a/Closures2.thy Tue Aug 30 11:31:18 2011 +0000 +++ b/Closures2.thy Thu Sep 01 20:26:30 2011 +0000 @@ -1,243 +1,141 @@ theory Closure2 -imports Closures +imports + Closures + (* "~~/src/HOL/Proofs/Extraction/Higman" *) begin -inductive emb :: "'a list \ 'a list \ bool" ("_ \ _") +inductive + emb :: "'a list \ 'a list \ bool" ("_ \ _") where - emb0 [Pure.intro]: "emb [] bs" - | emb1 [Pure.intro]: "emb as bs \ emb as (b # bs)" - | emb2 [Pure.intro]: "emb as bs \ emb (a # as) (a # bs)" + emb0 [intro]: "emb [] y" + | emb1 [intro]: "emb x y \ emb x (c # y)" + | emb2 [intro]: "emb x y \ emb (c # x) (c # y)" -lemma emb_refl: +lemma emb_refl [intro]: shows "x \ x" -apply(induct x) -apply(auto intro: emb.intros) -done +by (induct x) (auto intro: emb.intros) -lemma emb_right: +lemma emb_right [intro]: assumes a: "x \ y" shows "x \ y @ y'" -using a -apply(induct arbitrary: y') -apply(auto intro: emb.intros) -done +using a by (induct arbitrary: y') (auto) -lemma emb_left: +lemma emb_left [intro]: assumes a: "x \ y" shows "x \ y' @ y" -using a -apply(induct y') -apply(auto intro: emb.intros) -done +using a by (induct y') (auto) -lemma emb_appendI: +lemma emb_appendI [intro]: assumes a: "x \ x'" and b: "y \ y'" shows "x @ y \ x' @ y'" -using a b -apply(induct) -apply(auto intro: emb.intros emb_left) +using a b by (induct) (auto) + +lemma emb_cons_leftD: + assumes "a # x \ y" + shows "\y1 y2. y = y1 @ [a] @ y2 \ x \ y2" +using assms +apply(induct x\"a # x" y\"y" arbitrary: a x y) +apply(auto) +apply(metis append_Cons) +done + +lemma emb_append_leftD: + assumes "x1 @ x2 \ y" + shows "\y1 y2. y = y1 @ y2 \ x1 \ y1 \ x2 \ y2" +using assms +apply(induct x1 arbitrary: x2 y) +apply(auto) +apply(drule emb_cons_leftD) +apply(auto) +apply(drule_tac x="x2" in meta_spec) +apply(drule_tac x="y2" in meta_spec) +apply(auto) +apply(rule_tac x="y1 @ (a # y1a)" in exI) +apply(rule_tac x="y2a" in exI) +apply(auto) done -lemma emb_append: - assumes a: "x \ y1 @ y2" - shows "\x1 x2. x = x1 @ x2 \ x1 \ y1 \ x2 \ y2" -using a -apply(induct x y\"y1 @ y2" arbitrary: y1 y2) -apply(auto intro: emb0)[1] -apply(simp add: Cons_eq_append_conv) -apply(auto)[1] -apply(rule_tac x="[]" in exI) -apply(rule_tac x="as" in exI) -apply(auto intro: emb.intros)[1] -apply(simp add: append_eq_append_conv2) -apply(drule_tac x="ys'" in meta_spec) -apply(drule_tac x="y2" in meta_spec) -apply(auto)[1] -apply(rule_tac x="x1" in exI) -apply(rule_tac x="x2" in exI) -apply(auto intro: emb.intros)[1] -apply(subst (asm) Cons_eq_append_conv) -apply(auto)[1] -apply(rule_tac x="[]" in exI) -apply(rule_tac x="a # as" in exI) -apply(auto intro: emb.intros)[1] -apply(simp add: append_eq_append_conv2) -apply(drule_tac x="ys'" in meta_spec) -apply(drule_tac x="y2" in meta_spec) -apply(auto)[1] -apply(rule_tac x="a # x1" in exI) -apply(rule_tac x="x2" in exI) -apply(auto intro: emb.intros)[1] +lemma emb_trans: + assumes a: "x1 \ x2" + and b: "x2 \ x3" + shows "x1 \ x3" +using a b +apply(induct arbitrary: x3) +apply(metis emb0) +apply(metis emb_cons_leftD emb_left) +apply(drule_tac emb_cons_leftD) +apply(auto) done +lemma emb_strict_length: + assumes a: "x \ y" "x \ y" + shows "length x < length y" +using a +by (induct) (auto simp add: less_Suc_eq) + +lemma emb_antisym: + assumes a: "x \ y" "y \ x" + shows "x = y" +using a emb_strict_length +by (metis not_less_iff_gr_or_eq) + +lemma emb_wf: + shows "wf {(x, y). x \ y \ x \ y}" +proof - + have "wf (measure length)" by simp + moreover + have "{(x, y). x \ y \ x \ y} \ measure length" + unfolding measure_def by (auto simp add: emb_strict_length) + ultimately + show "wf {(x, y). x \ y \ x \ y}" by (rule wf_subset) +qed + +subsection {* Sub- and Supsequences *} definition "SUBSEQ A \ {x. \y \ A. x \ y}" definition - "SUPSEQ A \ (- SUBSEQ A) \ A" - -lemma [simp]: - "SUBSEQ {} = {}" -unfolding SUBSEQ_def -by auto - -lemma [simp]: - "SUBSEQ {[]} = {[]}" -unfolding SUBSEQ_def -apply(auto) -apply(erule emb.cases) -apply(auto)[3] -apply(rule emb0) -done + "SUPSEQ A \ {x. \y \ A. y \ x}" -lemma SUBSEQ_atom [simp]: - "SUBSEQ {[a]} = {[], [a]}" -apply(auto simp add: SUBSEQ_def) -apply(erule emb.cases) -apply(auto)[3] -apply(erule emb.cases) -apply(auto)[3] -apply(erule emb.cases) -apply(auto)[3] -apply(rule emb0) -apply(rule emb2) -apply(rule emb0) -done +lemma SUPSEQ_simps [simp]: + shows "SUPSEQ {} = {}" + and "SUPSEQ {[]} = UNIV" +unfolding SUPSEQ_def by auto -lemma SUBSEQ_union [simp]: - "SUBSEQ (A \ B) = SUBSEQ A \ SUBSEQ B" -unfolding SUBSEQ_def by auto - -lemma SUBSEQ_Union [simp]: - fixes A :: "nat \ 'a lang" - shows "SUBSEQ (\n. (A n)) = (\n. (SUBSEQ (A n)))" -unfolding SUBSEQ_def image_def by auto +lemma SUPSEQ_atom [simp]: + shows "SUPSEQ {[a]} = UNIV \ {[a]} \ UNIV" +unfolding SUPSEQ_def conc_def +by (auto) (metis append_Cons emb_cons_leftD) -lemma SUBSEQ_conc1: - "\x \ SUBSEQ A; y \ SUBSEQ B\ \ x @ y \ SUBSEQ (A \ B)" -unfolding SUBSEQ_def -apply(auto) -apply(rule_tac x="xa @ xaa" in bexI) -apply(rule emb_appendI) -apply(simp_all) -done - -lemma SUBSEQ_conc2: - "x \ SUBSEQ (A \ B) \ x \ (SUBSEQ A) \ (SUBSEQ B)" -unfolding SUBSEQ_def conc_def -apply(auto) -apply(drule emb_append) -apply(auto) -done +lemma SUPSEQ_union [simp]: + shows "SUPSEQ (A \ B) = SUPSEQ A \ SUPSEQ B" +unfolding SUPSEQ_def by auto -lemma SUBSEQ_conc [simp]: - "SUBSEQ (A \ B) = SUBSEQ A \ SUBSEQ B" -apply(auto) -apply(simp add: SUBSEQ_conc2) -apply(subst (asm) conc_def) -apply(auto simp add: SUBSEQ_conc1) -done +lemma SUPSEQ_conc [simp]: + shows "SUPSEQ (A \ B) = SUPSEQ A \ SUPSEQ B" +unfolding SUPSEQ_def conc_def +by (auto) (metis emb_append_leftD) -lemma SUBSEQ_star1: - assumes a: "x \ (SUBSEQ A)\" - shows "x \ SUBSEQ (A\)" -using a -apply(induct rule: star_induct) -apply(simp add: SUBSEQ_def) -apply(rule_tac x="[]" in bexI) -apply(rule emb0) -apply(auto)[1] -apply(drule SUBSEQ_conc1) -apply(assumption) +lemma SUPSEQ_star [simp]: + shows "SUPSEQ (A\) = UNIV" apply(subst star_unfold_left) -apply(simp only: SUBSEQ_union) +apply(simp only: SUPSEQ_union) apply(simp) done -lemma SUBSEQ_star2_aux: - assumes a: "x \ SUBSEQ (A ^^ n)" - shows "x \ (SUBSEQ A)\" -using a -apply(induct n arbitrary: x) -apply(simp) -apply(simp) -apply(simp add: conc_def) -apply(auto) -done - -lemma SUBSEQ_star2: - assumes a: "x \ SUBSEQ (A\)" - shows "x \ (SUBSEQ A)\" -using a -apply(subst (asm) star_def) -apply(auto simp add: SUBSEQ_star2_aux) -done - -lemma SUBSEQ_star [simp]: - shows "SUBSEQ (A\) = (SUBSEQ A)\" -using SUBSEQ_star1 SUBSEQ_star2 by auto - -lemma SUBSEQ_fold: - shows "SUBSEQ A \ A = SUBSEQ A" -apply(auto simp add: SUBSEQ_def) -apply(rule_tac x="x" in bexI) -apply(auto simp add: emb_refl) -done - - -lemma SUPSEQ_union [simp]: - "SUPSEQ (A \ B) = (SUPSEQ A \ B) \ (SUPSEQ B \ A)" -unfolding SUPSEQ_def -by auto - - -definition - Notreg :: "'a::finite rexp \ 'a rexp" -where - "Notreg r \ SOME r'. lang r' = - (lang r)" - -lemma [simp]: - "lang (Notreg r) = - lang r" -apply(simp add: Notreg_def) -apply(rule someI2_ex) -apply(auto) -apply(subgoal_tac "regular (lang r)") -apply(drule closure_complement) -apply(auto) -done - -definition - Interreg :: "'a::finite rexp \ 'a rexp \ 'a rexp" -where - "Interreg r1 r2 = Notreg (Plus (Notreg r1) (Notreg r2))" - -lemma [simp]: - "lang (Interreg r1 r2) = (lang r1) \ (lang r2)" -by (simp add: Interreg_def) - -definition - Diffreg :: "'a::finite rexp \ 'a rexp \ 'a rexp" -where - "Diffreg r1 r2 = Notreg (Plus (Notreg r1) r2)" - -lemma [simp]: - "lang (Diffreg r1 r2) = (lang r1) - (lang r2)" -by (auto simp add: Diffreg_def) - definition Allreg :: "'a::finite rexp" where "Allreg \ \(Atom ` UNIV)" lemma Allreg_lang [simp]: - "lang Allreg = (\a. {[a]})" -unfolding Allreg_def -by auto + shows "lang Allreg = (\a. {[a]})" +unfolding Allreg_def by auto lemma [simp]: - "(\a. {[a]})\ = UNIV" + shows "(\a. {[a]})\ = UNIV" apply(auto) apply(induct_tac x rule: list.induct) apply(auto) @@ -248,63 +146,149 @@ done lemma Star_Allreg_lang [simp]: - "lang (Star Allreg) = UNIV" -by (simp) - -fun UP :: "'a::finite rexp \ 'a rexp" -where - "UP (Zero) = Star Allreg" -| "UP (One) = Star Allreg" -| "UP (Atom c) = Times Allreg (Star Allreg)" -| "UP (Plus r1 r2) = Interreg (Plus (UP r1) (r2)) (Plus (UP r2) r1)" -| "UP (Times r1 r2) = - Plus (Notreg (Times (Plus (Notreg (UP r1)) r1) (Plus (Notreg (UP r2)) r2))) (Times r1 r2)" -| "UP (Star r) = Plus (Notreg (Star (Plus (Notreg (UP r)) r))) (Star r)" + shows "lang (Star Allreg) = UNIV" +by simp -lemma UP: - "lang (UP r) = SUPSEQ (lang r)" -apply(induct r) -apply(simp add: SUPSEQ_def) -apply(simp add: SUPSEQ_def) -apply(simp add: Compl_eq_Diff_UNIV) -apply(auto)[1] -apply(simp add: SUPSEQ_def) -apply(simp add: Compl_eq_Diff_UNIV) -apply(rule sym) -apply(rule_tac s="UNIV - {[]}" in trans) -apply(auto)[1] -apply(auto simp add: conc_def)[1] -apply(case_tac x) -apply(simp) -apply(simp) -apply(rule_tac x="[a]" in exI) -apply(simp) -apply(simp) -apply(simp) -apply(simp add: SUPSEQ_def) -apply(simp add: Un_Int_distrib2) -apply(simp add: Compl_partition2) -apply(simp add: SUBSEQ_fold) -apply(simp add: Un_Diff) -apply(simp add: SUPSEQ_def) -apply(simp add: Un_Int_distrib2) -apply(simp add: Compl_partition2) -apply(simp add: SUBSEQ_fold) -done +fun + UP :: "'a::finite rexp \ 'a rexp" +where + "UP (Zero) = Zero" +| "UP (One) = Star Allreg" +| "UP (Atom c) = Times (Star Allreg) (Times (Atom c) (Star Allreg))" +| "UP (Plus r1 r2) = Plus (UP r1) (UP r2)" +| "UP (Times r1 r2) = Times (UP r1) (UP r2)" +| "UP (Star r) = Star Allreg" -lemma SUPSEQ_reg: - fixes A :: "'a::finite lang" +lemma lang_UP: + shows "lang (UP r) = SUPSEQ (lang r)" +by (induct r) (simp_all) + +lemma regular_SUPSEQ: + fixes A::"'a::finite lang" assumes "regular A" shows "regular (SUPSEQ A)" proof - - from assms obtain r::"'a::finite rexp" where eq: "lang r = A" by auto - moreover - have "lang (UP r) = SUPSEQ (lang r)" by (rule UP) - ultimately show "regular (SUPSEQ A)" by auto + from assms obtain r::"'a::finite rexp" where "lang r = A" by auto + then have "lang (UP r) = SUPSEQ A" by (simp add: lang_UP) + then show "regular (SUPSEQ A)" by auto qed - + +lemma SUPSEQ_subset: + shows "A \ SUPSEQ A" +unfolding SUPSEQ_def by auto + +lemma w3: + assumes eq: "T = - (SUBSEQ A)" + shows "T = SUPSEQ T" +apply(rule) +apply(rule SUPSEQ_subset) +apply(rule ccontr) +apply(auto) +apply(rule ccontr) +apply(subgoal_tac "x \ SUBSEQ A") +prefer 2 +apply(subst (asm) (2) eq) +apply(simp) +apply(simp add: SUPSEQ_def) +apply(erule bexE) +apply(subgoal_tac "y \ SUBSEQ A") +prefer 2 +apply(simp add: SUBSEQ_def) +apply(erule bexE) +apply(rule_tac x="xa" in bexI) +apply(rule emb_trans) +apply(assumption) +apply(assumption) +apply(assumption) +apply(subst (asm) (2) eq) +apply(simp) +done + +lemma w4: + shows "- (SUBSEQ A) = SUPSEQ (- (SUBSEQ A))" +by (rule w3) (simp) + +definition + "minimal_in x L \ \y \ L. y \ x \ y = x" + +lemma minimal_in2: + shows "minimal_in x L = (\y \ L. y \ x \ x \ y)" +by (auto simp add: minimal_in_def intro: emb_antisym) + +lemma higman: + assumes "\x \ A. \y \ A. x \ y \ \(x \ y) \ \(y \ x)" + shows "finite A" +sorry + +lemma minimal: + assumes "minimal_in x A" "minimal_in y A" + and "x \ y" "x \ A" "y \ A" + shows "\(x \ y) \ \(y \ x)" +using assms unfolding minimal_in_def +by auto - +lemma main_lemma: + "\M. M \ A \ finite M \ SUPSEQ A = SUPSEQ M" +proof - + def M \ "{x \ A. minimal_in x A}" + have "M \ A" unfolding M_def minimal_in_def by auto + moreover + have "finite M" + apply(rule higman) + unfolding M_def minimal_in_def + by auto + moreover + have "SUPSEQ A \ SUPSEQ M" + apply(rule) + apply(simp only: SUPSEQ_def) + apply(auto)[1] + using emb_wf + apply(erule_tac Q="{y' \ A. y' \ x}" and x="y" in wfE_min) + apply(simp) + apply(simp) + apply(rule_tac x="z" in bexI) + apply(simp) + apply(simp add: M_def) + apply(simp add: minimal_in2) + apply(rule ballI) + apply(rule impI) + apply(drule_tac x="ya" in meta_spec) + apply(simp) + apply(case_tac "ya = z") + apply(auto)[1] + apply(simp) + by (metis emb_trans) + moreover + have "SUPSEQ M \ SUPSEQ A" + by (auto simp add: SUPSEQ_def M_def) + ultimately + show "\M. M \ A \ finite M \ SUPSEQ A = SUPSEQ M" by blast +qed + +lemma closure_SUPSEQ: + fixes A::"'a::finite lang" + shows "regular (SUPSEQ A)" +proof - + obtain M where a: "finite M" and b: "SUPSEQ A = SUPSEQ M" + using main_lemma by blast + have "regular M" using a by (rule finite_regular) + then have "regular (SUPSEQ M)" by (rule regular_SUPSEQ) + then show "regular (SUPSEQ A)" using b by simp +qed + +lemma closure_SUBSEQ: + fixes A::"'a::finite lang" + shows "regular (SUBSEQ A)" +proof - + have "regular (SUPSEQ (- SUBSEQ A))" by (rule closure_SUPSEQ) + then have "regular (- SUBSEQ A)" + apply(subst w4) + apply(assumption) + done + then have "regular (- (- (SUBSEQ A)))" by (rule closure_complement) + then show "regular (SUBSEQ A)" by simp +qed + end