| author | wenzelm | 
| Sat, 13 Mar 2010 14:42:16 +0100 | |
| changeset 35741 | 4f3660a3e5af | 
| parent 35355 | 613e133966ea | 
| child 35847 | 19f1f7066917 | 
| permissions | -rw-r--r-- | 
| 27701 | 1 | (* | 
| 2 | Title: Algebra/Congruence.thy | |
| 3 | Author: Clemens Ballarin, started 3 January 2008 | |
| 4 | Copyright: Clemens Ballarin | |
| 5 | *) | |
| 6 | ||
| 7 | theory Congruence imports Main begin | |
| 8 | ||
| 9 | section {* Objects *}
 | |
| 10 | ||
| 27717 
21bbd410ba04
Generalised polynomial lemmas from cring to ring.
 ballarin parents: 
27701diff
changeset | 11 | subsection {* Structure with Carrier Set. *}
 | 
| 27701 | 12 | |
| 13 | record 'a partial_object = | |
| 14 | carrier :: "'a set" | |
| 15 | ||
| 27717 
21bbd410ba04
Generalised polynomial lemmas from cring to ring.
 ballarin parents: 
27701diff
changeset | 16 | |
| 
21bbd410ba04
Generalised polynomial lemmas from cring to ring.
 ballarin parents: 
27701diff
changeset | 17 | subsection {* Structure with Carrier and Equivalence Relation @{text eq} *}
 | 
| 27701 | 18 | |
| 19 | record 'a eq_object = "'a partial_object" + | |
| 20 | eq :: "'a \<Rightarrow> 'a \<Rightarrow> bool" (infixl ".=\<index>" 50) | |
| 21 | ||
| 22 | constdefs (structure S) | |
| 23 | elem :: "_ \<Rightarrow> 'a \<Rightarrow> 'a set \<Rightarrow> bool" (infixl ".\<in>\<index>" 50) | |
| 24 | "x .\<in> A \<equiv> (\<exists>y \<in> A. x .= y)" | |
| 25 | ||
| 26 |   set_eq :: "_ \<Rightarrow> 'a set \<Rightarrow> 'a set \<Rightarrow> bool" (infixl "{.=}\<index>" 50)
 | |
| 27 |   "A {.=} B == ((\<forall>x \<in> A. x .\<in> B) \<and> (\<forall>x \<in> B. x .\<in> A))"
 | |
| 28 | ||
| 29 |   eq_class_of :: "_ \<Rightarrow> 'a \<Rightarrow> 'a set" ("class'_of\<index> _")
 | |
| 30 |   "class_of x == {y \<in> carrier S. x .= y}"
 | |
| 31 | ||
| 32 |   eq_closure_of :: "_ \<Rightarrow> 'a set \<Rightarrow> 'a set" ("closure'_of\<index> _")
 | |
| 33 |   "closure_of A == {y \<in> carrier S. y .\<in> A}"
 | |
| 34 | ||
| 35 |   eq_is_closed :: "_ \<Rightarrow> 'a set \<Rightarrow> bool" ("is'_closed\<index> _")
 | |
| 36 | "is_closed A == (A \<subseteq> carrier S \<and> closure_of A = A)" | |
| 37 | ||
| 35355 
613e133966ea
modernized syntax declarations, and make them actually work with authentic syntax;
 wenzelm parents: 
29237diff
changeset | 38 | abbreviation | 
| 27701 | 39 | not_eq :: "_ \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> bool" (infixl ".\<noteq>\<index>" 50) | 
| 35355 
613e133966ea
modernized syntax declarations, and make them actually work with authentic syntax;
 wenzelm parents: 
29237diff
changeset | 40 | where "x .\<noteq>\<^bsub>S\<^esub> y == ~(x .=\<^bsub>S\<^esub> y)" | 
| 27701 | 41 | |
| 35355 
613e133966ea
modernized syntax declarations, and make them actually work with authentic syntax;
 wenzelm parents: 
29237diff
changeset | 42 | abbreviation | 
| 
613e133966ea
modernized syntax declarations, and make them actually work with authentic syntax;
 wenzelm parents: 
29237diff
changeset | 43 | not_elem :: "_ \<Rightarrow> 'a \<Rightarrow> 'a set \<Rightarrow> bool" (infixl ".\<notin>\<index>" 50) | 
| 
613e133966ea
modernized syntax declarations, and make them actually work with authentic syntax;
 wenzelm parents: 
29237diff
changeset | 44 | where "x .\<notin>\<^bsub>S\<^esub> A == ~(x .\<in>\<^bsub>S\<^esub> A)" | 
| 
613e133966ea
modernized syntax declarations, and make them actually work with authentic syntax;
 wenzelm parents: 
29237diff
changeset | 45 | |
| 
613e133966ea
modernized syntax declarations, and make them actually work with authentic syntax;
 wenzelm parents: 
29237diff
changeset | 46 | abbreviation | 
| 
613e133966ea
modernized syntax declarations, and make them actually work with authentic syntax;
 wenzelm parents: 
29237diff
changeset | 47 |   set_not_eq :: "_ \<Rightarrow> 'a set \<Rightarrow> 'a set \<Rightarrow> bool" (infixl "{.\<noteq>}\<index>" 50)
 | 
| 
613e133966ea
modernized syntax declarations, and make them actually work with authentic syntax;
 wenzelm parents: 
29237diff
changeset | 48 |   where "A {.\<noteq>}\<^bsub>S\<^esub> B == ~(A {.=}\<^bsub>S\<^esub> B)"
 | 
| 27701 | 49 | |
| 50 | locale equivalence = | |
| 51 | fixes S (structure) | |
| 52 | assumes refl [simp, intro]: "x \<in> carrier S \<Longrightarrow> x .= x" | |
| 53 | and sym [sym]: "\<lbrakk> x .= y; x \<in> carrier S; y \<in> carrier S \<rbrakk> \<Longrightarrow> y .= x" | |
| 54 | and trans [trans]: "\<lbrakk> x .= y; y .= z; x \<in> carrier S; y \<in> carrier S; z \<in> carrier S \<rbrakk> \<Longrightarrow> x .= z" | |
| 55 | ||
| 27717 
21bbd410ba04
Generalised polynomial lemmas from cring to ring.
 ballarin parents: 
27701diff
changeset | 56 | (* Lemmas by Stephan Hohe *) | 
| 
21bbd410ba04
Generalised polynomial lemmas from cring to ring.
 ballarin parents: 
27701diff
changeset | 57 | |
| 27701 | 58 | lemma elemI: | 
| 59 | fixes R (structure) | |
| 60 | assumes "a' \<in> A" and "a .= a'" | |
| 61 | shows "a .\<in> A" | |
| 62 | unfolding elem_def | |
| 63 | using assms | |
| 64 | by fast | |
| 65 | ||
| 66 | lemma (in equivalence) elem_exact: | |
| 67 | assumes "a \<in> carrier S" and "a \<in> A" | |
| 68 | shows "a .\<in> A" | |
| 69 | using assms | |
| 70 | by (fast intro: elemI) | |
| 71 | ||
| 72 | lemma elemE: | |
| 73 | fixes S (structure) | |
| 74 | assumes "a .\<in> A" | |
| 75 | and "\<And>a'. \<lbrakk>a' \<in> A; a .= a'\<rbrakk> \<Longrightarrow> P" | |
| 76 | shows "P" | |
| 77 | using assms | |
| 78 | unfolding elem_def | |
| 79 | by fast | |
| 80 | ||
| 81 | lemma (in equivalence) elem_cong_l [trans]: | |
| 82 | assumes cong: "a' .= a" | |
| 83 | and a: "a .\<in> A" | |
| 84 | and carr: "a \<in> carrier S" "a' \<in> carrier S" | |
| 85 | and Acarr: "A \<subseteq> carrier S" | |
| 86 | shows "a' .\<in> A" | |
| 87 | using a | |
| 88 | apply (elim elemE, intro elemI) | |
| 89 | proof assumption | |
| 90 | fix b | |
| 91 | assume bA: "b \<in> A" | |
| 92 | note [simp] = carr bA[THEN subsetD[OF Acarr]] | |
| 93 | note cong | |
| 94 | also assume "a .= b" | |
| 95 | finally show "a' .= b" by simp | |
| 96 | qed | |
| 97 | ||
| 98 | lemma (in equivalence) elem_subsetD: | |
| 99 | assumes "A \<subseteq> B" | |
| 100 | and aA: "a .\<in> A" | |
| 101 | shows "a .\<in> B" | |
| 102 | using assms | |
| 103 | by (fast intro: elemI elim: elemE dest: subsetD) | |
| 104 | ||
| 105 | lemma (in equivalence) mem_imp_elem [simp, intro]: | |
| 106 | "[| x \<in> A; x \<in> carrier S |] ==> x .\<in> A" | |
| 107 | unfolding elem_def by blast | |
| 108 | ||
| 109 | lemma set_eqI: | |
| 110 | fixes R (structure) | |
| 111 | assumes ltr: "\<And>a. a \<in> A \<Longrightarrow> a .\<in> B" | |
| 112 | and rtl: "\<And>b. b \<in> B \<Longrightarrow> b .\<in> A" | |
| 113 |   shows "A {.=} B"
 | |
| 114 | unfolding set_eq_def | |
| 115 | by (fast intro: ltr rtl) | |
| 116 | ||
| 117 | lemma set_eqI2: | |
| 118 | fixes R (structure) | |
| 119 | assumes ltr: "\<And>a b. a \<in> A \<Longrightarrow> \<exists>b\<in>B. a .= b" | |
| 120 | and rtl: "\<And>b. b \<in> B \<Longrightarrow> \<exists>a\<in>A. b .= a" | |
| 121 |   shows "A {.=} B"
 | |
| 122 | by (intro set_eqI, unfold elem_def) (fast intro: ltr rtl)+ | |
| 123 | ||
| 124 | lemma set_eqD1: | |
| 125 | fixes R (structure) | |
| 126 |   assumes AA': "A {.=} A'"
 | |
| 127 | and "a \<in> A" | |
| 128 | shows "\<exists>a'\<in>A'. a .= a'" | |
| 129 | using assms | |
| 130 | unfolding set_eq_def elem_def | |
| 131 | by fast | |
| 132 | ||
| 133 | lemma set_eqD2: | |
| 134 | fixes R (structure) | |
| 135 |   assumes AA': "A {.=} A'"
 | |
| 136 | and "a' \<in> A'" | |
| 137 | shows "\<exists>a\<in>A. a' .= a" | |
| 138 | using assms | |
| 139 | unfolding set_eq_def elem_def | |
| 140 | by fast | |
| 141 | ||
| 142 | lemma set_eqE: | |
| 143 | fixes R (structure) | |
| 144 |   assumes AB: "A {.=} B"
 | |
| 145 | and r: "\<lbrakk>\<forall>a\<in>A. a .\<in> B; \<forall>b\<in>B. b .\<in> A\<rbrakk> \<Longrightarrow> P" | |
| 146 | shows "P" | |
| 147 | using AB | |
| 148 | unfolding set_eq_def | |
| 149 | by (blast dest: r) | |
| 150 | ||
| 151 | lemma set_eqE2: | |
| 152 | fixes R (structure) | |
| 153 |   assumes AB: "A {.=} B"
 | |
| 154 | and r: "\<lbrakk>\<forall>a\<in>A. (\<exists>b\<in>B. a .= b); \<forall>b\<in>B. (\<exists>a\<in>A. b .= a)\<rbrakk> \<Longrightarrow> P" | |
| 155 | shows "P" | |
| 156 | using AB | |
| 157 | unfolding set_eq_def elem_def | |
| 158 | by (blast dest: r) | |
| 159 | ||
| 160 | lemma set_eqE': | |
| 161 | fixes R (structure) | |
| 162 |   assumes AB: "A {.=} B"
 | |
| 163 | and aA: "a \<in> A" and bB: "b \<in> B" | |
| 164 | and r: "\<And>a' b'. \<lbrakk>a' \<in> A; b .= a'; b' \<in> B; a .= b'\<rbrakk> \<Longrightarrow> P" | |
| 165 | shows "P" | |
| 166 | proof - | |
| 167 | from AB aA | |
| 168 | have "\<exists>b'\<in>B. a .= b'" by (rule set_eqD1) | |
| 169 | from this obtain b' | |
| 170 | where b': "b' \<in> B" "a .= b'" by auto | |
| 171 | ||
| 172 | from AB bB | |
| 173 | have "\<exists>a'\<in>A. b .= a'" by (rule set_eqD2) | |
| 174 | from this obtain a' | |
| 175 | where a': "a' \<in> A" "b .= a'" by auto | |
| 176 | ||
| 177 | from a' b' | |
| 178 | show "P" by (rule r) | |
| 179 | qed | |
| 180 | ||
| 181 | lemma (in equivalence) eq_elem_cong_r [trans]: | |
| 182 | assumes a: "a .\<in> A" | |
| 183 |     and cong: "A {.=} A'"
 | |
| 184 | and carr: "a \<in> carrier S" | |
| 185 | and Carr: "A \<subseteq> carrier S" "A' \<subseteq> carrier S" | |
| 186 | shows "a .\<in> A'" | |
| 187 | using a cong | |
| 188 | proof (elim elemE set_eqE) | |
| 189 | fix b | |
| 190 | assume bA: "b \<in> A" | |
| 191 | and inA': "\<forall>b\<in>A. b .\<in> A'" | |
| 192 | note [simp] = carr Carr Carr[THEN subsetD] bA | |
| 193 | assume "a .= b" | |
| 194 | also from bA inA' | |
| 195 | have "b .\<in> A'" by fast | |
| 196 | finally | |
| 197 | show "a .\<in> A'" by simp | |
| 198 | qed | |
| 199 | ||
| 200 | lemma (in equivalence) set_eq_sym [sym]: | |
| 201 |   assumes "A {.=} B"
 | |
| 202 | and "A \<subseteq> carrier S" "B \<subseteq> carrier S" | |
| 203 |   shows "B {.=} A"
 | |
| 204 | using assms | |
| 205 | unfolding set_eq_def elem_def | |
| 206 | by fast | |
| 207 | ||
| 208 | (* FIXME: the following two required in Isabelle 2008, not Isabelle 2007 *) | |
| 27717 
21bbd410ba04
Generalised polynomial lemmas from cring to ring.
 ballarin parents: 
27701diff
changeset | 209 | (* alternatively, could declare lemmas [trans] = ssubst [where 'a = "'a set"] *) | 
| 27701 | 210 | |
| 211 | lemma (in equivalence) equal_set_eq_trans [trans]: | |
| 212 |   assumes AB: "A = B" and BC: "B {.=} C"
 | |
| 213 |   shows "A {.=} C"
 | |
| 214 | using AB BC by simp | |
| 215 | ||
| 216 | lemma (in equivalence) set_eq_equal_trans [trans]: | |
| 217 |   assumes AB: "A {.=} B" and BC: "B = C"
 | |
| 218 |   shows "A {.=} C"
 | |
| 219 | using AB BC by simp | |
| 220 | ||
| 27717 
21bbd410ba04
Generalised polynomial lemmas from cring to ring.
 ballarin parents: 
27701diff
changeset | 221 | |
| 27701 | 222 | lemma (in equivalence) set_eq_trans [trans]: | 
| 223 |   assumes AB: "A {.=} B" and BC: "B {.=} C"
 | |
| 224 | and carr: "A \<subseteq> carrier S" "B \<subseteq> carrier S" "C \<subseteq> carrier S" | |
| 225 |   shows "A {.=} C"
 | |
| 226 | proof (intro set_eqI) | |
| 227 | fix a | |
| 228 | assume aA: "a \<in> A" | |
| 229 | with carr have "a \<in> carrier S" by fast | |
| 230 | note [simp] = carr this | |
| 231 | ||
| 232 | from aA | |
| 233 | have "a .\<in> A" by (simp add: elem_exact) | |
| 234 | also note AB | |
| 235 | also note BC | |
| 236 | finally | |
| 237 | show "a .\<in> C" by simp | |
| 238 | next | |
| 239 | fix c | |
| 240 | assume cC: "c \<in> C" | |
| 241 | with carr have "c \<in> carrier S" by fast | |
| 242 | note [simp] = carr this | |
| 243 | ||
| 244 | from cC | |
| 245 | have "c .\<in> C" by (simp add: elem_exact) | |
| 246 | also note BC[symmetric] | |
| 247 | also note AB[symmetric] | |
| 248 | finally | |
| 249 | show "c .\<in> A" by simp | |
| 250 | qed | |
| 251 | ||
| 252 | (* FIXME: generalise for insert *) | |
| 253 | ||
| 254 | (* | |
| 255 | lemma (in equivalence) set_eq_insert: | |
| 256 | assumes x: "x .= x'" | |
| 257 | and carr: "x \<in> carrier S" "x' \<in> carrier S" "A \<subseteq> carrier S" | |
| 258 |   shows "insert x A {.=} insert x' A"
 | |
| 259 | unfolding set_eq_def elem_def | |
| 260 | apply rule | |
| 261 | apply rule | |
| 262 | apply (case_tac "xa = x") | |
| 263 | using x apply fast | |
| 264 | apply (subgoal_tac "xa \<in> A") prefer 2 apply fast | |
| 265 | apply (rule_tac x=xa in bexI) | |
| 266 | using carr apply (rule_tac refl) apply auto [1] | |
| 267 | apply safe | |
| 268 | *) | |
| 269 | ||
| 270 | lemma (in equivalence) set_eq_pairI: | |
| 271 | assumes xx': "x .= x'" | |
| 272 | and carr: "x \<in> carrier S" "x' \<in> carrier S" "y \<in> carrier S" | |
| 273 |   shows "{x, y} {.=} {x', y}"
 | |
| 274 | unfolding set_eq_def elem_def | |
| 275 | proof safe | |
| 276 |   have "x' \<in> {x', y}" by fast
 | |
| 277 |   with xx' show "\<exists>b\<in>{x', y}. x .= b" by fast
 | |
| 278 | next | |
| 279 |   have "y \<in> {x', y}" by fast
 | |
| 280 |   with carr show "\<exists>b\<in>{x', y}. y .= b" by fast
 | |
| 281 | next | |
| 282 |   have "x \<in> {x, y}" by fast
 | |
| 283 | with xx'[symmetric] carr | |
| 284 |   show "\<exists>a\<in>{x, y}. x' .= a" by fast
 | |
| 285 | next | |
| 286 |   have "y \<in> {x, y}" by fast
 | |
| 287 |   with carr show "\<exists>a\<in>{x, y}. y .= a" by fast
 | |
| 288 | qed | |
| 289 | ||
| 290 | lemma (in equivalence) is_closedI: | |
| 291 | assumes closed: "!!x y. [| x .= y; x \<in> A; y \<in> carrier S |] ==> y \<in> A" | |
| 292 | and S: "A \<subseteq> carrier S" | |
| 293 | shows "is_closed A" | |
| 294 | unfolding eq_is_closed_def eq_closure_of_def elem_def | |
| 295 | using S | |
| 296 | by (blast dest: closed sym) | |
| 297 | ||
| 298 | lemma (in equivalence) closure_of_eq: | |
| 299 | "[| x .= x'; A \<subseteq> carrier S; x \<in> closure_of A; x \<in> carrier S; x' \<in> carrier S |] ==> x' \<in> closure_of A" | |
| 300 | unfolding eq_closure_of_def elem_def | |
| 301 | by (blast intro: trans sym) | |
| 302 | ||
| 303 | lemma (in equivalence) is_closed_eq [dest]: | |
| 304 | "[| x .= x'; x \<in> A; is_closed A; x \<in> carrier S; x' \<in> carrier S |] ==> x' \<in> A" | |
| 305 | unfolding eq_is_closed_def | |
| 306 | using closure_of_eq [where A = A] | |
| 307 | by simp | |
| 308 | ||
| 309 | lemma (in equivalence) is_closed_eq_rev [dest]: | |
| 310 | "[| x .= x'; x' \<in> A; is_closed A; x \<in> carrier S; x' \<in> carrier S |] ==> x \<in> A" | |
| 311 | by (drule sym) (simp_all add: is_closed_eq) | |
| 312 | ||
| 313 | lemma closure_of_closed [simp, intro]: | |
| 314 | fixes S (structure) | |
| 315 | shows "closure_of A \<subseteq> carrier S" | |
| 316 | unfolding eq_closure_of_def | |
| 317 | by fast | |
| 318 | ||
| 319 | lemma closure_of_memI: | |
| 320 | fixes S (structure) | |
| 321 | assumes "a .\<in> A" | |
| 322 | and "a \<in> carrier S" | |
| 323 | shows "a \<in> closure_of A" | |
| 324 | unfolding eq_closure_of_def | |
| 325 | using assms | |
| 326 | by fast | |
| 327 | ||
| 328 | lemma closure_ofI2: | |
| 329 | fixes S (structure) | |
| 330 | assumes "a .= a'" | |
| 331 | and "a' \<in> A" | |
| 332 | and "a \<in> carrier S" | |
| 333 | shows "a \<in> closure_of A" | |
| 334 | unfolding eq_closure_of_def elem_def | |
| 335 | using assms | |
| 336 | by fast | |
| 337 | ||
| 338 | lemma closure_of_memE: | |
| 339 | fixes S (structure) | |
| 340 | assumes p: "a \<in> closure_of A" | |
| 341 | and r: "\<lbrakk>a \<in> carrier S; a .\<in> A\<rbrakk> \<Longrightarrow> P" | |
| 342 | shows "P" | |
| 343 | proof - | |
| 344 | from p | |
| 345 | have acarr: "a \<in> carrier S" | |
| 346 | and "a .\<in> A" | |
| 347 | by (simp add: eq_closure_of_def)+ | |
| 348 | thus "P" by (rule r) | |
| 349 | qed | |
| 350 | ||
| 351 | lemma closure_ofE2: | |
| 352 | fixes S (structure) | |
| 353 | assumes p: "a \<in> closure_of A" | |
| 354 | and r: "\<And>a'. \<lbrakk>a \<in> carrier S; a' \<in> A; a .= a'\<rbrakk> \<Longrightarrow> P" | |
| 355 | shows "P" | |
| 356 | proof - | |
| 357 | from p have acarr: "a \<in> carrier S" by (simp add: eq_closure_of_def) | |
| 358 | ||
| 359 | from p have "\<exists>a'\<in>A. a .= a'" by (simp add: eq_closure_of_def elem_def) | |
| 360 | from this obtain a' | |
| 361 | where "a' \<in> A" and "a .= a'" by auto | |
| 362 | ||
| 363 | from acarr and this | |
| 364 | show "P" by (rule r) | |
| 365 | qed | |
| 366 | ||
| 367 | (* | |
| 368 | lemma (in equivalence) classes_consistent: | |
| 369 | assumes Acarr: "A \<subseteq> carrier S" | |
| 370 | shows "is_closed (closure_of A)" | |
| 371 | apply (blast intro: elemI elim elemE) | |
| 372 | using assms | |
| 373 | apply (intro is_closedI closure_of_memI, simp) | |
| 374 | apply (elim elemE closure_of_memE) | |
| 375 | proof - | |
| 376 | fix x a' a'' | |
| 377 | assume carr: "x \<in> carrier S" "a' \<in> carrier S" | |
| 378 | assume a''A: "a'' \<in> A" | |
| 379 | with Acarr have "a'' \<in> carrier S" by fast | |
| 380 | note [simp] = carr this Acarr | |
| 381 | ||
| 382 | assume "x .= a'" | |
| 383 | also assume "a' .= a''" | |
| 384 | also from a''A | |
| 385 | have "a'' .\<in> A" by (simp add: elem_exact) | |
| 386 | finally show "x .\<in> A" by simp | |
| 387 | qed | |
| 388 | *) | |
| 389 | (* | |
| 390 | lemma (in equivalence) classes_small: | |
| 391 | assumes "is_closed B" | |
| 392 | and "A \<subseteq> B" | |
| 393 | shows "closure_of A \<subseteq> B" | |
| 394 | using assms | |
| 395 | by (blast dest: is_closedD2 elem_subsetD elim: closure_of_memE) | |
| 396 | ||
| 397 | lemma (in equivalence) classes_eq: | |
| 398 | assumes "A \<subseteq> carrier S" | |
| 399 |   shows "A {.=} closure_of A"
 | |
| 400 | using assms | |
| 401 | by (blast intro: set_eqI elem_exact closure_of_memI elim: closure_of_memE) | |
| 402 | ||
| 403 | lemma (in equivalence) complete_classes: | |
| 404 | assumes c: "is_closed A" | |
| 405 | shows "A = closure_of A" | |
| 406 | using assms | |
| 407 | by (blast intro: closure_of_memI elem_exact dest: is_closedD1 is_closedD2 closure_of_memE) | |
| 408 | *) | |
| 409 | ||
| 410 | end |