# HG changeset patch # User Cezary Kaliszyk # Date 1272454180 -7200 # Node ID 15e834a035096dd6c16efc29cb90826735dda6b2 # Parent 06081e4921d618fe374022c4ed0988d35408b22c Tuned FSet diff -r 06081e4921d6 -r 15e834a03509 src/HOL/Quotient_Examples/FSet.thy --- a/src/HOL/Quotient_Examples/FSet.thy Wed Apr 28 08:25:02 2010 +0200 +++ b/src/HOL/Quotient_Examples/FSet.thy Wed Apr 28 13:29:40 2010 +0200 @@ -1,11 +1,12 @@ -(* Title: Quotient.thy - Author: Cezary Kaliszyk - Author: Christian Urban +(* Title: HOL/Quotient_Examples/Quotient.thy + Author: Cezary Kaliszyk, TU Munich + Author: Christian Urban, TU Munich - provides a reasoning infrastructure for the type of finite sets +A reasoning infrastructure for the type of finite sets. *) + theory FSet -imports Quotient Quotient_List List +imports Quotient_List begin text {* Definiton of List relation and the quotient type *} @@ -80,9 +81,9 @@ lemma compose_list_refl: shows "(list_rel op \ OOO op \) r r" proof - show c: "list_rel op \ r r" by (rule list_rel_refl) - have d: "r \ r" by (rule equivp_reflp[OF fset_equivp]) - show b: "(op \ OO list_rel op \) r r" by (rule pred_compI) (rule d, rule c) + have *: "r \ r" by (rule equivp_reflp[OF fset_equivp]) + show "list_rel op \ r r" by (rule list_rel_refl) + with * show "(op \ OO list_rel op \) r r" .. qed lemma Quotient_fset_list: @@ -117,7 +118,8 @@ show "(list_rel op \ OOO op \) s s" by (rule compose_list_refl) next assume a: "(list_rel op \ OOO op \) r s" - then have b: "map abs_fset r \ map abs_fset s" proof (elim pred_compE) + then have b: "map abs_fset r \ map abs_fset s" + proof (elim pred_compE) fix b ba assume c: "list_rel op \ r b" assume d: "b \ ba" @@ -221,20 +223,43 @@ assumes a: "xs \ ys" shows "fcard_raw xs = fcard_raw ys" using a - apply (induct xs arbitrary: ys) - apply (auto simp add: memb_def) - apply (subgoal_tac "\x. (x \ set xs) = (x \ set ys)") - apply (auto) - apply (drule_tac x="x" in spec) - apply (blast) - apply (drule_tac x="[x \ ys. x \ a]" in meta_spec) - apply (simp add: fcard_raw_delete_one memb_def) - apply (case_tac "a \ set ys") - apply (simp only: if_True) - apply (subgoal_tac "\x. (x \ set xs) = (x \ set ys \ x \ a)") - apply (drule Suc_pred'[OF fcard_raw_gt_0]) - apply (auto) - done + proof (induct xs arbitrary: ys) + case Nil + show ?case using Nil.prems by simp + next + case (Cons a xs) + have a: "a # xs \ ys" by fact + have b: "\ys. xs \ ys \ fcard_raw xs = fcard_raw ys" by fact + show ?case proof (cases "a \ set xs") + assume c: "a \ set xs" + have "\x. (x \ set xs) = (x \ set ys)" + proof (intro allI iffI) + fix x + assume "x \ set xs" + then show "x \ set ys" using a by auto + next + fix x + assume d: "x \ set ys" + have e: "(x \ set (a # xs)) = (x \ set ys)" using a by simp + show "x \ set xs" using c d e unfolding list_eq.simps by simp blast + qed + then show ?thesis using b c by (simp add: memb_def) + next + assume c: "a \ set xs" + have d: "xs \ [x\ys . x \ a] \ fcard_raw xs = fcard_raw [x\ys . x \ a]" using b by simp + have "Suc (fcard_raw xs) = fcard_raw ys" + proof (cases "a \ set ys") + assume e: "a \ set ys" + have f: "\x. (x \ set xs) = (x \ set ys \ x \ a)" using a c + by (auto simp add: fcard_raw_delete_one) + have "fcard_raw ys = Suc (fcard_raw ys - 1)" by (rule Suc_pred'[OF fcard_raw_gt_0]) (rule e) + then show ?thesis using d e f by (simp_all add: fcard_raw_delete_one memb_def) + next + case False then show ?thesis using a c d by auto + qed + then show ?thesis using a c d by (simp add: memb_def) + qed +qed lemma fcard_raw_rsp[quot_respect]: shows "(op \ ===> op =) fcard_raw fcard_raw" @@ -306,8 +331,8 @@ obtain xb where e: "xb \ set x" and f: "xa \ set xb" using d by auto have "\y. y \ set x' \ xb \ y" by (rule list_rel_find_element[OF e a]) then obtain ya where h: "ya \ set x'" and i: "xb \ ya" by auto - have j: "ya \ set y'" using b h by simp - have "\yb. yb \ set y \ ya \ yb" by (rule list_rel_find_element[OF j c]) + have "ya \ set y'" using b h by simp + then have "\yb. yb \ set y \ ya \ yb" using c by (rule list_rel_find_element) then show ?thesis using f i by auto qed @@ -385,7 +410,8 @@ apply (induct x) apply (simp_all add: memb_def) apply (simp add: memb_def[symmetric] memb_finter_raw) - by (auto simp add: memb_def) + apply (auto simp add: memb_def) + done instantiation fset :: (type) "{bounded_lattice_bot,distrib_lattice}" begin @@ -496,10 +522,10 @@ where "x |\| S \ \ (x |\| S)" -section {* Other constants on the Quotient Type *} +section {* Other constants on the Quotient Type *} quotient_definition - "fcard :: 'a fset \ nat" + "fcard :: 'a fset \ nat" is "fcard_raw" @@ -509,11 +535,11 @@ "map" quotient_definition - "fdelete :: 'a fset \ 'a \ 'a fset" + "fdelete :: 'a fset \ 'a \ 'a fset" is "delete_raw" quotient_definition - "fset_to_set :: 'a fset \ 'a set" + "fset_to_set :: 'a fset \ 'a set" is "set" quotient_definition @@ -701,23 +727,37 @@ by auto lemma fset_raw_strong_cases: - "(xs = []) \ (\x ys. ((\ memb x ys) \ (xs \ x # ys)))" - apply (induct xs) - apply (simp) - apply (rule disjI2) - apply (erule disjE) - apply (rule_tac x="a" in exI) - apply (rule_tac x="[]" in exI) - apply (simp add: memb_def) - apply (erule exE)+ - apply (case_tac "x = a") - apply (rule_tac x="a" in exI) - apply (rule_tac x="ys" in exI) - apply (simp) - apply (rule_tac x="x" in exI) - apply (rule_tac x="a # ys" in exI) - apply (auto simp add: memb_def) - done + obtains "xs = []" + | x ys where "\ memb x ys" 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 c: "xs = [] \ thesis" by (metis no_memb_nil singleton_list_eq b) + have "\x ys. \\ memb x ys; xs \ x # ys\ \ thesis" + proof - + fix x :: 'a + fix ys :: "'a list" + assume d:"\ memb x ys" + 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 + 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 unfolding memb_def by auto + have g: "a # xs \ x # (a # ys)" using e h by auto + show thesis using b f g by simp + qed + qed + then show thesis using a c by blast +qed section {* deletion *} @@ -741,7 +781,7 @@ "finter_raw l [] = []" by (induct l) (simp_all add: not_memb_nil) -lemma set_cong: +lemma set_cong: shows "(set x = set y) = (x \ y)" by auto @@ -812,13 +852,13 @@ case (Suc m) have b: "l \ r" by fact have d: "fcard_raw l = Suc m" by fact - have "\a. memb a l" by (rule fcard_raw_suc_memb[OF d]) + then have "\a. memb a l" by (rule fcard_raw_suc_memb) then obtain a where e: "memb a l" by auto then have e': "memb a r" using list_eq.simps[simplified memb_def[symmetric], of l r] b by auto have f: "fcard_raw (delete_raw l a) = m" using fcard_raw_delete[of l a] e d by simp have g: "delete_raw l a \ delete_raw r a" using delete_raw_rsp[OF b] by simp - have g': "list_eq2 (delete_raw l a) (delete_raw r a)" by (rule Suc.hyps[OF f g]) - have h: "list_eq2 (a # delete_raw l a) (a # delete_raw r a)" by (rule list_eq2.intros(5)[OF g']) + have "list_eq2 (delete_raw l a) (delete_raw r a)" by (rule Suc.hyps[OF f g]) + then have h: "list_eq2 (a # delete_raw l a) (a # delete_raw r a)" by (rule list_eq2.intros(5)) have i: "list_eq2 l (a # delete_raw l a)" by (rule list_eq2.intros(3)[OF memb_delete_list_eq2[OF e]]) have "list_eq2 l (a # delete_raw r a)" by (rule list_eq2.intros(6)[OF i h]) @@ -899,11 +939,11 @@ shows "(fcard S = 1) = (\x. S = {|x|})" by (lifting fcard_raw_1) -lemma fcard_gt_0: +lemma fcard_gt_0: shows "x \ fset_to_set S \ 0 < fcard S" by (lifting fcard_raw_gt_0) -lemma fcard_not_fin: +lemma fcard_not_fin: shows "(x |\| S) = (fcard (finsert x S) = Suc (fcard S))" by (lifting fcard_raw_not_memb) @@ -923,8 +963,8 @@ text {* funion *} lemmas [simp] = - sup_bot_left[where 'a="'a fset"] - sup_bot_right[where 'a="'a fset"] + sup_bot_left[where 'a="'a fset", standard] + sup_bot_right[where 'a="'a fset", standard] lemma funion_finsert[simp]: shows "finsert x S |\| T = finsert x (S |\| T)" @@ -941,7 +981,8 @@ section {* Induction and Cases rules for finite sets *} lemma fset_strong_cases: - "S = {||} \ (\x T. x |\| T \ S = finsert x T)" + obtains "xs = {||}" + | x ys where "x |\| ys" and "xs = finsert x ys" by (lifting fset_raw_strong_cases) lemma fset_exhaust[case_names fempty finsert, cases type: fset]: @@ -953,7 +994,7 @@ by (lifting list.induct) lemma fset_induct[case_names fempty finsert, induct type: fset]: - assumes prem1: "P {||}" + assumes prem1: "P {||}" and prem2: "\x S. \x |\| S; P S\ \ P (finsert x S)" shows "P S" proof(induct S rule: fset_induct_weak) @@ -1016,15 +1057,15 @@ text {* fdelete *} -lemma fin_fdelete: +lemma fin_fdelete: shows "x |\| fdelete S y \ x |\| S \ x \ y" by (lifting memb_delete_raw) -lemma fin_fdelete_ident: +lemma fin_fdelete_ident: shows "x |\| fdelete S x" by (lifting memb_delete_raw_ident) -lemma not_memb_fdelete_ident: +lemma not_memb_fdelete_ident: shows "x |\| S \ fdelete S x = S" by (lifting not_memb_delete_raw_ident) @@ -1102,7 +1143,7 @@ by (lifting concat_append) ML {* -fun dest_fsetT (Type ("FSet.fset", [T])) = T +fun dest_fsetT (Type (@{type_name fset}, [T])) = T | dest_fsetT T = raise TYPE ("dest_fsetT: fset type expected", [T], []); *}