# HG changeset patch # User haftmann # Date 1291412426 -3600 # Node ID 2dbce761696ab6ac2fc62ca4d9f5b51b7db4658e # Parent ecca598474ddced47b92174e18bfc8f434d12558# Parent 6c35a88d8f61f86100e53a686074d8bbdc7ca136 merged diff -r 6c35a88d8f61 -r 2dbce761696a src/HOL/Quotient_Examples/FSet.thy --- a/src/HOL/Quotient_Examples/FSet.thy Fri Dec 03 22:39:34 2010 +0100 +++ b/src/HOL/Quotient_Examples/FSet.thy Fri Dec 03 22:40:26 2010 +0100 @@ -6,7 +6,7 @@ *) theory FSet -imports Quotient_List +imports Quotient_List More_List begin text {* @@ -17,7 +17,7 @@ definition list_eq :: "'a list \ 'a list \ bool" (infix "\" 50) where - [simp]: "list_eq xs ys \ set xs = set ys" + [simp]: "xs \ ys \ set xs = set ys" lemma list_eq_reflp: "reflp list_eq" @@ -42,15 +42,12 @@ by (rule list_eq_equivp) text {* - Definitions for membership, sublist, cardinality, + Definitions for sublist, cardinality, intersection, difference and respectful fold over lists. *} -definition - memb :: "'a \ 'a list \ bool" -where - [simp]: "memb x xs \ x \ set xs" +declare List.member_def [simp] definition sub_list :: "'a list \ 'a list \ bool" @@ -73,9 +70,9 @@ [simp]: "diff_list xs ys = [x \ xs. x \ set ys]" definition - rsp_fold + rsp_fold :: "('a \ 'b \ 'b) \ bool" where - "rsp_fold f \ \u v w. (f u (f v w) = f v (f u w))" + "rsp_fold f \ (\u v. f u \ f v = f v \ f u)" primrec fold_list :: "('a \ 'b \ 'b) \ 'b \ 'a list \ 'b" @@ -186,9 +183,9 @@ shows "(op \ ===> op \ ===> op =) sub_list sub_list" by (auto intro!: fun_relI) -lemma memb_rsp [quot_respect]: - shows "(op = ===> op \ ===> op =) memb memb" - by (auto intro!: fun_relI) +lemma member_rsp [quot_respect]: + shows "(op \ ===> op =) List.member List.member" + by (auto intro!: fun_relI simp add: mem_def) lemma nil_rsp [quot_respect]: shows "(op \) Nil Nil" @@ -226,11 +223,11 @@ shows "(op = ===> op \ ===> op \) filter filter" by (auto intro!: fun_relI) -lemma memb_commute_fold_list: +lemma member_commute_fold_list: assumes a: "rsp_fold f" and b: "x \ set xs" shows "fold_list f y xs = f x (fold_list f y (removeAll x xs))" - using a b by (induct xs) (auto simp add: rsp_fold_def) + using a b by (induct xs) (auto simp add: rsp_fold_def fun_eq_iff) lemma fold_list_rsp_pre: assumes a: "set xs = set ys" @@ -245,7 +242,7 @@ apply (rule_tac [!] impI) apply (metis insert_absorb) apply (metis List.insert_def List.set.simps(2) List.set_insert fold_list.simps(2)) - apply (metis Diff_insert_absorb insertI1 memb_commute_fold_list set_removeAll) + apply (metis Diff_insert_absorb insertI1 member_commute_fold_list set_removeAll) apply(drule_tac x="removeAll a ys" in meta_spec) apply(auto) apply(drule meta_mp) @@ -408,9 +405,14 @@ "{|x|}" == "CONST insert_fset x {||}" quotient_definition - in_fset (infix "|\|" 50) + fset_member where - "in_fset :: 'a \ 'a fset \ bool" is "memb" + "fset_member :: 'a fset \ 'a \ bool" is "List.member" + +abbreviation + in_fset :: "'a \ 'a fset \ bool" (infix "|\|" 50) +where + "x |\| S \ fset_member S x" abbreviation notin_fset :: "'a \ 'a fset \ bool" (infix "|\|" 50) @@ -570,7 +572,7 @@ lemma in_fset: shows "x |\| S \ x \ fset S" - by (descending) (simp) + by descending simp lemma notin_fset: shows "x |\| S \ x \ fset S" @@ -582,18 +584,18 @@ lemma fset_eq_iff: shows "S = T \ (\x. (x |\| S) = (x |\| T))" - by (descending) (auto) + by descending auto lemma none_in_empty_fset: shows "(\x. x |\| S) \ S = {||}" - by (descending) (simp) + by descending simp subsection {* insert_fset *} lemma in_insert_fset_iff [simp]: shows "x |\| insert_fset y S \ x = y \ x |\| S" - by (descending) (simp) + by descending simp lemma shows insert_fsetI1: "x |\| insert_fset x S" @@ -926,7 +928,7 @@ lemma in_commute_fold_fset: "\rsp_fold f; h |\| b\ \ fold_fset f z b = f h (fold_fset f z (remove_fset h b))" - by (descending) (simp add: memb_commute_fold_list) + by (descending) (simp add: member_commute_fold_list) subsection {* Choice in fsets *} @@ -988,34 +990,35 @@ lemma fset_raw_strong_cases: obtains "xs = []" - | x ys where "\ memb x ys" and "xs \ x # ys" + | ys x where "\ List.member ys x" and "xs \ x # ys" proof (induct xs arbitrary: x ys) case Nil then show thesis by simp next case (Cons a xs) - have a: "\xs = [] \ thesis; \x ys. \\ memb x ys; xs \ x # ys\ \ thesis\ \ thesis" by fact - have b: "\x' ys'. \\ memb x' ys'; a # xs \ x' # ys'\ \ thesis" by fact + have a: "\xs = [] \ thesis; \x ys. \\ List.member ys x; xs \ x # ys\ \ thesis\ \ thesis" + by (rule Cons(1)) + have b: "\x' ys'. \\ List.member ys' x'; a # xs \ x' # ys'\ \ thesis" by fact have c: "xs = [] \ thesis" using b apply(simp) by (metis List.set.simps(1) emptyE empty_subsetI) - have "\x ys. \\ memb x ys; xs \ x # ys\ \ thesis" + have "\x ys. \\ List.member ys x; xs \ x # ys\ \ thesis" proof - fix x :: 'a fix ys :: "'a list" - assume d:"\ memb x ys" + assume d:"\ List.member ys x" assume e:"xs \ x # ys" show thesis proof (cases "x = a") assume h: "x = a" - then have f: "\ memb a ys" using d by simp + then have f: "\ List.member ys a" using d by simp have g: "a # xs \ a # ys" using e h by auto show thesis using b f g by simp next assume h: "x \ a" - then have f: "\ memb x (a # ys)" using d by auto + then have f: "\ List.member (a # ys) x" using d by auto have g: "a # xs \ x # (a # ys)" using e h by auto - show thesis using b f g by (simp del: memb_def) + show thesis using b f g by (simp del: List.member_def) qed qed then show thesis using a c by blast @@ -1024,7 +1027,7 @@ lemma fset_strong_cases: obtains "xs = {||}" - | x ys where "x |\| ys" and "xs = insert_fset x ys" + | ys x where "x |\| ys" and "xs = insert_fset x ys" by (lifting fset_raw_strong_cases) @@ -1047,36 +1050,36 @@ and a proof of equivalence *} inductive - list_eq2 ("_ \2 _") + list_eq2 :: "'a list \ 'a list \ bool" ("_ \2 _") where "(a # b # xs) \2 (b # a # xs)" | "[] \2 []" -| "xs \2 ys \ ys \2 xs" +| "xs \2 ys \ ys \2 xs" | "(a # a # xs) \2 (a # xs)" -| "xs \2 ys \ (a # xs) \2 (a # ys)" -| "\xs1 \2 xs2; xs2 \2 xs3\ \ xs1 \2 xs3" +| "xs \2 ys \ (a # xs) \2 (a # ys)" +| "xs1 \2 xs2 \ xs2 \2 xs3 \ xs1 \2 xs3" lemma list_eq2_refl: shows "xs \2 xs" by (induct xs) (auto intro: list_eq2.intros) lemma cons_delete_list_eq2: - shows "(a # (removeAll a A)) \2 (if memb a A then A else a # A)" + shows "(a # (removeAll a A)) \2 (if List.member A a then A else a # A)" apply (induct A) apply (simp add: list_eq2_refl) - apply (case_tac "memb a (aa # A)") + apply (case_tac "List.member (aa # A) a") apply (simp_all) apply (case_tac [!] "a = aa") apply (simp_all) - apply (case_tac "memb a A") + apply (case_tac "List.member A a") apply (auto)[2] apply (metis list_eq2.intros(3) list_eq2.intros(4) list_eq2.intros(5) list_eq2.intros(6)) apply (metis list_eq2.intros(1) list_eq2.intros(5) list_eq2.intros(6)) - apply (auto simp add: list_eq2_refl memb_def) + apply (auto simp add: list_eq2_refl) done -lemma memb_delete_list_eq2: - assumes a: "memb e r" +lemma member_delete_list_eq2: + assumes a: "List.member r e" shows "(e # removeAll e r) \2 r" using a cons_delete_list_eq2[of e r] by simp @@ -1094,7 +1097,7 @@ proof (induct n arbitrary: l r) case 0 have "card_list l = 0" by fact - then have "\x. \ memb x l" by auto + then have "\x. \ List.member l x" by auto then have z: "l = []" by auto then have "r = []" using `l \ r` by simp then show ?case using z list_eq2_refl by simp @@ -1102,22 +1105,22 @@ case (Suc m) have b: "l \ r" by fact have d: "card_list l = Suc m" by fact - then have "\a. memb a l" + then have "\a. List.member l a" apply(simp) apply(drule card_eq_SucD) apply(blast) done - then obtain a where e: "memb a l" by auto - then have e': "memb a r" using list_eq_def [simplified memb_def [symmetric], of l r] b + then obtain a where e: "List.member l a" by auto + then have e': "List.member r a" using list_eq_def [simplified List.member_def [symmetric], of l r] b by auto have f: "card_list (removeAll a l) = m" using e d by (simp) have g: "removeAll a l \ removeAll a r" using removeAll_rsp b by simp have "(removeAll a l) \2 (removeAll a r)" by (rule Suc.hyps[OF f g]) then have h: "(a # removeAll a l) \2 (a # removeAll a r)" by (rule list_eq2.intros(5)) have i: "l \2 (a # removeAll a l)" - by (rule list_eq2.intros(3)[OF memb_delete_list_eq2[OF e]]) + by (rule list_eq2.intros(3)[OF member_delete_list_eq2[OF e]]) have "l \2 (a # removeAll a r)" by (rule list_eq2.intros(6)[OF i h]) - then show ?case using list_eq2.intros(6)[OF _ memb_delete_list_eq2[OF e']] by simp + then show ?case using list_eq2.intros(6)[OF _ member_delete_list_eq2[OF e']] by simp qed } then show "l \ r \ l \2 r" by blast