| author | wenzelm | 
| Thu, 15 Aug 2019 16:57:09 +0200 | |
| changeset 70538 | fc9ba6fe367f | 
| parent 69745 | aec42cee2521 | 
| child 73477 | 1d8a79aa2a99 | 
| permissions | -rw-r--r-- | 
| 60727 | 1 | (* Title: HOL/Library/Disjoint_Sets.thy | 
| 2 | Author: Johannes Hölzl, TU München | |
| 3 | *) | |
| 4 | ||
| 63098 | 5 | section \<open>Partitions and Disjoint Sets\<close> | 
| 60727 | 6 | |
| 7 | theory Disjoint_Sets | |
| 8 | imports Main | |
| 9 | begin | |
| 10 | ||
| 11 | lemma range_subsetD: "range f \<subseteq> B \<Longrightarrow> f i \<in> B" | |
| 12 | by blast | |
| 13 | ||
| 14 | lemma Int_Diff_disjoint: "A \<inter> B \<inter> (A - B) = {}"
 | |
| 15 | by blast | |
| 16 | ||
| 17 | lemma Int_Diff_Un: "A \<inter> B \<union> (A - B) = A" | |
| 18 | by blast | |
| 19 | ||
| 20 | lemma mono_Un: "mono A \<Longrightarrow> (\<Union>i\<le>n. A i) = A n" | |
| 21 | unfolding mono_def by auto | |
| 22 | ||
| 63098 | 23 | lemma disjnt_equiv_class: "equiv A r \<Longrightarrow> disjnt (r``{a}) (r``{b}) \<longleftrightarrow> (a, b) \<notin> r"
 | 
| 24 | by (auto dest: equiv_class_self simp: equiv_class_eq_iff disjnt_def) | |
| 25 | ||
| 60727 | 26 | subsection \<open>Set of Disjoint Sets\<close> | 
| 27 | ||
| 62843 
313d3b697c9a
Mostly renaming (from HOL Light to Isabelle conventions), with a couple of new results
 paulson <lp15@cam.ac.uk> parents: 
62390diff
changeset | 28 | abbreviation disjoint :: "'a set set \<Rightarrow> bool" where "disjoint \<equiv> pairwise disjnt" | 
| 
313d3b697c9a
Mostly renaming (from HOL Light to Isabelle conventions), with a couple of new results
 paulson <lp15@cam.ac.uk> parents: 
62390diff
changeset | 29 | |
| 
313d3b697c9a
Mostly renaming (from HOL Light to Isabelle conventions), with a couple of new results
 paulson <lp15@cam.ac.uk> parents: 
62390diff
changeset | 30 | lemma disjoint_def: "disjoint A \<longleftrightarrow> (\<forall>a\<in>A. \<forall>b\<in>A. a \<noteq> b \<longrightarrow> a \<inter> b = {})"
 | 
| 
313d3b697c9a
Mostly renaming (from HOL Light to Isabelle conventions), with a couple of new results
 paulson <lp15@cam.ac.uk> parents: 
62390diff
changeset | 31 | unfolding pairwise_def disjnt_def by auto | 
| 60727 | 32 | |
| 33 | lemma disjointI: | |
| 34 |   "(\<And>a b. a \<in> A \<Longrightarrow> b \<in> A \<Longrightarrow> a \<noteq> b \<Longrightarrow> a \<inter> b = {}) \<Longrightarrow> disjoint A"
 | |
| 35 | unfolding disjoint_def by auto | |
| 36 | ||
| 37 | lemma disjointD: | |
| 38 |   "disjoint A \<Longrightarrow> a \<in> A \<Longrightarrow> b \<in> A \<Longrightarrow> a \<noteq> b \<Longrightarrow> a \<inter> b = {}"
 | |
| 39 | unfolding disjoint_def by auto | |
| 40 | ||
| 67399 | 41 | lemma disjoint_image: "inj_on f (\<Union>A) \<Longrightarrow> disjoint A \<Longrightarrow> disjoint ((`) f ` A)" | 
| 63099 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 42 | unfolding inj_on_def disjoint_def by blast | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 43 | |
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 44 | lemma assumes "disjoint (A \<union> B)" | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 45 | shows disjoint_unionD1: "disjoint A" and disjoint_unionD2: "disjoint B" | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 46 | using assms by (simp_all add: disjoint_def) | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 47 | |
| 60727 | 48 | lemma disjoint_INT: | 
| 49 | assumes *: "\<And>i. i \<in> I \<Longrightarrow> disjoint (F i)" | |
| 50 |   shows "disjoint {\<Inter>i\<in>I. X i | X. \<forall>i\<in>I. X i \<in> F i}"
 | |
| 51 | proof (safe intro!: disjointI del: equalityI) | |
| 63098 | 52 | fix A B :: "'a \<Rightarrow> 'b set" assume "(\<Inter>i\<in>I. A i) \<noteq> (\<Inter>i\<in>I. B i)" | 
| 60727 | 53 | then obtain i where "A i \<noteq> B i" "i \<in> I" | 
| 54 | by auto | |
| 55 | moreover assume "\<forall>i\<in>I. A i \<in> F i" "\<forall>i\<in>I. B i \<in> F i" | |
| 56 |   ultimately show "(\<Inter>i\<in>I. A i) \<inter> (\<Inter>i\<in>I. B i) = {}"
 | |
| 57 | using *[OF \<open>i\<in>I\<close>, THEN disjointD, of "A i" "B i"] | |
| 68406 | 58 | by (auto simp flip: INT_Int_distrib) | 
| 60727 | 59 | qed | 
| 60 | ||
| 69712 | 61 | lemma diff_Union_pairwise_disjoint: | 
| 62 | assumes "pairwise disjnt \<A>" "\<B> \<subseteq> \<A>" | |
| 63 | shows "\<Union>\<A> - \<Union>\<B> = \<Union>(\<A> - \<B>)" | |
| 64 | proof - | |
| 65 | have "False" | |
| 66 | if x: "x \<in> A" "x \<in> B" and AB: "A \<in> \<A>" "A \<notin> \<B>" "B \<in> \<B>" for x A B | |
| 67 | proof - | |
| 68 |     have "A \<inter> B = {}"
 | |
| 69 | using assms disjointD AB by blast | |
| 70 | with x show ?thesis | |
| 71 | by blast | |
| 72 | qed | |
| 73 | then show ?thesis by auto | |
| 74 | qed | |
| 75 | ||
| 76 | lemma Int_Union_pairwise_disjoint: | |
| 77 | assumes "pairwise disjnt (\<A> \<union> \<B>)" | |
| 78 | shows "\<Union>\<A> \<inter> \<Union>\<B> = \<Union>(\<A> \<inter> \<B>)" | |
| 79 | proof - | |
| 80 | have "False" | |
| 81 | if x: "x \<in> A" "x \<in> B" and AB: "A \<in> \<A>" "A \<notin> \<B>" "B \<in> \<B>" for x A B | |
| 82 | proof - | |
| 83 |     have "A \<inter> B = {}"
 | |
| 84 | using assms disjointD AB by blast | |
| 85 | with x show ?thesis | |
| 86 | by blast | |
| 87 | qed | |
| 88 | then show ?thesis by auto | |
| 89 | qed | |
| 90 | ||
| 91 | lemma psubset_Union_pairwise_disjoint: | |
| 92 |   assumes \<B>: "pairwise disjnt \<B>" and "\<A> \<subset> \<B> - {{}}"
 | |
| 93 | shows "\<Union>\<A> \<subset> \<Union>\<B>" | |
| 94 | unfolding psubset_eq | |
| 95 | proof | |
| 96 | show "\<Union>\<A> \<subseteq> \<Union>\<B>" | |
| 97 | using assms by blast | |
| 98 |   have "\<A> \<subseteq> \<B>" "\<Union>(\<B> - \<A> \<inter> (\<B> - {{}})) \<noteq> {}"
 | |
| 99 | using assms by blast+ | |
| 100 | then show "\<Union>\<A> \<noteq> \<Union>\<B>" | |
| 101 | using diff_Union_pairwise_disjoint [OF \<B>] by blast | |
| 102 | qed | |
| 103 | ||
| 60727 | 104 | subsubsection "Family of Disjoint Sets" | 
| 105 | ||
| 106 | definition disjoint_family_on :: "('i \<Rightarrow> 'a set) \<Rightarrow> 'i set \<Rightarrow> bool" where
 | |
| 107 |   "disjoint_family_on A S \<longleftrightarrow> (\<forall>m\<in>S. \<forall>n\<in>S. m \<noteq> n \<longrightarrow> A m \<inter> A n = {})"
 | |
| 108 | ||
| 109 | abbreviation "disjoint_family A \<equiv> disjoint_family_on A UNIV" | |
| 110 | ||
| 63928 
d81fb5b46a5c
new material about topological concepts, etc
 paulson <lp15@cam.ac.uk> parents: 
63148diff
changeset | 111 | lemma disjoint_family_elem_disjnt: | 
| 
d81fb5b46a5c
new material about topological concepts, etc
 paulson <lp15@cam.ac.uk> parents: 
63148diff
changeset | 112 | assumes "infinite A" "finite C" | 
| 
d81fb5b46a5c
new material about topological concepts, etc
 paulson <lp15@cam.ac.uk> parents: 
63148diff
changeset | 113 | and df: "disjoint_family_on B A" | 
| 
d81fb5b46a5c
new material about topological concepts, etc
 paulson <lp15@cam.ac.uk> parents: 
63148diff
changeset | 114 | obtains x where "x \<in> A" "disjnt C (B x)" | 
| 
d81fb5b46a5c
new material about topological concepts, etc
 paulson <lp15@cam.ac.uk> parents: 
63148diff
changeset | 115 | proof - | 
| 
d81fb5b46a5c
new material about topological concepts, etc
 paulson <lp15@cam.ac.uk> parents: 
63148diff
changeset | 116 | have "False" if *: "\<forall>x \<in> A. \<exists>y. y \<in> C \<and> y \<in> B x" | 
| 
d81fb5b46a5c
new material about topological concepts, etc
 paulson <lp15@cam.ac.uk> parents: 
63148diff
changeset | 117 | proof - | 
| 
d81fb5b46a5c
new material about topological concepts, etc
 paulson <lp15@cam.ac.uk> parents: 
63148diff
changeset | 118 | obtain g where g: "\<forall>x \<in> A. g x \<in> C \<and> g x \<in> B x" | 
| 
d81fb5b46a5c
new material about topological concepts, etc
 paulson <lp15@cam.ac.uk> parents: 
63148diff
changeset | 119 | using * by metis | 
| 
d81fb5b46a5c
new material about topological concepts, etc
 paulson <lp15@cam.ac.uk> parents: 
63148diff
changeset | 120 | with df have "inj_on g A" | 
| 
d81fb5b46a5c
new material about topological concepts, etc
 paulson <lp15@cam.ac.uk> parents: 
63148diff
changeset | 121 | by (fastforce simp add: inj_on_def disjoint_family_on_def) | 
| 
d81fb5b46a5c
new material about topological concepts, etc
 paulson <lp15@cam.ac.uk> parents: 
63148diff
changeset | 122 | then have "infinite (g ` A)" | 
| 
d81fb5b46a5c
new material about topological concepts, etc
 paulson <lp15@cam.ac.uk> parents: 
63148diff
changeset | 123 | using \<open>infinite A\<close> finite_image_iff by blast | 
| 
d81fb5b46a5c
new material about topological concepts, etc
 paulson <lp15@cam.ac.uk> parents: 
63148diff
changeset | 124 | then show False | 
| 
d81fb5b46a5c
new material about topological concepts, etc
 paulson <lp15@cam.ac.uk> parents: 
63148diff
changeset | 125 | by (meson \<open>finite C\<close> finite_subset g image_subset_iff) | 
| 
d81fb5b46a5c
new material about topological concepts, etc
 paulson <lp15@cam.ac.uk> parents: 
63148diff
changeset | 126 | qed | 
| 
d81fb5b46a5c
new material about topological concepts, etc
 paulson <lp15@cam.ac.uk> parents: 
63148diff
changeset | 127 | then show ?thesis | 
| 
d81fb5b46a5c
new material about topological concepts, etc
 paulson <lp15@cam.ac.uk> parents: 
63148diff
changeset | 128 | by (force simp: disjnt_iff intro: that) | 
| 
d81fb5b46a5c
new material about topological concepts, etc
 paulson <lp15@cam.ac.uk> parents: 
63148diff
changeset | 129 | qed | 
| 
d81fb5b46a5c
new material about topological concepts, etc
 paulson <lp15@cam.ac.uk> parents: 
63148diff
changeset | 130 | |
| 60727 | 131 | lemma disjoint_family_onD: | 
| 132 |   "disjoint_family_on A I \<Longrightarrow> i \<in> I \<Longrightarrow> j \<in> I \<Longrightarrow> i \<noteq> j \<Longrightarrow> A i \<inter> A j = {}"
 | |
| 133 | by (auto simp: disjoint_family_on_def) | |
| 134 | ||
| 135 | lemma disjoint_family_subset: "disjoint_family A \<Longrightarrow> (\<And>x. B x \<subseteq> A x) \<Longrightarrow> disjoint_family B" | |
| 136 | by (force simp add: disjoint_family_on_def) | |
| 137 | ||
| 138 | lemma disjoint_family_on_bisimulation: | |
| 139 | assumes "disjoint_family_on f S" | |
| 140 |   and "\<And>n m. n \<in> S \<Longrightarrow> m \<in> S \<Longrightarrow> n \<noteq> m \<Longrightarrow> f n \<inter> f m = {} \<Longrightarrow> g n \<inter> g m = {}"
 | |
| 141 | shows "disjoint_family_on g S" | |
| 142 | using assms unfolding disjoint_family_on_def by auto | |
| 143 | ||
| 144 | lemma disjoint_family_on_mono: | |
| 145 | "A \<subseteq> B \<Longrightarrow> disjoint_family_on f B \<Longrightarrow> disjoint_family_on f A" | |
| 146 | unfolding disjoint_family_on_def by auto | |
| 147 | ||
| 148 | lemma disjoint_family_Suc: | |
| 149 | "(\<And>n. A n \<subseteq> A (Suc n)) \<Longrightarrow> disjoint_family (\<lambda>i. A (Suc i) - A i)" | |
| 150 | using lift_Suc_mono_le[of A] | |
| 151 | by (auto simp add: disjoint_family_on_def) | |
| 61824 
dcbe9f756ae0
not_leE -> not_le_imp_less and other tidying
 paulson <lp15@cam.ac.uk> parents: 
60727diff
changeset | 152 | (metis insert_absorb insert_subset le_SucE le_antisym not_le_imp_less less_imp_le) | 
| 60727 | 153 | |
| 154 | lemma disjoint_family_on_disjoint_image: | |
| 155 | "disjoint_family_on A I \<Longrightarrow> disjoint (A ` I)" | |
| 156 | unfolding disjoint_family_on_def disjoint_def by force | |
| 63099 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 157 | |
| 60727 | 158 | lemma disjoint_family_on_vimageI: "disjoint_family_on F I \<Longrightarrow> disjoint_family_on (\<lambda>i. f -` F i) I" | 
| 159 | by (auto simp: disjoint_family_on_def) | |
| 160 | ||
| 161 | lemma disjoint_image_disjoint_family_on: | |
| 162 | assumes d: "disjoint (A ` I)" and i: "inj_on A I" | |
| 163 | shows "disjoint_family_on A I" | |
| 164 | unfolding disjoint_family_on_def | |
| 165 | proof (intro ballI impI) | |
| 166 | fix n m assume nm: "m \<in> I" "n \<in> I" and "n \<noteq> m" | |
| 167 |   with i[THEN inj_onD, of n m] show "A n \<inter> A m = {}"
 | |
| 168 | by (intro disjointD[OF d]) auto | |
| 169 | qed | |
| 170 | ||
| 171 | lemma disjoint_UN: | |
| 69745 | 172 | assumes F: "\<And>i. i \<in> I \<Longrightarrow> disjoint (F i)" and *: "disjoint_family_on (\<lambda>i. \<Union>(F i)) I" | 
| 60727 | 173 | shows "disjoint (\<Union>i\<in>I. F i)" | 
| 174 | proof (safe intro!: disjointI del: equalityI) | |
| 175 | fix A B i j assume "A \<noteq> B" "A \<in> F i" "i \<in> I" "B \<in> F j" "j \<in> I" | |
| 176 |   show "A \<inter> B = {}"
 | |
| 177 | proof cases | |
| 178 |     assume "i = j" with F[of i] \<open>i \<in> I\<close> \<open>A \<in> F i\<close> \<open>B \<in> F j\<close> \<open>A \<noteq> B\<close> show "A \<inter> B = {}"
 | |
| 179 | by (auto dest: disjointD) | |
| 180 | next | |
| 181 | assume "i \<noteq> j" | |
| 69745 | 182 |     with * \<open>i\<in>I\<close> \<open>j\<in>I\<close> have "(\<Union>(F i)) \<inter> (\<Union>(F j)) = {}"
 | 
| 60727 | 183 | by (rule disjoint_family_onD) | 
| 184 | with \<open>A\<in>F i\<close> \<open>i\<in>I\<close> \<open>B\<in>F j\<close> \<open>j\<in>I\<close> | |
| 185 |     show "A \<inter> B = {}"
 | |
| 186 | by auto | |
| 187 | qed | |
| 188 | qed | |
| 189 | ||
| 63099 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 190 | lemma distinct_list_bind: | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 191 | assumes "distinct xs" "\<And>x. x \<in> set xs \<Longrightarrow> distinct (f x)" | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 192 | "disjoint_family_on (set \<circ> f) (set xs)" | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 193 | shows "distinct (List.bind xs f)" | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 194 | using assms | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 195 | by (induction xs) | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 196 | (auto simp: disjoint_family_on_def distinct_map inj_on_def set_list_bind) | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 197 | |
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 198 | lemma bij_betw_UNION_disjoint: | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 199 | assumes disj: "disjoint_family_on A' I" | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 200 | assumes bij: "\<And>i. i \<in> I \<Longrightarrow> bij_betw f (A i) (A' i)" | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 201 | shows "bij_betw f (\<Union>i\<in>I. A i) (\<Union>i\<in>I. A' i)" | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 202 | unfolding bij_betw_def | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 203 | proof | 
| 69313 | 204 | from bij show eq: "f ` \<Union>(A ` I) = \<Union>(A' ` I)" | 
| 63099 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 205 | by (auto simp: bij_betw_def image_UN) | 
| 69313 | 206 | show "inj_on f (\<Union>(A ` I))" | 
| 63099 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 207 | proof (rule inj_onI, clarify) | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 208 | fix i j x y assume A: "i \<in> I" "j \<in> I" "x \<in> A i" "y \<in> A j" and B: "f x = f y" | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 209 | from A bij[of i] bij[of j] have "f x \<in> A' i" "f y \<in> A' j" | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 210 | by (auto simp: bij_betw_def) | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 211 |     with B have "A' i \<inter> A' j \<noteq> {}" by auto
 | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 212 | with disj A have "i = j" unfolding disjoint_family_on_def by blast | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 213 | with A B bij[of i] show "x = y" by (auto simp: bij_betw_def dest: inj_onD) | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 214 | qed | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 215 | qed | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 216 | |
| 60727 | 217 | lemma disjoint_union: "disjoint C \<Longrightarrow> disjoint B \<Longrightarrow> \<Union>C \<inter> \<Union>B = {} \<Longrightarrow> disjoint (C \<union> B)"
 | 
| 218 |   using disjoint_UN[of "{C, B}" "\<lambda>x. x"] by (auto simp add: disjoint_family_on_def)
 | |
| 219 | ||
| 63099 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 220 | text \<open> | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 221 | The union of an infinite disjoint family of non-empty sets is infinite. | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 222 | \<close> | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 223 | lemma infinite_disjoint_family_imp_infinite_UNION: | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 224 |   assumes "\<not>finite A" "\<And>x. x \<in> A \<Longrightarrow> f x \<noteq> {}" "disjoint_family_on f A"
 | 
| 69313 | 225 | shows "\<not>finite (\<Union>(f ` A))" | 
| 63099 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 226 | proof - | 
| 63148 | 227 | define g where "g x = (SOME y. y \<in> f x)" for x | 
| 63099 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 228 | have g: "g x \<in> f x" if "x \<in> A" for x | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 229 | unfolding g_def by (rule someI_ex, insert assms(2) that) blast | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 230 | have inj_on_g: "inj_on g A" | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 231 | proof (rule inj_onI, rule ccontr) | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 232 | fix x y assume A: "x \<in> A" "y \<in> A" "g x = g y" "x \<noteq> y" | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 233 | with g[of x] g[of y] have "g x \<in> f x" "g x \<in> f y" by auto | 
| 63145 | 234 | with A \<open>x \<noteq> y\<close> assms show False | 
| 63099 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 235 | by (auto simp: disjoint_family_on_def inj_on_def) | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 236 | qed | 
| 69313 | 237 | from g have "g ` A \<subseteq> \<Union>(f ` A)" by blast | 
| 63099 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 238 | moreover from inj_on_g \<open>\<not>finite A\<close> have "\<not>finite (g ` A)" | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 239 | using finite_imageD by blast | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 240 | ultimately show ?thesis using finite_subset by blast | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 241 | qed | 
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 242 | |
| 
af0e964aad7b
Moved material from AFP/Randomised_Social_Choice to distribution
 eberlm parents: 
62843diff
changeset | 243 | |
| 60727 | 244 | subsection \<open>Construct Disjoint Sequences\<close> | 
| 245 | ||
| 246 | definition disjointed :: "(nat \<Rightarrow> 'a set) \<Rightarrow> nat \<Rightarrow> 'a set" where | |
| 247 |   "disjointed A n = A n - (\<Union>i\<in>{0..<n}. A i)"
 | |
| 248 | ||
| 249 | lemma finite_UN_disjointed_eq: "(\<Union>i\<in>{0..<n}. disjointed A i) = (\<Union>i\<in>{0..<n}. A i)"
 | |
| 250 | proof (induct n) | |
| 251 | case 0 show ?case by simp | |
| 252 | next | |
| 253 | case (Suc n) | |
| 254 | thus ?case by (simp add: atLeastLessThanSuc disjointed_def) | |
| 255 | qed | |
| 256 | ||
| 257 | lemma UN_disjointed_eq: "(\<Union>i. disjointed A i) = (\<Union>i. A i)" | |
| 258 | by (rule UN_finite2_eq [where k=0]) | |
| 259 | (simp add: finite_UN_disjointed_eq) | |
| 260 | ||
| 261 | lemma less_disjoint_disjointed: "m < n \<Longrightarrow> disjointed A m \<inter> disjointed A n = {}"
 | |
| 262 | by (auto simp add: disjointed_def) | |
| 263 | ||
| 264 | lemma disjoint_family_disjointed: "disjoint_family (disjointed A)" | |
| 265 | by (simp add: disjoint_family_on_def) | |
| 266 | (metis neq_iff Int_commute less_disjoint_disjointed) | |
| 267 | ||
| 268 | lemma disjointed_subset: "disjointed A n \<subseteq> A n" | |
| 269 | by (auto simp add: disjointed_def) | |
| 270 | ||
| 271 | lemma disjointed_0[simp]: "disjointed A 0 = A 0" | |
| 272 | by (simp add: disjointed_def) | |
| 273 | ||
| 274 | lemma disjointed_mono: "mono A \<Longrightarrow> disjointed A (Suc n) = A (Suc n) - A n" | |
| 275 | using mono_Un[of A] by (simp add: disjointed_def atLeastLessThanSuc_atLeastAtMost atLeast0AtMost) | |
| 276 | ||
| 63098 | 277 | subsection \<open>Partitions\<close> | 
| 278 | ||
| 279 | text \<open> | |
| 69593 | 280 | Partitions \<^term>\<open>P\<close> of a set \<^term>\<open>A\<close>. We explicitly disallow empty sets. | 
| 63098 | 281 | \<close> | 
| 282 | ||
| 283 | definition partition_on :: "'a set \<Rightarrow> 'a set set \<Rightarrow> bool" | |
| 284 | where | |
| 285 |   "partition_on A P \<longleftrightarrow> \<Union>P = A \<and> disjoint P \<and> {} \<notin> P"
 | |
| 286 | ||
| 287 | lemma partition_onI: | |
| 288 |   "\<Union>P = A \<Longrightarrow> (\<And>p q. p \<in> P \<Longrightarrow> q \<in> P \<Longrightarrow> p \<noteq> q \<Longrightarrow> disjnt p q) \<Longrightarrow> {} \<notin> P \<Longrightarrow> partition_on A P"
 | |
| 289 | by (auto simp: partition_on_def pairwise_def) | |
| 290 | ||
| 291 | lemma partition_onD1: "partition_on A P \<Longrightarrow> A = \<Union>P" | |
| 292 | by (auto simp: partition_on_def) | |
| 293 | ||
| 294 | lemma partition_onD2: "partition_on A P \<Longrightarrow> disjoint P" | |
| 295 | by (auto simp: partition_on_def) | |
| 296 | ||
| 297 | lemma partition_onD3: "partition_on A P \<Longrightarrow> {} \<notin> P"
 | |
| 298 | by (auto simp: partition_on_def) | |
| 299 | ||
| 300 | subsection \<open>Constructions of partitions\<close> | |
| 301 | ||
| 302 | lemma partition_on_empty: "partition_on {} P \<longleftrightarrow> P = {}"
 | |
| 303 | unfolding partition_on_def by fastforce | |
| 304 | ||
| 305 | lemma partition_on_space: "A \<noteq> {} \<Longrightarrow> partition_on A {A}"
 | |
| 306 | by (auto simp: partition_on_def disjoint_def) | |
| 307 | ||
| 308 | lemma partition_on_singletons: "partition_on A ((\<lambda>x. {x}) ` A)"
 | |
| 309 | by (auto simp: partition_on_def disjoint_def) | |
| 310 | ||
| 311 | lemma partition_on_transform: | |
| 312 | assumes P: "partition_on A P" | |
| 313 | assumes F_UN: "\<Union>(F ` P) = F (\<Union>P)" and F_disjnt: "\<And>p q. p \<in> P \<Longrightarrow> q \<in> P \<Longrightarrow> disjnt p q \<Longrightarrow> disjnt (F p) (F q)" | |
| 314 |   shows "partition_on (F A) (F ` P - {{}})"
 | |
| 315 | proof - | |
| 316 |   have "\<Union>(F ` P - {{}}) = F A"
 | |
| 317 | unfolding P[THEN partition_onD1] F_UN[symmetric] by auto | |
| 318 | with P show ?thesis | |
| 319 | by (auto simp add: partition_on_def pairwise_def intro!: F_disjnt) | |
| 320 | qed | |
| 321 | ||
| 67399 | 322 | lemma partition_on_restrict: "partition_on A P \<Longrightarrow> partition_on (B \<inter> A) ((\<inter>) B ` P - {{}})"
 | 
| 63098 | 323 | by (intro partition_on_transform) (auto simp: disjnt_def) | 
| 324 | ||
| 67399 | 325 | lemma partition_on_vimage: "partition_on A P \<Longrightarrow> partition_on (f -` A) ((-`) f ` P - {{}})"
 | 
| 63098 | 326 | by (intro partition_on_transform) (auto simp: disjnt_def) | 
| 327 | ||
| 328 | lemma partition_on_inj_image: | |
| 329 | assumes P: "partition_on A P" and f: "inj_on f A" | |
| 67399 | 330 |   shows "partition_on (f ` A) ((`) f ` P - {{}})"
 | 
| 63098 | 331 | proof (rule partition_on_transform[OF P]) | 
| 332 | show "p \<in> P \<Longrightarrow> q \<in> P \<Longrightarrow> disjnt p q \<Longrightarrow> disjnt (f ` p) (f ` q)" for p q | |
| 333 | using f[THEN inj_onD] P[THEN partition_onD1] by (auto simp: disjnt_def) | |
| 334 | qed auto | |
| 335 | ||
| 336 | subsection \<open>Finiteness of partitions\<close> | |
| 337 | ||
| 338 | lemma finitely_many_partition_on: | |
| 339 | assumes "finite A" | |
| 340 |   shows "finite {P. partition_on A P}"
 | |
| 341 | proof (rule finite_subset) | |
| 342 |   show "{P. partition_on A P} \<subseteq> Pow (Pow A)"
 | |
| 343 | unfolding partition_on_def by auto | |
| 344 | show "finite (Pow (Pow A))" | |
| 345 | using assms by simp | |
| 346 | qed | |
| 347 | ||
| 348 | lemma finite_elements: "finite A \<Longrightarrow> partition_on A P \<Longrightarrow> finite P" | |
| 349 | using partition_onD1[of A P] by (simp add: finite_UnionD) | |
| 350 | ||
| 351 | subsection \<open>Equivalence of partitions and equivalence classes\<close> | |
| 352 | ||
| 353 | lemma partition_on_quotient: | |
| 354 | assumes r: "equiv A r" | |
| 355 | shows "partition_on A (A // r)" | |
| 356 | proof (rule partition_onI) | |
| 357 | from r have "refl_on A r" | |
| 358 | by (auto elim: equivE) | |
| 359 |   then show "\<Union>(A // r) = A" "{} \<notin> A // r"
 | |
| 360 | by (auto simp: refl_on_def quotient_def) | |
| 361 | ||
| 362 | fix p q assume "p \<in> A // r" "q \<in> A // r" "p \<noteq> q" | |
| 363 |   then obtain x y where "x \<in> A" "y \<in> A" "p = r `` {x}" "q = r `` {y}"
 | |
| 364 | by (auto simp: quotient_def) | |
| 365 | with r equiv_class_eq_iff[OF r, of x y] \<open>p \<noteq> q\<close> show "disjnt p q" | |
| 366 | by (auto simp: disjnt_equiv_class) | |
| 367 | qed | |
| 368 | ||
| 369 | lemma equiv_partition_on: | |
| 370 | assumes P: "partition_on A P" | |
| 371 |   shows "equiv A {(x, y). \<exists>p \<in> P. x \<in> p \<and> y \<in> p}"
 | |
| 372 | proof (rule equivI) | |
| 373 |   have "A = \<Union>P" "disjoint P" "{} \<notin> P"
 | |
| 374 | using P by (auto simp: partition_on_def) | |
| 375 |   then show "refl_on A {(x, y). \<exists>p\<in>P. x \<in> p \<and> y \<in> p}"
 | |
| 376 | unfolding refl_on_def by auto | |
| 377 |   show "trans {(x, y). \<exists>p\<in>P. x \<in> p \<and> y \<in> p}"
 | |
| 378 | using \<open>disjoint P\<close> by (auto simp: trans_def disjoint_def) | |
| 379 | qed (auto simp: sym_def) | |
| 380 | ||
| 381 | lemma partition_on_eq_quotient: | |
| 382 | assumes P: "partition_on A P" | |
| 383 |   shows "A // {(x, y). \<exists>p \<in> P. x \<in> p \<and> y \<in> p} = P"
 | |
| 384 | unfolding quotient_def | |
| 385 | proof safe | |
| 386 | fix x assume "x \<in> A" | |
| 387 | then obtain p where "p \<in> P" "x \<in> p" "\<And>q. q \<in> P \<Longrightarrow> x \<in> q \<Longrightarrow> p = q" | |
| 388 | using P by (auto simp: partition_on_def disjoint_def) | |
| 389 |   then have "{y. \<exists>p\<in>P. x \<in> p \<and> y \<in> p} = p"
 | |
| 390 | by (safe intro!: bexI[of _ p]) simp | |
| 391 |   then show "{(x, y). \<exists>p\<in>P. x \<in> p \<and> y \<in> p} `` {x} \<in> P"
 | |
| 392 | by (simp add: \<open>p \<in> P\<close>) | |
| 393 | next | |
| 394 | fix p assume "p \<in> P" | |
| 395 |   then have "p \<noteq> {}"
 | |
| 396 | using P by (auto simp: partition_on_def) | |
| 397 | then obtain x where "x \<in> p" | |
| 398 | by auto | |
| 399 | then have "x \<in> A" "\<And>q. q \<in> P \<Longrightarrow> x \<in> q \<Longrightarrow> p = q" | |
| 400 | using P \<open>p \<in> P\<close> by (auto simp: partition_on_def disjoint_def) | |
| 401 |   with \<open>p\<in>P\<close> \<open>x \<in> p\<close> have "{y. \<exists>p\<in>P. x \<in> p \<and> y \<in> p} = p"
 | |
| 402 | by (safe intro!: bexI[of _ p]) simp | |
| 403 |   then show "p \<in> (\<Union>x\<in>A. {{(x, y). \<exists>p\<in>P. x \<in> p \<and> y \<in> p} `` {x}})"
 | |
| 404 | by (auto intro: \<open>x \<in> A\<close>) | |
| 405 | qed | |
| 406 | ||
| 407 | lemma partition_on_alt: "partition_on A P \<longleftrightarrow> (\<exists>r. equiv A r \<and> P = A // r)" | |
| 408 | by (auto simp: partition_on_eq_quotient intro!: partition_on_quotient intro: equiv_partition_on) | |
| 409 | ||
| 62390 | 410 | end |