src/HOL/Library/More_Set.thy
 author bulwahn Fri Apr 08 16:31:14 2011 +0200 (2011-04-08) changeset 42316 12635bb655fd parent 39302 d7728f65b353 child 42868 1608daf27c1f permissions -rw-r--r--
deactivating other compilations in quickcheck_exhaustive momentarily that only interesting for my benchmarks and experiments
 haftmann@31807 ` 1` haftmann@31807 ` 2` ```(* Author: Florian Haftmann, TU Muenchen *) ``` haftmann@31807 ` 3` haftmann@31807 ` 4` ```header {* Relating (finite) sets and lists *} ``` haftmann@31807 ` 5` haftmann@37024 ` 6` ```theory More_Set ``` haftmann@37023 ` 7` ```imports Main More_List ``` haftmann@31807 ` 8` ```begin ``` haftmann@31807 ` 9` haftmann@31807 ` 10` ```subsection {* Various additional set functions *} ``` haftmann@31807 ` 11` haftmann@31807 ` 12` ```definition is_empty :: "'a set \ bool" where ``` haftmann@31807 ` 13` ``` "is_empty A \ A = {}" ``` haftmann@31807 ` 14` haftmann@31807 ` 15` ```definition remove :: "'a \ 'a set \ 'a set" where ``` haftmann@31807 ` 16` ``` "remove x A = A - {x}" ``` haftmann@31807 ` 17` haftmann@31807 ` 18` ```lemma fun_left_comm_idem_remove: ``` haftmann@31807 ` 19` ``` "fun_left_comm_idem remove" ``` haftmann@31807 ` 20` ```proof - ``` nipkow@39302 ` 21` ``` have rem: "remove = (\x A. A - {x})" by (simp add: fun_eq_iff remove_def) ``` haftmann@31807 ` 22` ``` show ?thesis by (simp only: fun_left_comm_idem_remove rem) ``` haftmann@31807 ` 23` ```qed ``` haftmann@31807 ` 24` haftmann@31807 ` 25` ```lemma minus_fold_remove: ``` haftmann@31807 ` 26` ``` assumes "finite A" ``` haftmann@37023 ` 27` ``` shows "B - A = Finite_Set.fold remove B A" ``` haftmann@31807 ` 28` ```proof - ``` nipkow@39302 ` 29` ``` have rem: "remove = (\x A. A - {x})" by (simp add: fun_eq_iff remove_def) ``` haftmann@31807 ` 30` ``` show ?thesis by (simp only: rem assms minus_fold_remove) ``` haftmann@31807 ` 31` ```qed ``` haftmann@31807 ` 32` haftmann@31807 ` 33` ```definition project :: "('a \ bool) \ 'a set \ 'a set" where ``` haftmann@31807 ` 34` ``` "project P A = {a\A. P a}" ``` haftmann@31807 ` 35` haftmann@31807 ` 36` haftmann@31807 ` 37` ```subsection {* Basic set operations *} ``` haftmann@31807 ` 38` haftmann@31807 ` 39` ```lemma is_empty_set: ``` haftmann@37595 ` 40` ``` "is_empty (set xs) \ List.null xs" ``` haftmann@37595 ` 41` ``` by (simp add: is_empty_def null_def) ``` haftmann@31807 ` 42` haftmann@31807 ` 43` ```lemma empty_set: ``` haftmann@31807 ` 44` ``` "{} = set []" ``` haftmann@31807 ` 45` ``` by simp ``` haftmann@31807 ` 46` haftmann@32880 ` 47` ```lemma insert_set_compl: ``` haftmann@34977 ` 48` ``` "insert x (- set xs) = - set (removeAll x xs)" ``` haftmann@34977 ` 49` ``` by auto ``` haftmann@31807 ` 50` haftmann@32880 ` 51` ```lemma remove_set_compl: ``` haftmann@34977 ` 52` ``` "remove x (- set xs) = - set (List.insert x xs)" ``` haftmann@34977 ` 53` ``` by (auto simp del: mem_def simp add: remove_def List.insert_def) ``` haftmann@32880 ` 54` haftmann@31807 ` 55` ```lemma image_set: ``` haftmann@31846 ` 56` ``` "image f (set xs) = set (map f xs)" ``` haftmann@31807 ` 57` ``` by simp ``` haftmann@31807 ` 58` haftmann@31807 ` 59` ```lemma project_set: ``` haftmann@31807 ` 60` ``` "project P (set xs) = set (filter P xs)" ``` haftmann@31807 ` 61` ``` by (auto simp add: project_def) ``` haftmann@31807 ` 62` haftmann@31807 ` 63` haftmann@31807 ` 64` ```subsection {* Functorial set operations *} ``` haftmann@31807 ` 65` haftmann@31807 ` 66` ```lemma union_set: ``` haftmann@37023 ` 67` ``` "set xs \ A = fold Set.insert xs A" ``` haftmann@31807 ` 68` ```proof - ``` haftmann@31807 ` 69` ``` interpret fun_left_comm_idem Set.insert ``` haftmann@31807 ` 70` ``` by (fact fun_left_comm_idem_insert) ``` haftmann@31807 ` 71` ``` show ?thesis by (simp add: union_fold_insert fold_set) ``` haftmann@31807 ` 72` ```qed ``` haftmann@31807 ` 73` haftmann@37023 ` 74` ```lemma union_set_foldr: ``` haftmann@37023 ` 75` ``` "set xs \ A = foldr Set.insert xs A" ``` haftmann@37023 ` 76` ```proof - ``` haftmann@37023 ` 77` ``` have "\x y :: 'a. insert y \ insert x = insert x \ insert y" ``` haftmann@37023 ` 78` ``` by (auto intro: ext) ``` haftmann@37023 ` 79` ``` then show ?thesis by (simp add: union_set foldr_fold) ``` haftmann@37023 ` 80` ```qed ``` haftmann@37023 ` 81` haftmann@31807 ` 82` ```lemma minus_set: ``` haftmann@37023 ` 83` ``` "A - set xs = fold remove xs A" ``` haftmann@31807 ` 84` ```proof - ``` haftmann@31807 ` 85` ``` interpret fun_left_comm_idem remove ``` haftmann@31807 ` 86` ``` by (fact fun_left_comm_idem_remove) ``` haftmann@31807 ` 87` ``` show ?thesis ``` haftmann@31807 ` 88` ``` by (simp add: minus_fold_remove [of _ A] fold_set) ``` haftmann@31807 ` 89` ```qed ``` haftmann@31807 ` 90` haftmann@37023 ` 91` ```lemma minus_set_foldr: ``` haftmann@37023 ` 92` ``` "A - set xs = foldr remove xs A" ``` haftmann@37023 ` 93` ```proof - ``` haftmann@37023 ` 94` ``` have "\x y :: 'a. remove y \ remove x = remove x \ remove y" ``` haftmann@37023 ` 95` ``` by (auto simp add: remove_def intro: ext) ``` haftmann@37023 ` 96` ``` then show ?thesis by (simp add: minus_set foldr_fold) ``` haftmann@37023 ` 97` ```qed ``` haftmann@37023 ` 98` haftmann@31807 ` 99` haftmann@31807 ` 100` ```subsection {* Derived set operations *} ``` haftmann@31807 ` 101` haftmann@31807 ` 102` ```lemma member: ``` haftmann@31807 ` 103` ``` "a \ A \ (\x\A. a = x)" ``` haftmann@31807 ` 104` ``` by simp ``` haftmann@31807 ` 105` haftmann@31807 ` 106` ```lemma subset_eq: ``` haftmann@31807 ` 107` ``` "A \ B \ (\x\A. x \ B)" ``` haftmann@31807 ` 108` ``` by (fact subset_eq) ``` haftmann@31807 ` 109` haftmann@31807 ` 110` ```lemma subset: ``` haftmann@31807 ` 111` ``` "A \ B \ A \ B \ \ B \ A" ``` haftmann@31807 ` 112` ``` by (fact less_le_not_le) ``` haftmann@31807 ` 113` haftmann@31807 ` 114` ```lemma set_eq: ``` haftmann@31807 ` 115` ``` "A = B \ A \ B \ B \ A" ``` haftmann@31807 ` 116` ``` by (fact eq_iff) ``` haftmann@31807 ` 117` haftmann@31807 ` 118` ```lemma inter: ``` haftmann@31807 ` 119` ``` "A \ B = project (\x. x \ A) B" ``` haftmann@31807 ` 120` ``` by (auto simp add: project_def) ``` haftmann@31807 ` 121` haftmann@37023 ` 122` haftmann@37023 ` 123` ```subsection {* Various lemmas *} ``` haftmann@37023 ` 124` haftmann@37023 ` 125` ```lemma not_set_compl: ``` haftmann@37023 ` 126` ``` "Not \ set xs = - set xs" ``` nipkow@39302 ` 127` ``` by (simp add: fun_Compl_def bool_Compl_def comp_def fun_eq_iff) ``` haftmann@37023 ` 128` haftmann@37024 ` 129` ```end ```