| author | wenzelm | 
| Sat, 23 Aug 2008 17:22:53 +0200 | |
| changeset 27952 | 0576c91a6803 | 
| parent 26791 | 3581a9c71909 | 
| child 28229 | 4f06fae6a55e | 
| permissions | -rw-r--r-- | 
| 15300 | 1 | (* ID: $Id$ | 
| 2 | Authors: Lawrence C Paulson, Cambridge University Computer Laboratory | |
| 3 | Copyright 1996 University of Cambridge | |
| 4 | *) | |
| 5 | ||
| 6 | header {* Equivalence Relations in Higher-Order Set Theory *}
 | |
| 7 | ||
| 8 | theory Equiv_Relations | |
| 24728 | 9 | imports Finite_Set Relation | 
| 15300 | 10 | begin | 
| 11 | ||
| 12 | subsection {* Equivalence relations *}
 | |
| 13 | ||
| 14 | locale equiv = | |
| 15 | fixes A and r | |
| 16 | assumes refl: "refl A r" | |
| 17 | and sym: "sym r" | |
| 18 | and trans: "trans r" | |
| 19 | ||
| 20 | text {*
 | |
| 21 |   Suppes, Theorem 70: @{text r} is an equiv relation iff @{text "r\<inverse> O
 | |
| 22 | r = r"}. | |
| 23 | ||
| 24 |   First half: @{text "equiv A r ==> r\<inverse> O r = r"}.
 | |
| 25 | *} | |
| 26 | ||
| 27 | lemma sym_trans_comp_subset: | |
| 28 | "sym r ==> trans r ==> r\<inverse> O r \<subseteq> r" | |
| 29 | by (unfold trans_def sym_def converse_def) blast | |
| 30 | ||
| 31 | lemma refl_comp_subset: "refl A r ==> r \<subseteq> r\<inverse> O r" | |
| 32 | by (unfold refl_def) blast | |
| 33 | ||
| 34 | lemma equiv_comp_eq: "equiv A r ==> r\<inverse> O r = r" | |
| 35 | apply (unfold equiv_def) | |
| 36 | apply clarify | |
| 37 | apply (rule equalityI) | |
| 17589 | 38 | apply (iprover intro: sym_trans_comp_subset refl_comp_subset)+ | 
| 15300 | 39 | done | 
| 40 | ||
| 41 | text {* Second half. *}
 | |
| 42 | ||
| 43 | lemma comp_equivI: | |
| 44 | "r\<inverse> O r = r ==> Domain r = A ==> equiv A r" | |
| 45 | apply (unfold equiv_def refl_def sym_def trans_def) | |
| 46 | apply (erule equalityE) | |
| 47 | apply (subgoal_tac "\<forall>x y. (x, y) \<in> r --> (y, x) \<in> r") | |
| 48 | apply fast | |
| 49 | apply fast | |
| 50 | done | |
| 51 | ||
| 52 | ||
| 53 | subsection {* Equivalence classes *}
 | |
| 54 | ||
| 55 | lemma equiv_class_subset: | |
| 56 |   "equiv A r ==> (a, b) \<in> r ==> r``{a} \<subseteq> r``{b}"
 | |
| 57 |   -- {* lemma for the next result *}
 | |
| 58 | by (unfold equiv_def trans_def sym_def) blast | |
| 59 | ||
| 60 | theorem equiv_class_eq: "equiv A r ==> (a, b) \<in> r ==> r``{a} = r``{b}"
 | |
| 61 | apply (assumption | rule equalityI equiv_class_subset)+ | |
| 62 | apply (unfold equiv_def sym_def) | |
| 63 | apply blast | |
| 64 | done | |
| 65 | ||
| 66 | lemma equiv_class_self: "equiv A r ==> a \<in> A ==> a \<in> r``{a}"
 | |
| 67 | by (unfold equiv_def refl_def) blast | |
| 68 | ||
| 69 | lemma subset_equiv_class: | |
| 70 |     "equiv A r ==> r``{b} \<subseteq> r``{a} ==> b \<in> A ==> (a,b) \<in> r"
 | |
| 71 |   -- {* lemma for the next result *}
 | |
| 72 | by (unfold equiv_def refl_def) blast | |
| 73 | ||
| 74 | lemma eq_equiv_class: | |
| 75 |     "r``{a} = r``{b} ==> equiv A r ==> b \<in> A ==> (a, b) \<in> r"
 | |
| 17589 | 76 | by (iprover intro: equalityD2 subset_equiv_class) | 
| 15300 | 77 | |
| 78 | lemma equiv_class_nondisjoint: | |
| 79 |     "equiv A r ==> x \<in> (r``{a} \<inter> r``{b}) ==> (a, b) \<in> r"
 | |
| 80 | by (unfold equiv_def trans_def sym_def) blast | |
| 81 | ||
| 82 | lemma equiv_type: "equiv A r ==> r \<subseteq> A \<times> A" | |
| 83 | by (unfold equiv_def refl_def) blast | |
| 84 | ||
| 85 | theorem equiv_class_eq_iff: | |
| 86 |   "equiv A r ==> ((x, y) \<in> r) = (r``{x} = r``{y} & x \<in> A & y \<in> A)"
 | |
| 87 | by (blast intro!: equiv_class_eq dest: eq_equiv_class equiv_type) | |
| 88 | ||
| 89 | theorem eq_equiv_class_iff: | |
| 90 |   "equiv A r ==> x \<in> A ==> y \<in> A ==> (r``{x} = r``{y}) = ((x, y) \<in> r)"
 | |
| 91 | by (blast intro!: equiv_class_eq dest: eq_equiv_class equiv_type) | |
| 92 | ||
| 93 | ||
| 94 | subsection {* Quotients *}
 | |
| 95 | ||
| 96 | constdefs | |
| 97 |   quotient :: "['a set, ('a*'a) set] => 'a set set"  (infixl "'/'/" 90)
 | |
| 98 |   "A//r == \<Union>x \<in> A. {r``{x}}"  -- {* set of equiv classes *}
 | |
| 99 | ||
| 100 | lemma quotientI: "x \<in> A ==> r``{x} \<in> A//r"
 | |
| 101 | by (unfold quotient_def) blast | |
| 102 | ||
| 103 | lemma quotientE: | |
| 104 |   "X \<in> A//r ==> (!!x. X = r``{x} ==> x \<in> A ==> P) ==> P"
 | |
| 105 | by (unfold quotient_def) blast | |
| 106 | ||
| 107 | lemma Union_quotient: "equiv A r ==> Union (A//r) = A" | |
| 108 | by (unfold equiv_def refl_def quotient_def) blast | |
| 109 | ||
| 110 | lemma quotient_disj: | |
| 111 |   "equiv A r ==> X \<in> A//r ==> Y \<in> A//r ==> X = Y | (X \<inter> Y = {})"
 | |
| 112 | apply (unfold quotient_def) | |
| 113 | apply clarify | |
| 114 | apply (rule equiv_class_eq) | |
| 115 | apply assumption | |
| 116 | apply (unfold equiv_def trans_def sym_def) | |
| 117 | apply blast | |
| 118 | done | |
| 119 | ||
| 120 | lemma quotient_eqI: | |
| 121 | "[|equiv A r; X \<in> A//r; Y \<in> A//r; x \<in> X; y \<in> Y; (x,y) \<in> r|] ==> X = Y" | |
| 122 | apply (clarify elim!: quotientE) | |
| 123 | apply (rule equiv_class_eq, assumption) | |
| 124 | apply (unfold equiv_def sym_def trans_def, blast) | |
| 125 | done | |
| 126 | ||
| 127 | lemma quotient_eq_iff: | |
| 128 | "[|equiv A r; X \<in> A//r; Y \<in> A//r; x \<in> X; y \<in> Y|] ==> (X = Y) = ((x,y) \<in> r)" | |
| 129 | apply (rule iffI) | |
| 130 | prefer 2 apply (blast del: equalityI intro: quotient_eqI) | |
| 131 | apply (clarify elim!: quotientE) | |
| 132 | apply (unfold equiv_def sym_def trans_def, blast) | |
| 133 | done | |
| 134 | ||
| 18493 | 135 | lemma eq_equiv_class_iff2: | 
| 136 |   "\<lbrakk> equiv A r; x \<in> A; y \<in> A \<rbrakk> \<Longrightarrow> ({x}//r = {y}//r) = ((x,y) : r)"
 | |
| 137 | by(simp add:quotient_def eq_equiv_class_iff) | |
| 138 | ||
| 15300 | 139 | |
| 140 | lemma quotient_empty [simp]: "{}//r = {}"
 | |
| 141 | by(simp add: quotient_def) | |
| 142 | ||
| 143 | lemma quotient_is_empty [iff]: "(A//r = {}) = (A = {})"
 | |
| 144 | by(simp add: quotient_def) | |
| 145 | ||
| 146 | lemma quotient_is_empty2 [iff]: "({} = A//r) = (A = {})"
 | |
| 147 | by(simp add: quotient_def) | |
| 148 | ||
| 149 | ||
| 15302 | 150 | lemma singleton_quotient: "{x}//r = {r `` {x}}"
 | 
| 151 | by(simp add:quotient_def) | |
| 152 | ||
| 153 | lemma quotient_diff1: | |
| 154 |   "\<lbrakk> inj_on (%a. {a}//r) A; a \<in> A \<rbrakk> \<Longrightarrow> (A - {a})//r = A//r - {a}//r"
 | |
| 155 | apply(simp add:quotient_def inj_on_def) | |
| 156 | apply blast | |
| 157 | done | |
| 158 | ||
| 15300 | 159 | subsection {* Defining unary operations upon equivalence classes *}
 | 
| 160 | ||
| 161 | text{*A congruence-preserving function*}
 | |
| 162 | locale congruent = | |
| 163 | fixes r and f | |
| 164 | assumes congruent: "(y,z) \<in> r ==> f y = f z" | |
| 165 | ||
| 19363 | 166 | abbreviation | 
| 21404 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 wenzelm parents: 
19979diff
changeset | 167 |   RESPECTS :: "('a => 'b) => ('a * 'a) set => bool"
 | 
| 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 wenzelm parents: 
19979diff
changeset | 168 | (infixr "respects" 80) where | 
| 19363 | 169 | "f respects r == congruent r f" | 
| 15300 | 170 | |
| 171 | ||
| 172 | lemma UN_constant_eq: "a \<in> A ==> \<forall>y \<in> A. f y = c ==> (\<Union>y \<in> A. f(y))=c" | |
| 173 |   -- {* lemma required to prove @{text UN_equiv_class} *}
 | |
| 174 | by auto | |
| 175 | ||
| 176 | lemma UN_equiv_class: | |
| 177 | "equiv A r ==> f respects r ==> a \<in> A | |
| 178 |     ==> (\<Union>x \<in> r``{a}. f x) = f a"
 | |
| 179 |   -- {* Conversion rule *}
 | |
| 180 | apply (rule equiv_class_self [THEN UN_constant_eq], assumption+) | |
| 181 | apply (unfold equiv_def congruent_def sym_def) | |
| 182 | apply (blast del: equalityI) | |
| 183 | done | |
| 184 | ||
| 185 | lemma UN_equiv_class_type: | |
| 186 | "equiv A r ==> f respects r ==> X \<in> A//r ==> | |
| 187 | (!!x. x \<in> A ==> f x \<in> B) ==> (\<Union>x \<in> X. f x) \<in> B" | |
| 188 | apply (unfold quotient_def) | |
| 189 | apply clarify | |
| 190 | apply (subst UN_equiv_class) | |
| 191 | apply auto | |
| 192 | done | |
| 193 | ||
| 194 | text {*
 | |
| 195 | Sufficient conditions for injectiveness. Could weaken premises! | |
| 196 |   major premise could be an inclusion; bcong could be @{text "!!y. y \<in>
 | |
| 197 | A ==> f y \<in> B"}. | |
| 198 | *} | |
| 199 | ||
| 200 | lemma UN_equiv_class_inject: | |
| 201 | "equiv A r ==> f respects r ==> | |
| 202 | (\<Union>x \<in> X. f x) = (\<Union>y \<in> Y. f y) ==> X \<in> A//r ==> Y \<in> A//r | |
| 203 | ==> (!!x y. x \<in> A ==> y \<in> A ==> f x = f y ==> (x, y) \<in> r) | |
| 204 | ==> X = Y" | |
| 205 | apply (unfold quotient_def) | |
| 206 | apply clarify | |
| 207 | apply (rule equiv_class_eq) | |
| 208 | apply assumption | |
| 209 | apply (subgoal_tac "f x = f xa") | |
| 210 | apply blast | |
| 211 | apply (erule box_equals) | |
| 212 | apply (assumption | rule UN_equiv_class)+ | |
| 213 | done | |
| 214 | ||
| 215 | ||
| 216 | subsection {* Defining binary operations upon equivalence classes *}
 | |
| 217 | ||
| 218 | text{*A congruence-preserving function of two arguments*}
 | |
| 219 | locale congruent2 = | |
| 220 | fixes r1 and r2 and f | |
| 221 | assumes congruent2: | |
| 222 | "(y1,z1) \<in> r1 ==> (y2,z2) \<in> r2 ==> f y1 y2 = f z1 z2" | |
| 223 | ||
| 224 | text{*Abbreviation for the common case where the relations are identical*}
 | |
| 19979 | 225 | abbreviation | 
| 21404 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 wenzelm parents: 
19979diff
changeset | 226 |   RESPECTS2:: "['a => 'a => 'b, ('a * 'a) set] => bool"
 | 
| 21749 | 227 | (infixr "respects2" 80) where | 
| 19979 | 228 | "f respects2 r == congruent2 r r f" | 
| 229 | ||
| 15300 | 230 | |
| 231 | lemma congruent2_implies_congruent: | |
| 232 | "equiv A r1 ==> congruent2 r1 r2 f ==> a \<in> A ==> congruent r2 (f a)" | |
| 233 | by (unfold congruent_def congruent2_def equiv_def refl_def) blast | |
| 234 | ||
| 235 | lemma congruent2_implies_congruent_UN: | |
| 236 | "equiv A1 r1 ==> equiv A2 r2 ==> congruent2 r1 r2 f ==> a \<in> A2 ==> | |
| 237 |     congruent r1 (\<lambda>x1. \<Union>x2 \<in> r2``{a}. f x1 x2)"
 | |
| 238 | apply (unfold congruent_def) | |
| 239 | apply clarify | |
| 240 | apply (rule equiv_type [THEN subsetD, THEN SigmaE2], assumption+) | |
| 241 | apply (simp add: UN_equiv_class congruent2_implies_congruent) | |
| 242 | apply (unfold congruent2_def equiv_def refl_def) | |
| 243 | apply (blast del: equalityI) | |
| 244 | done | |
| 245 | ||
| 246 | lemma UN_equiv_class2: | |
| 247 | "equiv A1 r1 ==> equiv A2 r2 ==> congruent2 r1 r2 f ==> a1 \<in> A1 ==> a2 \<in> A2 | |
| 248 |     ==> (\<Union>x1 \<in> r1``{a1}. \<Union>x2 \<in> r2``{a2}. f x1 x2) = f a1 a2"
 | |
| 249 | by (simp add: UN_equiv_class congruent2_implies_congruent | |
| 250 | congruent2_implies_congruent_UN) | |
| 251 | ||
| 252 | lemma UN_equiv_class_type2: | |
| 253 | "equiv A1 r1 ==> equiv A2 r2 ==> congruent2 r1 r2 f | |
| 254 | ==> X1 \<in> A1//r1 ==> X2 \<in> A2//r2 | |
| 255 | ==> (!!x1 x2. x1 \<in> A1 ==> x2 \<in> A2 ==> f x1 x2 \<in> B) | |
| 256 | ==> (\<Union>x1 \<in> X1. \<Union>x2 \<in> X2. f x1 x2) \<in> B" | |
| 257 | apply (unfold quotient_def) | |
| 258 | apply clarify | |
| 259 | apply (blast intro: UN_equiv_class_type congruent2_implies_congruent_UN | |
| 260 | congruent2_implies_congruent quotientI) | |
| 261 | done | |
| 262 | ||
| 263 | lemma UN_UN_split_split_eq: | |
| 264 | "(\<Union>(x1, x2) \<in> X. \<Union>(y1, y2) \<in> Y. A x1 x2 y1 y2) = | |
| 265 | (\<Union>x \<in> X. \<Union>y \<in> Y. (\<lambda>(x1, x2). (\<lambda>(y1, y2). A x1 x2 y1 y2) y) x)" | |
| 266 |   -- {* Allows a natural expression of binary operators, *}
 | |
| 267 |   -- {* without explicit calls to @{text split} *}
 | |
| 268 | by auto | |
| 269 | ||
| 270 | lemma congruent2I: | |
| 271 | "equiv A1 r1 ==> equiv A2 r2 | |
| 272 | ==> (!!y z w. w \<in> A2 ==> (y,z) \<in> r1 ==> f y w = f z w) | |
| 273 | ==> (!!y z w. w \<in> A1 ==> (y,z) \<in> r2 ==> f w y = f w z) | |
| 274 | ==> congruent2 r1 r2 f" | |
| 275 |   -- {* Suggested by John Harrison -- the two subproofs may be *}
 | |
| 276 |   -- {* \emph{much} simpler than the direct proof. *}
 | |
| 277 | apply (unfold congruent2_def equiv_def refl_def) | |
| 278 | apply clarify | |
| 279 | apply (blast intro: trans) | |
| 280 | done | |
| 281 | ||
| 282 | lemma congruent2_commuteI: | |
| 283 | assumes equivA: "equiv A r" | |
| 284 | and commute: "!!y z. y \<in> A ==> z \<in> A ==> f y z = f z y" | |
| 285 | and congt: "!!y z w. w \<in> A ==> (y,z) \<in> r ==> f w y = f w z" | |
| 286 | shows "f respects2 r" | |
| 287 | apply (rule congruent2I [OF equivA equivA]) | |
| 288 | apply (rule commute [THEN trans]) | |
| 289 | apply (rule_tac [3] commute [THEN trans, symmetric]) | |
| 290 | apply (rule_tac [5] sym) | |
| 25482 | 291 | apply (rule congt | assumption | | 
| 15300 | 292 | erule equivA [THEN equiv_type, THEN subsetD, THEN SigmaE2])+ | 
| 293 | done | |
| 294 | ||
| 24728 | 295 | |
| 296 | subsection {* Quotients and finiteness *}
 | |
| 297 | ||
| 298 | text {*Suggested by Florian Kammüller*}
 | |
| 299 | ||
| 300 | lemma finite_quotient: "finite A ==> r \<subseteq> A \<times> A ==> finite (A//r)" | |
| 301 |   -- {* recall @{thm equiv_type} *}
 | |
| 302 | apply (rule finite_subset) | |
| 303 | apply (erule_tac [2] finite_Pow_iff [THEN iffD2]) | |
| 304 | apply (unfold quotient_def) | |
| 305 | apply blast | |
| 306 | done | |
| 307 | ||
| 308 | lemma finite_equiv_class: | |
| 309 | "finite A ==> r \<subseteq> A \<times> A ==> X \<in> A//r ==> finite X" | |
| 310 | apply (unfold quotient_def) | |
| 311 | apply (rule finite_subset) | |
| 312 | prefer 2 apply assumption | |
| 313 | apply blast | |
| 314 | done | |
| 315 | ||
| 316 | lemma equiv_imp_dvd_card: | |
| 317 | "finite A ==> equiv A r ==> \<forall>X \<in> A//r. k dvd card X | |
| 318 | ==> k dvd card A" | |
| 26791 
3581a9c71909
Instantiated subst rule to avoid problems with HO unification.
 berghofe parents: 
25482diff
changeset | 319 | apply (rule Union_quotient [THEN subst [where P="\<lambda>A. k dvd card A"]]) | 
| 24728 | 320 | apply assumption | 
| 321 | apply (rule dvd_partition) | |
| 322 | prefer 3 apply (blast dest: quotient_disj) | |
| 323 | apply (simp_all add: Union_quotient equiv_type) | |
| 324 | done | |
| 325 | ||
| 326 | lemma card_quotient_disjoint: | |
| 327 |  "\<lbrakk> finite A; inj_on (\<lambda>x. {x} // r) A \<rbrakk> \<Longrightarrow> card(A//r) = card A"
 | |
| 328 | apply(simp add:quotient_def) | |
| 329 | apply(subst card_UN_disjoint) | |
| 330 | apply assumption | |
| 331 | apply simp | |
| 332 | apply(fastsimp simp add:inj_on_def) | |
| 333 | apply (simp add:setsum_constant) | |
| 334 | done | |
| 335 | ||
| 15300 | 336 | end |