# HG changeset patch # User Christian Urban # Date 1277827439 -3600 # Node ID 2116425cebc86ac80d37f114c1a95f38b18b6fed # Parent ff1137a9c0561b8375a98a4f5aed741b09970ee0 cleaned by using descending instead of lifting diff -r ff1137a9c056 -r 2116425cebc8 src/HOL/Quotient_Examples/FSet.thy --- a/src/HOL/Quotient_Examples/FSet.thy Tue Jun 29 11:38:51 2010 +0200 +++ b/src/HOL/Quotient_Examples/FSet.thy Tue Jun 29 17:03:59 2010 +0100 @@ -379,50 +379,6 @@ text {* Distributive lattice with bot *} -lemma sub_list_not_eq: - "(sub_list x y \ \ list_eq x y) = (sub_list x y \ \ sub_list y x)" - by (auto simp add: sub_list_def) - -lemma sub_list_refl: - "sub_list x x" - by (simp add: sub_list_def) - -lemma sub_list_trans: - "sub_list x y \ sub_list y z \ sub_list x z" - by (simp add: sub_list_def) - -lemma sub_list_empty: - "sub_list [] x" - by (simp add: sub_list_def) - -lemma sub_list_append_left: - "sub_list x (x @ y)" - by (simp add: sub_list_def) - -lemma sub_list_append_right: - "sub_list y (x @ y)" - by (simp add: sub_list_def) - -lemma sub_list_inter_left: - shows "sub_list (finter_raw x y) x" - by (simp add: sub_list_def memb_def[symmetric] memb_finter_raw) - -lemma sub_list_inter_right: - shows "sub_list (finter_raw x y) y" - by (simp add: sub_list_def memb_def[symmetric] memb_finter_raw) - -lemma sub_list_list_eq: - "sub_list x y \ sub_list y x \ list_eq x y" - unfolding sub_list_def list_eq.simps by blast - -lemma sub_list_append: - "sub_list y x \ sub_list z x \ sub_list (y @ z) x" - unfolding sub_list_def by auto - -lemma sub_list_inter: - "sub_list x y \ sub_list x z \ sub_list x (finter_raw y z)" - by (simp add: sub_list_def memb_def[symmetric] memb_finter_raw) - lemma append_inter_distrib: "x @ (finter_raw y z) \ finter_raw (x @ y) (x @ z)" apply (induct x) @@ -431,7 +387,7 @@ apply (auto simp add: memb_def) done -instantiation fset :: (type) "{bounded_lattice_bot,distrib_lattice,minus}" +instantiation fset :: (type) "{bounded_lattice_bot, distrib_lattice, minus}" begin quotient_definition @@ -482,42 +438,50 @@ "xs |\| ys \ inf (xs :: 'a fset) ys" quotient_definition - "minus \ ('a fset \ 'a fset \ 'a fset)" + "minus :: 'a fset \ 'a fset \ 'a fset" is - "fminus_raw \ ('a list \ 'a list \ 'a list)" + "fminus_raw :: 'a list \ 'a list \ 'a list" instance proof fix x y z :: "'a fset" - show "(x |\| y) = (x |\| y \ \ y |\| x)" - unfolding less_fset by (lifting sub_list_not_eq) - show "x |\| x" by (lifting sub_list_refl) - show "{||} |\| x" by (lifting sub_list_empty) - show "x |\| x |\| y" by (lifting sub_list_append_left) - show "y |\| x |\| y" by (lifting sub_list_append_right) - show "x |\| y |\| x" by (lifting sub_list_inter_left) - show "x |\| y |\| y" by (lifting sub_list_inter_right) - show "x |\| (y |\| z) = x |\| y |\| (x |\| z)" by (lifting append_inter_distrib) + show "x |\| y \ x |\| y \ \ y |\| x" + unfolding less_fset + by (descending) (auto simp add: sub_list_def) + show "x |\| x" by (descending) (simp add: sub_list_def) + show "{||} |\| x" by (descending) (simp add: sub_list_def) + show "x |\| x |\| y" by (descending) (simp add: sub_list_def) + show "y |\| x |\| y" by (descending) (simp add: sub_list_def) + show "x |\| y |\| x" + by (descending) (simp add: sub_list_def memb_def[symmetric] memb_finter_raw) + show "x |\| y |\| y" + by (descending) (simp add: sub_list_def memb_def[symmetric] memb_finter_raw) + show "x |\| (y |\| z) = x |\| y |\| (x |\| z)" + by (descending) (rule append_inter_distrib) next fix x y z :: "'a fset" assume a: "x |\| y" assume b: "y |\| z" - show "x |\| z" using a b by (lifting sub_list_trans) + show "x |\| z" using a b + by (descending) (simp add: sub_list_def) next fix x y :: "'a fset" assume a: "x |\| y" assume b: "y |\| x" - show "x = y" using a b by (lifting sub_list_list_eq) + show "x = y" using a b + by (descending) (unfold sub_list_def list_eq.simps, blast) next fix x y z :: "'a fset" assume a: "y |\| x" assume b: "z |\| x" - show "y |\| z |\| x" using a b by (lifting sub_list_append) + show "y |\| z |\| x" using a b + by (descending) (simp add: sub_list_def) next fix x y z :: "'a fset" assume a: "x |\| y" assume b: "x |\| z" - show "x |\| y |\| z" using a b by (lifting sub_list_inter) + show "x |\| y |\| z" using a b + by (descending) (simp add: sub_list_def memb_def[symmetric] memb_finter_raw) qed end @@ -750,14 +714,6 @@ "memb x (xs @ ys) \ memb x xs \ memb x ys" by (induct xs) (simp_all add: not_memb_nil memb_cons_iff) -lemma cons_left_comm: - "x # y # xs \ y # x # xs" - by auto - -lemma cons_left_idem: - "x # x # xs \ x # xs" - by auto - lemma fset_raw_strong_cases: obtains "xs = []" | x ys where "\ memb x ys" and "xs \ x # ys" @@ -809,10 +765,6 @@ "fcard_raw (delete_raw xs y) = (if memb y xs then fcard_raw xs - 1 else fcard_raw xs)" by (simp add: fdelete_raw_filter fcard_raw_delete_one) -lemma finter_raw_empty: - "finter_raw l [] = []" - by (induct l) (simp_all add: not_memb_nil) - lemma set_cong: shows "(x \ y) = (set x = set y)" by auto @@ -903,7 +855,7 @@ text {* Set *} lemma sub_list_set: "sub_list xs ys = (set xs \ set ys)" - by (metis rev_append set_append set_cong set_rev sub_list_append sub_list_append_left sub_list_def sub_list_not_eq subset_Un_eq) + unfolding sub_list_def by auto lemma sub_list_neq_set: "(sub_list xs ys \ \ list_eq xs ys) = (set xs \ set ys)" by (auto simp add: sub_list_set) @@ -939,20 +891,20 @@ text {* Lifted theorems *} lemma not_fin_fnil: "x |\| {||}" - by (lifting not_memb_nil) + by (descending) (simp add: memb_def) lemma fin_finsert_iff[simp]: - "x |\| finsert y S = (x = y \ x |\| S)" - by (lifting memb_cons_iff) + "x |\| finsert y S \ x = y \ x |\| S" + by (descending) (simp add: memb_def) lemma shows finsertI1: "x |\| finsert x S" and finsertI2: "x |\| S \ x |\| finsert y S" - by (lifting memb_consI1, lifting memb_consI2) + by (lifting memb_consI1 memb_consI2) lemma finsert_absorb[simp]: shows "x |\| S \ finsert x S = S" - by (lifting memb_absorb) + by (descending) (auto simp add: memb_def) lemma fempty_not_finsert[simp]: "{||} \ finsert x S" @@ -961,21 +913,23 @@ lemma finsert_left_comm: "finsert x (finsert y S) = finsert y (finsert x S)" - by (lifting cons_left_comm) + by (descending) (auto) lemma finsert_left_idem: "finsert x (finsert x S) = finsert x S" - by (lifting cons_left_idem) + by (descending) (auto) lemma fsingleton_eq[simp]: shows "{|x|} = {|y|} \ x = y" - by (lifting singleton_list_eq) + by (descending) (auto) + text {* fset_to_set *} -lemma fset_to_set_simps[simp]: - "fset_to_set {||} = ({} :: 'a set)" - "fset_to_set (finsert (h :: 'a) t) = insert h (fset_to_set t)" +lemma fset_to_set_simps [simp]: + fixes h::"'a" + shows "fset_to_set {||} = ({} :: 'a set)" + and "fset_to_set (finsert h t) = insert h (fset_to_set t)" by (lifting set.simps) lemma in_fset_to_set: @@ -983,28 +937,29 @@ by (lifting memb_def[symmetric]) lemma none_fin_fempty: - "(\x. x |\| S) = (S = {||})" + "(\x. x |\| S) \ S = {||}" by (lifting none_memb_nil) lemma fset_cong: - "(S = T) = (fset_to_set S = fset_to_set T)" + "S = T \ fset_to_set S = fset_to_set T" by (lifting set_cong) text {* fcard *} lemma fcard_fempty [simp]: shows "fcard {||} = 0" - by (lifting fcard_raw_nil) + by (descending) (simp) lemma fcard_finsert_if [simp]: shows "fcard (finsert x S) = (if x |\| S then fcard S else Suc (fcard S))" - by (lifting fcard_raw_cons) + by (descending) (simp) -lemma fcard_0: "(fcard S = 0) = (S = {||})" +lemma fcard_0: + "fcard S = 0 \ S = {||}" by (lifting fcard_raw_0) lemma fcard_1: - shows "(fcard S = 1) = (\x. S = {|x|})" + shows "fcard S = 1 \ (\x. S = {|x|})" by (lifting fcard_raw_1) lemma fcard_gt_0: @@ -1039,11 +994,11 @@ by (lifting append.simps(2)) lemma singleton_union_left: - "{|a|} |\| S = finsert a S" + shows "{|a|} |\| S = finsert a S" by simp lemma singleton_union_right: - "S |\| {|a|} = finsert a S" + shows "S |\| {|a|} = finsert a S" by (subst sup.commute) simp section {* Induction and Cases rules for finite sets *} @@ -1105,8 +1060,9 @@ text {* fmap *} lemma fmap_simps[simp]: - "fmap (f :: 'a \ 'b) {||} = {||}" - "fmap f (finsert x S) = finsert (f x) (fmap f S)" + fixes f::"'a \ 'b" + shows "fmap f {||} = {||}" + and "fmap f (finsert x S) = finsert (f x) (fmap f S)" by (lifting map.simps) lemma fmap_set_image: @@ -1114,51 +1070,62 @@ by (induct S) simp_all lemma inj_fmap_eq_iff: - "inj f \ (fmap f S = fmap f T) = (S = T)" + "inj f \ fmap f S = fmap f T \ S = T" by (lifting inj_map_eq_iff) -lemma fmap_funion: "fmap f (S |\| T) = fmap f S |\| fmap f T" +lemma fmap_funion: + shows "fmap f (S |\| T) = fmap f S |\| fmap f T" by (lifting map_append) lemma fin_funion: - "x |\| S |\| T \ x |\| S \ x |\| T" + shows "x |\| S |\| T \ x |\| S \ x |\| T" by (lifting memb_append) text {* to_set *} -lemma fin_set: "(x |\| xs) = (x \ fset_to_set xs)" +lemma fin_set: + shows "x |\| xs \ x \ fset_to_set xs" by (lifting memb_set) -lemma fnotin_set: "(x |\| xs) = (x \ fset_to_set xs)" +lemma fnotin_set: + shows "x |\| xs \ x \ fset_to_set xs" by (simp add: fin_set) -lemma fcard_set: "fcard xs = card (fset_to_set xs)" +lemma fcard_set: + shows "fcard xs = card (fset_to_set xs)" by (lifting fcard_raw_set) -lemma fsubseteq_set: "(xs |\| ys) = (fset_to_set xs \ fset_to_set ys)" +lemma fsubseteq_set: + shows "xs |\| ys \ fset_to_set xs \ fset_to_set ys" by (lifting sub_list_set) -lemma fsubset_set: "(xs |\| ys) = (fset_to_set xs \ fset_to_set ys)" +lemma fsubset_set: + shows "xs |\| ys \ fset_to_set xs \ fset_to_set ys" unfolding less_fset by (lifting sub_list_neq_set) -lemma ffilter_set: "fset_to_set (ffilter P xs) = P \ fset_to_set xs" +lemma ffilter_set: + shows "fset_to_set (ffilter P xs) = P \ fset_to_set xs" by (lifting filter_set) -lemma fdelete_set: "fset_to_set (fdelete xs x) = fset_to_set xs - {x}" +lemma fdelete_set: + shows "fset_to_set (fdelete xs x) = fset_to_set xs - {x}" by (lifting delete_raw_set) -lemma inter_set: "fset_to_set (xs |\| ys) = fset_to_set xs \ fset_to_set ys" +lemma finter_set: + shows "fset_to_set (xs |\| ys) = fset_to_set xs \ fset_to_set ys" by (lifting inter_raw_set) -lemma union_set: "fset_to_set (xs |\| ys) = fset_to_set xs \ fset_to_set ys" +lemma funion_set: + shows "fset_to_set (xs |\| ys) = fset_to_set xs \ fset_to_set ys" by (lifting set_append) -lemma fminus_set: "fset_to_set (xs - ys) = fset_to_set xs - fset_to_set ys" +lemma fminus_set: + shows "fset_to_set (xs - ys) = fset_to_set xs - fset_to_set ys" by (lifting fminus_raw_set) lemmas fset_to_set_trans = fin_set fnotin_set fcard_set fsubseteq_set fsubset_set - inter_set union_set ffilter_set fset_to_set_simps + finter_set funion_set ffilter_set fset_to_set_simps fset_cong fdelete_set fmap_set_image fminus_set @@ -1193,13 +1160,16 @@ shows "S = {||} \ (\x. x |\| S \ S = finsert x (fdelete S x))" by (lifting fset_raw_delete_raw_cases) -text {* inter *} +text {* finite intersection *} -lemma finter_empty_l: "({||} |\| S) = {||}" - by (lifting finter_raw.simps(1)) +lemma finter_empty_l: + shows "{||} |\| S = {||}" + by simp -lemma finter_empty_r: "(S |\| {||}) = {||}" - by (lifting finter_raw_empty) + +lemma finter_empty_r: + shows "S |\| {||} = {||}" + by simp lemma finter_finsert: "finsert x S |\| T = (if x |\| T then finsert x (S |\| T) else S |\| T)" @@ -1210,30 +1180,36 @@ by (lifting memb_finter_raw) lemma fsubset_finsert: - "(finsert x xs |\| ys) = (x |\| ys \ xs |\| ys)" + shows "finsert x xs |\| ys \ x |\| ys \ xs |\| ys" by (lifting sub_list_cons) -lemma "xs |\| ys \ \x. x |\| xs \ x |\| ys" +lemma + shows "xs |\| ys \ \x. x |\| xs \ x |\| ys" by (lifting sub_list_def[simplified memb_def[symmetric]]) -lemma fsubset_fin: "xs |\| ys = (\x. x |\| xs \ x |\| ys)" +lemma fsubset_fin: + shows "xs |\| ys = (\x. x |\| xs \ x |\| ys)" by (rule meta_eq_to_obj_eq) (lifting sub_list_def[simplified memb_def[symmetric]]) -lemma fminus_fin: "(x |\| xs - ys) = (x |\| xs \ x |\| ys)" +lemma fminus_fin: + shows "x |\| xs - ys \ x |\| xs \ x |\| ys" by (lifting fminus_raw_memb) -lemma fminus_red: "finsert x xs - ys = (if x |\| ys then xs - ys else finsert x (xs - ys))" +lemma fminus_red: + shows "finsert x xs - ys = (if x |\| ys then xs - ys else finsert x (xs - ys))" by (lifting fminus_raw_red) -lemma fminus_red_fin[simp]: "x |\| ys \ finsert x xs - ys = xs - ys" +lemma fminus_red_fin [simp]: + shows "x |\| ys \ finsert x xs - ys = xs - ys" by (simp add: fminus_red) -lemma fminus_red_fnotin[simp]: "x |\| ys \ finsert x xs - ys = finsert x (xs - ys)" +lemma fminus_red_fnotin[simp]: + shows "x |\| ys \ finsert x xs - ys = finsert x (xs - ys)" by (simp add: fminus_red) lemma expand_fset_eq: - "(S = T) = (\x. (x |\| S) = (x |\| T))" + shows "S = T \ (\x. (x |\| S) = (x |\| T))" by (lifting list_eq.simps[simplified memb_def[symmetric]]) (* We cannot write it as "assumes .. shows" since Isabelle changes @@ -1261,7 +1237,7 @@ using assms by (lifting list_eq2.induct[simplified list_eq2_equiv[symmetric]]) -text {* concat *} +section {* fconcat *} lemma fconcat_empty: shows "fconcat {||} = {||}" @@ -1271,19 +1247,24 @@ shows "fconcat (finsert x S) = x |\| fconcat S" by (lifting concat.simps(2)) -lemma "fconcat (xs |\| ys) = fconcat xs |\| fconcat ys" +lemma + shows "fconcat (xs |\| ys) = fconcat xs |\| fconcat ys" by (lifting concat_append) -text {* ffilter *} + +section {* ffilter *} -lemma subseteq_filter: "ffilter P xs <= ffilter Q xs = (\ x. x |\| xs \ P x \ Q x)" -by (lifting sub_list_filter) +lemma subseteq_filter: + shows "ffilter P xs <= ffilter Q xs = (\ x. x |\| xs \ P x \ Q x)" + by (lifting sub_list_filter) -lemma eq_ffilter: "(ffilter P xs = ffilter Q xs) = (\x. x |\| xs \ P x = Q x)" -by (lifting list_eq_filter) +lemma eq_ffilter: + shows "(ffilter P xs = ffilter Q xs) = (\x. x |\| xs \ P x = Q x)" + by (lifting list_eq_filter) -lemma subset_ffilter: "(\x. x |\| xs \ P x \ Q x) \ (x |\| xs & \ P x & Q x) \ ffilter P xs < ffilter Q xs" -unfolding less_fset by (auto simp add: subseteq_filter eq_ffilter) +lemma subset_ffilter: + shows "(\x. x |\| xs \ P x \ Q x) \ (x |\| xs & \ P x & Q x) \ ffilter P xs < ffilter Q xs" + unfolding less_fset by (auto simp add: subseteq_filter eq_ffilter) section {* lemmas transferred from Finite_Set theory *} @@ -1291,67 +1272,82 @@ lemma finite_fset: "finite (fset_to_set S)" by (induct S) auto -lemma fset_choice: "\x. x |\| A \ (\y. P x y) \ \f. \x. x |\| A \ P x (f x)" +lemma fset_choice: + shows "\x. x |\| A \ (\y. P x y) \ \f. \x. x |\| A \ P x (f x)" unfolding fset_to_set_trans by (rule finite_set_choice[simplified Ball_def, OF finite_fset]) -lemma fsubseteq_fnil: "xs |\| {||} = (xs = {||})" +lemma fsubseteq_fnil: + shows "xs |\| {||} \ xs = {||}" unfolding fset_to_set_trans by (rule subset_empty) -lemma not_fsubset_fnil: "\ xs |\| {||}" +lemma not_fsubset_fnil: + shows "\ xs |\| {||}" unfolding fset_to_set_trans by (rule not_psubset_empty) -lemma fcard_mono: "xs |\| ys \ fcard xs \ fcard ys" +lemma fcard_mono: + shows "xs |\| ys \ fcard xs \ fcard ys" unfolding fset_to_set_trans by (rule card_mono[OF finite_fset]) -lemma fcard_fseteq: "xs |\| ys \ fcard ys \ fcard xs \ xs = ys" +lemma fcard_fseteq: + shows "xs |\| ys \ fcard ys \ fcard xs \ xs = ys" unfolding fset_to_set_trans by (rule card_seteq[OF finite_fset]) -lemma psubset_fcard_mono: "xs |\| ys \ fcard xs < fcard ys" +lemma psubset_fcard_mono: + shows "xs |\| ys \ fcard xs < fcard ys" unfolding fset_to_set_trans by (rule psubset_card_mono[OF finite_fset]) -lemma fcard_funion_finter: "fcard xs + fcard ys = fcard (xs |\| ys) + fcard (xs |\| ys)" +lemma fcard_funion_finter: + shows "fcard xs + fcard ys = fcard (xs |\| ys) + fcard (xs |\| ys)" unfolding fset_to_set_trans by (rule card_Un_Int[OF finite_fset finite_fset]) -lemma fcard_funion_disjoint: "xs |\| ys = {||} \ fcard (xs |\| ys) = fcard xs + fcard ys" +lemma fcard_funion_disjoint: + shows "xs |\| ys = {||} \ fcard (xs |\| ys) = fcard xs + fcard ys" unfolding fset_to_set_trans by (rule card_Un_disjoint[OF finite_fset finite_fset]) -lemma fcard_delete1_less: "x |\| xs \ fcard (fdelete xs x) < fcard xs" +lemma fcard_delete1_less: + shows "x |\| xs \ fcard (fdelete xs x) < fcard xs" unfolding fset_to_set_trans by (rule card_Diff1_less[OF finite_fset]) -lemma fcard_delete2_less: "x |\| xs \ y |\| xs \ fcard (fdelete (fdelete xs x) y) < fcard xs" +lemma fcard_delete2_less: + shows "x |\| xs \ y |\| xs \ fcard (fdelete (fdelete xs x) y) < fcard xs" unfolding fset_to_set_trans by (rule card_Diff2_less[OF finite_fset]) -lemma fcard_delete1_le: "fcard (fdelete xs x) <= fcard xs" +lemma fcard_delete1_le: + shows "fcard (fdelete xs x) \ fcard xs" unfolding fset_to_set_trans by (rule card_Diff1_le[OF finite_fset]) -lemma fcard_psubset: "ys |\| xs \ fcard ys < fcard xs \ ys |\| xs" +lemma fcard_psubset: + shows "ys |\| xs \ fcard ys < fcard xs \ ys |\| xs" unfolding fset_to_set_trans by (rule card_psubset[OF finite_fset]) -lemma fcard_fmap_le: "fcard (fmap f xs) \ fcard xs" +lemma fcard_fmap_le: + shows "fcard (fmap f xs) \ fcard xs" unfolding fset_to_set_trans by (rule card_image_le[OF finite_fset]) -lemma fin_fminus_fnotin: "x |\| F - S \ x |\| S" +lemma fin_fminus_fnotin: + shows "x |\| F - S \ x |\| S" unfolding fset_to_set_trans by blast -lemma fin_fnotin_fminus: "x |\| S \ x |\| F - S" +lemma fin_fnotin_fminus: + shows "x |\| S \ x |\| F - S" unfolding fset_to_set_trans by blast -lemma fin_mdef: "x |\| F = ((x |\| (F - {|x|})) & (F = finsert x (F - {|x|})))" +lemma fin_mdef: "x |\| F \ x |\| (F - {|x|}) \ F = finsert x (F - {|x|})" unfolding fset_to_set_trans by blast @@ -1370,7 +1366,7 @@ lemma fcard_fminus_subset_finter: "fcard (A - B) = fcard A - fcard (A |\| B)" unfolding fset_to_set_trans - by (rule card_Diff_subset_Int) (fold inter_set, rule finite_fset) + by (rule card_Diff_subset_Int) (fold finter_set, rule finite_fset) ML {*