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