| author | haftmann | 
| Thu, 08 Jan 2009 17:10:41 +0100 | |
| changeset 29399 | ebcd69a00872 | 
| parent 29237 | e90d9d51106b | 
| child 32456 | 341c83339aeb | 
| permissions | -rw-r--r-- | 
| 27701 | 1 | (* | 
| 2 | Title: Divisibility in monoids and rings | |
| 3 | Author: Clemens Ballarin, started 18 July 2008 | |
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 4 | |
| 27717 
21bbd410ba04
Generalised polynomial lemmas from cring to ring.
 ballarin parents: 
27713diff
changeset | 5 | Based on work by Stephan Hohe. | 
| 27701 | 6 | *) | 
| 7 | ||
| 8 | theory Divisibility | |
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 9 | imports Permutation Coset Group | 
| 27701 | 10 | begin | 
| 11 | ||
| 27717 
21bbd410ba04
Generalised polynomial lemmas from cring to ring.
 ballarin parents: 
27713diff
changeset | 12 | section {* Factorial Monoids *}
 | 
| 
21bbd410ba04
Generalised polynomial lemmas from cring to ring.
 ballarin parents: 
27713diff
changeset | 13 | |
| 
21bbd410ba04
Generalised polynomial lemmas from cring to ring.
 ballarin parents: 
27713diff
changeset | 14 | subsection {* Monoids with Cancellation Law *}
 | 
| 27701 | 15 | |
| 16 | locale monoid_cancel = monoid + | |
| 17 | assumes l_cancel: | |
| 18 | "\<lbrakk>c \<otimes> a = c \<otimes> b; a \<in> carrier G; b \<in> carrier G; c \<in> carrier G\<rbrakk> \<Longrightarrow> a = b" | |
| 19 | and r_cancel: | |
| 20 | "\<lbrakk>a \<otimes> c = b \<otimes> c; a \<in> carrier G; b \<in> carrier G; c \<in> carrier G\<rbrakk> \<Longrightarrow> a = b" | |
| 21 | ||
| 22 | lemma (in monoid) monoid_cancelI: | |
| 23 | assumes l_cancel: | |
| 24 | "\<And>a b c. \<lbrakk>c \<otimes> a = c \<otimes> b; a \<in> carrier G; b \<in> carrier G; c \<in> carrier G\<rbrakk> \<Longrightarrow> a = b" | |
| 25 | and r_cancel: | |
| 26 | "\<And>a b c. \<lbrakk>a \<otimes> c = b \<otimes> c; a \<in> carrier G; b \<in> carrier G; c \<in> carrier G\<rbrakk> \<Longrightarrow> a = b" | |
| 27 | shows "monoid_cancel G" | |
| 28823 | 28 | proof qed fact+ | 
| 27701 | 29 | |
| 30 | lemma (in monoid_cancel) is_monoid_cancel: | |
| 31 | "monoid_cancel G" | |
| 28823 | 32 | .. | 
| 27701 | 33 | |
| 29237 | 34 | sublocale group \<subseteq> monoid_cancel | 
| 28823 | 35 | proof qed simp+ | 
| 27701 | 36 | |
| 37 | ||
| 38 | locale comm_monoid_cancel = monoid_cancel + comm_monoid | |
| 39 | ||
| 40 | lemma comm_monoid_cancelI: | |
| 28599 | 41 | fixes G (structure) | 
| 42 | assumes "comm_monoid G" | |
| 27701 | 43 | assumes cancel: | 
| 44 | "\<And>a b c. \<lbrakk>a \<otimes> c = b \<otimes> c; a \<in> carrier G; b \<in> carrier G; c \<in> carrier G\<rbrakk> \<Longrightarrow> a = b" | |
| 45 | shows "comm_monoid_cancel G" | |
| 28599 | 46 | proof - | 
| 29237 | 47 | interpret comm_monoid G by fact | 
| 28599 | 48 | show "comm_monoid_cancel G" | 
| 49 | apply unfold_locales | |
| 50 | apply (subgoal_tac "a \<otimes> c = b \<otimes> c") | |
| 51 | apply (iprover intro: cancel) | |
| 52 | apply (simp add: m_comm) | |
| 53 | apply (iprover intro: cancel) | |
| 54 | done | |
| 55 | qed | |
| 27701 | 56 | |
| 57 | lemma (in comm_monoid_cancel) is_comm_monoid_cancel: | |
| 58 | "comm_monoid_cancel G" | |
| 28823 | 59 | by intro_locales | 
| 27701 | 60 | |
| 29237 | 61 | sublocale comm_group \<subseteq> comm_monoid_cancel | 
| 28823 | 62 | .. | 
| 27701 | 63 | |
| 64 | ||
| 27717 
21bbd410ba04
Generalised polynomial lemmas from cring to ring.
 ballarin parents: 
27713diff
changeset | 65 | subsection {* Products of Units in Monoids *}
 | 
| 27701 | 66 | |
| 67 | lemma (in monoid) Units_m_closed[simp, intro]: | |
| 68 | assumes h1unit: "h1 \<in> Units G" and h2unit: "h2 \<in> Units G" | |
| 69 | shows "h1 \<otimes> h2 \<in> Units G" | |
| 70 | unfolding Units_def | |
| 71 | using assms | |
| 72 | apply safe | |
| 73 | apply fast | |
| 74 | apply (intro bexI[of _ "inv h2 \<otimes> inv h1"], safe) | |
| 75 | apply (simp add: m_assoc Units_closed) | |
| 76 | apply (simp add: m_assoc[symmetric] Units_closed Units_l_inv) | |
| 77 | apply (simp add: m_assoc Units_closed) | |
| 78 | apply (simp add: m_assoc[symmetric] Units_closed Units_r_inv) | |
| 79 | apply fast | |
| 80 | done | |
| 81 | ||
| 82 | lemma (in monoid) prod_unit_l: | |
| 83 | assumes abunit[simp]: "a \<otimes> b \<in> Units G" and aunit[simp]: "a \<in> Units G" | |
| 84 | and carr[simp]: "a \<in> carrier G" "b \<in> carrier G" | |
| 85 | shows "b \<in> Units G" | |
| 86 | proof - | |
| 87 | have c: "inv (a \<otimes> b) \<otimes> a \<in> carrier G" by simp | |
| 88 | ||
| 89 | have "(inv (a \<otimes> b) \<otimes> a) \<otimes> b = inv (a \<otimes> b) \<otimes> (a \<otimes> b)" by (simp add: m_assoc) | |
| 90 | also have "\<dots> = \<one>" by (simp add: Units_l_inv) | |
| 91 | finally have li: "(inv (a \<otimes> b) \<otimes> a) \<otimes> b = \<one>" . | |
| 92 | ||
| 93 | have "\<one> = inv a \<otimes> a" by (simp add: Units_l_inv[symmetric]) | |
| 94 | also have "\<dots> = inv a \<otimes> \<one> \<otimes> a" by simp | |
| 95 | also have "\<dots> = inv a \<otimes> ((a \<otimes> b) \<otimes> inv (a \<otimes> b)) \<otimes> a" | |
| 96 | by (simp add: Units_r_inv[OF abunit, symmetric] del: Units_r_inv) | |
| 97 | also have "\<dots> = ((inv a \<otimes> a) \<otimes> b) \<otimes> inv (a \<otimes> b) \<otimes> a" | |
| 98 | by (simp add: m_assoc del: Units_l_inv) | |
| 99 | also have "\<dots> = b \<otimes> inv (a \<otimes> b) \<otimes> a" by (simp add: Units_l_inv) | |
| 100 | also have "\<dots> = b \<otimes> (inv (a \<otimes> b) \<otimes> a)" by (simp add: m_assoc) | |
| 101 | finally have ri: "b \<otimes> (inv (a \<otimes> b) \<otimes> a) = \<one> " by simp | |
| 102 | ||
| 103 | from c li ri | |
| 104 | show "b \<in> Units G" by (simp add: Units_def, fast) | |
| 105 | qed | |
| 106 | ||
| 107 | lemma (in monoid) prod_unit_r: | |
| 108 | assumes abunit[simp]: "a \<otimes> b \<in> Units G" and bunit[simp]: "b \<in> Units G" | |
| 109 | and carr[simp]: "a \<in> carrier G" "b \<in> carrier G" | |
| 110 | shows "a \<in> Units G" | |
| 111 | proof - | |
| 112 | have c: "b \<otimes> inv (a \<otimes> b) \<in> carrier G" by simp | |
| 113 | ||
| 114 | have "a \<otimes> (b \<otimes> inv (a \<otimes> b)) = (a \<otimes> b) \<otimes> inv (a \<otimes> b)" | |
| 115 | by (simp add: m_assoc del: Units_r_inv) | |
| 116 | also have "\<dots> = \<one>" by simp | |
| 117 | finally have li: "a \<otimes> (b \<otimes> inv (a \<otimes> b)) = \<one>" . | |
| 118 | ||
| 119 | have "\<one> = b \<otimes> inv b" by (simp add: Units_r_inv[symmetric]) | |
| 120 | also have "\<dots> = b \<otimes> \<one> \<otimes> inv b" by simp | |
| 121 | also have "\<dots> = b \<otimes> (inv (a \<otimes> b) \<otimes> (a \<otimes> b)) \<otimes> inv b" | |
| 122 | by (simp add: Units_l_inv[OF abunit, symmetric] del: Units_l_inv) | |
| 123 | also have "\<dots> = (b \<otimes> inv (a \<otimes> b) \<otimes> a) \<otimes> (b \<otimes> inv b)" | |
| 124 | by (simp add: m_assoc del: Units_l_inv) | |
| 125 | also have "\<dots> = b \<otimes> inv (a \<otimes> b) \<otimes> a" by simp | |
| 126 | finally have ri: "(b \<otimes> inv (a \<otimes> b)) \<otimes> a = \<one> " by simp | |
| 127 | ||
| 128 | from c li ri | |
| 129 | show "a \<in> Units G" by (simp add: Units_def, fast) | |
| 130 | qed | |
| 131 | ||
| 132 | lemma (in comm_monoid) unit_factor: | |
| 133 | assumes abunit: "a \<otimes> b \<in> Units G" | |
| 134 | and [simp]: "a \<in> carrier G" "b \<in> carrier G" | |
| 135 | shows "a \<in> Units G" | |
| 136 | using abunit[simplified Units_def] | |
| 137 | proof clarsimp | |
| 138 | fix i | |
| 139 | assume [simp]: "i \<in> carrier G" | |
| 140 | and li: "i \<otimes> (a \<otimes> b) = \<one>" | |
| 141 | and ri: "a \<otimes> b \<otimes> i = \<one>" | |
| 142 | ||
| 143 | have carr': "b \<otimes> i \<in> carrier G" by simp | |
| 144 | ||
| 145 | have "(b \<otimes> i) \<otimes> a = (i \<otimes> b) \<otimes> a" by (simp add: m_comm) | |
| 146 | also have "\<dots> = i \<otimes> (b \<otimes> a)" by (simp add: m_assoc) | |
| 147 | also have "\<dots> = i \<otimes> (a \<otimes> b)" by (simp add: m_comm) | |
| 148 | also note li | |
| 149 | finally have li': "(b \<otimes> i) \<otimes> a = \<one>" . | |
| 150 | ||
| 151 | have "a \<otimes> (b \<otimes> i) = a \<otimes> b \<otimes> i" by (simp add: m_assoc) | |
| 152 | also note ri | |
| 153 | finally have ri': "a \<otimes> (b \<otimes> i) = \<one>" . | |
| 154 | ||
| 155 | from carr' li' ri' | |
| 156 | show "a \<in> Units G" by (simp add: Units_def, fast) | |
| 157 | qed | |
| 158 | ||
| 27717 
21bbd410ba04
Generalised polynomial lemmas from cring to ring.
 ballarin parents: 
27713diff
changeset | 159 | subsection {* Divisibility and Association *}
 | 
| 27701 | 160 | |
| 161 | subsubsection {* Function definitions *}
 | |
| 162 | ||
| 163 | constdefs (structure G) | |
| 164 | factor :: "[_, 'a, 'a] \<Rightarrow> bool" (infix "divides\<index>" 65) | |
| 165 | "a divides b == \<exists>c\<in>carrier G. b = a \<otimes> c" | |
| 166 | ||
| 167 | constdefs (structure G) | |
| 168 | associated :: "[_, 'a, 'a] => bool" (infix "\<sim>\<index>" 55) | |
| 169 | "a \<sim> b == a divides b \<and> b divides a" | |
| 170 | ||
| 171 | abbreviation | |
| 172 | "division_rel G == \<lparr>carrier = carrier G, eq = op \<sim>\<^bsub>G\<^esub>, le = op divides\<^bsub>G\<^esub>\<rparr>" | |
| 173 | ||
| 174 | constdefs (structure G) | |
| 175 | properfactor :: "[_, 'a, 'a] \<Rightarrow> bool" | |
| 176 | "properfactor G a b == a divides b \<and> \<not>(b divides a)" | |
| 177 | ||
| 178 | constdefs (structure G) | |
| 179 | irreducible :: "[_, 'a] \<Rightarrow> bool" | |
| 180 | "irreducible G a == a \<notin> Units G \<and> (\<forall>b\<in>carrier G. properfactor G b a \<longrightarrow> b \<in> Units G)" | |
| 181 | ||
| 182 | constdefs (structure G) | |
| 183 | prime :: "[_, 'a] \<Rightarrow> bool" | |
| 184 | "prime G p == p \<notin> Units G \<and> | |
| 185 | (\<forall>a\<in>carrier G. \<forall>b\<in>carrier G. p divides (a \<otimes> b) \<longrightarrow> p divides a \<or> p divides b)" | |
| 186 | ||
| 187 | ||
| 188 | ||
| 189 | subsubsection {* Divisibility *}
 | |
| 190 | ||
| 191 | lemma dividesI: | |
| 192 | fixes G (structure) | |
| 193 | assumes carr: "c \<in> carrier G" | |
| 194 | and p: "b = a \<otimes> c" | |
| 195 | shows "a divides b" | |
| 196 | unfolding factor_def | |
| 197 | using assms by fast | |
| 198 | ||
| 199 | lemma dividesI' [intro]: | |
| 200 | fixes G (structure) | |
| 201 | assumes p: "b = a \<otimes> c" | |
| 202 | and carr: "c \<in> carrier G" | |
| 203 | shows "a divides b" | |
| 204 | using assms | |
| 205 | by (fast intro: dividesI) | |
| 206 | ||
| 207 | lemma dividesD: | |
| 208 | fixes G (structure) | |
| 209 | assumes "a divides b" | |
| 210 | shows "\<exists>c\<in>carrier G. b = a \<otimes> c" | |
| 211 | using assms | |
| 212 | unfolding factor_def | |
| 213 | by fast | |
| 214 | ||
| 215 | lemma dividesE [elim]: | |
| 216 | fixes G (structure) | |
| 217 | assumes d: "a divides b" | |
| 218 | and elim: "\<And>c. \<lbrakk>b = a \<otimes> c; c \<in> carrier G\<rbrakk> \<Longrightarrow> P" | |
| 219 | shows "P" | |
| 220 | proof - | |
| 221 | from dividesD[OF d] | |
| 222 | obtain c | |
| 223 | where "c\<in>carrier G" | |
| 224 | and "b = a \<otimes> c" | |
| 225 | by auto | |
| 226 | thus "P" by (elim elim) | |
| 227 | qed | |
| 228 | ||
| 229 | lemma (in monoid) divides_refl[simp, intro!]: | |
| 230 | assumes carr: "a \<in> carrier G" | |
| 231 | shows "a divides a" | |
| 232 | apply (intro dividesI[of "\<one>"]) | |
| 233 | apply (simp, simp add: carr) | |
| 234 | done | |
| 235 | ||
| 236 | lemma (in monoid) divides_trans [trans]: | |
| 237 | assumes dvds: "a divides b" "b divides c" | |
| 238 | and acarr: "a \<in> carrier G" | |
| 239 | shows "a divides c" | |
| 240 | using dvds[THEN dividesD] | |
| 241 | by (blast intro: dividesI m_assoc acarr) | |
| 242 | ||
| 243 | lemma (in monoid) divides_mult_lI [intro]: | |
| 244 | assumes ab: "a divides b" | |
| 245 | and carr: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | |
| 246 | shows "(c \<otimes> a) divides (c \<otimes> b)" | |
| 247 | using ab | |
| 248 | apply (elim dividesE, simp add: m_assoc[symmetric] carr) | |
| 249 | apply (fast intro: dividesI) | |
| 250 | done | |
| 251 | ||
| 252 | lemma (in monoid_cancel) divides_mult_l [simp]: | |
| 253 | assumes carr: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | |
| 254 | shows "(c \<otimes> a) divides (c \<otimes> b) = a divides b" | |
| 255 | apply safe | |
| 256 | apply (elim dividesE, intro dividesI, assumption) | |
| 257 | apply (rule l_cancel[of c]) | |
| 258 | apply (simp add: m_assoc carr)+ | |
| 259 | apply (fast intro: divides_mult_lI carr) | |
| 260 | done | |
| 261 | ||
| 262 | lemma (in comm_monoid) divides_mult_rI [intro]: | |
| 263 | assumes ab: "a divides b" | |
| 264 | and carr: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | |
| 265 | shows "(a \<otimes> c) divides (b \<otimes> c)" | |
| 266 | using carr ab | |
| 267 | apply (simp add: m_comm[of a c] m_comm[of b c]) | |
| 268 | apply (rule divides_mult_lI, assumption+) | |
| 269 | done | |
| 270 | ||
| 271 | lemma (in comm_monoid_cancel) divides_mult_r [simp]: | |
| 272 | assumes carr: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | |
| 273 | shows "(a \<otimes> c) divides (b \<otimes> c) = a divides b" | |
| 274 | using carr | |
| 275 | by (simp add: m_comm[of a c] m_comm[of b c]) | |
| 276 | ||
| 277 | lemma (in monoid) divides_prod_r: | |
| 278 | assumes ab: "a divides b" | |
| 279 | and carr: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | |
| 280 | shows "a divides (b \<otimes> c)" | |
| 281 | using ab carr | |
| 282 | by (fast intro: m_assoc) | |
| 283 | ||
| 284 | lemma (in comm_monoid) divides_prod_l: | |
| 285 | assumes carr[intro]: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | |
| 286 | and ab: "a divides b" | |
| 287 | shows "a divides (c \<otimes> b)" | |
| 288 | using ab carr | |
| 289 | apply (simp add: m_comm[of c b]) | |
| 290 | apply (fast intro: divides_prod_r) | |
| 291 | done | |
| 292 | ||
| 293 | lemma (in monoid) unit_divides: | |
| 294 | assumes uunit: "u \<in> Units G" | |
| 295 | and acarr: "a \<in> carrier G" | |
| 296 | shows "u divides a" | |
| 297 | proof (intro dividesI[of "(inv u) \<otimes> a"], fast intro: uunit acarr) | |
| 298 | from uunit acarr | |
| 299 | have xcarr: "inv u \<otimes> a \<in> carrier G" by fast | |
| 300 | ||
| 301 | from uunit acarr | |
| 302 | have "u \<otimes> (inv u \<otimes> a) = (u \<otimes> inv u) \<otimes> a" by (fast intro: m_assoc[symmetric]) | |
| 303 | also have "\<dots> = \<one> \<otimes> a" by (simp add: Units_r_inv[OF uunit]) | |
| 304 | also from acarr | |
| 305 | have "\<dots> = a" by simp | |
| 306 | finally | |
| 307 | show "a = u \<otimes> (inv u \<otimes> a)" .. | |
| 308 | qed | |
| 309 | ||
| 310 | lemma (in comm_monoid) divides_unit: | |
| 311 | assumes udvd: "a divides u" | |
| 312 | and carr: "a \<in> carrier G" "u \<in> Units G" | |
| 313 | shows "a \<in> Units G" | |
| 314 | using udvd carr | |
| 315 | by (blast intro: unit_factor) | |
| 316 | ||
| 317 | lemma (in comm_monoid) Unit_eq_dividesone: | |
| 318 | assumes ucarr: "u \<in> carrier G" | |
| 319 | shows "u \<in> Units G = u divides \<one>" | |
| 320 | using ucarr | |
| 321 | by (fast dest: divides_unit intro: unit_divides) | |
| 322 | ||
| 323 | ||
| 324 | subsubsection {* Association *}
 | |
| 325 | ||
| 326 | lemma associatedI: | |
| 327 | fixes G (structure) | |
| 328 | assumes "a divides b" "b divides a" | |
| 329 | shows "a \<sim> b" | |
| 330 | using assms | |
| 331 | by (simp add: associated_def) | |
| 332 | ||
| 333 | lemma (in monoid) associatedI2: | |
| 334 | assumes uunit[simp]: "u \<in> Units G" | |
| 335 | and a: "a = b \<otimes> u" | |
| 336 | and bcarr[simp]: "b \<in> carrier G" | |
| 337 | shows "a \<sim> b" | |
| 338 | using uunit bcarr | |
| 339 | unfolding a | |
| 340 | apply (intro associatedI) | |
| 341 | apply (rule dividesI[of "inv u"], simp) | |
| 342 | apply (simp add: m_assoc Units_closed Units_r_inv) | |
| 343 | apply fast | |
| 344 | done | |
| 345 | ||
| 346 | lemma (in monoid) associatedI2': | |
| 347 | assumes a: "a = b \<otimes> u" | |
| 348 | and uunit: "u \<in> Units G" | |
| 349 | and bcarr: "b \<in> carrier G" | |
| 350 | shows "a \<sim> b" | |
| 351 | using assms by (intro associatedI2) | |
| 352 | ||
| 353 | lemma associatedD: | |
| 354 | fixes G (structure) | |
| 355 | assumes "a \<sim> b" | |
| 356 | shows "a divides b" | |
| 357 | using assms by (simp add: associated_def) | |
| 358 | ||
| 359 | lemma (in monoid_cancel) associatedD2: | |
| 360 | assumes assoc: "a \<sim> b" | |
| 361 | and carr: "a \<in> carrier G" "b \<in> carrier G" | |
| 362 | shows "\<exists>u\<in>Units G. a = b \<otimes> u" | |
| 363 | using assoc | |
| 364 | unfolding associated_def | |
| 365 | proof clarify | |
| 366 | assume "b divides a" | |
| 367 | hence "\<exists>u\<in>carrier G. a = b \<otimes> u" by (rule dividesD) | |
| 368 | from this obtain u | |
| 369 | where ucarr: "u \<in> carrier G" and a: "a = b \<otimes> u" | |
| 370 | by auto | |
| 371 | ||
| 372 | assume "a divides b" | |
| 373 | hence "\<exists>u'\<in>carrier G. b = a \<otimes> u'" by (rule dividesD) | |
| 374 | from this obtain u' | |
| 375 | where u'carr: "u' \<in> carrier G" and b: "b = a \<otimes> u'" | |
| 376 | by auto | |
| 377 | note carr = carr ucarr u'carr | |
| 378 | ||
| 379 | from carr | |
| 380 | have "a \<otimes> \<one> = a" by simp | |
| 381 | also have "\<dots> = b \<otimes> u" by (simp add: a) | |
| 382 | also have "\<dots> = a \<otimes> u' \<otimes> u" by (simp add: b) | |
| 383 | also from carr | |
| 384 | have "\<dots> = a \<otimes> (u' \<otimes> u)" by (simp add: m_assoc) | |
| 385 | finally | |
| 386 | have "a \<otimes> \<one> = a \<otimes> (u' \<otimes> u)" . | |
| 387 | with carr | |
| 388 | have u1: "\<one> = u' \<otimes> u" by (fast dest: l_cancel) | |
| 389 | ||
| 390 | from carr | |
| 391 | have "b \<otimes> \<one> = b" by simp | |
| 392 | also have "\<dots> = a \<otimes> u'" by (simp add: b) | |
| 393 | also have "\<dots> = b \<otimes> u \<otimes> u'" by (simp add: a) | |
| 394 | also from carr | |
| 395 | have "\<dots> = b \<otimes> (u \<otimes> u')" by (simp add: m_assoc) | |
| 396 | finally | |
| 397 | have "b \<otimes> \<one> = b \<otimes> (u \<otimes> u')" . | |
| 398 | with carr | |
| 399 | have u2: "\<one> = u \<otimes> u'" by (fast dest: l_cancel) | |
| 400 | ||
| 401 | from u'carr u1[symmetric] u2[symmetric] | |
| 402 | have "\<exists>u'\<in>carrier G. u' \<otimes> u = \<one> \<and> u \<otimes> u' = \<one>" by fast | |
| 403 | hence "u \<in> Units G" by (simp add: Units_def ucarr) | |
| 404 | ||
| 405 | from ucarr this a | |
| 406 | show "\<exists>u\<in>Units G. a = b \<otimes> u" by fast | |
| 407 | qed | |
| 408 | ||
| 409 | lemma associatedE: | |
| 410 | fixes G (structure) | |
| 411 | assumes assoc: "a \<sim> b" | |
| 412 | and e: "\<lbrakk>a divides b; b divides a\<rbrakk> \<Longrightarrow> P" | |
| 413 | shows "P" | |
| 414 | proof - | |
| 415 | from assoc | |
| 416 | have "a divides b" "b divides a" | |
| 417 | by (simp add: associated_def)+ | |
| 418 | thus "P" by (elim e) | |
| 419 | qed | |
| 420 | ||
| 421 | lemma (in monoid_cancel) associatedE2: | |
| 422 | assumes assoc: "a \<sim> b" | |
| 423 | and e: "\<And>u. \<lbrakk>a = b \<otimes> u; u \<in> Units G\<rbrakk> \<Longrightarrow> P" | |
| 424 | and carr: "a \<in> carrier G" "b \<in> carrier G" | |
| 425 | shows "P" | |
| 426 | proof - | |
| 427 | from assoc and carr | |
| 428 | have "\<exists>u\<in>Units G. a = b \<otimes> u" by (rule associatedD2) | |
| 429 | from this obtain u | |
| 430 | where "u \<in> Units G" "a = b \<otimes> u" | |
| 431 | by auto | |
| 432 | thus "P" by (elim e) | |
| 433 | qed | |
| 434 | ||
| 435 | lemma (in monoid) associated_refl [simp, intro!]: | |
| 436 | assumes "a \<in> carrier G" | |
| 437 | shows "a \<sim> a" | |
| 438 | using assms | |
| 439 | by (fast intro: associatedI) | |
| 440 | ||
| 441 | lemma (in monoid) associated_sym [sym]: | |
| 442 | assumes "a \<sim> b" | |
| 443 | and "a \<in> carrier G" "b \<in> carrier G" | |
| 444 | shows "b \<sim> a" | |
| 445 | using assms | |
| 446 | by (iprover intro: associatedI elim: associatedE) | |
| 447 | ||
| 448 | lemma (in monoid) associated_trans [trans]: | |
| 449 | assumes "a \<sim> b" "b \<sim> c" | |
| 450 | and "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | |
| 451 | shows "a \<sim> c" | |
| 452 | using assms | |
| 453 | by (iprover intro: associatedI divides_trans elim: associatedE) | |
| 454 | ||
| 455 | lemma (in monoid) division_equiv [intro, simp]: | |
| 456 | "equivalence (division_rel G)" | |
| 457 | apply unfold_locales | |
| 458 | apply simp_all | |
| 459 | apply (rule associated_sym, assumption+) | |
| 460 | apply (iprover intro: associated_trans) | |
| 461 | done | |
| 462 | ||
| 463 | ||
| 464 | subsubsection {* Division and associativity *}
 | |
| 465 | ||
| 466 | lemma divides_antisym: | |
| 467 | fixes G (structure) | |
| 468 | assumes "a divides b" "b divides a" | |
| 469 | and "a \<in> carrier G" "b \<in> carrier G" | |
| 470 | shows "a \<sim> b" | |
| 471 | using assms | |
| 472 | by (fast intro: associatedI) | |
| 473 | ||
| 474 | lemma (in monoid) divides_cong_l [trans]: | |
| 475 | assumes xx': "x \<sim> x'" | |
| 476 | and xdvdy: "x' divides y" | |
| 477 | and carr [simp]: "x \<in> carrier G" "x' \<in> carrier G" "y \<in> carrier G" | |
| 478 | shows "x divides y" | |
| 479 | proof - | |
| 480 | from xx' | |
| 481 | have "x divides x'" by (simp add: associatedD) | |
| 482 | also note xdvdy | |
| 483 | finally | |
| 484 | show "x divides y" by simp | |
| 485 | qed | |
| 486 | ||
| 487 | lemma (in monoid) divides_cong_r [trans]: | |
| 488 | assumes xdvdy: "x divides y" | |
| 489 | and yy': "y \<sim> y'" | |
| 490 | and carr[simp]: "x \<in> carrier G" "y \<in> carrier G" "y' \<in> carrier G" | |
| 491 | shows "x divides y'" | |
| 492 | proof - | |
| 493 | note xdvdy | |
| 494 | also from yy' | |
| 495 | have "y divides y'" by (simp add: associatedD) | |
| 496 | finally | |
| 497 | show "x divides y'" by simp | |
| 498 | qed | |
| 499 | ||
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 500 | lemma (in monoid) division_weak_partial_order [simp, intro!]: | 
| 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 501 | "weak_partial_order (division_rel G)" | 
| 27701 | 502 | apply unfold_locales | 
| 503 | apply simp_all | |
| 504 | apply (simp add: associated_sym) | |
| 505 | apply (blast intro: associated_trans) | |
| 506 | apply (simp add: divides_antisym) | |
| 507 | apply (blast intro: divides_trans) | |
| 508 | apply (blast intro: divides_cong_l divides_cong_r associated_sym) | |
| 509 | done | |
| 510 | ||
| 511 | ||
| 512 | subsubsection {* Multiplication and associativity *}
 | |
| 513 | ||
| 514 | lemma (in monoid_cancel) mult_cong_r: | |
| 515 | assumes "b \<sim> b'" | |
| 516 | and carr: "a \<in> carrier G" "b \<in> carrier G" "b' \<in> carrier G" | |
| 517 | shows "a \<otimes> b \<sim> a \<otimes> b'" | |
| 518 | using assms | |
| 519 | apply (elim associatedE2, intro associatedI2) | |
| 520 | apply (auto intro: m_assoc[symmetric]) | |
| 521 | done | |
| 522 | ||
| 523 | lemma (in comm_monoid_cancel) mult_cong_l: | |
| 524 | assumes "a \<sim> a'" | |
| 525 | and carr: "a \<in> carrier G" "a' \<in> carrier G" "b \<in> carrier G" | |
| 526 | shows "a \<otimes> b \<sim> a' \<otimes> b" | |
| 527 | using assms | |
| 528 | apply (elim associatedE2, intro associatedI2) | |
| 529 | apply assumption | |
| 530 | apply (simp add: m_assoc Units_closed) | |
| 531 | apply (simp add: m_comm Units_closed) | |
| 532 | apply simp+ | |
| 533 | done | |
| 534 | ||
| 535 | lemma (in monoid_cancel) assoc_l_cancel: | |
| 536 | assumes carr: "a \<in> carrier G" "b \<in> carrier G" "b' \<in> carrier G" | |
| 537 | and "a \<otimes> b \<sim> a \<otimes> b'" | |
| 538 | shows "b \<sim> b'" | |
| 539 | using assms | |
| 540 | apply (elim associatedE2, intro associatedI2) | |
| 541 | apply assumption | |
| 542 | apply (rule l_cancel[of a]) | |
| 543 | apply (simp add: m_assoc Units_closed) | |
| 544 | apply fast+ | |
| 545 | done | |
| 546 | ||
| 547 | lemma (in comm_monoid_cancel) assoc_r_cancel: | |
| 548 | assumes "a \<otimes> b \<sim> a' \<otimes> b" | |
| 549 | and carr: "a \<in> carrier G" "a' \<in> carrier G" "b \<in> carrier G" | |
| 550 | shows "a \<sim> a'" | |
| 551 | using assms | |
| 552 | apply (elim associatedE2, intro associatedI2) | |
| 553 | apply assumption | |
| 554 | apply (rule r_cancel[of a b]) | |
| 555 | apply (simp add: m_assoc Units_closed) | |
| 556 | apply (simp add: m_comm Units_closed) | |
| 557 | apply fast+ | |
| 558 | done | |
| 559 | ||
| 560 | ||
| 561 | subsubsection {* Units *}
 | |
| 562 | ||
| 563 | lemma (in monoid_cancel) assoc_unit_l [trans]: | |
| 564 | assumes asc: "a \<sim> b" and bunit: "b \<in> Units G" | |
| 565 | and carr: "a \<in> carrier G" | |
| 566 | shows "a \<in> Units G" | |
| 567 | using assms | |
| 568 | by (fast elim: associatedE2) | |
| 569 | ||
| 570 | lemma (in monoid_cancel) assoc_unit_r [trans]: | |
| 571 | assumes aunit: "a \<in> Units G" and asc: "a \<sim> b" | |
| 572 | and bcarr: "b \<in> carrier G" | |
| 573 | shows "b \<in> Units G" | |
| 574 | using aunit bcarr associated_sym[OF asc] | |
| 575 | by (blast intro: assoc_unit_l) | |
| 576 | ||
| 577 | lemma (in comm_monoid) Units_cong: | |
| 578 | assumes aunit: "a \<in> Units G" and asc: "a \<sim> b" | |
| 579 | and bcarr: "b \<in> carrier G" | |
| 580 | shows "b \<in> Units G" | |
| 581 | using assms | |
| 582 | by (blast intro: divides_unit elim: associatedE) | |
| 583 | ||
| 584 | lemma (in monoid) Units_assoc: | |
| 585 | assumes units: "a \<in> Units G" "b \<in> Units G" | |
| 586 | shows "a \<sim> b" | |
| 587 | using units | |
| 588 | by (fast intro: associatedI unit_divides) | |
| 589 | ||
| 590 | lemma (in monoid) Units_are_ones: | |
| 591 |   "Units G {.=}\<^bsub>(division_rel G)\<^esub> {\<one>}"
 | |
| 592 | apply (simp add: set_eq_def elem_def, rule, simp_all) | |
| 593 | proof clarsimp | |
| 594 | fix a | |
| 595 | assume aunit: "a \<in> Units G" | |
| 596 | show "a \<sim> \<one>" | |
| 597 | apply (rule associatedI) | |
| 598 | apply (fast intro: dividesI[of "inv a"] aunit Units_r_inv[symmetric]) | |
| 599 | apply (fast intro: dividesI[of "a"] l_one[symmetric] Units_closed[OF aunit]) | |
| 600 | done | |
| 601 | next | |
| 602 | have "\<one> \<in> Units G" by simp | |
| 603 | moreover have "\<one> \<sim> \<one>" by simp | |
| 604 | ultimately show "\<exists>a \<in> Units G. \<one> \<sim> a" by fast | |
| 605 | qed | |
| 606 | ||
| 607 | lemma (in comm_monoid) Units_Lower: | |
| 608 | "Units G = Lower (division_rel G) (carrier G)" | |
| 609 | apply (simp add: Units_def Lower_def) | |
| 610 | apply (rule, rule) | |
| 611 | apply clarsimp | |
| 612 | apply (rule unit_divides) | |
| 613 | apply (unfold Units_def, fast) | |
| 614 | apply assumption | |
| 615 | apply clarsimp | |
| 616 | proof - | |
| 617 | fix x | |
| 618 | assume xcarr: "x \<in> carrier G" | |
| 619 | assume r[rule_format]: "\<forall>y. y \<in> carrier G \<longrightarrow> x divides y" | |
| 620 | have "\<one> \<in> carrier G" by simp | |
| 621 | hence "x divides \<one>" by (rule r) | |
| 622 | hence "\<exists>x'\<in>carrier G. \<one> = x \<otimes> x'" by (rule dividesE, fast) | |
| 623 | from this obtain x' | |
| 624 | where x'carr: "x' \<in> carrier G" | |
| 625 | and xx': "\<one> = x \<otimes> x'" | |
| 626 | by auto | |
| 627 | ||
| 628 | note xx' | |
| 629 | also with xcarr x'carr | |
| 630 | have "\<dots> = x' \<otimes> x" by (simp add: m_comm) | |
| 631 | finally | |
| 632 | have "\<one> = x' \<otimes> x" . | |
| 633 | ||
| 634 | from x'carr xx'[symmetric] this[symmetric] | |
| 635 | show "\<exists>y\<in>carrier G. y \<otimes> x = \<one> \<and> x \<otimes> y = \<one>" by fast | |
| 636 | qed | |
| 637 | ||
| 638 | ||
| 639 | subsubsection {* Proper factors *}
 | |
| 640 | ||
| 641 | lemma properfactorI: | |
| 642 | fixes G (structure) | |
| 643 | assumes "a divides b" | |
| 644 | and "\<not>(b divides a)" | |
| 645 | shows "properfactor G a b" | |
| 646 | using assms | |
| 647 | unfolding properfactor_def | |
| 648 | by simp | |
| 649 | ||
| 650 | lemma properfactorI2: | |
| 651 | fixes G (structure) | |
| 652 | assumes advdb: "a divides b" | |
| 653 | and neq: "\<not>(a \<sim> b)" | |
| 654 | shows "properfactor G a b" | |
| 655 | apply (rule properfactorI, rule advdb) | |
| 656 | proof (rule ccontr, simp) | |
| 657 | assume "b divides a" | |
| 658 | with advdb have "a \<sim> b" by (rule associatedI) | |
| 659 | with neq show "False" by fast | |
| 660 | qed | |
| 661 | ||
| 662 | lemma (in comm_monoid_cancel) properfactorI3: | |
| 663 | assumes p: "p = a \<otimes> b" | |
| 664 | and nunit: "b \<notin> Units G" | |
| 665 | and carr: "a \<in> carrier G" "b \<in> carrier G" "p \<in> carrier G" | |
| 666 | shows "properfactor G a p" | |
| 667 | unfolding p | |
| 668 | using carr | |
| 669 | apply (intro properfactorI, fast) | |
| 670 | proof (clarsimp, elim dividesE) | |
| 671 | fix c | |
| 672 | assume ccarr: "c \<in> carrier G" | |
| 673 | note [simp] = carr ccarr | |
| 674 | ||
| 675 | have "a \<otimes> \<one> = a" by simp | |
| 676 | also assume "a = a \<otimes> b \<otimes> c" | |
| 677 | also have "\<dots> = a \<otimes> (b \<otimes> c)" by (simp add: m_assoc) | |
| 678 | finally have "a \<otimes> \<one> = a \<otimes> (b \<otimes> c)" . | |
| 679 | ||
| 680 | hence rinv: "\<one> = b \<otimes> c" by (intro l_cancel[of "a" "\<one>" "b \<otimes> c"], simp+) | |
| 681 | also have "\<dots> = c \<otimes> b" by (simp add: m_comm) | |
| 682 | finally have linv: "\<one> = c \<otimes> b" . | |
| 683 | ||
| 684 | from ccarr linv[symmetric] rinv[symmetric] | |
| 685 | have "b \<in> Units G" unfolding Units_def by fastsimp | |
| 686 | with nunit | |
| 687 | show "False" .. | |
| 688 | qed | |
| 689 | ||
| 690 | lemma properfactorE: | |
| 691 | fixes G (structure) | |
| 692 | assumes pf: "properfactor G a b" | |
| 693 | and r: "\<lbrakk>a divides b; \<not>(b divides a)\<rbrakk> \<Longrightarrow> P" | |
| 694 | shows "P" | |
| 695 | using pf | |
| 696 | unfolding properfactor_def | |
| 697 | by (fast intro: r) | |
| 698 | ||
| 699 | lemma properfactorE2: | |
| 700 | fixes G (structure) | |
| 701 | assumes pf: "properfactor G a b" | |
| 702 | and elim: "\<lbrakk>a divides b; \<not>(a \<sim> b)\<rbrakk> \<Longrightarrow> P" | |
| 703 | shows "P" | |
| 704 | using pf | |
| 705 | unfolding properfactor_def | |
| 706 | by (fast elim: elim associatedE) | |
| 707 | ||
| 708 | lemma (in monoid) properfactor_unitE: | |
| 709 | assumes uunit: "u \<in> Units G" | |
| 710 | and pf: "properfactor G a u" | |
| 711 | and acarr: "a \<in> carrier G" | |
| 712 | shows "P" | |
| 713 | using pf unit_divides[OF uunit acarr] | |
| 714 | by (fast elim: properfactorE) | |
| 715 | ||
| 716 | ||
| 717 | lemma (in monoid) properfactor_divides: | |
| 718 | assumes pf: "properfactor G a b" | |
| 719 | shows "a divides b" | |
| 720 | using pf | |
| 721 | by (elim properfactorE) | |
| 722 | ||
| 723 | lemma (in monoid) properfactor_trans1 [trans]: | |
| 724 | assumes dvds: "a divides b" "properfactor G b c" | |
| 725 | and carr: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | |
| 726 | shows "properfactor G a c" | |
| 727 | using dvds carr | |
| 728 | apply (elim properfactorE, intro properfactorI) | |
| 729 | apply (iprover intro: divides_trans)+ | |
| 730 | done | |
| 731 | ||
| 732 | lemma (in monoid) properfactor_trans2 [trans]: | |
| 733 | assumes dvds: "properfactor G a b" "b divides c" | |
| 734 | and carr: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | |
| 735 | shows "properfactor G a c" | |
| 736 | using dvds carr | |
| 737 | apply (elim properfactorE, intro properfactorI) | |
| 738 | apply (iprover intro: divides_trans)+ | |
| 739 | done | |
| 740 | ||
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 741 | lemma properfactor_lless: | 
| 27701 | 742 | fixes G (structure) | 
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 743 | shows "properfactor G = lless (division_rel G)" | 
| 27701 | 744 | apply (rule ext) apply (rule ext) apply rule | 
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 745 | apply (fastsimp elim: properfactorE2 intro: weak_llessI) | 
| 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 746 | apply (fastsimp elim: weak_llessE intro: properfactorI2) | 
| 27701 | 747 | done | 
| 748 | ||
| 749 | lemma (in monoid) properfactor_cong_l [trans]: | |
| 750 | assumes x'x: "x' \<sim> x" | |
| 751 | and pf: "properfactor G x y" | |
| 752 | and carr: "x \<in> carrier G" "x' \<in> carrier G" "y \<in> carrier G" | |
| 753 | shows "properfactor G x' y" | |
| 754 | using pf | |
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 755 | unfolding properfactor_lless | 
| 27701 | 756 | proof - | 
| 29237 | 757 | interpret weak_partial_order "division_rel G" .. | 
| 27701 | 758 | from x'x | 
| 759 | have "x' .=\<^bsub>division_rel G\<^esub> x" by simp | |
| 760 | also assume "x \<sqsubset>\<^bsub>division_rel G\<^esub> y" | |
| 761 | finally | |
| 762 | show "x' \<sqsubset>\<^bsub>division_rel G\<^esub> y" by (simp add: carr) | |
| 763 | qed | |
| 764 | ||
| 765 | lemma (in monoid) properfactor_cong_r [trans]: | |
| 766 | assumes pf: "properfactor G x y" | |
| 767 | and yy': "y \<sim> y'" | |
| 768 | and carr: "x \<in> carrier G" "y \<in> carrier G" "y' \<in> carrier G" | |
| 769 | shows "properfactor G x y'" | |
| 770 | using pf | |
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 771 | unfolding properfactor_lless | 
| 27701 | 772 | proof - | 
| 29237 | 773 | interpret weak_partial_order "division_rel G" .. | 
| 27701 | 774 | assume "x \<sqsubset>\<^bsub>division_rel G\<^esub> y" | 
| 775 | also from yy' | |
| 776 | have "y .=\<^bsub>division_rel G\<^esub> y'" by simp | |
| 777 | finally | |
| 778 | show "x \<sqsubset>\<^bsub>division_rel G\<^esub> y'" by (simp add: carr) | |
| 779 | qed | |
| 780 | ||
| 781 | lemma (in monoid_cancel) properfactor_mult_lI [intro]: | |
| 782 | assumes ab: "properfactor G a b" | |
| 783 | and carr: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | |
| 784 | shows "properfactor G (c \<otimes> a) (c \<otimes> b)" | |
| 785 | using ab carr | |
| 786 | by (fastsimp elim: properfactorE intro: properfactorI) | |
| 787 | ||
| 788 | lemma (in monoid_cancel) properfactor_mult_l [simp]: | |
| 789 | assumes carr: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | |
| 790 | shows "properfactor G (c \<otimes> a) (c \<otimes> b) = properfactor G a b" | |
| 791 | using carr | |
| 792 | by (fastsimp elim: properfactorE intro: properfactorI) | |
| 793 | ||
| 794 | lemma (in comm_monoid_cancel) properfactor_mult_rI [intro]: | |
| 795 | assumes ab: "properfactor G a b" | |
| 796 | and carr: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | |
| 797 | shows "properfactor G (a \<otimes> c) (b \<otimes> c)" | |
| 798 | using ab carr | |
| 799 | by (fastsimp elim: properfactorE intro: properfactorI) | |
| 800 | ||
| 801 | lemma (in comm_monoid_cancel) properfactor_mult_r [simp]: | |
| 802 | assumes carr: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | |
| 803 | shows "properfactor G (a \<otimes> c) (b \<otimes> c) = properfactor G a b" | |
| 804 | using carr | |
| 805 | by (fastsimp elim: properfactorE intro: properfactorI) | |
| 806 | ||
| 807 | lemma (in monoid) properfactor_prod_r: | |
| 808 | assumes ab: "properfactor G a b" | |
| 809 | and carr[simp]: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | |
| 810 | shows "properfactor G a (b \<otimes> c)" | |
| 811 | by (intro properfactor_trans2[OF ab] divides_prod_r, simp+) | |
| 812 | ||
| 813 | lemma (in comm_monoid) properfactor_prod_l: | |
| 814 | assumes ab: "properfactor G a b" | |
| 815 | and carr[simp]: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | |
| 816 | shows "properfactor G a (c \<otimes> b)" | |
| 817 | by (intro properfactor_trans2[OF ab] divides_prod_l, simp+) | |
| 818 | ||
| 819 | ||
| 27717 
21bbd410ba04
Generalised polynomial lemmas from cring to ring.
 ballarin parents: 
27713diff
changeset | 820 | subsection {* Irreducible Elements and Primes *}
 | 
| 27701 | 821 | |
| 822 | subsubsection {* Irreducible elements *}
 | |
| 823 | ||
| 824 | lemma irreducibleI: | |
| 825 | fixes G (structure) | |
| 826 | assumes "a \<notin> Units G" | |
| 827 | and "\<And>b. \<lbrakk>b \<in> carrier G; properfactor G b a\<rbrakk> \<Longrightarrow> b \<in> Units G" | |
| 828 | shows "irreducible G a" | |
| 829 | using assms | |
| 830 | unfolding irreducible_def | |
| 831 | by blast | |
| 832 | ||
| 833 | lemma irreducibleE: | |
| 834 | fixes G (structure) | |
| 835 | assumes irr: "irreducible G a" | |
| 836 | and elim: "\<lbrakk>a \<notin> Units G; \<forall>b. b \<in> carrier G \<and> properfactor G b a \<longrightarrow> b \<in> Units G\<rbrakk> \<Longrightarrow> P" | |
| 837 | shows "P" | |
| 838 | using assms | |
| 839 | unfolding irreducible_def | |
| 840 | by blast | |
| 841 | ||
| 842 | lemma irreducibleD: | |
| 843 | fixes G (structure) | |
| 844 | assumes irr: "irreducible G a" | |
| 845 | and pf: "properfactor G b a" | |
| 846 | and bcarr: "b \<in> carrier G" | |
| 847 | shows "b \<in> Units G" | |
| 848 | using assms | |
| 849 | by (fast elim: irreducibleE) | |
| 850 | ||
| 851 | lemma (in monoid_cancel) irreducible_cong [trans]: | |
| 852 | assumes irred: "irreducible G a" | |
| 853 | and aa': "a \<sim> a'" | |
| 854 | and carr[simp]: "a \<in> carrier G" "a' \<in> carrier G" | |
| 855 | shows "irreducible G a'" | |
| 856 | using assms | |
| 857 | apply (elim irreducibleE, intro irreducibleI) | |
| 858 | apply simp_all | |
| 859 | proof clarify | |
| 860 | assume "a' \<in> Units G" | |
| 861 | also note aa'[symmetric] | |
| 862 | finally have aunit: "a \<in> Units G" by simp | |
| 863 | ||
| 864 | assume "a \<notin> Units G" | |
| 865 | with aunit | |
| 866 | show "False" by fast | |
| 867 | next | |
| 868 | fix b | |
| 869 | assume r[rule_format]: "\<forall>b. b \<in> carrier G \<and> properfactor G b a \<longrightarrow> b \<in> Units G" | |
| 870 | and bcarr[simp]: "b \<in> carrier G" | |
| 871 | assume "properfactor G b a'" | |
| 872 | also note aa'[symmetric] | |
| 873 | finally | |
| 874 | have "properfactor G b a" by simp | |
| 875 | ||
| 876 | with bcarr | |
| 877 | show "b \<in> Units G" by (fast intro: r) | |
| 878 | qed | |
| 879 | ||
| 880 | ||
| 881 | lemma (in monoid) irreducible_prod_rI: | |
| 882 | assumes airr: "irreducible G a" | |
| 883 | and bunit: "b \<in> Units G" | |
| 884 | and carr[simp]: "a \<in> carrier G" "b \<in> carrier G" | |
| 885 | shows "irreducible G (a \<otimes> b)" | |
| 886 | using airr carr bunit | |
| 887 | apply (elim irreducibleE, intro irreducibleI, clarify) | |
| 888 | apply (subgoal_tac "a \<in> Units G", simp) | |
| 889 | apply (intro prod_unit_r[of a b] carr bunit, assumption) | |
| 890 | proof - | |
| 891 | fix c | |
| 892 | assume [simp]: "c \<in> carrier G" | |
| 893 | and r[rule_format]: "\<forall>b. b \<in> carrier G \<and> properfactor G b a \<longrightarrow> b \<in> Units G" | |
| 894 | assume "properfactor G c (a \<otimes> b)" | |
| 895 | also have "a \<otimes> b \<sim> a" by (intro associatedI2[OF bunit], simp+) | |
| 896 | finally | |
| 897 | have pfa: "properfactor G c a" by simp | |
| 898 | show "c \<in> Units G" by (rule r, simp add: pfa) | |
| 899 | qed | |
| 900 | ||
| 901 | lemma (in comm_monoid) irreducible_prod_lI: | |
| 902 | assumes birr: "irreducible G b" | |
| 903 | and aunit: "a \<in> Units G" | |
| 904 | and carr [simp]: "a \<in> carrier G" "b \<in> carrier G" | |
| 905 | shows "irreducible G (a \<otimes> b)" | |
| 906 | apply (subst m_comm, simp+) | |
| 907 | apply (intro irreducible_prod_rI assms) | |
| 908 | done | |
| 909 | ||
| 910 | lemma (in comm_monoid_cancel) irreducible_prodE [elim]: | |
| 911 | assumes irr: "irreducible G (a \<otimes> b)" | |
| 912 | and carr[simp]: "a \<in> carrier G" "b \<in> carrier G" | |
| 913 | and e1: "\<lbrakk>irreducible G a; b \<in> Units G\<rbrakk> \<Longrightarrow> P" | |
| 914 | and e2: "\<lbrakk>a \<in> Units G; irreducible G b\<rbrakk> \<Longrightarrow> P" | |
| 915 | shows "P" | |
| 916 | using irr | |
| 917 | proof (elim irreducibleE) | |
| 918 | assume abnunit: "a \<otimes> b \<notin> Units G" | |
| 919 | and isunit[rule_format]: "\<forall>ba. ba \<in> carrier G \<and> properfactor G ba (a \<otimes> b) \<longrightarrow> ba \<in> Units G" | |
| 920 | ||
| 921 | show "P" | |
| 922 | proof (cases "a \<in> Units G") | |
| 923 | assume aunit: "a \<in> Units G" | |
| 924 | ||
| 925 | have "irreducible G b" | |
| 926 | apply (rule irreducibleI) | |
| 927 | proof (rule ccontr, simp) | |
| 928 | assume "b \<in> Units G" | |
| 929 | with aunit have "(a \<otimes> b) \<in> Units G" by fast | |
| 930 | with abnunit show "False" .. | |
| 931 | next | |
| 932 | fix c | |
| 933 | assume ccarr: "c \<in> carrier G" | |
| 934 | and "properfactor G c b" | |
| 935 | hence "properfactor G c (a \<otimes> b)" by (simp add: properfactor_prod_l[of c b a]) | |
| 936 | from ccarr this show "c \<in> Units G" by (fast intro: isunit) | |
| 937 | qed | |
| 938 | ||
| 939 | from aunit this show "P" by (rule e2) | |
| 940 | next | |
| 941 | assume anunit: "a \<notin> Units G" | |
| 942 | with carr have "properfactor G b (b \<otimes> a)" by (fast intro: properfactorI3) | |
| 943 | hence bf: "properfactor G b (a \<otimes> b)" by (subst m_comm[of a b], simp+) | |
| 944 | hence bunit: "b \<in> Units G" by (intro isunit, simp) | |
| 945 | ||
| 946 | have "irreducible G a" | |
| 947 | apply (rule irreducibleI) | |
| 948 | proof (rule ccontr, simp) | |
| 949 | assume "a \<in> Units G" | |
| 950 | with bunit have "(a \<otimes> b) \<in> Units G" by fast | |
| 951 | with abnunit show "False" .. | |
| 952 | next | |
| 953 | fix c | |
| 954 | assume ccarr: "c \<in> carrier G" | |
| 955 | and "properfactor G c a" | |
| 956 | hence "properfactor G c (a \<otimes> b)" by (simp add: properfactor_prod_r[of c a b]) | |
| 957 | from ccarr this show "c \<in> Units G" by (fast intro: isunit) | |
| 958 | qed | |
| 959 | ||
| 960 | from this bunit show "P" by (rule e1) | |
| 961 | qed | |
| 962 | qed | |
| 963 | ||
| 964 | ||
| 965 | subsubsection {* Prime elements *}
 | |
| 966 | ||
| 967 | lemma primeI: | |
| 968 | fixes G (structure) | |
| 969 | assumes "p \<notin> Units G" | |
| 970 | and "\<And>a b. \<lbrakk>a \<in> carrier G; b \<in> carrier G; p divides (a \<otimes> b)\<rbrakk> \<Longrightarrow> p divides a \<or> p divides b" | |
| 971 | shows "prime G p" | |
| 972 | using assms | |
| 973 | unfolding prime_def | |
| 974 | by blast | |
| 975 | ||
| 976 | lemma primeE: | |
| 977 | fixes G (structure) | |
| 978 | assumes pprime: "prime G p" | |
| 979 | and e: "\<lbrakk>p \<notin> Units G; \<forall>a\<in>carrier G. \<forall>b\<in>carrier G. | |
| 980 | p divides a \<otimes> b \<longrightarrow> p divides a \<or> p divides b\<rbrakk> \<Longrightarrow> P" | |
| 981 | shows "P" | |
| 982 | using pprime | |
| 983 | unfolding prime_def | |
| 984 | by (blast dest: e) | |
| 985 | ||
| 986 | lemma (in comm_monoid_cancel) prime_divides: | |
| 987 | assumes carr: "a \<in> carrier G" "b \<in> carrier G" | |
| 988 | and pprime: "prime G p" | |
| 989 | and pdvd: "p divides a \<otimes> b" | |
| 990 | shows "p divides a \<or> p divides b" | |
| 991 | using assms | |
| 992 | by (blast elim: primeE) | |
| 993 | ||
| 994 | lemma (in monoid_cancel) prime_cong [trans]: | |
| 995 | assumes pprime: "prime G p" | |
| 996 | and pp': "p \<sim> p'" | |
| 997 | and carr[simp]: "p \<in> carrier G" "p' \<in> carrier G" | |
| 998 | shows "prime G p'" | |
| 999 | using pprime | |
| 1000 | apply (elim primeE, intro primeI) | |
| 1001 | proof clarify | |
| 1002 | assume pnunit: "p \<notin> Units G" | |
| 1003 | assume "p' \<in> Units G" | |
| 1004 | also note pp'[symmetric] | |
| 1005 | finally | |
| 1006 | have "p \<in> Units G" by simp | |
| 1007 | with pnunit | |
| 1008 | show False .. | |
| 1009 | next | |
| 1010 | fix a b | |
| 1011 | assume r[rule_format]: | |
| 1012 | "\<forall>a\<in>carrier G. \<forall>b\<in>carrier G. p divides a \<otimes> b \<longrightarrow> p divides a \<or> p divides b" | |
| 1013 | assume p'dvd: "p' divides a \<otimes> b" | |
| 1014 | and carr'[simp]: "a \<in> carrier G" "b \<in> carrier G" | |
| 1015 | ||
| 1016 | note pp' | |
| 1017 | also note p'dvd | |
| 1018 | finally | |
| 1019 | have "p divides a \<otimes> b" by simp | |
| 1020 | hence "p divides a \<or> p divides b" by (intro r, simp+) | |
| 1021 |   moreover {
 | |
| 1022 | note pp'[symmetric] | |
| 1023 | also assume "p divides a" | |
| 1024 | finally | |
| 1025 | have "p' divides a" by simp | |
| 1026 | hence "p' divides a \<or> p' divides b" by simp | |
| 1027 | } | |
| 1028 |   moreover {
 | |
| 1029 | note pp'[symmetric] | |
| 1030 | also assume "p divides b" | |
| 1031 | finally | |
| 1032 | have "p' divides b" by simp | |
| 1033 | hence "p' divides a \<or> p' divides b" by simp | |
| 1034 | } | |
| 1035 | ultimately | |
| 1036 | show "p' divides a \<or> p' divides b" by fast | |
| 1037 | qed | |
| 1038 | ||
| 1039 | ||
| 27717 
21bbd410ba04
Generalised polynomial lemmas from cring to ring.
 ballarin parents: 
27713diff
changeset | 1040 | subsection {* Factorization and Factorial Monoids *}
 | 
| 27701 | 1041 | |
| 1042 | subsubsection {* Function definitions *}
 | |
| 1043 | ||
| 1044 | constdefs (structure G) | |
| 1045 | factors :: "[_, 'a list, 'a] \<Rightarrow> bool" | |
| 1046 | "factors G fs a == (\<forall>x \<in> (set fs). irreducible G x) \<and> foldr (op \<otimes>) fs \<one> = a" | |
| 1047 | ||
| 1048 | wfactors ::"[_, 'a list, 'a] \<Rightarrow> bool" | |
| 1049 | "wfactors G fs a == (\<forall>x \<in> (set fs). irreducible G x) \<and> foldr (op \<otimes>) fs \<one> \<sim> a" | |
| 1050 | ||
| 1051 | abbreviation | |
| 1052 |   list_assoc :: "('a,_) monoid_scheme \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> bool" (infix "[\<sim>]\<index>" 44) where
 | |
| 1053 | "list_assoc G == list_all2 (op \<sim>\<^bsub>G\<^esub>)" | |
| 1054 | ||
| 1055 | constdefs (structure G) | |
| 1056 | essentially_equal :: "[_, 'a list, 'a list] \<Rightarrow> bool" | |
| 1057 | "essentially_equal G fs1 fs2 == (\<exists>fs1'. fs1 <~~> fs1' \<and> fs1' [\<sim>] fs2)" | |
| 1058 | ||
| 1059 | ||
| 1060 | locale factorial_monoid = comm_monoid_cancel + | |
| 1061 | assumes factors_exist: | |
| 1062 | "\<lbrakk>a \<in> carrier G; a \<notin> Units G\<rbrakk> \<Longrightarrow> \<exists>fs. set fs \<subseteq> carrier G \<and> factors G fs a" | |
| 1063 | and factors_unique: | |
| 1064 | "\<lbrakk>factors G fs a; factors G fs' a; a \<in> carrier G; a \<notin> Units G; | |
| 1065 | set fs \<subseteq> carrier G; set fs' \<subseteq> carrier G\<rbrakk> \<Longrightarrow> essentially_equal G fs fs'" | |
| 1066 | ||
| 1067 | ||
| 1068 | subsubsection {* Comparing lists of elements *}
 | |
| 1069 | ||
| 1070 | text {* Association on lists *}
 | |
| 1071 | ||
| 1072 | lemma (in monoid) listassoc_refl [simp, intro]: | |
| 1073 | assumes "set as \<subseteq> carrier G" | |
| 1074 | shows "as [\<sim>] as" | |
| 1075 | using assms | |
| 1076 | by (induct as) simp+ | |
| 1077 | ||
| 1078 | lemma (in monoid) listassoc_sym [sym]: | |
| 1079 | assumes "as [\<sim>] bs" | |
| 1080 | and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G" | |
| 1081 | shows "bs [\<sim>] as" | |
| 1082 | using assms | |
| 1083 | proof (induct as arbitrary: bs, simp) | |
| 1084 | case Cons | |
| 1085 | thus ?case | |
| 1086 | apply (induct bs, simp) | |
| 1087 | apply clarsimp | |
| 1088 | apply (iprover intro: associated_sym) | |
| 1089 | done | |
| 1090 | qed | |
| 1091 | ||
| 1092 | lemma (in monoid) listassoc_trans [trans]: | |
| 1093 | assumes "as [\<sim>] bs" and "bs [\<sim>] cs" | |
| 1094 | and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G" and "set cs \<subseteq> carrier G" | |
| 1095 | shows "as [\<sim>] cs" | |
| 1096 | using assms | |
| 1097 | apply (simp add: list_all2_conv_all_nth set_conv_nth, safe) | |
| 1098 | apply (rule associated_trans) | |
| 1099 | apply (subgoal_tac "as ! i \<sim> bs ! i", assumption) | |
| 1100 | apply (simp, simp) | |
| 1101 | apply blast+ | |
| 1102 | done | |
| 1103 | ||
| 1104 | lemma (in monoid_cancel) irrlist_listassoc_cong: | |
| 1105 | assumes "\<forall>a\<in>set as. irreducible G a" | |
| 1106 | and "as [\<sim>] bs" | |
| 1107 | and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G" | |
| 1108 | shows "\<forall>a\<in>set bs. irreducible G a" | |
| 1109 | using assms | |
| 1110 | apply (clarsimp simp add: list_all2_conv_all_nth set_conv_nth) | |
| 1111 | apply (blast intro: irreducible_cong) | |
| 1112 | done | |
| 1113 | ||
| 1114 | ||
| 1115 | text {* Permutations *}
 | |
| 1116 | ||
| 1117 | lemma perm_map [intro]: | |
| 1118 | assumes p: "a <~~> b" | |
| 1119 | shows "map f a <~~> map f b" | |
| 1120 | using p | |
| 1121 | by induct auto | |
| 1122 | ||
| 1123 | lemma perm_map_switch: | |
| 1124 | assumes m: "map f a = map f b" and p: "b <~~> c" | |
| 1125 | shows "\<exists>d. a <~~> d \<and> map f d = map f c" | |
| 1126 | using p m | |
| 1127 | by (induct arbitrary: a) (simp, force, force, blast) | |
| 1128 | ||
| 1129 | lemma (in monoid) perm_assoc_switch: | |
| 1130 | assumes a:"as [\<sim>] bs" and p: "bs <~~> cs" | |
| 1131 | shows "\<exists>bs'. as <~~> bs' \<and> bs' [\<sim>] cs" | |
| 1132 | using p a | |
| 1133 | apply (induct bs cs arbitrary: as, simp) | |
| 1134 | apply (clarsimp simp add: list_all2_Cons2, blast) | |
| 1135 | apply (clarsimp simp add: list_all2_Cons2) | |
| 1136 | apply blast | |
| 1137 | apply blast | |
| 1138 | done | |
| 1139 | ||
| 1140 | lemma (in monoid) perm_assoc_switch_r: | |
| 1141 | assumes p: "as <~~> bs" and a:"bs [\<sim>] cs" | |
| 1142 | shows "\<exists>bs'. as [\<sim>] bs' \<and> bs' <~~> cs" | |
| 1143 | using p a | |
| 1144 | apply (induct as bs arbitrary: cs, simp) | |
| 1145 | apply (clarsimp simp add: list_all2_Cons1, blast) | |
| 1146 | apply (clarsimp simp add: list_all2_Cons1) | |
| 1147 | apply blast | |
| 1148 | apply blast | |
| 1149 | done | |
| 1150 | ||
| 1151 | declare perm_sym [sym] | |
| 1152 | ||
| 1153 | lemma perm_setP: | |
| 1154 | assumes perm: "as <~~> bs" | |
| 1155 | and as: "P (set as)" | |
| 1156 | shows "P (set bs)" | |
| 1157 | proof - | |
| 1158 | from perm | |
| 1159 | have "multiset_of as = multiset_of bs" | |
| 1160 | by (simp add: multiset_of_eq_perm) | |
| 1161 | hence "set as = set bs" by (rule multiset_of_eq_setD) | |
| 1162 | with as | |
| 1163 | show "P (set bs)" by simp | |
| 1164 | qed | |
| 1165 | ||
| 1166 | lemmas (in monoid) perm_closed = | |
| 1167 | perm_setP[of _ _ "\<lambda>as. as \<subseteq> carrier G"] | |
| 1168 | ||
| 1169 | lemmas (in monoid) irrlist_perm_cong = | |
| 1170 | perm_setP[of _ _ "\<lambda>as. \<forall>a\<in>as. irreducible G a"] | |
| 1171 | ||
| 1172 | ||
| 1173 | text {* Essentially equal factorizations *}
 | |
| 1174 | ||
| 1175 | lemma (in monoid) essentially_equalI: | |
| 1176 | assumes ex: "fs1 <~~> fs1'" "fs1' [\<sim>] fs2" | |
| 1177 | shows "essentially_equal G fs1 fs2" | |
| 1178 | using ex | |
| 1179 | unfolding essentially_equal_def | |
| 1180 | by fast | |
| 1181 | ||
| 1182 | lemma (in monoid) essentially_equalE: | |
| 1183 | assumes ee: "essentially_equal G fs1 fs2" | |
| 1184 | and e: "\<And>fs1'. \<lbrakk>fs1 <~~> fs1'; fs1' [\<sim>] fs2\<rbrakk> \<Longrightarrow> P" | |
| 1185 | shows "P" | |
| 1186 | using ee | |
| 1187 | unfolding essentially_equal_def | |
| 1188 | by (fast intro: e) | |
| 1189 | ||
| 1190 | lemma (in monoid) ee_refl [simp,intro]: | |
| 1191 | assumes carr: "set as \<subseteq> carrier G" | |
| 1192 | shows "essentially_equal G as as" | |
| 1193 | using carr | |
| 1194 | by (fast intro: essentially_equalI) | |
| 1195 | ||
| 1196 | lemma (in monoid) ee_sym [sym]: | |
| 1197 | assumes ee: "essentially_equal G as bs" | |
| 1198 | and carr: "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" | |
| 1199 | shows "essentially_equal G bs as" | |
| 1200 | using ee | |
| 1201 | proof (elim essentially_equalE) | |
| 1202 | fix fs | |
| 1203 | assume "as <~~> fs" "fs [\<sim>] bs" | |
| 1204 | hence "\<exists>fs'. as [\<sim>] fs' \<and> fs' <~~> bs" by (rule perm_assoc_switch_r) | |
| 1205 | from this obtain fs' | |
| 1206 | where a: "as [\<sim>] fs'" and p: "fs' <~~> bs" | |
| 1207 | by auto | |
| 1208 | from p have "bs <~~> fs'" by (rule perm_sym) | |
| 1209 | with a[symmetric] carr | |
| 1210 | show ?thesis | |
| 1211 | by (iprover intro: essentially_equalI perm_closed) | |
| 1212 | qed | |
| 1213 | ||
| 1214 | lemma (in monoid) ee_trans [trans]: | |
| 1215 | assumes ab: "essentially_equal G as bs" and bc: "essentially_equal G bs cs" | |
| 1216 | and ascarr: "set as \<subseteq> carrier G" | |
| 1217 | and bscarr: "set bs \<subseteq> carrier G" | |
| 1218 | and cscarr: "set cs \<subseteq> carrier G" | |
| 1219 | shows "essentially_equal G as cs" | |
| 1220 | using ab bc | |
| 1221 | proof (elim essentially_equalE) | |
| 1222 | fix abs bcs | |
| 1223 | assume "abs [\<sim>] bs" and pb: "bs <~~> bcs" | |
| 1224 | hence "\<exists>bs'. abs <~~> bs' \<and> bs' [\<sim>] bcs" by (rule perm_assoc_switch) | |
| 1225 | from this obtain bs' | |
| 1226 | where p: "abs <~~> bs'" and a: "bs' [\<sim>] bcs" | |
| 1227 | by auto | |
| 1228 | ||
| 1229 | assume "as <~~> abs" | |
| 1230 | with p | |
| 1231 | have pp: "as <~~> bs'" by fast | |
| 1232 | ||
| 1233 | from pp ascarr have c1: "set bs' \<subseteq> carrier G" by (rule perm_closed) | |
| 1234 | from pb bscarr have c2: "set bcs \<subseteq> carrier G" by (rule perm_closed) | |
| 1235 | note a | |
| 1236 | also assume "bcs [\<sim>] cs" | |
| 1237 | finally (listassoc_trans) have"bs' [\<sim>] cs" by (simp add: c1 c2 cscarr) | |
| 1238 | ||
| 1239 | with pp | |
| 1240 | show ?thesis | |
| 1241 | by (rule essentially_equalI) | |
| 1242 | qed | |
| 1243 | ||
| 1244 | ||
| 1245 | subsubsection {* Properties of lists of elements *}
 | |
| 1246 | ||
| 1247 | text {* Multiplication of factors in a list *}
 | |
| 1248 | ||
| 1249 | lemma (in monoid) multlist_closed [simp, intro]: | |
| 1250 | assumes ascarr: "set fs \<subseteq> carrier G" | |
| 1251 | shows "foldr (op \<otimes>) fs \<one> \<in> carrier G" | |
| 1252 | by (insert ascarr, induct fs, simp+) | |
| 1253 | ||
| 1254 | lemma (in comm_monoid) multlist_dividesI (*[intro]*): | |
| 1255 | assumes "f \<in> set fs" and "f \<in> carrier G" and "set fs \<subseteq> carrier G" | |
| 1256 | shows "f divides (foldr (op \<otimes>) fs \<one>)" | |
| 1257 | using assms | |
| 1258 | apply (induct fs) | |
| 1259 | apply simp | |
| 1260 | apply (case_tac "f = a", simp) | |
| 1261 | apply (fast intro: dividesI) | |
| 1262 | apply clarsimp | |
| 1263 | apply (elim dividesE, intro dividesI) | |
| 1264 | defer 1 | |
| 1265 | apply (simp add: m_comm) | |
| 1266 | apply (simp add: m_assoc[symmetric]) | |
| 1267 | apply (simp add: m_comm) | |
| 1268 | apply simp | |
| 1269 | done | |
| 1270 | ||
| 1271 | lemma (in comm_monoid_cancel) multlist_listassoc_cong: | |
| 1272 | assumes "fs [\<sim>] fs'" | |
| 1273 | and "set fs \<subseteq> carrier G" and "set fs' \<subseteq> carrier G" | |
| 1274 | shows "foldr (op \<otimes>) fs \<one> \<sim> foldr (op \<otimes>) fs' \<one>" | |
| 1275 | using assms | |
| 1276 | proof (induct fs arbitrary: fs', simp) | |
| 1277 | case (Cons a as fs') | |
| 1278 | thus ?case | |
| 1279 | apply (induct fs', simp) | |
| 1280 | proof clarsimp | |
| 1281 | fix b bs | |
| 1282 | assume "a \<sim> b" | |
| 1283 | and acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" | |
| 1284 | and ascarr: "set as \<subseteq> carrier G" | |
| 1285 | hence p: "a \<otimes> foldr op \<otimes> as \<one> \<sim> b \<otimes> foldr op \<otimes> as \<one>" | |
| 1286 | by (fast intro: mult_cong_l) | |
| 1287 | also | |
| 1288 | assume "as [\<sim>] bs" | |
| 1289 | and bscarr: "set bs \<subseteq> carrier G" | |
| 1290 | and "\<And>fs'. \<lbrakk>as [\<sim>] fs'; set fs' \<subseteq> carrier G\<rbrakk> \<Longrightarrow> foldr op \<otimes> as \<one> \<sim> foldr op \<otimes> fs' \<one>" | |
| 1291 | hence "foldr op \<otimes> as \<one> \<sim> foldr op \<otimes> bs \<one>" by simp | |
| 1292 | with ascarr bscarr bcarr | |
| 1293 | have "b \<otimes> foldr op \<otimes> as \<one> \<sim> b \<otimes> foldr op \<otimes> bs \<one>" | |
| 1294 | by (fast intro: mult_cong_r) | |
| 1295 | finally | |
| 1296 | show "a \<otimes> foldr op \<otimes> as \<one> \<sim> b \<otimes> foldr op \<otimes> bs \<one>" | |
| 1297 | by (simp add: ascarr bscarr acarr bcarr) | |
| 1298 | qed | |
| 1299 | qed | |
| 1300 | ||
| 1301 | lemma (in comm_monoid) multlist_perm_cong: | |
| 1302 | assumes prm: "as <~~> bs" | |
| 1303 | and ascarr: "set as \<subseteq> carrier G" | |
| 1304 | shows "foldr (op \<otimes>) as \<one> = foldr (op \<otimes>) bs \<one>" | |
| 1305 | using prm ascarr | |
| 1306 | apply (induct, simp, clarsimp simp add: m_ac, clarsimp) | |
| 1307 | proof clarsimp | |
| 1308 | fix xs ys zs | |
| 1309 | assume "xs <~~> ys" "set xs \<subseteq> carrier G" | |
| 1310 | hence "set ys \<subseteq> carrier G" by (rule perm_closed) | |
| 1311 | moreover assume "set ys \<subseteq> carrier G \<Longrightarrow> foldr op \<otimes> ys \<one> = foldr op \<otimes> zs \<one>" | |
| 1312 | ultimately show "foldr op \<otimes> ys \<one> = foldr op \<otimes> zs \<one>" by simp | |
| 1313 | qed | |
| 1314 | ||
| 1315 | lemma (in comm_monoid_cancel) multlist_ee_cong: | |
| 1316 | assumes "essentially_equal G fs fs'" | |
| 1317 | and "set fs \<subseteq> carrier G" and "set fs' \<subseteq> carrier G" | |
| 1318 | shows "foldr (op \<otimes>) fs \<one> \<sim> foldr (op \<otimes>) fs' \<one>" | |
| 1319 | using assms | |
| 1320 | apply (elim essentially_equalE) | |
| 1321 | apply (simp add: multlist_perm_cong multlist_listassoc_cong perm_closed) | |
| 1322 | done | |
| 1323 | ||
| 1324 | ||
| 1325 | subsubsection {* Factorization in irreducible elements *}
 | |
| 1326 | ||
| 1327 | lemma wfactorsI: | |
| 28599 | 1328 | fixes G (structure) | 
| 27701 | 1329 | assumes "\<forall>f\<in>set fs. irreducible G f" | 
| 1330 | and "foldr (op \<otimes>) fs \<one> \<sim> a" | |
| 1331 | shows "wfactors G fs a" | |
| 1332 | using assms | |
| 1333 | unfolding wfactors_def | |
| 1334 | by simp | |
| 1335 | ||
| 1336 | lemma wfactorsE: | |
| 28599 | 1337 | fixes G (structure) | 
| 27701 | 1338 | assumes wf: "wfactors G fs a" | 
| 1339 | and e: "\<lbrakk>\<forall>f\<in>set fs. irreducible G f; foldr (op \<otimes>) fs \<one> \<sim> a\<rbrakk> \<Longrightarrow> P" | |
| 1340 | shows "P" | |
| 1341 | using wf | |
| 1342 | unfolding wfactors_def | |
| 1343 | by (fast dest: e) | |
| 1344 | ||
| 1345 | lemma (in monoid) factorsI: | |
| 1346 | assumes "\<forall>f\<in>set fs. irreducible G f" | |
| 1347 | and "foldr (op \<otimes>) fs \<one> = a" | |
| 1348 | shows "factors G fs a" | |
| 1349 | using assms | |
| 1350 | unfolding factors_def | |
| 1351 | by simp | |
| 1352 | ||
| 1353 | lemma factorsE: | |
| 28599 | 1354 | fixes G (structure) | 
| 27701 | 1355 | assumes f: "factors G fs a" | 
| 1356 | and e: "\<lbrakk>\<forall>f\<in>set fs. irreducible G f; foldr (op \<otimes>) fs \<one> = a\<rbrakk> \<Longrightarrow> P" | |
| 1357 | shows "P" | |
| 1358 | using f | |
| 1359 | unfolding factors_def | |
| 1360 | by (simp add: e) | |
| 1361 | ||
| 1362 | lemma (in monoid) factors_wfactors: | |
| 1363 | assumes "factors G as a" and "set as \<subseteq> carrier G" | |
| 1364 | shows "wfactors G as a" | |
| 1365 | using assms | |
| 1366 | by (blast elim: factorsE intro: wfactorsI) | |
| 1367 | ||
| 1368 | lemma (in monoid) wfactors_factors: | |
| 1369 | assumes "wfactors G as a" and "set as \<subseteq> carrier G" | |
| 1370 | shows "\<exists>a'. factors G as a' \<and> a' \<sim> a" | |
| 1371 | using assms | |
| 1372 | by (blast elim: wfactorsE intro: factorsI) | |
| 1373 | ||
| 1374 | lemma (in monoid) factors_closed [dest]: | |
| 1375 | assumes "factors G fs a" and "set fs \<subseteq> carrier G" | |
| 1376 | shows "a \<in> carrier G" | |
| 1377 | using assms | |
| 1378 | by (elim factorsE, clarsimp) | |
| 1379 | ||
| 1380 | lemma (in monoid) nunit_factors: | |
| 1381 | assumes anunit: "a \<notin> Units G" | |
| 1382 | and fs: "factors G as a" | |
| 1383 | shows "length as > 0" | |
| 1384 | apply (insert fs, elim factorsE) | |
| 1385 | proof (cases "length as = 0") | |
| 1386 | assume "length as = 0" | |
| 1387 | hence fold: "foldr op \<otimes> as \<one> = \<one>" by force | |
| 1388 | ||
| 1389 | assume "foldr op \<otimes> as \<one> = a" | |
| 1390 | with fold | |
| 1391 | have "a = \<one>" by simp | |
| 1392 | then have "a \<in> Units G" by fast | |
| 1393 | with anunit | |
| 1394 | have "False" by simp | |
| 1395 | thus ?thesis .. | |
| 1396 | qed simp | |
| 1397 | ||
| 1398 | lemma (in monoid) unit_wfactors [simp]: | |
| 1399 | assumes aunit: "a \<in> Units G" | |
| 1400 | shows "wfactors G [] a" | |
| 1401 | using aunit | |
| 1402 | by (intro wfactorsI) (simp, simp add: Units_assoc) | |
| 1403 | ||
| 1404 | lemma (in comm_monoid_cancel) unit_wfactors_empty: | |
| 1405 | assumes aunit: "a \<in> Units G" | |
| 1406 | and wf: "wfactors G fs a" | |
| 1407 | and carr[simp]: "set fs \<subseteq> carrier G" | |
| 1408 | shows "fs = []" | |
| 1409 | proof (rule ccontr, cases fs, simp) | |
| 1410 | fix f fs' | |
| 1411 | assume fs: "fs = f # fs'" | |
| 1412 | ||
| 1413 | from carr | |
| 1414 | have fcarr[simp]: "f \<in> carrier G" | |
| 1415 | and carr'[simp]: "set fs' \<subseteq> carrier G" | |
| 1416 | by (simp add: fs)+ | |
| 1417 | ||
| 1418 | from fs wf | |
| 1419 | have "irreducible G f" by (simp add: wfactors_def) | |
| 1420 | hence fnunit: "f \<notin> Units G" by (fast elim: irreducibleE) | |
| 1421 | ||
| 1422 | from fs wf | |
| 1423 | have a: "f \<otimes> foldr (op \<otimes>) fs' \<one> \<sim> a" by (simp add: wfactors_def) | |
| 1424 | ||
| 1425 | note aunit | |
| 1426 | also from fs wf | |
| 1427 | have a: "f \<otimes> foldr (op \<otimes>) fs' \<one> \<sim> a" by (simp add: wfactors_def) | |
| 1428 | have "a \<sim> f \<otimes> foldr (op \<otimes>) fs' \<one>" | |
| 1429 | by (simp add: Units_closed[OF aunit] a[symmetric]) | |
| 1430 | finally | |
| 1431 | have "f \<otimes> foldr (op \<otimes>) fs' \<one> \<in> Units G" by simp | |
| 1432 | hence "f \<in> Units G" by (intro unit_factor[of f], simp+) | |
| 1433 | ||
| 1434 | with fnunit show "False" by simp | |
| 1435 | qed | |
| 1436 | ||
| 1437 | ||
| 1438 | text {* Comparing wfactors *}
 | |
| 1439 | ||
| 1440 | lemma (in comm_monoid_cancel) wfactors_listassoc_cong_l: | |
| 1441 | assumes fact: "wfactors G fs a" | |
| 1442 | and asc: "fs [\<sim>] fs'" | |
| 1443 | and carr: "a \<in> carrier G" "set fs \<subseteq> carrier G" "set fs' \<subseteq> carrier G" | |
| 1444 | shows "wfactors G fs' a" | |
| 1445 | using fact | |
| 1446 | apply (elim wfactorsE, intro wfactorsI) | |
| 1447 | proof - | |
| 1448 | assume "\<forall>f\<in>set fs. irreducible G f" | |
| 1449 | also note asc | |
| 1450 | finally (irrlist_listassoc_cong) | |
| 1451 | show "\<forall>f\<in>set fs'. irreducible G f" by (simp add: carr) | |
| 1452 | next | |
| 1453 | from asc[symmetric] | |
| 1454 | have "foldr op \<otimes> fs' \<one> \<sim> foldr op \<otimes> fs \<one>" | |
| 1455 | by (simp add: multlist_listassoc_cong carr) | |
| 1456 | also assume "foldr op \<otimes> fs \<one> \<sim> a" | |
| 1457 | finally | |
| 1458 | show "foldr op \<otimes> fs' \<one> \<sim> a" by (simp add: carr) | |
| 1459 | qed | |
| 1460 | ||
| 1461 | lemma (in comm_monoid) wfactors_perm_cong_l: | |
| 1462 | assumes "wfactors G fs a" | |
| 1463 | and "fs <~~> fs'" | |
| 1464 | and "set fs \<subseteq> carrier G" | |
| 1465 | shows "wfactors G fs' a" | |
| 1466 | using assms | |
| 1467 | apply (elim wfactorsE, intro wfactorsI) | |
| 1468 | apply (rule irrlist_perm_cong, assumption+) | |
| 1469 | apply (simp add: multlist_perm_cong[symmetric]) | |
| 1470 | done | |
| 1471 | ||
| 1472 | lemma (in comm_monoid_cancel) wfactors_ee_cong_l [trans]: | |
| 1473 | assumes ee: "essentially_equal G as bs" | |
| 1474 | and bfs: "wfactors G bs b" | |
| 1475 | and carr: "b \<in> carrier G" "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" | |
| 1476 | shows "wfactors G as b" | |
| 1477 | using ee | |
| 1478 | proof (elim essentially_equalE) | |
| 1479 | fix fs | |
| 1480 | assume prm: "as <~~> fs" | |
| 1481 | with carr | |
| 1482 | have fscarr: "set fs \<subseteq> carrier G" by (simp add: perm_closed) | |
| 1483 | ||
| 1484 | note bfs | |
| 1485 | also assume [symmetric]: "fs [\<sim>] bs" | |
| 1486 | also (wfactors_listassoc_cong_l) | |
| 1487 | note prm[symmetric] | |
| 1488 | finally (wfactors_perm_cong_l) | |
| 1489 | show "wfactors G as b" by (simp add: carr fscarr) | |
| 1490 | qed | |
| 1491 | ||
| 1492 | lemma (in monoid) wfactors_cong_r [trans]: | |
| 1493 | assumes fac: "wfactors G fs a" and aa': "a \<sim> a'" | |
| 1494 | and carr[simp]: "a \<in> carrier G" "a' \<in> carrier G" "set fs \<subseteq> carrier G" | |
| 1495 | shows "wfactors G fs a'" | |
| 1496 | using fac | |
| 1497 | proof (elim wfactorsE, intro wfactorsI) | |
| 1498 | assume "foldr op \<otimes> fs \<one> \<sim> a" also note aa' | |
| 1499 | finally show "foldr op \<otimes> fs \<one> \<sim> a'" by simp | |
| 1500 | qed | |
| 1501 | ||
| 1502 | ||
| 1503 | subsubsection {* Essentially equal factorizations *}
 | |
| 1504 | ||
| 1505 | lemma (in comm_monoid_cancel) unitfactor_ee: | |
| 1506 | assumes uunit: "u \<in> Units G" | |
| 1507 | and carr: "set as \<subseteq> carrier G" | |
| 1508 | shows "essentially_equal G (as[0 := (as!0 \<otimes> u)]) as" (is "essentially_equal G ?as' as") | |
| 1509 | using assms | |
| 1510 | apply (intro essentially_equalI[of _ ?as'], simp) | |
| 1511 | apply (cases as, simp) | |
| 1512 | apply (clarsimp, fast intro: associatedI2[of u]) | |
| 1513 | done | |
| 1514 | ||
| 1515 | lemma (in comm_monoid_cancel) factors_cong_unit: | |
| 1516 | assumes uunit: "u \<in> Units G" and anunit: "a \<notin> Units G" | |
| 1517 | and afs: "factors G as a" | |
| 1518 | and ascarr: "set as \<subseteq> carrier G" | |
| 1519 | shows "factors G (as[0 := (as!0 \<otimes> u)]) (a \<otimes> u)" (is "factors G ?as' ?a'") | |
| 1520 | using assms | |
| 1521 | apply (elim factorsE, clarify) | |
| 1522 | apply (cases as) | |
| 1523 | apply (simp add: nunit_factors) | |
| 1524 | apply clarsimp | |
| 1525 | apply (elim factorsE, intro factorsI) | |
| 1526 | apply (clarsimp, fast intro: irreducible_prod_rI) | |
| 1527 | apply (simp add: m_ac Units_closed) | |
| 1528 | done | |
| 1529 | ||
| 1530 | lemma (in comm_monoid) perm_wfactorsD: | |
| 1531 | assumes prm: "as <~~> bs" | |
| 1532 | and afs: "wfactors G as a" and bfs: "wfactors G bs b" | |
| 1533 | and [simp]: "a \<in> carrier G" "b \<in> carrier G" | |
| 1534 | and ascarr[simp]: "set as \<subseteq> carrier G" | |
| 1535 | shows "a \<sim> b" | |
| 1536 | using afs bfs | |
| 1537 | proof (elim wfactorsE) | |
| 1538 | from prm have [simp]: "set bs \<subseteq> carrier G" by (simp add: perm_closed) | |
| 1539 | assume "foldr op \<otimes> as \<one> \<sim> a" | |
| 1540 | hence "a \<sim> foldr op \<otimes> as \<one>" by (rule associated_sym, simp+) | |
| 1541 | also from prm | |
| 1542 | have "foldr op \<otimes> as \<one> = foldr op \<otimes> bs \<one>" by (rule multlist_perm_cong, simp) | |
| 1543 | also assume "foldr op \<otimes> bs \<one> \<sim> b" | |
| 1544 | finally | |
| 1545 | show "a \<sim> b" by simp | |
| 1546 | qed | |
| 1547 | ||
| 1548 | lemma (in comm_monoid_cancel) listassoc_wfactorsD: | |
| 1549 | assumes assoc: "as [\<sim>] bs" | |
| 1550 | and afs: "wfactors G as a" and bfs: "wfactors G bs b" | |
| 1551 | and [simp]: "a \<in> carrier G" "b \<in> carrier G" | |
| 1552 | and [simp]: "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" | |
| 1553 | shows "a \<sim> b" | |
| 1554 | using afs bfs | |
| 1555 | proof (elim wfactorsE) | |
| 1556 | assume "foldr op \<otimes> as \<one> \<sim> a" | |
| 1557 | hence "a \<sim> foldr op \<otimes> as \<one>" by (rule associated_sym, simp+) | |
| 1558 | also from assoc | |
| 1559 | have "foldr op \<otimes> as \<one> \<sim> foldr op \<otimes> bs \<one>" by (rule multlist_listassoc_cong, simp+) | |
| 1560 | also assume "foldr op \<otimes> bs \<one> \<sim> b" | |
| 1561 | finally | |
| 1562 | show "a \<sim> b" by simp | |
| 1563 | qed | |
| 1564 | ||
| 1565 | lemma (in comm_monoid_cancel) ee_wfactorsD: | |
| 1566 | assumes ee: "essentially_equal G as bs" | |
| 1567 | and afs: "wfactors G as a" and bfs: "wfactors G bs b" | |
| 1568 | and [simp]: "a \<in> carrier G" "b \<in> carrier G" | |
| 1569 | and ascarr[simp]: "set as \<subseteq> carrier G" and bscarr[simp]: "set bs \<subseteq> carrier G" | |
| 1570 | shows "a \<sim> b" | |
| 1571 | using ee | |
| 1572 | proof (elim essentially_equalE) | |
| 1573 | fix fs | |
| 1574 | assume prm: "as <~~> fs" | |
| 1575 | hence as'carr[simp]: "set fs \<subseteq> carrier G" by (simp add: perm_closed) | |
| 1576 | from afs prm | |
| 1577 | have afs': "wfactors G fs a" by (rule wfactors_perm_cong_l, simp) | |
| 1578 | assume "fs [\<sim>] bs" | |
| 1579 | from this afs' bfs | |
| 1580 | show "a \<sim> b" by (rule listassoc_wfactorsD, simp+) | |
| 1581 | qed | |
| 1582 | ||
| 1583 | lemma (in comm_monoid_cancel) ee_factorsD: | |
| 1584 | assumes ee: "essentially_equal G as bs" | |
| 1585 | and afs: "factors G as a" and bfs:"factors G bs b" | |
| 1586 | and "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" | |
| 1587 | shows "a \<sim> b" | |
| 1588 | using assms | |
| 1589 | by (blast intro: factors_wfactors dest: ee_wfactorsD) | |
| 1590 | ||
| 1591 | lemma (in factorial_monoid) ee_factorsI: | |
| 1592 | assumes ab: "a \<sim> b" | |
| 1593 | and afs: "factors G as a" and anunit: "a \<notin> Units G" | |
| 1594 | and bfs: "factors G bs b" and bnunit: "b \<notin> Units G" | |
| 1595 | and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G" | |
| 1596 | shows "essentially_equal G as bs" | |
| 1597 | proof - | |
| 1598 | note carr[simp] = factors_closed[OF afs ascarr] ascarr[THEN subsetD] | |
| 1599 | factors_closed[OF bfs bscarr] bscarr[THEN subsetD] | |
| 1600 | ||
| 1601 | from ab carr | |
| 1602 | have "\<exists>u\<in>Units G. a = b \<otimes> u" by (fast elim: associatedE2) | |
| 1603 | from this obtain u | |
| 1604 | where uunit: "u \<in> Units G" | |
| 1605 | and a: "a = b \<otimes> u" by auto | |
| 1606 | ||
| 1607 | from uunit bscarr | |
| 1608 | have ee: "essentially_equal G (bs[0 := (bs!0 \<otimes> u)]) bs" | |
| 1609 | (is "essentially_equal G ?bs' bs") | |
| 1610 | by (rule unitfactor_ee) | |
| 1611 | ||
| 1612 | from bscarr uunit | |
| 1613 | have bs'carr: "set ?bs' \<subseteq> carrier G" | |
| 1614 | by (cases bs) (simp add: Units_closed)+ | |
| 1615 | ||
| 1616 | from uunit bnunit bfs bscarr | |
| 1617 | have fac: "factors G ?bs' (b \<otimes> u)" | |
| 1618 | by (rule factors_cong_unit) | |
| 1619 | ||
| 1620 | from afs fac[simplified a[symmetric]] ascarr bs'carr anunit | |
| 1621 | have "essentially_equal G as ?bs'" | |
| 1622 | by (blast intro: factors_unique) | |
| 1623 | also note ee | |
| 1624 | finally | |
| 1625 | show "essentially_equal G as bs" by (simp add: ascarr bscarr bs'carr) | |
| 1626 | qed | |
| 1627 | ||
| 1628 | lemma (in factorial_monoid) ee_wfactorsI: | |
| 1629 | assumes asc: "a \<sim> b" | |
| 1630 | and asf: "wfactors G as a" and bsf: "wfactors G bs b" | |
| 1631 | and acarr[simp]: "a \<in> carrier G" and bcarr[simp]: "b \<in> carrier G" | |
| 1632 | and ascarr[simp]: "set as \<subseteq> carrier G" and bscarr[simp]: "set bs \<subseteq> carrier G" | |
| 1633 | shows "essentially_equal G as bs" | |
| 1634 | using assms | |
| 1635 | proof (cases "a \<in> Units G") | |
| 1636 | assume aunit: "a \<in> Units G" | |
| 1637 | also note asc | |
| 1638 | finally have bunit: "b \<in> Units G" by simp | |
| 1639 | ||
| 1640 | from aunit asf ascarr | |
| 1641 | have e: "as = []" by (rule unit_wfactors_empty) | |
| 1642 | from bunit bsf bscarr | |
| 1643 | have e': "bs = []" by (rule unit_wfactors_empty) | |
| 1644 | ||
| 1645 | have "essentially_equal G [] []" | |
| 1646 | by (fast intro: essentially_equalI) | |
| 1647 | thus ?thesis by (simp add: e e') | |
| 1648 | next | |
| 1649 | assume anunit: "a \<notin> Units G" | |
| 1650 | have bnunit: "b \<notin> Units G" | |
| 1651 | proof clarify | |
| 1652 | assume "b \<in> Units G" | |
| 1653 | also note asc[symmetric] | |
| 1654 | finally have "a \<in> Units G" by simp | |
| 1655 | with anunit | |
| 1656 | show "False" .. | |
| 1657 | qed | |
| 1658 | ||
| 1659 | have "\<exists>a'. factors G as a' \<and> a' \<sim> a" by (rule wfactors_factors[OF asf ascarr]) | |
| 1660 | from this obtain a' | |
| 1661 | where fa': "factors G as a'" | |
| 1662 | and a': "a' \<sim> a" | |
| 1663 | by auto | |
| 1664 | from fa' ascarr | |
| 1665 | have a'carr[simp]: "a' \<in> carrier G" by fast | |
| 1666 | ||
| 1667 | have a'nunit: "a' \<notin> Units G" | |
| 1668 | proof (clarify) | |
| 1669 | assume "a' \<in> Units G" | |
| 1670 | also note a' | |
| 1671 | finally have "a \<in> Units G" by simp | |
| 1672 | with anunit | |
| 1673 | show "False" .. | |
| 1674 | qed | |
| 1675 | ||
| 1676 | have "\<exists>b'. factors G bs b' \<and> b' \<sim> b" by (rule wfactors_factors[OF bsf bscarr]) | |
| 1677 | from this obtain b' | |
| 1678 | where fb': "factors G bs b'" | |
| 1679 | and b': "b' \<sim> b" | |
| 1680 | by auto | |
| 1681 | from fb' bscarr | |
| 1682 | have b'carr[simp]: "b' \<in> carrier G" by fast | |
| 1683 | ||
| 1684 | have b'nunit: "b' \<notin> Units G" | |
| 1685 | proof (clarify) | |
| 1686 | assume "b' \<in> Units G" | |
| 1687 | also note b' | |
| 1688 | finally have "b \<in> Units G" by simp | |
| 1689 | with bnunit | |
| 1690 | show "False" .. | |
| 1691 | qed | |
| 1692 | ||
| 1693 | note a' | |
| 1694 | also note asc | |
| 1695 | also note b'[symmetric] | |
| 1696 | finally | |
| 1697 | have "a' \<sim> b'" by simp | |
| 1698 | ||
| 1699 | from this fa' a'nunit fb' b'nunit ascarr bscarr | |
| 1700 | show "essentially_equal G as bs" | |
| 1701 | by (rule ee_factorsI) | |
| 1702 | qed | |
| 1703 | ||
| 1704 | lemma (in factorial_monoid) ee_wfactors: | |
| 1705 | assumes asf: "wfactors G as a" | |
| 1706 | and bsf: "wfactors G bs b" | |
| 1707 | and acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" | |
| 1708 | and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G" | |
| 1709 | shows asc: "a \<sim> b = essentially_equal G as bs" | |
| 1710 | using assms | |
| 1711 | by (fast intro: ee_wfactorsI ee_wfactorsD) | |
| 1712 | ||
| 1713 | lemma (in factorial_monoid) wfactors_exist [intro, simp]: | |
| 1714 | assumes acarr[simp]: "a \<in> carrier G" | |
| 1715 | shows "\<exists>fs. set fs \<subseteq> carrier G \<and> wfactors G fs a" | |
| 1716 | proof (cases "a \<in> Units G") | |
| 1717 | assume "a \<in> Units G" | |
| 1718 | hence "wfactors G [] a" by (rule unit_wfactors) | |
| 1719 | thus ?thesis by (intro exI) force | |
| 1720 | next | |
| 1721 | assume "a \<notin> Units G" | |
| 1722 | hence "\<exists>fs. set fs \<subseteq> carrier G \<and> factors G fs a" by (intro factors_exist acarr) | |
| 1723 | from this obtain fs | |
| 1724 | where fscarr: "set fs \<subseteq> carrier G" | |
| 1725 | and f: "factors G fs a" | |
| 1726 | by auto | |
| 1727 | from f have "wfactors G fs a" by (rule factors_wfactors) fact | |
| 1728 | from fscarr this | |
| 1729 | show ?thesis by fast | |
| 1730 | qed | |
| 1731 | ||
| 1732 | lemma (in monoid) wfactors_prod_exists [intro, simp]: | |
| 1733 | assumes "\<forall>a \<in> set as. irreducible G a" and "set as \<subseteq> carrier G" | |
| 1734 | shows "\<exists>a. a \<in> carrier G \<and> wfactors G as a" | |
| 1735 | unfolding wfactors_def | |
| 1736 | using assms | |
| 1737 | by blast | |
| 1738 | ||
| 1739 | lemma (in factorial_monoid) wfactors_unique: | |
| 1740 | assumes "wfactors G fs a" and "wfactors G fs' a" | |
| 1741 | and "a \<in> carrier G" | |
| 1742 | and "set fs \<subseteq> carrier G" and "set fs' \<subseteq> carrier G" | |
| 1743 | shows "essentially_equal G fs fs'" | |
| 1744 | using assms | |
| 1745 | by (fast intro: ee_wfactorsI[of a a]) | |
| 1746 | ||
| 1747 | lemma (in monoid) factors_mult_single: | |
| 1748 | assumes "irreducible G a" and "factors G fb b" and "a \<in> carrier G" | |
| 1749 | shows "factors G (a # fb) (a \<otimes> b)" | |
| 1750 | using assms | |
| 1751 | unfolding factors_def | |
| 1752 | by simp | |
| 1753 | ||
| 1754 | lemma (in monoid_cancel) wfactors_mult_single: | |
| 1755 | assumes f: "irreducible G a" "wfactors G fb b" | |
| 1756 | "a \<in> carrier G" "b \<in> carrier G" "set fb \<subseteq> carrier G" | |
| 1757 | shows "wfactors G (a # fb) (a \<otimes> b)" | |
| 1758 | using assms | |
| 1759 | unfolding wfactors_def | |
| 1760 | by (simp add: mult_cong_r) | |
| 1761 | ||
| 1762 | lemma (in monoid) factors_mult: | |
| 1763 | assumes factors: "factors G fa a" "factors G fb b" | |
| 1764 | and ascarr: "set fa \<subseteq> carrier G" and bscarr:"set fb \<subseteq> carrier G" | |
| 1765 | shows "factors G (fa @ fb) (a \<otimes> b)" | |
| 1766 | using assms | |
| 1767 | unfolding factors_def | |
| 1768 | apply (safe, force) | |
| 1769 | apply (induct fa) | |
| 1770 | apply simp | |
| 1771 | apply (simp add: m_assoc) | |
| 1772 | done | |
| 1773 | ||
| 1774 | lemma (in comm_monoid_cancel) wfactors_mult [intro]: | |
| 1775 | assumes asf: "wfactors G as a" and bsf:"wfactors G bs b" | |
| 1776 | and acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" | |
| 1777 | and ascarr: "set as \<subseteq> carrier G" and bscarr:"set bs \<subseteq> carrier G" | |
| 1778 | shows "wfactors G (as @ bs) (a \<otimes> b)" | |
| 1779 | apply (insert wfactors_factors[OF asf ascarr]) | |
| 1780 | apply (insert wfactors_factors[OF bsf bscarr]) | |
| 1781 | proof (clarsimp) | |
| 1782 | fix a' b' | |
| 1783 | assume asf': "factors G as a'" and a'a: "a' \<sim> a" | |
| 1784 | and bsf': "factors G bs b'" and b'b: "b' \<sim> b" | |
| 1785 | from asf' have a'carr: "a' \<in> carrier G" by (rule factors_closed) fact | |
| 1786 | from bsf' have b'carr: "b' \<in> carrier G" by (rule factors_closed) fact | |
| 1787 | ||
| 1788 | note carr = acarr bcarr a'carr b'carr ascarr bscarr | |
| 1789 | ||
| 1790 | from asf' bsf' | |
| 1791 | have "factors G (as @ bs) (a' \<otimes> b')" by (rule factors_mult) fact+ | |
| 1792 | ||
| 1793 | with carr | |
| 1794 | have abf': "wfactors G (as @ bs) (a' \<otimes> b')" by (intro factors_wfactors) simp+ | |
| 1795 | also from b'b carr | |
| 1796 | have trb: "a' \<otimes> b' \<sim> a' \<otimes> b" by (intro mult_cong_r) | |
| 1797 | also from a'a carr | |
| 1798 | have tra: "a' \<otimes> b \<sim> a \<otimes> b" by (intro mult_cong_l) | |
| 1799 | finally | |
| 1800 | show "wfactors G (as @ bs) (a \<otimes> b)" | |
| 1801 | by (simp add: carr) | |
| 1802 | qed | |
| 1803 | ||
| 1804 | lemma (in comm_monoid) factors_dividesI: | |
| 1805 | assumes "factors G fs a" and "f \<in> set fs" | |
| 1806 | and "set fs \<subseteq> carrier G" | |
| 1807 | shows "f divides a" | |
| 1808 | using assms | |
| 1809 | by (fast elim: factorsE intro: multlist_dividesI) | |
| 1810 | ||
| 1811 | lemma (in comm_monoid) wfactors_dividesI: | |
| 1812 | assumes p: "wfactors G fs a" | |
| 1813 | and fscarr: "set fs \<subseteq> carrier G" and acarr: "a \<in> carrier G" | |
| 1814 | and f: "f \<in> set fs" | |
| 1815 | shows "f divides a" | |
| 1816 | apply (insert wfactors_factors[OF p fscarr], clarsimp) | |
| 1817 | proof - | |
| 1818 | fix a' | |
| 1819 | assume fsa': "factors G fs a'" | |
| 1820 | and a'a: "a' \<sim> a" | |
| 1821 | with fscarr | |
| 1822 | have a'carr: "a' \<in> carrier G" by (simp add: factors_closed) | |
| 1823 | ||
| 1824 | from fsa' fscarr f | |
| 1825 | have "f divides a'" by (fast intro: factors_dividesI) | |
| 1826 | also note a'a | |
| 1827 | finally | |
| 1828 | show "f divides a" by (simp add: f fscarr[THEN subsetD] acarr a'carr) | |
| 1829 | qed | |
| 1830 | ||
| 1831 | ||
| 1832 | subsubsection {* Factorial monoids and wfactors *}
 | |
| 1833 | ||
| 1834 | lemma (in comm_monoid_cancel) factorial_monoidI: | |
| 1835 | assumes wfactors_exists: | |
| 1836 | "\<And>a. a \<in> carrier G \<Longrightarrow> \<exists>fs. set fs \<subseteq> carrier G \<and> wfactors G fs a" | |
| 1837 | and wfactors_unique: | |
| 1838 | "\<And>a fs fs'. \<lbrakk>a \<in> carrier G; set fs \<subseteq> carrier G; set fs' \<subseteq> carrier G; | |
| 1839 | wfactors G fs a; wfactors G fs' a\<rbrakk> \<Longrightarrow> essentially_equal G fs fs'" | |
| 1840 | shows "factorial_monoid G" | |
| 28823 | 1841 | proof | 
| 27701 | 1842 | fix a | 
| 1843 | assume acarr: "a \<in> carrier G" and anunit: "a \<notin> Units G" | |
| 1844 | ||
| 1845 | from wfactors_exists[OF acarr] | |
| 1846 | obtain as | |
| 1847 | where ascarr: "set as \<subseteq> carrier G" | |
| 1848 | and afs: "wfactors G as a" | |
| 1849 | by auto | |
| 1850 | from afs ascarr | |
| 1851 | have "\<exists>a'. factors G as a' \<and> a' \<sim> a" by (rule wfactors_factors) | |
| 1852 | from this obtain a' | |
| 1853 | where afs': "factors G as a'" | |
| 1854 | and a'a: "a' \<sim> a" | |
| 1855 | by auto | |
| 1856 | from afs' ascarr | |
| 1857 | have a'carr: "a' \<in> carrier G" by fast | |
| 1858 | have a'nunit: "a' \<notin> Units G" | |
| 1859 | proof clarify | |
| 1860 | assume "a' \<in> Units G" | |
| 1861 | also note a'a | |
| 1862 | finally have "a \<in> Units G" by (simp add: acarr) | |
| 1863 | with anunit | |
| 1864 | show "False" .. | |
| 1865 | qed | |
| 1866 | ||
| 1867 | from a'carr acarr a'a | |
| 1868 | have "\<exists>u. u \<in> Units G \<and> a' = a \<otimes> u" by (blast elim: associatedE2) | |
| 1869 | from this obtain u | |
| 1870 | where uunit: "u \<in> Units G" | |
| 1871 | and a': "a' = a \<otimes> u" | |
| 1872 | by auto | |
| 1873 | ||
| 1874 | note [simp] = acarr Units_closed[OF uunit] Units_inv_closed[OF uunit] | |
| 1875 | ||
| 1876 | have "a = a \<otimes> \<one>" by simp | |
| 1877 | also have "\<dots> = a \<otimes> (u \<otimes> inv u)" by (simp add: Units_r_inv uunit) | |
| 1878 | also have "\<dots> = a' \<otimes> inv u" by (simp add: m_assoc[symmetric] a'[symmetric]) | |
| 1879 | finally | |
| 1880 | have a: "a = a' \<otimes> inv u" . | |
| 1881 | ||
| 1882 | from ascarr uunit | |
| 1883 | have cr: "set (as[0:=(as!0 \<otimes> inv u)]) \<subseteq> carrier G" | |
| 1884 | by (cases as, clarsimp+) | |
| 1885 | ||
| 1886 | from afs' uunit a'nunit acarr ascarr | |
| 1887 | have "factors G (as[0:=(as!0 \<otimes> inv u)]) a" | |
| 1888 | by (simp add: a factors_cong_unit) | |
| 1889 | ||
| 1890 | with cr | |
| 1891 | show "\<exists>fs. set fs \<subseteq> carrier G \<and> factors G fs a" by fast | |
| 1892 | qed (blast intro: factors_wfactors wfactors_unique) | |
| 1893 | ||
| 1894 | ||
| 27717 
21bbd410ba04
Generalised polynomial lemmas from cring to ring.
 ballarin parents: 
27713diff
changeset | 1895 | subsection {* Factorizations as Multisets *}
 | 
| 27701 | 1896 | |
| 1897 | text {* Gives useful operations like intersection *}
 | |
| 1898 | ||
| 1899 | (* FIXME: use class_of x instead of closure_of {x} *)
 | |
| 1900 | ||
| 1901 | abbreviation | |
| 1902 |   "assocs G x == eq_closure_of (division_rel G) {x}"
 | |
| 1903 | ||
| 1904 | constdefs (structure G) | |
| 1905 | "fmset G as \<equiv> multiset_of (map (\<lambda>a. assocs G a) as)" | |
| 1906 | ||
| 1907 | ||
| 1908 | text {* Helper lemmas *}
 | |
| 1909 | ||
| 1910 | lemma (in monoid) assocs_repr_independence: | |
| 1911 | assumes "y \<in> assocs G x" | |
| 1912 | and "x \<in> carrier G" | |
| 1913 | shows "assocs G x = assocs G y" | |
| 1914 | using assms | |
| 1915 | apply safe | |
| 1916 | apply (elim closure_ofE2, intro closure_ofI2[of _ _ y]) | |
| 1917 | apply (clarsimp, iprover intro: associated_trans associated_sym, simp+) | |
| 1918 | apply (elim closure_ofE2, intro closure_ofI2[of _ _ x]) | |
| 1919 | apply (clarsimp, iprover intro: associated_trans, simp+) | |
| 1920 | done | |
| 1921 | ||
| 1922 | lemma (in monoid) assocs_self: | |
| 1923 | assumes "x \<in> carrier G" | |
| 1924 | shows "x \<in> assocs G x" | |
| 1925 | using assms | |
| 1926 | by (fastsimp intro: closure_ofI2) | |
| 1927 | ||
| 1928 | lemma (in monoid) assocs_repr_independenceD: | |
| 1929 | assumes repr: "assocs G x = assocs G y" | |
| 1930 | and ycarr: "y \<in> carrier G" | |
| 1931 | shows "y \<in> assocs G x" | |
| 1932 | unfolding repr | |
| 1933 | using ycarr | |
| 1934 | by (intro assocs_self) | |
| 1935 | ||
| 1936 | lemma (in comm_monoid) assocs_assoc: | |
| 1937 | assumes "a \<in> assocs G b" | |
| 1938 | and "b \<in> carrier G" | |
| 1939 | shows "a \<sim> b" | |
| 1940 | using assms | |
| 1941 | by (elim closure_ofE2, simp) | |
| 1942 | ||
| 1943 | lemmas (in comm_monoid) assocs_eqD = | |
| 1944 | assocs_repr_independenceD[THEN assocs_assoc] | |
| 1945 | ||
| 1946 | ||
| 1947 | subsubsection {* Comparing multisets *}
 | |
| 1948 | ||
| 1949 | lemma (in monoid) fmset_perm_cong: | |
| 1950 | assumes prm: "as <~~> bs" | |
| 1951 | shows "fmset G as = fmset G bs" | |
| 1952 | using perm_map[OF prm] | |
| 1953 | by (simp add: multiset_of_eq_perm fmset_def) | |
| 1954 | ||
| 1955 | lemma (in comm_monoid_cancel) eqc_listassoc_cong: | |
| 1956 | assumes "as [\<sim>] bs" | |
| 1957 | and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G" | |
| 1958 | shows "map (assocs G) as = map (assocs G) bs" | |
| 1959 | using assms | |
| 1960 | apply (induct as arbitrary: bs, simp) | |
| 1961 | apply (clarsimp simp add: Cons_eq_map_conv list_all2_Cons1, safe) | |
| 1962 | apply (clarsimp elim!: closure_ofE2) defer 1 | |
| 1963 | apply (clarsimp elim!: closure_ofE2) defer 1 | |
| 1964 | proof - | |
| 1965 | fix a x z | |
| 1966 | assume carr[simp]: "a \<in> carrier G" "x \<in> carrier G" "z \<in> carrier G" | |
| 1967 | assume "x \<sim> a" | |
| 1968 | also assume "a \<sim> z" | |
| 1969 | finally have "x \<sim> z" by simp | |
| 1970 | with carr | |
| 1971 | show "x \<in> assocs G z" | |
| 1972 | by (intro closure_ofI2) simp+ | |
| 1973 | next | |
| 1974 | fix a x z | |
| 1975 | assume carr[simp]: "a \<in> carrier G" "x \<in> carrier G" "z \<in> carrier G" | |
| 1976 | assume "x \<sim> z" | |
| 1977 | also assume [symmetric]: "a \<sim> z" | |
| 1978 | finally have "x \<sim> a" by simp | |
| 1979 | with carr | |
| 1980 | show "x \<in> assocs G a" | |
| 1981 | by (intro closure_ofI2) simp+ | |
| 1982 | qed | |
| 1983 | ||
| 1984 | lemma (in comm_monoid_cancel) fmset_listassoc_cong: | |
| 1985 | assumes "as [\<sim>] bs" | |
| 1986 | and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G" | |
| 1987 | shows "fmset G as = fmset G bs" | |
| 1988 | using assms | |
| 1989 | unfolding fmset_def | |
| 1990 | by (simp add: eqc_listassoc_cong) | |
| 1991 | ||
| 1992 | lemma (in comm_monoid_cancel) ee_fmset: | |
| 1993 | assumes ee: "essentially_equal G as bs" | |
| 1994 | and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G" | |
| 1995 | shows "fmset G as = fmset G bs" | |
| 1996 | using ee | |
| 1997 | proof (elim essentially_equalE) | |
| 1998 | fix as' | |
| 1999 | assume prm: "as <~~> as'" | |
| 2000 | from prm ascarr | |
| 2001 | have as'carr: "set as' \<subseteq> carrier G" by (rule perm_closed) | |
| 2002 | ||
| 2003 | from prm | |
| 2004 | have "fmset G as = fmset G as'" by (rule fmset_perm_cong) | |
| 2005 | also assume "as' [\<sim>] bs" | |
| 2006 | with as'carr bscarr | |
| 2007 | have "fmset G as' = fmset G bs" by (simp add: fmset_listassoc_cong) | |
| 2008 | finally | |
| 2009 | show "fmset G as = fmset G bs" . | |
| 2010 | qed | |
| 2011 | ||
| 2012 | lemma (in monoid_cancel) fmset_ee__hlp_induct: | |
| 2013 | assumes prm: "cas <~~> cbs" | |
| 2014 | and cdef: "cas = map (assocs G) as" "cbs = map (assocs G) bs" | |
| 2015 | shows "\<forall>as bs. (cas <~~> cbs \<and> cas = map (assocs G) as \<and> | |
| 2016 | cbs = map (assocs G) bs) \<longrightarrow> (\<exists>as'. as <~~> as' \<and> map (assocs G) as' = cbs)" | |
| 2017 | apply (rule perm.induct[of cas cbs], rule prm) | |
| 2018 | apply safe apply simp_all | |
| 2019 | apply (simp add: map_eq_Cons_conv, blast) | |
| 2020 | apply force | |
| 2021 | proof - | |
| 2022 | fix ys as bs | |
| 2023 | assume p1: "map (assocs G) as <~~> ys" | |
| 2024 | and r1[rule_format]: | |
| 2025 | "\<forall>asa bs. map (assocs G) as = map (assocs G) asa \<and> | |
| 2026 | ys = map (assocs G) bs | |
| 2027 | \<longrightarrow> (\<exists>as'. asa <~~> as' \<and> map (assocs G) as' = map (assocs G) bs)" | |
| 2028 | and p2: "ys <~~> map (assocs G) bs" | |
| 2029 | and r2[rule_format]: | |
| 2030 | "\<forall>as bsa. ys = map (assocs G) as \<and> | |
| 2031 | map (assocs G) bs = map (assocs G) bsa | |
| 2032 | \<longrightarrow> (\<exists>as'. as <~~> as' \<and> map (assocs G) as' = map (assocs G) bsa)" | |
| 2033 | and p3: "map (assocs G) as <~~> map (assocs G) bs" | |
| 2034 | ||
| 2035 | from p1 | |
| 2036 | have "multiset_of (map (assocs G) as) = multiset_of ys" | |
| 2037 | by (simp add: multiset_of_eq_perm) | |
| 2038 | hence setys: "set (map (assocs G) as) = set ys" by (rule multiset_of_eq_setD) | |
| 2039 | ||
| 2040 |   have "set (map (assocs G) as) = { assocs G x | x. x \<in> set as}" by clarsimp fast
 | |
| 2041 |   with setys have "set ys \<subseteq> { assocs G x | x. x \<in> set as}" by simp
 | |
| 2042 | hence "\<exists>yy. ys = map (assocs G) yy" | |
| 2043 | apply (induct ys, simp, clarsimp) | |
| 2044 | proof - | |
| 2045 | fix yy x | |
| 2046 | show "\<exists>yya. (assocs G x) # map (assocs G) yy = | |
| 2047 | map (assocs G) yya" | |
| 2048 | by (rule exI[of _ "x#yy"], simp) | |
| 2049 | qed | |
| 2050 | from this obtain yy | |
| 2051 | where ys: "ys = map (assocs G) yy" | |
| 2052 | by auto | |
| 2053 | ||
| 2054 | from p1 ys | |
| 2055 | have "\<exists>as'. as <~~> as' \<and> map (assocs G) as' = map (assocs G) yy" | |
| 2056 | by (intro r1, simp) | |
| 2057 | from this obtain as' | |
| 2058 | where asas': "as <~~> as'" | |
| 2059 | and as'yy: "map (assocs G) as' = map (assocs G) yy" | |
| 2060 | by auto | |
| 2061 | ||
| 2062 | from p2 ys | |
| 2063 | have "\<exists>as'. yy <~~> as' \<and> map (assocs G) as' = map (assocs G) bs" | |
| 2064 | by (intro r2, simp) | |
| 2065 | from this obtain as'' | |
| 2066 | where yyas'': "yy <~~> as''" | |
| 2067 | and as''bs: "map (assocs G) as'' = map (assocs G) bs" | |
| 2068 | by auto | |
| 2069 | ||
| 2070 | from as'yy and yyas'' | |
| 2071 | have "\<exists>cs. as' <~~> cs \<and> map (assocs G) cs = map (assocs G) as''" | |
| 2072 | by (rule perm_map_switch) | |
| 2073 | from this obtain cs | |
| 2074 | where as'cs: "as' <~~> cs" | |
| 2075 | and csas'': "map (assocs G) cs = map (assocs G) as''" | |
| 2076 | by auto | |
| 2077 | ||
| 2078 | from asas' and as'cs | |
| 2079 | have ascs: "as <~~> cs" by fast | |
| 2080 | from csas'' and as''bs | |
| 2081 | have "map (assocs G) cs = map (assocs G) bs" by simp | |
| 2082 | from ascs and this | |
| 2083 | show "\<exists>as'. as <~~> as' \<and> map (assocs G) as' = map (assocs G) bs" by fast | |
| 2084 | qed | |
| 2085 | ||
| 2086 | lemma (in comm_monoid_cancel) fmset_ee: | |
| 2087 | assumes mset: "fmset G as = fmset G bs" | |
| 2088 | and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G" | |
| 2089 | shows "essentially_equal G as bs" | |
| 2090 | proof - | |
| 2091 | from mset | |
| 2092 | have mpp: "map (assocs G) as <~~> map (assocs G) bs" | |
| 2093 | by (simp add: fmset_def multiset_of_eq_perm) | |
| 2094 | ||
| 2095 | have "\<exists>cas. cas = map (assocs G) as" by simp | |
| 2096 | from this obtain cas where cas: "cas = map (assocs G) as" by simp | |
| 2097 | ||
| 2098 | have "\<exists>cbs. cbs = map (assocs G) bs" by simp | |
| 2099 | from this obtain cbs where cbs: "cbs = map (assocs G) bs" by simp | |
| 2100 | ||
| 2101 | from cas cbs mpp | |
| 2102 | have [rule_format]: | |
| 2103 | "\<forall>as bs. (cas <~~> cbs \<and> cas = map (assocs G) as \<and> | |
| 2104 | cbs = map (assocs G) bs) | |
| 2105 | \<longrightarrow> (\<exists>as'. as <~~> as' \<and> map (assocs G) as' = cbs)" | |
| 2106 | by (intro fmset_ee__hlp_induct, simp+) | |
| 2107 | with mpp cas cbs | |
| 2108 | have "\<exists>as'. as <~~> as' \<and> map (assocs G) as' = map (assocs G) bs" | |
| 2109 | by simp | |
| 2110 | ||
| 2111 | from this obtain as' | |
| 2112 | where tp: "as <~~> as'" | |
| 2113 | and tm: "map (assocs G) as' = map (assocs G) bs" | |
| 2114 | by auto | |
| 2115 | from tm have lene: "length as' = length bs" by (rule map_eq_imp_length_eq) | |
| 2116 | from tp have "set as = set as'" by (simp add: multiset_of_eq_perm multiset_of_eq_setD) | |
| 2117 | with ascarr | |
| 2118 | have as'carr: "set as' \<subseteq> carrier G" by simp | |
| 2119 | ||
| 2120 | from tm as'carr[THEN subsetD] bscarr[THEN subsetD] | |
| 2121 | have "as' [\<sim>] bs" | |
| 2122 | by (induct as' arbitrary: bs) (simp, fastsimp dest: assocs_eqD[THEN associated_sym]) | |
| 2123 | ||
| 2124 | from tp and this | |
| 2125 | show "essentially_equal G as bs" by (fast intro: essentially_equalI) | |
| 2126 | qed | |
| 2127 | ||
| 2128 | lemma (in comm_monoid_cancel) ee_is_fmset: | |
| 2129 | assumes "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G" | |
| 2130 | shows "essentially_equal G as bs = (fmset G as = fmset G bs)" | |
| 2131 | using assms | |
| 2132 | by (fast intro: ee_fmset fmset_ee) | |
| 2133 | ||
| 2134 | ||
| 2135 | subsubsection {* Interpreting multisets as factorizations *}
 | |
| 2136 | ||
| 2137 | lemma (in monoid) mset_fmsetEx: | |
| 2138 | assumes elems: "\<And>X. X \<in> set_of Cs \<Longrightarrow> \<exists>x. P x \<and> X = assocs G x" | |
| 2139 | shows "\<exists>cs. (\<forall>c \<in> set cs. P c) \<and> fmset G cs = Cs" | |
| 2140 | proof - | |
| 2141 | have "\<exists>Cs'. Cs = multiset_of Cs'" | |
| 2142 | by (rule surjE[OF surj_multiset_of], fast) | |
| 2143 | from this obtain Cs' | |
| 2144 | where Cs: "Cs = multiset_of Cs'" | |
| 2145 | by auto | |
| 2146 | ||
| 2147 | have "\<exists>cs. (\<forall>c \<in> set cs. P c) \<and> multiset_of (map (assocs G) cs) = Cs" | |
| 2148 | using elems | |
| 2149 | unfolding Cs | |
| 2150 | apply (induct Cs', simp) | |
| 2151 | apply clarsimp | |
| 2152 | apply (subgoal_tac "\<exists>cs. (\<forall>x\<in>set cs. P x) \<and> | |
| 2153 | multiset_of (map (assocs G) cs) = multiset_of Cs'") | |
| 2154 | proof clarsimp | |
| 2155 | fix a Cs' cs | |
| 2156 | assume ih: "\<And>X. X = a \<or> X \<in> set Cs' \<Longrightarrow> \<exists>x. P x \<and> X = assocs G x" | |
| 2157 | and csP: "\<forall>x\<in>set cs. P x" | |
| 2158 | and mset: "multiset_of (map (assocs G) cs) = multiset_of Cs'" | |
| 2159 | from ih | |
| 2160 | have "\<exists>x. P x \<and> a = assocs G x" by fast | |
| 2161 | from this obtain c | |
| 2162 | where cP: "P c" | |
| 2163 | and a: "a = assocs G c" | |
| 2164 | by auto | |
| 2165 | from cP csP | |
| 2166 | have tP: "\<forall>x\<in>set (c#cs). P x" by simp | |
| 2167 | from mset a | |
| 2168 |     have "multiset_of (map (assocs G) (c#cs)) = multiset_of Cs' + {#a#}" by simp
 | |
| 2169 | from tP this | |
| 2170 | show "\<exists>cs. (\<forall>x\<in>set cs. P x) \<and> | |
| 2171 | multiset_of (map (assocs G) cs) = | |
| 2172 |                multiset_of Cs' + {#a#}" by fast
 | |
| 2173 | qed simp | |
| 2174 | thus ?thesis by (simp add: fmset_def) | |
| 2175 | qed | |
| 2176 | ||
| 2177 | lemma (in monoid) mset_wfactorsEx: | |
| 2178 | assumes elems: "\<And>X. X \<in> set_of Cs | |
| 2179 | \<Longrightarrow> \<exists>x. (x \<in> carrier G \<and> irreducible G x) \<and> X = assocs G x" | |
| 2180 | shows "\<exists>c cs. c \<in> carrier G \<and> set cs \<subseteq> carrier G \<and> wfactors G cs c \<and> fmset G cs = Cs" | |
| 2181 | proof - | |
| 2182 | have "\<exists>cs. (\<forall>c\<in>set cs. c \<in> carrier G \<and> irreducible G c) \<and> fmset G cs = Cs" | |
| 2183 | by (intro mset_fmsetEx, rule elems) | |
| 2184 | from this obtain cs | |
| 2185 | where p[rule_format]: "\<forall>c\<in>set cs. c \<in> carrier G \<and> irreducible G c" | |
| 2186 | and Cs[symmetric]: "fmset G cs = Cs" | |
| 2187 | by auto | |
| 2188 | ||
| 2189 | from p | |
| 2190 | have cscarr: "set cs \<subseteq> carrier G" by fast | |
| 2191 | ||
| 2192 | from p | |
| 2193 | have "\<exists>c. c \<in> carrier G \<and> wfactors G cs c" | |
| 2194 | by (intro wfactors_prod_exists) fast+ | |
| 2195 | from this obtain c | |
| 2196 | where ccarr: "c \<in> carrier G" | |
| 2197 | and cfs: "wfactors G cs c" | |
| 2198 | by auto | |
| 2199 | ||
| 2200 | with cscarr Cs | |
| 2201 | show ?thesis by fast | |
| 2202 | qed | |
| 2203 | ||
| 2204 | ||
| 2205 | subsubsection {* Multiplication on multisets *}
 | |
| 2206 | ||
| 2207 | lemma (in factorial_monoid) mult_wfactors_fmset: | |
| 2208 | assumes afs: "wfactors G as a" and bfs: "wfactors G bs b" and cfs: "wfactors G cs (a \<otimes> b)" | |
| 2209 | and carr: "a \<in> carrier G" "b \<in> carrier G" | |
| 2210 | "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" "set cs \<subseteq> carrier G" | |
| 2211 | shows "fmset G cs = fmset G as + fmset G bs" | |
| 2212 | proof - | |
| 2213 | from assms | |
| 2214 | have "wfactors G (as @ bs) (a \<otimes> b)" by (intro wfactors_mult) | |
| 2215 | with carr cfs | |
| 2216 | have "essentially_equal G cs (as@bs)" by (intro ee_wfactorsI[of "a\<otimes>b" "a\<otimes>b"], simp+) | |
| 2217 | with carr | |
| 2218 | have "fmset G cs = fmset G (as@bs)" by (intro ee_fmset, simp+) | |
| 2219 | also have "fmset G (as@bs) = fmset G as + fmset G bs" by (simp add: fmset_def) | |
| 2220 | finally show "fmset G cs = fmset G as + fmset G bs" . | |
| 2221 | qed | |
| 2222 | ||
| 2223 | lemma (in factorial_monoid) mult_factors_fmset: | |
| 2224 | assumes afs: "factors G as a" and bfs: "factors G bs b" and cfs: "factors G cs (a \<otimes> b)" | |
| 2225 | and "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" "set cs \<subseteq> carrier G" | |
| 2226 | shows "fmset G cs = fmset G as + fmset G bs" | |
| 2227 | using assms | |
| 2228 | by (blast intro: factors_wfactors mult_wfactors_fmset) | |
| 2229 | ||
| 2230 | lemma (in comm_monoid_cancel) fmset_wfactors_mult: | |
| 2231 | assumes mset: "fmset G cs = fmset G as + fmset G bs" | |
| 2232 | and carr: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | |
| 2233 | "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" "set cs \<subseteq> carrier G" | |
| 2234 | and fs: "wfactors G as a" "wfactors G bs b" "wfactors G cs c" | |
| 2235 | shows "c \<sim> a \<otimes> b" | |
| 2236 | proof - | |
| 2237 | from carr fs | |
| 2238 | have m: "wfactors G (as @ bs) (a \<otimes> b)" by (intro wfactors_mult) | |
| 2239 | ||
| 2240 | from mset | |
| 2241 | have "fmset G cs = fmset G (as@bs)" by (simp add: fmset_def) | |
| 2242 | then have "essentially_equal G cs (as@bs)" by (rule fmset_ee) (simp add: carr)+ | |
| 2243 | then show "c \<sim> a \<otimes> b" by (rule ee_wfactorsD[of "cs" "as@bs"]) (simp add: assms m)+ | |
| 2244 | qed | |
| 2245 | ||
| 2246 | ||
| 2247 | subsubsection {* Divisibility on multisets *}
 | |
| 2248 | ||
| 2249 | lemma (in factorial_monoid) divides_fmsubset: | |
| 2250 | assumes ab: "a divides b" | |
| 2251 | and afs: "wfactors G as a" and bfs: "wfactors G bs b" | |
| 2252 | and carr: "a \<in> carrier G" "b \<in> carrier G" "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" | |
| 2253 | shows "fmset G as \<le># fmset G bs" | |
| 2254 | using ab | |
| 2255 | proof (elim dividesE) | |
| 2256 | fix c | |
| 2257 | assume ccarr: "c \<in> carrier G" | |
| 2258 | hence "\<exists>cs. set cs \<subseteq> carrier G \<and> wfactors G cs c" by (rule wfactors_exist) | |
| 2259 | from this obtain cs | |
| 2260 | where cscarr: "set cs \<subseteq> carrier G" | |
| 2261 | and cfs: "wfactors G cs c" by auto | |
| 2262 | note carr = carr ccarr cscarr | |
| 2263 | ||
| 2264 | assume "b = a \<otimes> c" | |
| 2265 | with afs bfs cfs carr | |
| 2266 | have "fmset G bs = fmset G as + fmset G cs" | |
| 2267 | by (intro mult_wfactors_fmset[OF afs cfs]) simp+ | |
| 2268 | ||
| 2269 | thus ?thesis by simp | |
| 2270 | qed | |
| 2271 | ||
| 2272 | lemma (in comm_monoid_cancel) fmsubset_divides: | |
| 2273 | assumes msubset: "fmset G as \<le># fmset G bs" | |
| 2274 | and afs: "wfactors G as a" and bfs: "wfactors G bs b" | |
| 2275 | and acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" | |
| 2276 | and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G" | |
| 2277 | shows "a divides b" | |
| 2278 | proof - | |
| 2279 | from afs have airr: "\<forall>a \<in> set as. irreducible G a" by (fast elim: wfactorsE) | |
| 2280 | from bfs have birr: "\<forall>b \<in> set bs. irreducible G b" by (fast elim: wfactorsE) | |
| 2281 | ||
| 2282 | have "\<exists>c cs. c \<in> carrier G \<and> set cs \<subseteq> carrier G \<and> wfactors G cs c \<and> fmset G cs = fmset G bs - fmset G as" | |
| 2283 | proof (intro mset_wfactorsEx, simp) | |
| 2284 | fix X | |
| 2285 | assume "count (fmset G as) X < count (fmset G bs) X" | |
| 2286 | hence "0 < count (fmset G bs) X" by simp | |
| 2287 | hence "X \<in> set_of (fmset G bs)" by simp | |
| 2288 | hence "X \<in> set (map (assocs G) bs)" by (simp add: fmset_def) | |
| 2289 | hence "\<exists>x. x \<in> set bs \<and> X = assocs G x" by (induct bs) auto | |
| 2290 | from this obtain x | |
| 2291 | where xbs: "x \<in> set bs" | |
| 2292 | and X: "X = assocs G x" | |
| 2293 | by auto | |
| 2294 | ||
| 2295 | with bscarr have xcarr: "x \<in> carrier G" by fast | |
| 2296 | from xbs birr have xirr: "irreducible G x" by simp | |
| 2297 | ||
| 2298 | from xcarr and xirr and X | |
| 2299 | show "\<exists>x. x \<in> carrier G \<and> irreducible G x \<and> X = assocs G x" by fast | |
| 2300 | qed | |
| 2301 | from this obtain c cs | |
| 2302 | where ccarr: "c \<in> carrier G" | |
| 2303 | and cscarr: "set cs \<subseteq> carrier G" | |
| 2304 | and csf: "wfactors G cs c" | |
| 2305 | and csmset: "fmset G cs = fmset G bs - fmset G as" by auto | |
| 2306 | ||
| 2307 | from csmset msubset | |
| 2308 | have "fmset G bs = fmset G as + fmset G cs" | |
| 2309 | by (simp add: multiset_eq_conv_count_eq mset_le_def) | |
| 2310 | hence basc: "b \<sim> a \<otimes> c" | |
| 2311 | by (rule fmset_wfactors_mult) fact+ | |
| 2312 | ||
| 2313 | thus ?thesis | |
| 2314 | proof (elim associatedE2) | |
| 2315 | fix u | |
| 2316 | assume "u \<in> Units G" "b = a \<otimes> c \<otimes> u" | |
| 2317 | with acarr ccarr | |
| 2318 | show "a divides b" by (fast intro: dividesI[of "c \<otimes> u"] m_assoc) | |
| 2319 | qed (simp add: acarr bcarr ccarr)+ | |
| 2320 | qed | |
| 2321 | ||
| 2322 | lemma (in factorial_monoid) divides_as_fmsubset: | |
| 2323 | assumes "wfactors G as a" and "wfactors G bs b" | |
| 2324 | and "a \<in> carrier G" and "b \<in> carrier G" | |
| 2325 | and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G" | |
| 2326 | shows "a divides b = (fmset G as \<le># fmset G bs)" | |
| 2327 | using assms | |
| 2328 | by (blast intro: divides_fmsubset fmsubset_divides) | |
| 2329 | ||
| 2330 | ||
| 2331 | text {* Proper factors on multisets *}
 | |
| 2332 | ||
| 2333 | lemma (in factorial_monoid) fmset_properfactor: | |
| 2334 | assumes asubb: "fmset G as \<le># fmset G bs" | |
| 2335 | and anb: "fmset G as \<noteq> fmset G bs" | |
| 2336 | and "wfactors G as a" and "wfactors G bs b" | |
| 2337 | and "a \<in> carrier G" and "b \<in> carrier G" | |
| 2338 | and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G" | |
| 2339 | shows "properfactor G a b" | |
| 2340 | apply (rule properfactorI) | |
| 2341 | apply (rule fmsubset_divides[of as bs], fact+) | |
| 2342 | proof | |
| 2343 | assume "b divides a" | |
| 2344 | hence "fmset G bs \<le># fmset G as" | |
| 2345 | by (rule divides_fmsubset) fact+ | |
| 2346 | with asubb | |
| 2347 | have "fmset G as = fmset G bs" by (simp add: mset_le_antisym) | |
| 2348 | with anb | |
| 2349 | show "False" .. | |
| 2350 | qed | |
| 2351 | ||
| 2352 | lemma (in factorial_monoid) properfactor_fmset: | |
| 2353 | assumes pf: "properfactor G a b" | |
| 2354 | and "wfactors G as a" and "wfactors G bs b" | |
| 2355 | and "a \<in> carrier G" and "b \<in> carrier G" | |
| 2356 | and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G" | |
| 2357 | shows "fmset G as \<le># fmset G bs \<and> fmset G as \<noteq> fmset G bs" | |
| 2358 | using pf | |
| 2359 | apply (elim properfactorE) | |
| 2360 | apply rule | |
| 2361 | apply (intro divides_fmsubset, assumption) | |
| 2362 | apply (rule assms)+ | |
| 2363 | proof | |
| 2364 | assume bna: "\<not> b divides a" | |
| 2365 | assume "fmset G as = fmset G bs" | |
| 2366 | then have "essentially_equal G as bs" by (rule fmset_ee) fact+ | |
| 2367 | hence "a \<sim> b" by (rule ee_wfactorsD[of as bs]) fact+ | |
| 2368 | hence "b divides a" by (elim associatedE) | |
| 2369 | with bna | |
| 2370 | show "False" .. | |
| 2371 | qed | |
| 2372 | ||
| 2373 | ||
| 27717 
21bbd410ba04
Generalised polynomial lemmas from cring to ring.
 ballarin parents: 
27713diff
changeset | 2374 | subsection {* Irreducible Elements are Prime *}
 | 
| 27701 | 2375 | |
| 2376 | lemma (in factorial_monoid) irreducible_is_prime: | |
| 2377 | assumes pirr: "irreducible G p" | |
| 2378 | and pcarr: "p \<in> carrier G" | |
| 2379 | shows "prime G p" | |
| 2380 | using pirr | |
| 2381 | proof (elim irreducibleE, intro primeI) | |
| 2382 | fix a b | |
| 2383 | assume acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" | |
| 2384 | and pdvdab: "p divides (a \<otimes> b)" | |
| 2385 | and pnunit: "p \<notin> Units G" | |
| 2386 | assume irreduc[rule_format]: | |
| 2387 | "\<forall>b. b \<in> carrier G \<and> properfactor G b p \<longrightarrow> b \<in> Units G" | |
| 2388 | from pdvdab | |
| 2389 | have "\<exists>c\<in>carrier G. a \<otimes> b = p \<otimes> c" by (rule dividesD) | |
| 2390 | from this obtain c | |
| 2391 | where ccarr: "c \<in> carrier G" | |
| 2392 | and abpc: "a \<otimes> b = p \<otimes> c" | |
| 2393 | by auto | |
| 2394 | ||
| 2395 | from acarr have "\<exists>fs. set fs \<subseteq> carrier G \<and> wfactors G fs a" by (rule wfactors_exist) | |
| 2396 | from this obtain as where ascarr: "set as \<subseteq> carrier G" and afs: "wfactors G as a" by auto | |
| 2397 | ||
| 2398 | from bcarr have "\<exists>fs. set fs \<subseteq> carrier G \<and> wfactors G fs b" by (rule wfactors_exist) | |
| 2399 | from this obtain bs where bscarr: "set bs \<subseteq> carrier G" and bfs: "wfactors G bs b" by auto | |
| 2400 | ||
| 2401 | from ccarr have "\<exists>fs. set fs \<subseteq> carrier G \<and> wfactors G fs c" by (rule wfactors_exist) | |
| 2402 | from this obtain cs where cscarr: "set cs \<subseteq> carrier G" and cfs: "wfactors G cs c" by auto | |
| 2403 | ||
| 2404 | note carr[simp] = pcarr acarr bcarr ccarr ascarr bscarr cscarr | |
| 2405 | ||
| 2406 | from afs and bfs | |
| 2407 | have abfs: "wfactors G (as @ bs) (a \<otimes> b)" by (rule wfactors_mult) fact+ | |
| 2408 | ||
| 2409 | from pirr cfs | |
| 2410 | have pcfs: "wfactors G (p # cs) (p \<otimes> c)" by (rule wfactors_mult_single) fact+ | |
| 2411 | with abpc | |
| 2412 | have abfs': "wfactors G (p # cs) (a \<otimes> b)" by simp | |
| 2413 | ||
| 2414 | from abfs' abfs | |
| 2415 | have "essentially_equal G (p # cs) (as @ bs)" | |
| 2416 | by (rule wfactors_unique) simp+ | |
| 2417 | ||
| 2418 | hence "\<exists>ds. p # cs <~~> ds \<and> ds [\<sim>] (as @ bs)" | |
| 2419 | by (fast elim: essentially_equalE) | |
| 2420 | from this obtain ds | |
| 2421 | where "p # cs <~~> ds" | |
| 2422 | and dsassoc: "ds [\<sim>] (as @ bs)" | |
| 2423 | by auto | |
| 2424 | ||
| 2425 | then have "p \<in> set ds" | |
| 2426 | by (simp add: perm_set_eq[symmetric]) | |
| 2427 | with dsassoc | |
| 2428 | have "\<exists>p'. p' \<in> set (as@bs) \<and> p \<sim> p'" | |
| 2429 | unfolding list_all2_conv_all_nth set_conv_nth | |
| 2430 | by force | |
| 2431 | ||
| 2432 | from this obtain p' | |
| 2433 | where "p' \<in> set (as@bs)" | |
| 2434 | and pp': "p \<sim> p'" | |
| 2435 | by auto | |
| 2436 | ||
| 2437 | hence "p' \<in> set as \<or> p' \<in> set bs" by simp | |
| 2438 | moreover | |
| 2439 |   {
 | |
| 2440 | assume p'elem: "p' \<in> set as" | |
| 2441 | with ascarr have [simp]: "p' \<in> carrier G" by fast | |
| 2442 | ||
| 2443 | note pp' | |
| 2444 | also from afs | |
| 2445 | have "p' divides a" by (rule wfactors_dividesI) fact+ | |
| 2446 | finally | |
| 2447 | have "p divides a" by simp | |
| 2448 | } | |
| 2449 | moreover | |
| 2450 |   {
 | |
| 2451 | assume p'elem: "p' \<in> set bs" | |
| 2452 | with bscarr have [simp]: "p' \<in> carrier G" by fast | |
| 2453 | ||
| 2454 | note pp' | |
| 2455 | also from bfs | |
| 2456 | have "p' divides b" by (rule wfactors_dividesI) fact+ | |
| 2457 | finally | |
| 2458 | have "p divides b" by simp | |
| 2459 | } | |
| 2460 | ultimately | |
| 2461 | show "p divides a \<or> p divides b" by fast | |
| 2462 | qed | |
| 2463 | ||
| 2464 | ||
| 2465 | --"A version using @{const factors}, more complicated"
 | |
| 2466 | lemma (in factorial_monoid) factors_irreducible_is_prime: | |
| 2467 | assumes pirr: "irreducible G p" | |
| 2468 | and pcarr: "p \<in> carrier G" | |
| 2469 | shows "prime G p" | |
| 2470 | using pirr | |
| 2471 | apply (elim irreducibleE, intro primeI) | |
| 2472 | apply assumption | |
| 2473 | proof - | |
| 2474 | fix a b | |
| 2475 | assume acarr: "a \<in> carrier G" | |
| 2476 | and bcarr: "b \<in> carrier G" | |
| 2477 | and pdvdab: "p divides (a \<otimes> b)" | |
| 2478 | assume irreduc[rule_format]: | |
| 2479 | "\<forall>b. b \<in> carrier G \<and> properfactor G b p \<longrightarrow> b \<in> Units G" | |
| 2480 | from pdvdab | |
| 2481 | have "\<exists>c\<in>carrier G. a \<otimes> b = p \<otimes> c" by (rule dividesD) | |
| 2482 | from this obtain c | |
| 2483 | where ccarr: "c \<in> carrier G" | |
| 2484 | and abpc: "a \<otimes> b = p \<otimes> c" | |
| 2485 | by auto | |
| 2486 | note [simp] = pcarr acarr bcarr ccarr | |
| 2487 | ||
| 2488 | show "p divides a \<or> p divides b" | |
| 2489 | proof (cases "a \<in> Units G") | |
| 2490 | assume aunit: "a \<in> Units G" | |
| 2491 | ||
| 2492 | note pdvdab | |
| 2493 | also have "a \<otimes> b = b \<otimes> a" by (simp add: m_comm) | |
| 2494 | also from aunit | |
| 2495 | have bab: "b \<otimes> a \<sim> b" | |
| 2496 | by (intro associatedI2[of "a"], simp+) | |
| 2497 | finally | |
| 2498 | have "p divides b" by simp | |
| 2499 | thus "p divides a \<or> p divides b" .. | |
| 2500 | next | |
| 2501 | assume anunit: "a \<notin> Units G" | |
| 2502 | ||
| 2503 | show "p divides a \<or> p divides b" | |
| 2504 | proof (cases "b \<in> Units G") | |
| 2505 | assume bunit: "b \<in> Units G" | |
| 2506 | ||
| 2507 | note pdvdab | |
| 2508 | also from bunit | |
| 2509 | have baa: "a \<otimes> b \<sim> a" | |
| 2510 | by (intro associatedI2[of "b"], simp+) | |
| 2511 | finally | |
| 2512 | have "p divides a" by simp | |
| 2513 | thus "p divides a \<or> p divides b" .. | |
| 2514 | next | |
| 2515 | assume bnunit: "b \<notin> Units G" | |
| 2516 | ||
| 2517 | have cnunit: "c \<notin> Units G" | |
| 2518 | proof (rule ccontr, simp) | |
| 2519 | assume cunit: "c \<in> Units G" | |
| 2520 | from bnunit | |
| 2521 | have "properfactor G a (a \<otimes> b)" | |
| 2522 | by (intro properfactorI3[of _ _ b], simp+) | |
| 2523 | also note abpc | |
| 2524 | also from cunit | |
| 2525 | have "p \<otimes> c \<sim> p" | |
| 2526 | by (intro associatedI2[of c], simp+) | |
| 2527 | finally | |
| 2528 | have "properfactor G a p" by simp | |
| 2529 | ||
| 2530 | with acarr | |
| 2531 | have "a \<in> Units G" by (fast intro: irreduc) | |
| 2532 | with anunit | |
| 2533 | show "False" .. | |
| 2534 | qed | |
| 2535 | ||
| 2536 | have abnunit: "a \<otimes> b \<notin> Units G" | |
| 2537 | proof clarsimp | |
| 2538 | assume abunit: "a \<otimes> b \<in> Units G" | |
| 2539 | hence "a \<in> Units G" by (rule unit_factor) fact+ | |
| 2540 | with anunit | |
| 2541 | show "False" .. | |
| 2542 | qed | |
| 2543 | ||
| 2544 | from acarr anunit have "\<exists>fs. set fs \<subseteq> carrier G \<and> factors G fs a" by (rule factors_exist) | |
| 2545 | then obtain as where ascarr: "set as \<subseteq> carrier G" and afac: "factors G as a" by auto | |
| 2546 | ||
| 2547 | from bcarr bnunit have "\<exists>fs. set fs \<subseteq> carrier G \<and> factors G fs b" by (rule factors_exist) | |
| 2548 | then obtain bs where bscarr: "set bs \<subseteq> carrier G" and bfac: "factors G bs b" by auto | |
| 2549 | ||
| 2550 | from ccarr cnunit have "\<exists>fs. set fs \<subseteq> carrier G \<and> factors G fs c" by (rule factors_exist) | |
| 2551 | then obtain cs where cscarr: "set cs \<subseteq> carrier G" and cfac: "factors G cs c" by auto | |
| 2552 | ||
| 2553 | note [simp] = ascarr bscarr cscarr | |
| 2554 | ||
| 2555 | from afac and bfac | |
| 2556 | have abfac: "factors G (as @ bs) (a \<otimes> b)" by (rule factors_mult) fact+ | |
| 2557 | ||
| 2558 | from pirr cfac | |
| 2559 | have pcfac: "factors G (p # cs) (p \<otimes> c)" by (rule factors_mult_single) fact+ | |
| 2560 | with abpc | |
| 2561 | have abfac': "factors G (p # cs) (a \<otimes> b)" by simp | |
| 2562 | ||
| 2563 | from abfac' abfac | |
| 2564 | have "essentially_equal G (p # cs) (as @ bs)" | |
| 2565 | by (rule factors_unique) (fact | simp)+ | |
| 2566 | ||
| 2567 | hence "\<exists>ds. p # cs <~~> ds \<and> ds [\<sim>] (as @ bs)" | |
| 2568 | by (fast elim: essentially_equalE) | |
| 2569 | from this obtain ds | |
| 2570 | where "p # cs <~~> ds" | |
| 2571 | and dsassoc: "ds [\<sim>] (as @ bs)" | |
| 2572 | by auto | |
| 2573 | ||
| 2574 | then have "p \<in> set ds" | |
| 2575 | by (simp add: perm_set_eq[symmetric]) | |
| 2576 | with dsassoc | |
| 2577 | have "\<exists>p'. p' \<in> set (as@bs) \<and> p \<sim> p'" | |
| 2578 | unfolding list_all2_conv_all_nth set_conv_nth | |
| 2579 | by force | |
| 2580 | ||
| 2581 | from this obtain p' | |
| 2582 | where "p' \<in> set (as@bs)" | |
| 2583 | and pp': "p \<sim> p'" by auto | |
| 2584 | ||
| 2585 | hence "p' \<in> set as \<or> p' \<in> set bs" by simp | |
| 2586 | moreover | |
| 2587 |       {
 | |
| 2588 | assume p'elem: "p' \<in> set as" | |
| 2589 | with ascarr have [simp]: "p' \<in> carrier G" by fast | |
| 2590 | ||
| 2591 | note pp' | |
| 2592 | also from afac p'elem | |
| 2593 | have "p' divides a" by (rule factors_dividesI) fact+ | |
| 2594 | finally | |
| 2595 | have "p divides a" by simp | |
| 2596 | } | |
| 2597 | moreover | |
| 2598 |       {
 | |
| 2599 | assume p'elem: "p' \<in> set bs" | |
| 2600 | with bscarr have [simp]: "p' \<in> carrier G" by fast | |
| 2601 | ||
| 2602 | note pp' | |
| 2603 | also from bfac | |
| 2604 | have "p' divides b" by (rule factors_dividesI) fact+ | |
| 2605 | finally have "p divides b" by simp | |
| 2606 | } | |
| 2607 | ultimately | |
| 2608 | show "p divides a \<or> p divides b" by fast | |
| 2609 | qed | |
| 2610 | qed | |
| 2611 | qed | |
| 2612 | ||
| 2613 | ||
| 27717 
21bbd410ba04
Generalised polynomial lemmas from cring to ring.
 ballarin parents: 
27713diff
changeset | 2614 | subsection {* Greatest Common Divisors and Lowest Common Multiples *}
 | 
| 27701 | 2615 | |
| 2616 | subsubsection {* Definitions *}
 | |
| 2617 | ||
| 2618 | constdefs (structure G) | |
| 2619 |   isgcd :: "[('a,_) monoid_scheme, 'a, 'a, 'a] \<Rightarrow> bool"  ("(_ gcdof\<index> _ _)" [81,81,81] 80)
 | |
| 2620 | "x gcdof a b \<equiv> x divides a \<and> x divides b \<and> | |
| 2621 | (\<forall>y\<in>carrier G. (y divides a \<and> y divides b \<longrightarrow> y divides x))" | |
| 2622 | ||
| 2623 |   islcm :: "[_, 'a, 'a, 'a] \<Rightarrow> bool"  ("(_ lcmof\<index> _ _)" [81,81,81] 80)
 | |
| 2624 | "x lcmof a b \<equiv> a divides x \<and> b divides x \<and> | |
| 2625 | (\<forall>y\<in>carrier G. (a divides y \<and> b divides y \<longrightarrow> x divides y))" | |
| 2626 | ||
| 2627 | constdefs (structure G) | |
| 2628 |   somegcd :: "('a,_) monoid_scheme \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'a"
 | |
| 2629 | "somegcd G a b == SOME x. x \<in> carrier G \<and> x gcdof a b" | |
| 2630 | ||
| 2631 |   somelcm :: "('a,_) monoid_scheme \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'a"
 | |
| 2632 | "somelcm G a b == SOME x. x \<in> carrier G \<and> x lcmof a b" | |
| 2633 | ||
| 2634 | constdefs (structure G) | |
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2635 | "SomeGcd G A == inf (division_rel G) A" | 
| 27701 | 2636 | |
| 2637 | ||
| 2638 | locale gcd_condition_monoid = comm_monoid_cancel + | |
| 2639 | assumes gcdof_exists: | |
| 2640 | "\<lbrakk>a \<in> carrier G; b \<in> carrier G\<rbrakk> \<Longrightarrow> \<exists>c. c \<in> carrier G \<and> c gcdof a b" | |
| 2641 | ||
| 2642 | locale primeness_condition_monoid = comm_monoid_cancel + | |
| 2643 | assumes irreducible_prime: | |
| 2644 | "\<lbrakk>a \<in> carrier G; irreducible G a\<rbrakk> \<Longrightarrow> prime G a" | |
| 2645 | ||
| 2646 | locale divisor_chain_condition_monoid = comm_monoid_cancel + | |
| 2647 | assumes division_wellfounded: | |
| 2648 |           "wf {(x, y). x \<in> carrier G \<and> y \<in> carrier G \<and> properfactor G x y}"
 | |
| 2649 | ||
| 2650 | ||
| 2651 | subsubsection {* Connections to \texttt{Lattice.thy} *}
 | |
| 2652 | ||
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2653 | lemma gcdof_greatestLower: | 
| 27701 | 2654 | fixes G (structure) | 
| 2655 | assumes carr[simp]: "a \<in> carrier G" "b \<in> carrier G" | |
| 2656 | shows "(x \<in> carrier G \<and> x gcdof a b) = | |
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2657 |          greatest (division_rel G) x (Lower (division_rel G) {a, b})"
 | 
| 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2658 | unfolding isgcd_def greatest_def Lower_def elem_def | 
| 27701 | 2659 | proof (simp, safe) | 
| 2660 | fix xa | |
| 2661 | assume r1[rule_format]: "\<forall>x. (x = a \<or> x = b) \<and> x \<in> carrier G \<longrightarrow> xa divides x" | |
| 2662 | assume r2[rule_format]: "\<forall>y\<in>carrier G. y divides a \<and> y divides b \<longrightarrow> y divides x" | |
| 2663 | ||
| 2664 | assume "xa \<in> carrier G" "x divides a" "x divides b" | |
| 2665 | with carr | |
| 2666 | show "xa divides x" | |
| 2667 | by (fast intro: r1 r2) | |
| 2668 | next | |
| 2669 | fix a' y | |
| 2670 | assume r1[rule_format]: | |
| 2671 |          "\<forall>xa\<in>{l. \<forall>x. (x = a \<or> x = b) \<and> x \<in> carrier G \<longrightarrow> l divides x} \<inter> carrier G.
 | |
| 2672 | xa divides x" | |
| 2673 | assume "y \<in> carrier G" "y divides a" "y divides b" | |
| 2674 | with carr | |
| 2675 | show "y divides x" | |
| 2676 | by (fast intro: r1) | |
| 2677 | qed (simp, simp) | |
| 2678 | ||
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2679 | lemma lcmof_leastUpper: | 
| 27701 | 2680 | fixes G (structure) | 
| 2681 | assumes carr[simp]: "a \<in> carrier G" "b \<in> carrier G" | |
| 2682 | shows "(x \<in> carrier G \<and> x lcmof a b) = | |
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2683 |          least (division_rel G) x (Upper (division_rel G) {a, b})"
 | 
| 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2684 | unfolding islcm_def least_def Upper_def elem_def | 
| 27701 | 2685 | proof (simp, safe) | 
| 2686 | fix xa | |
| 2687 | assume r1[rule_format]: "\<forall>x. (x = a \<or> x = b) \<and> x \<in> carrier G \<longrightarrow> x divides xa" | |
| 2688 | assume r2[rule_format]: "\<forall>y\<in>carrier G. a divides y \<and> b divides y \<longrightarrow> x divides y" | |
| 2689 | ||
| 2690 | assume "xa \<in> carrier G" "a divides x" "b divides x" | |
| 2691 | with carr | |
| 2692 | show "x divides xa" | |
| 2693 | by (fast intro: r1 r2) | |
| 2694 | next | |
| 2695 | fix a' y | |
| 2696 | assume r1[rule_format]: | |
| 2697 |          "\<forall>xa\<in>{l. \<forall>x. (x = a \<or> x = b) \<and> x \<in> carrier G \<longrightarrow> x divides l} \<inter> carrier G.
 | |
| 2698 | x divides xa" | |
| 2699 | assume "y \<in> carrier G" "a divides y" "b divides y" | |
| 2700 | with carr | |
| 2701 | show "x divides y" | |
| 2702 | by (fast intro: r1) | |
| 2703 | qed (simp, simp) | |
| 2704 | ||
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2705 | lemma somegcd_meet: | 
| 27701 | 2706 | fixes G (structure) | 
| 2707 | assumes carr: "a \<in> carrier G" "b \<in> carrier G" | |
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2708 | shows "somegcd G a b = meet (division_rel G) a b" | 
| 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2709 | unfolding somegcd_def meet_def inf_def | 
| 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2710 | by (simp add: gcdof_greatestLower[OF carr]) | 
| 27701 | 2711 | |
| 2712 | lemma (in monoid) isgcd_divides_l: | |
| 2713 | assumes "a divides b" | |
| 2714 | and "a \<in> carrier G" "b \<in> carrier G" | |
| 2715 | shows "a gcdof a b" | |
| 2716 | using assms | |
| 2717 | unfolding isgcd_def | |
| 2718 | by fast | |
| 2719 | ||
| 2720 | lemma (in monoid) isgcd_divides_r: | |
| 2721 | assumes "b divides a" | |
| 2722 | and "a \<in> carrier G" "b \<in> carrier G" | |
| 2723 | shows "b gcdof a b" | |
| 2724 | using assms | |
| 2725 | unfolding isgcd_def | |
| 2726 | by fast | |
| 2727 | ||
| 2728 | ||
| 2729 | subsubsection {* Existence of gcd and lcm *}
 | |
| 2730 | ||
| 2731 | lemma (in factorial_monoid) gcdof_exists: | |
| 2732 | assumes acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" | |
| 2733 | shows "\<exists>c. c \<in> carrier G \<and> c gcdof a b" | |
| 2734 | proof - | |
| 2735 | from acarr have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a" by (rule wfactors_exist) | |
| 2736 | from this obtain as | |
| 2737 | where ascarr: "set as \<subseteq> carrier G" | |
| 2738 | and afs: "wfactors G as a" | |
| 2739 | by auto | |
| 2740 | from afs have airr: "\<forall>a \<in> set as. irreducible G a" by (fast elim: wfactorsE) | |
| 2741 | ||
| 2742 | from bcarr have "\<exists>bs. set bs \<subseteq> carrier G \<and> wfactors G bs b" by (rule wfactors_exist) | |
| 2743 | from this obtain bs | |
| 2744 | where bscarr: "set bs \<subseteq> carrier G" | |
| 2745 | and bfs: "wfactors G bs b" | |
| 2746 | by auto | |
| 2747 | from bfs have birr: "\<forall>b \<in> set bs. irreducible G b" by (fast elim: wfactorsE) | |
| 2748 | ||
| 2749 | have "\<exists>c cs. c \<in> carrier G \<and> set cs \<subseteq> carrier G \<and> wfactors G cs c \<and> | |
| 2750 | fmset G cs = fmset G as #\<inter> fmset G bs" | |
| 2751 | proof (intro mset_wfactorsEx) | |
| 2752 | fix X | |
| 2753 | assume "X \<in> set_of (fmset G as #\<inter> fmset G bs)" | |
| 2754 | hence "X \<in> set_of (fmset G as)" by (simp add: multiset_inter_def) | |
| 2755 | hence "X \<in> set (map (assocs G) as)" by (simp add: fmset_def) | |
| 2756 | hence "\<exists>x. X = assocs G x \<and> x \<in> set as" by (induct as) auto | |
| 2757 | from this obtain x | |
| 2758 | where X: "X = assocs G x" | |
| 2759 | and xas: "x \<in> set as" | |
| 2760 | by auto | |
| 2761 | with ascarr have xcarr: "x \<in> carrier G" by fast | |
| 2762 | from xas airr have xirr: "irreducible G x" by simp | |
| 2763 | ||
| 2764 | from xcarr and xirr and X | |
| 2765 | show "\<exists>x. (x \<in> carrier G \<and> irreducible G x) \<and> X = assocs G x" by fast | |
| 2766 | qed | |
| 2767 | ||
| 2768 | from this obtain c cs | |
| 2769 | where ccarr: "c \<in> carrier G" | |
| 2770 | and cscarr: "set cs \<subseteq> carrier G" | |
| 2771 | and csirr: "wfactors G cs c" | |
| 2772 | and csmset: "fmset G cs = fmset G as #\<inter> fmset G bs" by auto | |
| 2773 | ||
| 2774 | have "c gcdof a b" | |
| 2775 | proof (simp add: isgcd_def, safe) | |
| 2776 | from csmset | |
| 2777 | have "fmset G cs \<le># fmset G as" | |
| 2778 | by (simp add: multiset_inter_def mset_le_def) | |
| 2779 | thus "c divides a" by (rule fmsubset_divides) fact+ | |
| 2780 | next | |
| 2781 | from csmset | |
| 2782 | have "fmset G cs \<le># fmset G bs" | |
| 2783 | by (simp add: multiset_inter_def mset_le_def, force) | |
| 2784 | thus "c divides b" by (rule fmsubset_divides) fact+ | |
| 2785 | next | |
| 2786 | fix y | |
| 2787 | assume ycarr: "y \<in> carrier G" | |
| 2788 | hence "\<exists>ys. set ys \<subseteq> carrier G \<and> wfactors G ys y" by (rule wfactors_exist) | |
| 2789 | from this obtain ys | |
| 2790 | where yscarr: "set ys \<subseteq> carrier G" | |
| 2791 | and yfs: "wfactors G ys y" | |
| 2792 | by auto | |
| 2793 | ||
| 2794 | assume "y divides a" | |
| 2795 | hence ya: "fmset G ys \<le># fmset G as" by (rule divides_fmsubset) fact+ | |
| 2796 | ||
| 2797 | assume "y divides b" | |
| 2798 | hence yb: "fmset G ys \<le># fmset G bs" by (rule divides_fmsubset) fact+ | |
| 2799 | ||
| 2800 | from ya yb csmset | |
| 2801 | have "fmset G ys \<le># fmset G cs" by (simp add: mset_le_def multiset_inter_count) | |
| 2802 | thus "y divides c" by (rule fmsubset_divides) fact+ | |
| 2803 | qed | |
| 2804 | ||
| 2805 | with ccarr | |
| 2806 | show "\<exists>c. c \<in> carrier G \<and> c gcdof a b" by fast | |
| 2807 | qed | |
| 2808 | ||
| 2809 | lemma (in factorial_monoid) lcmof_exists: | |
| 2810 | assumes acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" | |
| 2811 | shows "\<exists>c. c \<in> carrier G \<and> c lcmof a b" | |
| 2812 | proof - | |
| 2813 | from acarr have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a" by (rule wfactors_exist) | |
| 2814 | from this obtain as | |
| 2815 | where ascarr: "set as \<subseteq> carrier G" | |
| 2816 | and afs: "wfactors G as a" | |
| 2817 | by auto | |
| 2818 | from afs have airr: "\<forall>a \<in> set as. irreducible G a" by (fast elim: wfactorsE) | |
| 2819 | ||
| 2820 | from bcarr have "\<exists>bs. set bs \<subseteq> carrier G \<and> wfactors G bs b" by (rule wfactors_exist) | |
| 2821 | from this obtain bs | |
| 2822 | where bscarr: "set bs \<subseteq> carrier G" | |
| 2823 | and bfs: "wfactors G bs b" | |
| 2824 | by auto | |
| 2825 | from bfs have birr: "\<forall>b \<in> set bs. irreducible G b" by (fast elim: wfactorsE) | |
| 2826 | ||
| 2827 | have "\<exists>c cs. c \<in> carrier G \<and> set cs \<subseteq> carrier G \<and> wfactors G cs c \<and> | |
| 2828 | fmset G cs = (fmset G as - fmset G bs) + fmset G bs" | |
| 2829 | proof (intro mset_wfactorsEx) | |
| 2830 | fix X | |
| 2831 | assume "X \<in> set_of ((fmset G as - fmset G bs) + fmset G bs)" | |
| 2832 | hence "X \<in> set_of (fmset G as) \<or> X \<in> set_of (fmset G bs)" | |
| 2833 | by (cases "X :# fmset G bs", simp, simp) | |
| 2834 | moreover | |
| 2835 |     {
 | |
| 2836 | assume "X \<in> set_of (fmset G as)" | |
| 2837 | hence "X \<in> set (map (assocs G) as)" by (simp add: fmset_def) | |
| 2838 | hence "\<exists>x. x \<in> set as \<and> X = assocs G x" by (induct as) auto | |
| 2839 | from this obtain x | |
| 2840 | where xas: "x \<in> set as" | |
| 2841 | and X: "X = assocs G x" by auto | |
| 2842 | ||
| 2843 | with ascarr have xcarr: "x \<in> carrier G" by fast | |
| 2844 | from xas airr have xirr: "irreducible G x" by simp | |
| 2845 | ||
| 2846 | from xcarr and xirr and X | |
| 2847 | have "\<exists>x. (x \<in> carrier G \<and> irreducible G x) \<and> X = assocs G x" by fast | |
| 2848 | } | |
| 2849 | moreover | |
| 2850 |     {
 | |
| 2851 | assume "X \<in> set_of (fmset G bs)" | |
| 2852 | hence "X \<in> set (map (assocs G) bs)" by (simp add: fmset_def) | |
| 2853 | hence "\<exists>x. x \<in> set bs \<and> X = assocs G x" by (induct as) auto | |
| 2854 | from this obtain x | |
| 2855 | where xbs: "x \<in> set bs" | |
| 2856 | and X: "X = assocs G x" by auto | |
| 2857 | ||
| 2858 | with bscarr have xcarr: "x \<in> carrier G" by fast | |
| 2859 | from xbs birr have xirr: "irreducible G x" by simp | |
| 2860 | ||
| 2861 | from xcarr and xirr and X | |
| 2862 | have "\<exists>x. (x \<in> carrier G \<and> irreducible G x) \<and> X = assocs G x" by fast | |
| 2863 | } | |
| 2864 | ultimately | |
| 2865 | show "\<exists>x. (x \<in> carrier G \<and> irreducible G x) \<and> X = assocs G x" by fast | |
| 2866 | qed | |
| 2867 | ||
| 2868 | from this obtain c cs | |
| 2869 | where ccarr: "c \<in> carrier G" | |
| 2870 | and cscarr: "set cs \<subseteq> carrier G" | |
| 2871 | and csirr: "wfactors G cs c" | |
| 2872 | and csmset: "fmset G cs = fmset G as - fmset G bs + fmset G bs" by auto | |
| 2873 | ||
| 2874 | have "c lcmof a b" | |
| 2875 | proof (simp add: islcm_def, safe) | |
| 2876 | from csmset have "fmset G as \<le># fmset G cs" by (simp add: mset_le_def, force) | |
| 2877 | thus "a divides c" by (rule fmsubset_divides) fact+ | |
| 2878 | next | |
| 2879 | from csmset have "fmset G bs \<le># fmset G cs" by (simp add: mset_le_def) | |
| 2880 | thus "b divides c" by (rule fmsubset_divides) fact+ | |
| 2881 | next | |
| 2882 | fix y | |
| 2883 | assume ycarr: "y \<in> carrier G" | |
| 2884 | hence "\<exists>ys. set ys \<subseteq> carrier G \<and> wfactors G ys y" by (rule wfactors_exist) | |
| 2885 | from this obtain ys | |
| 2886 | where yscarr: "set ys \<subseteq> carrier G" | |
| 2887 | and yfs: "wfactors G ys y" | |
| 2888 | by auto | |
| 2889 | ||
| 2890 | assume "a divides y" | |
| 2891 | hence ya: "fmset G as \<le># fmset G ys" by (rule divides_fmsubset) fact+ | |
| 2892 | ||
| 2893 | assume "b divides y" | |
| 2894 | hence yb: "fmset G bs \<le># fmset G ys" by (rule divides_fmsubset) fact+ | |
| 2895 | ||
| 2896 | from ya yb csmset | |
| 2897 | have "fmset G cs \<le># fmset G ys" | |
| 2898 | apply (simp add: mset_le_def, clarify) | |
| 2899 | apply (case_tac "count (fmset G as) a < count (fmset G bs) a") | |
| 2900 | apply simp | |
| 2901 | apply simp | |
| 2902 | done | |
| 2903 | thus "c divides y" by (rule fmsubset_divides) fact+ | |
| 2904 | qed | |
| 2905 | ||
| 2906 | with ccarr | |
| 2907 | show "\<exists>c. c \<in> carrier G \<and> c lcmof a b" by fast | |
| 2908 | qed | |
| 2909 | ||
| 2910 | ||
| 27717 
21bbd410ba04
Generalised polynomial lemmas from cring to ring.
 ballarin parents: 
27713diff
changeset | 2911 | subsection {* Conditions for Factoriality *}
 | 
| 27701 | 2912 | |
| 2913 | subsubsection {* Gcd condition *}
 | |
| 2914 | ||
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2915 | lemma (in gcd_condition_monoid) division_weak_lower_semilattice [simp]: | 
| 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2916 | shows "weak_lower_semilattice (division_rel G)" | 
| 27701 | 2917 | proof - | 
| 29237 | 2918 | interpret weak_partial_order "division_rel G" .. | 
| 27701 | 2919 | show ?thesis | 
| 2920 | apply (unfold_locales, simp_all) | |
| 2921 | proof - | |
| 2922 | fix x y | |
| 2923 | assume carr: "x \<in> carrier G" "y \<in> carrier G" | |
| 2924 | hence "\<exists>z. z \<in> carrier G \<and> z gcdof x y" by (rule gcdof_exists) | |
| 2925 | from this obtain z | |
| 2926 | where zcarr: "z \<in> carrier G" | |
| 2927 | and isgcd: "z gcdof x y" | |
| 2928 | by auto | |
| 2929 | with carr | |
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2930 |     have "greatest (division_rel G) z (Lower (division_rel G) {x, y})"
 | 
| 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2931 | by (subst gcdof_greatestLower[symmetric], simp+) | 
| 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2932 |     thus "\<exists>z. greatest (division_rel G) z (Lower (division_rel G) {x, y})" by fast
 | 
| 27701 | 2933 | qed | 
| 2934 | qed | |
| 2935 | ||
| 2936 | lemma (in gcd_condition_monoid) gcdof_cong_l: | |
| 2937 | assumes a'a: "a' \<sim> a" | |
| 2938 | and agcd: "a gcdof b c" | |
| 2939 | and a'carr: "a' \<in> carrier G" and carr': "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | |
| 2940 | shows "a' gcdof b c" | |
| 2941 | proof - | |
| 2942 | note carr = a'carr carr' | |
| 29237 | 2943 | interpret weak_lower_semilattice "division_rel G" by simp | 
| 27701 | 2944 | have "a' \<in> carrier G \<and> a' gcdof b c" | 
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2945 | apply (simp add: gcdof_greatestLower carr') | 
| 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2946 | apply (subst greatest_Lower_cong_l[of _ a]) | 
| 27701 | 2947 | apply (simp add: a'a) | 
| 2948 | apply (simp add: carr) | |
| 2949 | apply (simp add: carr) | |
| 2950 | apply (simp add: carr) | |
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2951 | apply (simp add: gcdof_greatestLower[symmetric] agcd carr) | 
| 27701 | 2952 | done | 
| 2953 | thus ?thesis .. | |
| 2954 | qed | |
| 2955 | ||
| 2956 | lemma (in gcd_condition_monoid) gcd_closed [simp]: | |
| 2957 | assumes carr: "a \<in> carrier G" "b \<in> carrier G" | |
| 2958 | shows "somegcd G a b \<in> carrier G" | |
| 2959 | proof - | |
| 29237 | 2960 | interpret weak_lower_semilattice "division_rel G" by simp | 
| 27701 | 2961 | show ?thesis | 
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2962 | apply (simp add: somegcd_meet[OF carr]) | 
| 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2963 | apply (rule meet_closed[simplified], fact+) | 
| 27701 | 2964 | done | 
| 2965 | qed | |
| 2966 | ||
| 2967 | lemma (in gcd_condition_monoid) gcd_isgcd: | |
| 2968 | assumes carr: "a \<in> carrier G" "b \<in> carrier G" | |
| 2969 | shows "(somegcd G a b) gcdof a b" | |
| 2970 | proof - | |
| 29237 | 2971 | interpret weak_lower_semilattice "division_rel G" by simp | 
| 27701 | 2972 | from carr | 
| 2973 | have "somegcd G a b \<in> carrier G \<and> (somegcd G a b) gcdof a b" | |
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2974 | apply (subst gcdof_greatestLower, simp, simp) | 
| 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2975 | apply (simp add: somegcd_meet[OF carr] meet_def) | 
| 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2976 | apply (rule inf_of_two_greatest[simplified], assumption+) | 
| 27701 | 2977 | done | 
| 2978 | thus "(somegcd G a b) gcdof a b" by simp | |
| 2979 | qed | |
| 2980 | ||
| 2981 | lemma (in gcd_condition_monoid) gcd_exists: | |
| 2982 | assumes carr: "a \<in> carrier G" "b \<in> carrier G" | |
| 2983 | shows "\<exists>x\<in>carrier G. x = somegcd G a b" | |
| 2984 | proof - | |
| 29237 | 2985 | interpret weak_lower_semilattice "division_rel G" by simp | 
| 27701 | 2986 | show ?thesis | 
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2987 | apply (simp add: somegcd_meet[OF carr]) | 
| 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2988 | apply (rule meet_closed[simplified], fact+) | 
| 27701 | 2989 | done | 
| 2990 | qed | |
| 2991 | ||
| 2992 | lemma (in gcd_condition_monoid) gcd_divides_l: | |
| 2993 | assumes carr: "a \<in> carrier G" "b \<in> carrier G" | |
| 2994 | shows "(somegcd G a b) divides a" | |
| 2995 | proof - | |
| 29237 | 2996 | interpret weak_lower_semilattice "division_rel G" by simp | 
| 27701 | 2997 | show ?thesis | 
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2998 | apply (simp add: somegcd_meet[OF carr]) | 
| 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2999 | apply (rule meet_left[simplified], fact+) | 
| 27701 | 3000 | done | 
| 3001 | qed | |
| 3002 | ||
| 3003 | lemma (in gcd_condition_monoid) gcd_divides_r: | |
| 3004 | assumes carr: "a \<in> carrier G" "b \<in> carrier G" | |
| 3005 | shows "(somegcd G a b) divides b" | |
| 3006 | proof - | |
| 29237 | 3007 | interpret weak_lower_semilattice "division_rel G" by simp | 
| 27701 | 3008 | show ?thesis | 
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 3009 | apply (simp add: somegcd_meet[OF carr]) | 
| 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 3010 | apply (rule meet_right[simplified], fact+) | 
| 27701 | 3011 | done | 
| 3012 | qed | |
| 3013 | ||
| 3014 | lemma (in gcd_condition_monoid) gcd_divides: | |
| 3015 | assumes sub: "z divides x" "z divides y" | |
| 3016 | and L: "x \<in> carrier G" "y \<in> carrier G" "z \<in> carrier G" | |
| 3017 | shows "z divides (somegcd G x y)" | |
| 3018 | proof - | |
| 29237 | 3019 | interpret weak_lower_semilattice "division_rel G" by simp | 
| 27701 | 3020 | show ?thesis | 
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 3021 | apply (simp add: somegcd_meet L) | 
| 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 3022 | apply (rule meet_le[simplified], fact+) | 
| 27701 | 3023 | done | 
| 3024 | qed | |
| 3025 | ||
| 3026 | lemma (in gcd_condition_monoid) gcd_cong_l: | |
| 3027 | assumes xx': "x \<sim> x'" | |
| 3028 | and carr: "x \<in> carrier G" "x' \<in> carrier G" "y \<in> carrier G" | |
| 3029 | shows "somegcd G x y \<sim> somegcd G x' y" | |
| 3030 | proof - | |
| 29237 | 3031 | interpret weak_lower_semilattice "division_rel G" by simp | 
| 27701 | 3032 | show ?thesis | 
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 3033 | apply (simp add: somegcd_meet carr) | 
| 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 3034 | apply (rule meet_cong_l[simplified], fact+) | 
| 27701 | 3035 | done | 
| 3036 | qed | |
| 3037 | ||
| 3038 | lemma (in gcd_condition_monoid) gcd_cong_r: | |
| 3039 | assumes carr: "x \<in> carrier G" "y \<in> carrier G" "y' \<in> carrier G" | |
| 3040 | and yy': "y \<sim> y'" | |
| 3041 | shows "somegcd G x y \<sim> somegcd G x y'" | |
| 3042 | proof - | |
| 29237 | 3043 | interpret weak_lower_semilattice "division_rel G" by simp | 
| 27701 | 3044 | show ?thesis | 
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 3045 | apply (simp add: somegcd_meet carr) | 
| 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 3046 | apply (rule meet_cong_r[simplified], fact+) | 
| 27701 | 3047 | done | 
| 3048 | qed | |
| 3049 | ||
| 3050 | (* | |
| 3051 | lemma (in gcd_condition_monoid) asc_cong_gcd_l [intro]: | |
| 3052 | assumes carr: "b \<in> carrier G" | |
| 3053 | shows "asc_cong (\<lambda>a. somegcd G a b)" | |
| 3054 | using carr | |
| 3055 | unfolding CONG_def | |
| 3056 | by clarsimp (blast intro: gcd_cong_l) | |
| 3057 | ||
| 3058 | lemma (in gcd_condition_monoid) asc_cong_gcd_r [intro]: | |
| 3059 | assumes carr: "a \<in> carrier G" | |
| 3060 | shows "asc_cong (\<lambda>b. somegcd G a b)" | |
| 3061 | using carr | |
| 3062 | unfolding CONG_def | |
| 3063 | by clarsimp (blast intro: gcd_cong_r) | |
| 3064 | ||
| 3065 | lemmas (in gcd_condition_monoid) asc_cong_gcd_split [simp] = | |
| 3066 | assoc_split[OF _ asc_cong_gcd_l] assoc_split[OF _ asc_cong_gcd_r] | |
| 3067 | *) | |
| 3068 | ||
| 3069 | lemma (in gcd_condition_monoid) gcdI: | |
| 3070 | assumes dvd: "a divides b" "a divides c" | |
| 3071 | and others: "\<forall>y\<in>carrier G. y divides b \<and> y divides c \<longrightarrow> y divides a" | |
| 3072 | and acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" and ccarr: "c \<in> carrier G" | |
| 3073 | shows "a \<sim> somegcd G b c" | |
| 3074 | apply (simp add: somegcd_def) | |
| 3075 | apply (rule someI2_ex) | |
| 3076 | apply (rule exI[of _ a], simp add: isgcd_def) | |
| 3077 | apply (simp add: assms) | |
| 3078 | apply (simp add: isgcd_def assms, clarify) | |
| 3079 | apply (insert assms, blast intro: associatedI) | |
| 3080 | done | |
| 3081 | ||
| 3082 | lemma (in gcd_condition_monoid) gcdI2: | |
| 3083 | assumes "a gcdof b c" | |
| 3084 | and "a \<in> carrier G" and bcarr: "b \<in> carrier G" and ccarr: "c \<in> carrier G" | |
| 3085 | shows "a \<sim> somegcd G b c" | |
| 3086 | using assms | |
| 3087 | unfolding isgcd_def | |
| 3088 | by (blast intro: gcdI) | |
| 3089 | ||
| 3090 | lemma (in gcd_condition_monoid) SomeGcd_ex: | |
| 3091 |   assumes "finite A"  "A \<subseteq> carrier G"  "A \<noteq> {}"
 | |
| 3092 | shows "\<exists>x\<in> carrier G. x = SomeGcd G A" | |
| 3093 | proof - | |
| 29237 | 3094 | interpret weak_lower_semilattice "division_rel G" by simp | 
| 27701 | 3095 | show ?thesis | 
| 3096 | apply (simp add: SomeGcd_def) | |
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 3097 | apply (rule finite_inf_closed[simplified], fact+) | 
| 27701 | 3098 | done | 
| 3099 | qed | |
| 3100 | ||
| 3101 | lemma (in gcd_condition_monoid) gcd_assoc: | |
| 3102 | assumes carr: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | |
| 3103 | shows "somegcd G (somegcd G a b) c \<sim> somegcd G a (somegcd G b c)" | |
| 3104 | proof - | |
| 29237 | 3105 | interpret weak_lower_semilattice "division_rel G" by simp | 
| 27701 | 3106 | show ?thesis | 
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 3107 | apply (subst (2 3) somegcd_meet, (simp add: carr)+) | 
| 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 3108 | apply (simp add: somegcd_meet carr) | 
| 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 3109 | apply (rule weak_meet_assoc[simplified], fact+) | 
| 27701 | 3110 | done | 
| 3111 | qed | |
| 3112 | ||
| 3113 | lemma (in gcd_condition_monoid) gcd_mult: | |
| 3114 | assumes acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" and ccarr: "c \<in> carrier G" | |
| 3115 | shows "c \<otimes> somegcd G a b \<sim> somegcd G (c \<otimes> a) (c \<otimes> b)" | |
| 3116 | proof - (* following Jacobson, Basic Algebra, p.140 *) | |
| 3117 | let ?d = "somegcd G a b" | |
| 3118 | let ?e = "somegcd G (c \<otimes> a) (c \<otimes> b)" | |
| 3119 | note carr[simp] = acarr bcarr ccarr | |
| 3120 | have dcarr: "?d \<in> carrier G" by simp | |
| 3121 | have ecarr: "?e \<in> carrier G" by simp | |
| 3122 | note carr = carr dcarr ecarr | |
| 3123 | ||
| 3124 | have "?d divides a" by (simp add: gcd_divides_l) | |
| 3125 | hence cd'ca: "c \<otimes> ?d divides (c \<otimes> a)" by (simp add: divides_mult_lI) | |
| 3126 | ||
| 3127 | have "?d divides b" by (simp add: gcd_divides_r) | |
| 3128 | hence cd'cb: "c \<otimes> ?d divides (c \<otimes> b)" by (simp add: divides_mult_lI) | |
| 3129 | ||
| 3130 | from cd'ca cd'cb | |
| 3131 | have cd'e: "c \<otimes> ?d divides ?e" | |
| 3132 | by (rule gcd_divides) simp+ | |
| 3133 | ||
| 3134 | hence "\<exists>u. u \<in> carrier G \<and> ?e = c \<otimes> ?d \<otimes> u" | |
| 3135 | by (elim dividesE, fast) | |
| 3136 | from this obtain u | |
| 3137 | where ucarr[simp]: "u \<in> carrier G" | |
| 3138 | and e_cdu: "?e = c \<otimes> ?d \<otimes> u" | |
| 3139 | by auto | |
| 3140 | ||
| 3141 | note carr = carr ucarr | |
| 3142 | ||
| 3143 | have "?e divides c \<otimes> a" by (rule gcd_divides_l) simp+ | |
| 3144 | hence "\<exists>x. x \<in> carrier G \<and> c \<otimes> a = ?e \<otimes> x" | |
| 3145 | by (elim dividesE, fast) | |
| 3146 | from this obtain x | |
| 3147 | where xcarr: "x \<in> carrier G" | |
| 3148 | and ca_ex: "c \<otimes> a = ?e \<otimes> x" | |
| 3149 | by auto | |
| 3150 | with e_cdu | |
| 3151 | have ca_cdux: "c \<otimes> a = c \<otimes> ?d \<otimes> u \<otimes> x" by simp | |
| 3152 | ||
| 3153 | from ca_cdux xcarr | |
| 3154 | have "c \<otimes> a = c \<otimes> (?d \<otimes> u \<otimes> x)" by (simp add: m_assoc) | |
| 3155 | then have "a = ?d \<otimes> u \<otimes> x" by (rule l_cancel[of c a]) (simp add: xcarr)+ | |
| 3156 | hence du'a: "?d \<otimes> u divides a" by (rule dividesI[OF xcarr]) | |
| 3157 | ||
| 3158 | have "?e divides c \<otimes> b" by (intro gcd_divides_r, simp+) | |
| 3159 | hence "\<exists>x. x \<in> carrier G \<and> c \<otimes> b = ?e \<otimes> x" | |
| 3160 | by (elim dividesE, fast) | |
| 3161 | from this obtain x | |
| 3162 | where xcarr: "x \<in> carrier G" | |
| 3163 | and cb_ex: "c \<otimes> b = ?e \<otimes> x" | |
| 3164 | by auto | |
| 3165 | with e_cdu | |
| 3166 | have cb_cdux: "c \<otimes> b = c \<otimes> ?d \<otimes> u \<otimes> x" by simp | |
| 3167 | ||
| 3168 | from cb_cdux xcarr | |
| 3169 | have "c \<otimes> b = c \<otimes> (?d \<otimes> u \<otimes> x)" by (simp add: m_assoc) | |
| 3170 | with xcarr | |
| 3171 | have "b = ?d \<otimes> u \<otimes> x" by (intro l_cancel[of c b], simp+) | |
| 3172 | hence du'b: "?d \<otimes> u divides b" by (intro dividesI[OF xcarr]) | |
| 3173 | ||
| 3174 | from du'a du'b carr | |
| 3175 | have du'd: "?d \<otimes> u divides ?d" | |
| 3176 | by (intro gcd_divides, simp+) | |
| 3177 | hence uunit: "u \<in> Units G" | |
| 3178 | proof (elim dividesE) | |
| 3179 | fix v | |
| 3180 | assume vcarr[simp]: "v \<in> carrier G" | |
| 3181 | assume d: "?d = ?d \<otimes> u \<otimes> v" | |
| 3182 | have "?d \<otimes> \<one> = ?d \<otimes> u \<otimes> v" by simp fact | |
| 3183 | also have "?d \<otimes> u \<otimes> v = ?d \<otimes> (u \<otimes> v)" by (simp add: m_assoc) | |
| 3184 | finally have "?d \<otimes> \<one> = ?d \<otimes> (u \<otimes> v)" . | |
| 3185 | hence i2: "\<one> = u \<otimes> v" by (rule l_cancel) simp+ | |
| 3186 | hence i1: "\<one> = v \<otimes> u" by (simp add: m_comm) | |
| 3187 | from vcarr i1[symmetric] i2[symmetric] | |
| 3188 | show "u \<in> Units G" | |
| 3189 | by (unfold Units_def, simp, fast) | |
| 3190 | qed | |
| 3191 | ||
| 3192 | from e_cdu uunit | |
| 3193 | have "somegcd G (c \<otimes> a) (c \<otimes> b) \<sim> c \<otimes> somegcd G a b" | |
| 3194 | by (intro associatedI2[of u], simp+) | |
| 3195 | from this[symmetric] | |
| 3196 | show "c \<otimes> somegcd G a b \<sim> somegcd G (c \<otimes> a) (c \<otimes> b)" by simp | |
| 3197 | qed | |
| 3198 | ||
| 3199 | lemma (in monoid) assoc_subst: | |
| 3200 | assumes ab: "a \<sim> b" | |
| 3201 | and cP: "ALL a b. a : carrier G & b : carrier G & a \<sim> b | |
| 3202 | --> f a : carrier G & f b : carrier G & f a \<sim> f b" | |
| 3203 | and carr: "a \<in> carrier G" "b \<in> carrier G" | |
| 3204 | shows "f a \<sim> f b" | |
| 3205 | using assms by auto | |
| 3206 | ||
| 3207 | lemma (in gcd_condition_monoid) relprime_mult: | |
| 3208 | assumes abrelprime: "somegcd G a b \<sim> \<one>" and acrelprime: "somegcd G a c \<sim> \<one>" | |
| 3209 | and carr[simp]: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | |
| 3210 | shows "somegcd G a (b \<otimes> c) \<sim> \<one>" | |
| 3211 | proof - | |
| 3212 | have "c = c \<otimes> \<one>" by simp | |
| 3213 | also from abrelprime[symmetric] | |
| 3214 | have "\<dots> \<sim> c \<otimes> somegcd G a b" | |
| 3215 | by (rule assoc_subst) (simp add: mult_cong_r)+ | |
| 3216 | also have "\<dots> \<sim> somegcd G (c \<otimes> a) (c \<otimes> b)" by (rule gcd_mult) fact+ | |
| 3217 | finally | |
| 3218 | have c: "c \<sim> somegcd G (c \<otimes> a) (c \<otimes> b)" by simp | |
| 3219 | ||
| 3220 | from carr | |
| 3221 | have a: "a \<sim> somegcd G a (c \<otimes> a)" | |
| 3222 | by (fast intro: gcdI divides_prod_l) | |
| 3223 | ||
| 3224 | have "somegcd G a (b \<otimes> c) \<sim> somegcd G a (c \<otimes> b)" by (simp add: m_comm) | |
| 3225 | also from a | |
| 3226 | have "\<dots> \<sim> somegcd G (somegcd G a (c \<otimes> a)) (c \<otimes> b)" | |
| 3227 | by (rule assoc_subst) (simp add: gcd_cong_l)+ | |
| 3228 | also from gcd_assoc | |
| 3229 | have "\<dots> \<sim> somegcd G a (somegcd G (c \<otimes> a) (c \<otimes> b))" | |
| 3230 | by (rule assoc_subst) simp+ | |
| 3231 | also from c[symmetric] | |
| 3232 | have "\<dots> \<sim> somegcd G a c" | |
| 3233 | by (rule assoc_subst) (simp add: gcd_cong_r)+ | |
| 3234 | also note acrelprime | |
| 3235 | finally | |
| 3236 | show "somegcd G a (b \<otimes> c) \<sim> \<one>" by simp | |
| 3237 | qed | |
| 3238 | ||
| 3239 | lemma (in gcd_condition_monoid) primeness_condition: | |
| 3240 | "primeness_condition_monoid G" | |
| 3241 | apply unfold_locales | |
| 3242 | apply (rule primeI) | |
| 3243 | apply (elim irreducibleE, assumption) | |
| 3244 | proof - | |
| 3245 | fix p a b | |
| 3246 | assume pcarr: "p \<in> carrier G" and acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" | |
| 3247 | and pirr: "irreducible G p" | |
| 3248 | and pdvdab: "p divides a \<otimes> b" | |
| 3249 | from pirr | |
| 3250 | have pnunit: "p \<notin> Units G" | |
| 3251 | and r[rule_format]: "\<forall>b. b \<in> carrier G \<and> properfactor G b p \<longrightarrow> b \<in> Units G" | |
| 3252 | by - (fast elim: irreducibleE)+ | |
| 3253 | ||
| 3254 | show "p divides a \<or> p divides b" | |
| 3255 | proof (rule ccontr, clarsimp) | |
| 3256 | assume npdvda: "\<not> p divides a" | |
| 3257 | with pcarr acarr | |
| 3258 | have "\<one> \<sim> somegcd G p a" | |
| 3259 | apply (intro gcdI, simp, simp, simp) | |
| 3260 | apply (fast intro: unit_divides) | |
| 3261 | apply (fast intro: unit_divides) | |
| 3262 | apply (clarsimp simp add: Unit_eq_dividesone[symmetric]) | |
| 3263 | apply (rule r, rule, assumption) | |
| 3264 | apply (rule properfactorI, assumption) | |
| 3265 | proof (rule ccontr, simp) | |
| 3266 | fix y | |
| 3267 | assume ycarr: "y \<in> carrier G" | |
| 3268 | assume "p divides y" | |
| 3269 | also assume "y divides a" | |
| 3270 | finally | |
| 3271 | have "p divides a" by (simp add: pcarr ycarr acarr) | |
| 3272 | with npdvda | |
| 3273 | show "False" .. | |
| 3274 | qed simp+ | |
| 3275 | with pcarr acarr | |
| 3276 | have pa: "somegcd G p a \<sim> \<one>" by (fast intro: associated_sym[of "\<one>"] gcd_closed) | |
| 3277 | ||
| 3278 | assume npdvdb: "\<not> p divides b" | |
| 3279 | with pcarr bcarr | |
| 3280 | have "\<one> \<sim> somegcd G p b" | |
| 3281 | apply (intro gcdI, simp, simp, simp) | |
| 3282 | apply (fast intro: unit_divides) | |
| 3283 | apply (fast intro: unit_divides) | |
| 3284 | apply (clarsimp simp add: Unit_eq_dividesone[symmetric]) | |
| 3285 | apply (rule r, rule, assumption) | |
| 3286 | apply (rule properfactorI, assumption) | |
| 3287 | proof (rule ccontr, simp) | |
| 3288 | fix y | |
| 3289 | assume ycarr: "y \<in> carrier G" | |
| 3290 | assume "p divides y" | |
| 3291 | also assume "y divides b" | |
| 3292 | finally have "p divides b" by (simp add: pcarr ycarr bcarr) | |
| 3293 | with npdvdb | |
| 3294 | show "False" .. | |
| 3295 | qed simp+ | |
| 3296 | with pcarr bcarr | |
| 3297 | have pb: "somegcd G p b \<sim> \<one>" by (fast intro: associated_sym[of "\<one>"] gcd_closed) | |
| 3298 | ||
| 3299 | from pcarr acarr bcarr pdvdab | |
| 3300 | have "p gcdof p (a \<otimes> b)" by (fast intro: isgcd_divides_l) | |
| 3301 | ||
| 3302 | with pcarr acarr bcarr | |
| 3303 | have "p \<sim> somegcd G p (a \<otimes> b)" by (fast intro: gcdI2) | |
| 3304 | also from pa pb pcarr acarr bcarr | |
| 3305 | have "somegcd G p (a \<otimes> b) \<sim> \<one>" by (rule relprime_mult) | |
| 3306 | finally have "p \<sim> \<one>" by (simp add: pcarr acarr bcarr) | |
| 3307 | ||
| 3308 | with pcarr | |
| 3309 | have "p \<in> Units G" by (fast intro: assoc_unit_l) | |
| 3310 | with pnunit | |
| 3311 | show "False" .. | |
| 3312 | qed | |
| 3313 | qed | |
| 3314 | ||
| 29237 | 3315 | sublocale gcd_condition_monoid \<subseteq> primeness_condition_monoid | 
| 27701 | 3316 | by (rule primeness_condition) | 
| 3317 | ||
| 3318 | ||
| 3319 | subsubsection {* Divisor chain condition *}
 | |
| 3320 | ||
| 3321 | lemma (in divisor_chain_condition_monoid) wfactors_exist: | |
| 3322 | assumes acarr: "a \<in> carrier G" | |
| 3323 | shows "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a" | |
| 3324 | proof - | |
| 3325 | have r[rule_format]: "a \<in> carrier G \<longrightarrow> (\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a)" | |
| 3326 | apply (rule wf_induct[OF division_wellfounded]) | |
| 3327 | proof - | |
| 3328 | fix x | |
| 3329 |     assume ih: "\<forall>y. (y, x) \<in> {(x, y). x \<in> carrier G \<and> y \<in> carrier G \<and> properfactor G x y}
 | |
| 3330 | \<longrightarrow> y \<in> carrier G \<longrightarrow> (\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as y)" | |
| 3331 | ||
| 3332 | show "x \<in> carrier G \<longrightarrow> (\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as x)" | |
| 3333 | apply clarify | |
| 3334 | apply (cases "x \<in> Units G") | |
| 3335 | apply (rule exI[of _ "[]"], simp) | |
| 3336 | apply (cases "irreducible G x") | |
| 3337 | apply (rule exI[of _ "[x]"], simp add: wfactors_def) | |
| 3338 | proof - | |
| 3339 | assume xcarr: "x \<in> carrier G" | |
| 3340 | and xnunit: "x \<notin> Units G" | |
| 3341 | and xnirr: "\<not> irreducible G x" | |
| 3342 | hence "\<exists>y. y \<in> carrier G \<and> properfactor G y x \<and> y \<notin> Units G" | |
| 3343 | apply - apply (rule ccontr, simp) | |
| 3344 | apply (subgoal_tac "irreducible G x", simp) | |
| 3345 | apply (rule irreducibleI, simp, simp) | |
| 3346 | done | |
| 3347 | from this obtain y | |
| 3348 | where ycarr: "y \<in> carrier G" | |
| 3349 | and ynunit: "y \<notin> Units G" | |
| 3350 | and pfyx: "properfactor G y x" | |
| 3351 | by auto | |
| 3352 | ||
| 3353 | have ih': | |
| 3354 | "\<And>y. \<lbrakk>y \<in> carrier G; properfactor G y x\<rbrakk> | |
| 3355 | \<Longrightarrow> \<exists>as. set as \<subseteq> carrier G \<and> wfactors G as y" | |
| 3356 | by (rule ih[rule_format, simplified]) (simp add: xcarr)+ | |
| 3357 | ||
| 3358 | from ycarr pfyx | |
| 3359 | have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as y" | |
| 3360 | by (rule ih') | |
| 3361 | from this obtain ys | |
| 3362 | where yscarr: "set ys \<subseteq> carrier G" | |
| 3363 | and yfs: "wfactors G ys y" | |
| 3364 | by auto | |
| 3365 | ||
| 3366 | from pfyx | |
| 3367 | have "y divides x" | |
| 3368 | and nyx: "\<not> y \<sim> x" | |
| 3369 | by - (fast elim: properfactorE2)+ | |
| 3370 | hence "\<exists>z. z \<in> carrier G \<and> x = y \<otimes> z" | |
| 3371 | by (fast elim: dividesE) | |
| 3372 | ||
| 3373 | from this obtain z | |
| 3374 | where zcarr: "z \<in> carrier G" | |
| 3375 | and x: "x = y \<otimes> z" | |
| 3376 | by auto | |
| 3377 | ||
| 3378 | from zcarr ycarr | |
| 3379 | have "properfactor G z x" | |
| 3380 | apply (subst x) | |
| 3381 | apply (intro properfactorI3[of _ _ y]) | |
| 3382 | apply (simp add: m_comm) | |
| 3383 | apply (simp add: ynunit)+ | |
| 3384 | done | |
| 3385 | with zcarr | |
| 3386 | have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as z" | |
| 3387 | by (rule ih') | |
| 3388 | from this obtain zs | |
| 3389 | where zscarr: "set zs \<subseteq> carrier G" | |
| 3390 | and zfs: "wfactors G zs z" | |
| 3391 | by auto | |
| 3392 | ||
| 3393 | from yscarr zscarr | |
| 3394 | have xscarr: "set (ys@zs) \<subseteq> carrier G" by simp | |
| 3395 | from yfs zfs ycarr zcarr yscarr zscarr | |
| 3396 | have "wfactors G (ys@zs) (y\<otimes>z)" by (rule wfactors_mult) | |
| 3397 | hence "wfactors G (ys@zs) x" by (simp add: x) | |
| 3398 | ||
| 3399 | from xscarr this | |
| 3400 | show "\<exists>xs. set xs \<subseteq> carrier G \<and> wfactors G xs x" by fast | |
| 3401 | qed | |
| 3402 | qed | |
| 3403 | ||
| 3404 | from acarr | |
| 3405 | show ?thesis by (rule r) | |
| 3406 | qed | |
| 3407 | ||
| 3408 | ||
| 3409 | subsubsection {* Primeness condition *}
 | |
| 3410 | ||
| 3411 | lemma (in comm_monoid_cancel) multlist_prime_pos: | |
| 3412 | assumes carr: "a \<in> carrier G" "set as \<subseteq> carrier G" | |
| 3413 | and aprime: "prime G a" | |
| 3414 | and "a divides (foldr (op \<otimes>) as \<one>)" | |
| 3415 | shows "\<exists>i<length as. a divides (as!i)" | |
| 3416 | proof - | |
| 3417 | have r[rule_format]: | |
| 3418 | "set as \<subseteq> carrier G \<and> a divides (foldr (op \<otimes>) as \<one>) | |
| 3419 | \<longrightarrow> (\<exists>i. i < length as \<and> a divides (as!i))" | |
| 3420 | apply (induct as) | |
| 3421 | apply clarsimp defer 1 | |
| 3422 | apply clarsimp defer 1 | |
| 3423 | proof - | |
| 3424 | assume "a divides \<one>" | |
| 3425 | with carr | |
| 3426 | have "a \<in> Units G" | |
| 3427 | by (fast intro: divides_unit[of a \<one>]) | |
| 3428 | with aprime | |
| 3429 | show "False" by (elim primeE, simp) | |
| 3430 | next | |
| 3431 | fix aa as | |
| 3432 | assume ih[rule_format]: "a divides foldr op \<otimes> as \<one> \<longrightarrow> (\<exists>i<length as. a divides as ! i)" | |
| 3433 | and carr': "aa \<in> carrier G" "set as \<subseteq> carrier G" | |
| 3434 | and "a divides aa \<otimes> foldr op \<otimes> as \<one>" | |
| 3435 | with carr aprime | |
| 3436 | have "a divides aa \<or> a divides foldr op \<otimes> as \<one>" | |
| 3437 | by (intro prime_divides) simp+ | |
| 3438 |     moreover {
 | |
| 3439 | assume "a divides aa" | |
| 3440 | hence p1: "a divides (aa#as)!0" by simp | |
| 3441 | have "0 < Suc (length as)" by simp | |
| 3442 | with p1 have "\<exists>i<Suc (length as). a divides (aa # as) ! i" by fast | |
| 3443 | } | |
| 3444 |     moreover {
 | |
| 3445 | assume "a divides foldr op \<otimes> as \<one>" | |
| 3446 | hence "\<exists>i. i < length as \<and> a divides as ! i" by (rule ih) | |
| 3447 | from this obtain i where "a divides as ! i" and len: "i < length as" by auto | |
| 3448 | hence p1: "a divides (aa#as) ! (Suc i)" by simp | |
| 3449 | from len have "Suc i < Suc (length as)" by simp | |
| 3450 | with p1 have "\<exists>i<Suc (length as). a divides (aa # as) ! i" by force | |
| 3451 | } | |
| 3452 | ultimately | |
| 3453 | show "\<exists>i<Suc (length as). a divides (aa # as) ! i" by fast | |
| 3454 | qed | |
| 3455 | ||
| 3456 | from assms | |
| 3457 | show ?thesis | |
| 3458 | by (intro r, safe) | |
| 3459 | qed | |
| 3460 | ||
| 3461 | lemma (in primeness_condition_monoid) wfactors_unique__hlp_induct: | |
| 3462 | "\<forall>a as'. a \<in> carrier G \<and> set as \<subseteq> carrier G \<and> set as' \<subseteq> carrier G \<and> | |
| 3463 | wfactors G as a \<and> wfactors G as' a \<longrightarrow> essentially_equal G as as'" | |
| 3464 | apply (induct as) | |
| 3465 | apply clarsimp defer 1 | |
| 3466 | apply clarsimp defer 1 | |
| 3467 | proof - | |
| 3468 | fix a as' | |
| 3469 | assume acarr: "a \<in> carrier G" | |
| 3470 | and "wfactors G [] a" | |
| 3471 | hence aunit: "a \<in> Units G" | |
| 3472 | apply (elim wfactorsE) | |
| 3473 | apply (simp, rule assoc_unit_r[of "\<one>"], simp+) | |
| 3474 | done | |
| 3475 | ||
| 3476 | assume "set as' \<subseteq> carrier G" "wfactors G as' a" | |
| 3477 | with aunit | |
| 3478 | have "as' = []" | |
| 3479 | by (intro unit_wfactors_empty[of a]) | |
| 3480 | thus "essentially_equal G [] as'" by simp | |
| 3481 | next | |
| 3482 | fix a as ah as' | |
| 3483 | assume ih[rule_format]: | |
| 3484 | "\<forall>a as'. a \<in> carrier G \<and> set as' \<subseteq> carrier G \<and> | |
| 3485 | wfactors G as a \<and> wfactors G as' a \<longrightarrow> essentially_equal G as as'" | |
| 3486 | and acarr: "a \<in> carrier G" and ahcarr: "ah \<in> carrier G" | |
| 3487 | and ascarr: "set as \<subseteq> carrier G" and as'carr: "set as' \<subseteq> carrier G" | |
| 3488 | and afs: "wfactors G (ah # as) a" | |
| 3489 | and afs': "wfactors G as' a" | |
| 3490 | hence ahdvda: "ah divides a" | |
| 3491 | by (intro wfactors_dividesI[of "ah#as" "a"], simp+) | |
| 3492 | hence "\<exists>a'\<in> carrier G. a = ah \<otimes> a'" by (fast elim: dividesE) | |
| 3493 | from this obtain a' | |
| 3494 | where a'carr: "a' \<in> carrier G" | |
| 3495 | and a: "a = ah \<otimes> a'" | |
| 3496 | by auto | |
| 3497 | have a'fs: "wfactors G as a'" | |
| 3498 | apply (rule wfactorsE[OF afs], rule wfactorsI, simp) | |
| 3499 | apply (simp add: a, insert ascarr a'carr) | |
| 3500 | apply (intro assoc_l_cancel[of ah _ a'] multlist_closed ahcarr, assumption+) | |
| 3501 | done | |
| 3502 | ||
| 3503 | from afs have ahirr: "irreducible G ah" by (elim wfactorsE, simp) | |
| 3504 | with ascarr have ahprime: "prime G ah" by (intro irreducible_prime ahcarr) | |
| 3505 | ||
| 3506 | note carr [simp] = acarr ahcarr ascarr as'carr a'carr | |
| 3507 | ||
| 3508 | note ahdvda | |
| 3509 | also from afs' | |
| 3510 | have "a divides (foldr (op \<otimes>) as' \<one>)" | |
| 3511 | by (elim wfactorsE associatedE, simp) | |
| 3512 | finally have "ah divides (foldr (op \<otimes>) as' \<one>)" by simp | |
| 3513 | ||
| 3514 | with ahprime | |
| 3515 | have "\<exists>i<length as'. ah divides as'!i" | |
| 3516 | by (intro multlist_prime_pos, simp+) | |
| 3517 | from this obtain i | |
| 3518 | where len: "i<length as'" and ahdvd: "ah divides as'!i" | |
| 3519 | by auto | |
| 3520 | from afs' carr have irrasi: "irreducible G (as'!i)" | |
| 3521 | by (fast intro: nth_mem[OF len] elim: wfactorsE) | |
| 3522 | from len carr | |
| 3523 | have asicarr[simp]: "as'!i \<in> carrier G" by (unfold set_conv_nth, force) | |
| 3524 | note carr = carr asicarr | |
| 3525 | ||
| 3526 | from ahdvd have "\<exists>x \<in> carrier G. as'!i = ah \<otimes> x" by (fast elim: dividesE) | |
| 3527 | from this obtain x where "x \<in> carrier G" and asi: "as'!i = ah \<otimes> x" by auto | |
| 3528 | ||
| 3529 | with carr irrasi[simplified asi] | |
| 3530 | have asiah: "as'!i \<sim> ah" apply - | |
| 3531 | apply (elim irreducible_prodE[of "ah" "x"], assumption+) | |
| 3532 | apply (rule associatedI2[of x], assumption+) | |
| 3533 | apply (rule irreducibleE[OF ahirr], simp) | |
| 3534 | done | |
| 3535 | ||
| 3536 | note setparts = set_take_subset[of i as'] set_drop_subset[of "Suc i" as'] | |
| 3537 | note partscarr [simp] = setparts[THEN subset_trans[OF _ as'carr]] | |
| 3538 | note carr = carr partscarr | |
| 3539 | ||
| 3540 | have "\<exists>aa_1. aa_1 \<in> carrier G \<and> wfactors G (take i as') aa_1" | |
| 3541 | apply (intro wfactors_prod_exists) | |
| 3542 | using setparts afs' by (fast elim: wfactorsE, simp) | |
| 3543 | from this obtain aa_1 | |
| 3544 | where aa1carr: "aa_1 \<in> carrier G" | |
| 3545 | and aa1fs: "wfactors G (take i as') aa_1" | |
| 3546 | by auto | |
| 3547 | ||
| 3548 | have "\<exists>aa_2. aa_2 \<in> carrier G \<and> wfactors G (drop (Suc i) as') aa_2" | |
| 3549 | apply (intro wfactors_prod_exists) | |
| 3550 | using setparts afs' by (fast elim: wfactorsE, simp) | |
| 3551 | from this obtain aa_2 | |
| 3552 | where aa2carr: "aa_2 \<in> carrier G" | |
| 3553 | and aa2fs: "wfactors G (drop (Suc i) as') aa_2" | |
| 3554 | by auto | |
| 3555 | ||
| 3556 | note carr = carr aa1carr[simp] aa2carr[simp] | |
| 3557 | ||
| 3558 | from aa1fs aa2fs | |
| 3559 | have v1: "wfactors G (take i as' @ drop (Suc i) as') (aa_1 \<otimes> aa_2)" | |
| 3560 | by (intro wfactors_mult, simp+) | |
| 3561 | hence v1': "wfactors G (as'!i # take i as' @ drop (Suc i) as') (as'!i \<otimes> (aa_1 \<otimes> aa_2))" | |
| 3562 | apply (intro wfactors_mult_single) | |
| 3563 | using setparts afs' | |
| 3564 | by (fast intro: nth_mem[OF len] elim: wfactorsE, simp+) | |
| 3565 | ||
| 3566 | from aa2carr carr aa1fs aa2fs | |
| 3567 | have "wfactors G (as'!i # drop (Suc i) as') (as'!i \<otimes> aa_2)" | |
| 3568 | apply (intro wfactors_mult_single) | |
| 3569 | apply (rule wfactorsE[OF afs'], fast intro: nth_mem[OF len]) | |
| 3570 | apply (fast intro: nth_mem[OF len]) | |
| 3571 | apply fast | |
| 3572 | apply fast | |
| 3573 | apply assumption | |
| 3574 | done | |
| 3575 | with len carr aa1carr aa2carr aa1fs | |
| 3576 | have v2: "wfactors G (take i as' @ as'!i # drop (Suc i) as') (aa_1 \<otimes> (as'!i \<otimes> aa_2))" | |
| 3577 | apply (intro wfactors_mult) | |
| 3578 | apply fast | |
| 3579 | apply (simp, (fast intro: nth_mem[OF len])?)+ | |
| 3580 | done | |
| 3581 | ||
| 3582 | from len | |
| 3583 | have as': "as' = (take i as' @ as'!i # drop (Suc i) as')" | |
| 3584 | by (simp add: drop_Suc_conv_tl) | |
| 3585 | with carr | |
| 3586 | have eer: "essentially_equal G (take i as' @ as'!i # drop (Suc i) as') as'" | |
| 3587 | by simp | |
| 3588 | ||
| 3589 | with v2 afs' carr aa1carr aa2carr nth_mem[OF len] | |
| 3590 | have "aa_1 \<otimes> (as'!i \<otimes> aa_2) \<sim> a" | |
| 3591 | apply (intro ee_wfactorsD[of "take i as' @ as'!i # drop (Suc i) as'" "as'"]) | |
| 3592 | apply fast+ | |
| 3593 | apply (simp, fast) | |
| 3594 | done | |
| 3595 | then | |
| 3596 | have t1: "as'!i \<otimes> (aa_1 \<otimes> aa_2) \<sim> a" | |
| 3597 | apply (simp add: m_assoc[symmetric]) | |
| 3598 | apply (simp add: m_comm) | |
| 3599 | done | |
| 3600 | from carr asiah | |
| 3601 | have "ah \<otimes> (aa_1 \<otimes> aa_2) \<sim> as'!i \<otimes> (aa_1 \<otimes> aa_2)" | |
| 3602 | apply (intro mult_cong_l) | |
| 3603 | apply (fast intro: associated_sym, simp+) | |
| 3604 | done | |
| 3605 | also note t1 | |
| 3606 | finally | |
| 3607 | have "ah \<otimes> (aa_1 \<otimes> aa_2) \<sim> a" by simp | |
| 3608 | ||
| 3609 | with carr aa1carr aa2carr a'carr nth_mem[OF len] | |
| 3610 | have a': "aa_1 \<otimes> aa_2 \<sim> a'" | |
| 3611 | by (simp add: a, fast intro: assoc_l_cancel[of ah _ a']) | |
| 3612 | ||
| 3613 | note v1 | |
| 3614 | also note a' | |
| 3615 | finally have "wfactors G (take i as' @ drop (Suc i) as') a'" by simp | |
| 3616 | ||
| 3617 | from a'fs this carr | |
| 3618 | have "essentially_equal G as (take i as' @ drop (Suc i) as')" | |
| 3619 | by (intro ih[of a']) simp | |
| 3620 | ||
| 3621 | hence ee1: "essentially_equal G (ah # as) (ah # take i as' @ drop (Suc i) as')" | |
| 3622 | apply (elim essentially_equalE) apply (fastsimp intro: essentially_equalI) | |
| 3623 | done | |
| 3624 | ||
| 3625 | from carr | |
| 3626 | have ee2: "essentially_equal G (ah # take i as' @ drop (Suc i) as') | |
| 3627 | (as' ! i # take i as' @ drop (Suc i) as')" | |
| 3628 | proof (intro essentially_equalI) | |
| 3629 | show "ah # take i as' @ drop (Suc i) as' <~~> ah # take i as' @ drop (Suc i) as'" | |
| 3630 | by simp | |
| 3631 | next show "ah # take i as' @ drop (Suc i) as' [\<sim>] | |
| 3632 | as' ! i # take i as' @ drop (Suc i) as'" | |
| 3633 | apply (simp add: list_all2_append) | |
| 3634 | apply (simp add: asiah[symmetric] ahcarr asicarr) | |
| 3635 | done | |
| 3636 | qed | |
| 3637 | ||
| 3638 | note ee1 | |
| 3639 | also note ee2 | |
| 3640 | also have "essentially_equal G (as' ! i # take i as' @ drop (Suc i) as') | |
| 3641 | (take i as' @ as' ! i # drop (Suc i) as')" | |
| 3642 | apply (intro essentially_equalI) | |
| 3643 | apply (subgoal_tac "as' ! i # take i as' @ drop (Suc i) as' <~~> | |
| 3644 | take i as' @ as' ! i # drop (Suc i) as'") | |
| 3645 | apply simp | |
| 3646 | apply (rule perm_append_Cons) | |
| 3647 | apply simp | |
| 3648 | done | |
| 3649 | finally | |
| 3650 | have "essentially_equal G (ah # as) | |
| 3651 | (take i as' @ as' ! i # drop (Suc i) as')" by simp | |
| 3652 | ||
| 3653 | thus "essentially_equal G (ah # as) as'" by (subst as', assumption) | |
| 3654 | qed | |
| 3655 | ||
| 3656 | lemma (in primeness_condition_monoid) wfactors_unique: | |
| 3657 | assumes "wfactors G as a" "wfactors G as' a" | |
| 3658 | and "a \<in> carrier G" "set as \<subseteq> carrier G" "set as' \<subseteq> carrier G" | |
| 3659 | shows "essentially_equal G as as'" | |
| 3660 | apply (rule wfactors_unique__hlp_induct[rule_format, of a]) | |
| 3661 | apply (simp add: assms) | |
| 3662 | done | |
| 3663 | ||
| 3664 | ||
| 3665 | subsubsection {* Application to factorial monoids *}
 | |
| 3666 | ||
| 3667 | text {* Number of factors for wellfoundedness *}
 | |
| 3668 | ||
| 3669 | constdefs | |
| 3670 | factorcount :: "_ \<Rightarrow> 'a \<Rightarrow> nat" | |
| 3671 | "factorcount G a == THE c. (ALL as. set as \<subseteq> carrier G \<and> | |
| 3672 | wfactors G as a \<longrightarrow> c = length as)" | |
| 3673 | ||
| 3674 | lemma (in monoid) ee_length: | |
| 3675 | assumes ee: "essentially_equal G as bs" | |
| 3676 | shows "length as = length bs" | |
| 3677 | apply (rule essentially_equalE[OF ee]) | |
| 3678 | apply (subgoal_tac "length as = length fs1'") | |
| 3679 | apply (simp add: list_all2_lengthD) | |
| 3680 | apply (simp add: perm_length) | |
| 3681 | done | |
| 3682 | ||
| 3683 | lemma (in factorial_monoid) factorcount_exists: | |
| 3684 | assumes carr[simp]: "a \<in> carrier G" | |
| 3685 | shows "EX c. ALL as. set as \<subseteq> carrier G \<and> wfactors G as a \<longrightarrow> c = length as" | |
| 3686 | proof - | |
| 3687 | have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a" by (intro wfactors_exist, simp) | |
| 3688 | from this obtain as | |
| 3689 | where ascarr[simp]: "set as \<subseteq> carrier G" | |
| 3690 | and afs: "wfactors G as a" | |
| 3691 | by (auto simp del: carr) | |
| 3692 | ||
| 3693 | have "ALL as'. set as' \<subseteq> carrier G \<and> wfactors G as' a \<longrightarrow> length as = length as'" | |
| 3694 | proof clarify | |
| 3695 | fix as' | |
| 3696 | assume [simp]: "set as' \<subseteq> carrier G" | |
| 3697 | and bfs: "wfactors G as' a" | |
| 3698 | from afs bfs | |
| 3699 | have "essentially_equal G as as'" | |
| 3700 | by (intro ee_wfactorsI[of a a as as'], simp+) | |
| 3701 | thus "length as = length as'" by (rule ee_length) | |
| 3702 | qed | |
| 3703 | thus "EX c. ALL as'. set as' \<subseteq> carrier G \<and> wfactors G as' a \<longrightarrow> c = length as'" .. | |
| 3704 | qed | |
| 3705 | ||
| 3706 | lemma (in factorial_monoid) factorcount_unique: | |
| 3707 | assumes afs: "wfactors G as a" | |
| 3708 | and acarr[simp]: "a \<in> carrier G" and ascarr[simp]: "set as \<subseteq> carrier G" | |
| 3709 | shows "factorcount G a = length as" | |
| 3710 | proof - | |
| 3711 | have "EX ac. ALL as. set as \<subseteq> carrier G \<and> wfactors G as a \<longrightarrow> ac = length as" by (rule factorcount_exists, simp) | |
| 3712 | from this obtain ac where | |
| 3713 | alen: "ALL as. set as \<subseteq> carrier G \<and> wfactors G as a \<longrightarrow> ac = length as" | |
| 3714 | by auto | |
| 3715 | have ac: "ac = factorcount G a" | |
| 3716 | apply (simp add: factorcount_def) | |
| 3717 | apply (rule theI2) | |
| 3718 | apply (rule alen) | |
| 3719 | apply (elim allE[of _ "as"], rule allE[OF alen, of "as"], simp add: ascarr afs) | |
| 3720 | apply (elim allE[of _ "as"], rule allE[OF alen, of "as"], simp add: ascarr afs) | |
| 3721 | done | |
| 3722 | ||
| 3723 | from ascarr afs have "ac = length as" by (iprover intro: alen[rule_format]) | |
| 3724 | with ac show ?thesis by simp | |
| 3725 | qed | |
| 3726 | ||
| 3727 | lemma (in factorial_monoid) divides_fcount: | |
| 3728 | assumes dvd: "a divides b" | |
| 3729 | and acarr: "a \<in> carrier G" and bcarr:"b \<in> carrier G" | |
| 3730 | shows "factorcount G a <= factorcount G b" | |
| 3731 | apply (rule dividesE[OF dvd]) | |
| 3732 | proof - | |
| 3733 | fix c | |
| 3734 | from assms | |
| 3735 | have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a" by fast | |
| 3736 | from this obtain as | |
| 3737 | where ascarr: "set as \<subseteq> carrier G" | |
| 3738 | and afs: "wfactors G as a" | |
| 3739 | by auto | |
| 3740 | with acarr have fca: "factorcount G a = length as" by (intro factorcount_unique) | |
| 3741 | ||
| 3742 | assume ccarr: "c \<in> carrier G" | |
| 3743 | hence "\<exists>cs. set cs \<subseteq> carrier G \<and> wfactors G cs c" by fast | |
| 3744 | from this obtain cs | |
| 3745 | where cscarr: "set cs \<subseteq> carrier G" | |
| 3746 | and cfs: "wfactors G cs c" | |
| 3747 | by auto | |
| 3748 | ||
| 3749 | note [simp] = acarr bcarr ccarr ascarr cscarr | |
| 3750 | ||
| 3751 | assume b: "b = a \<otimes> c" | |
| 3752 | from afs cfs | |
| 3753 | have "wfactors G (as@cs) (a \<otimes> c)" by (intro wfactors_mult, simp+) | |
| 3754 | with b have "wfactors G (as@cs) b" by simp | |
| 3755 | hence "factorcount G b = length (as@cs)" by (intro factorcount_unique, simp+) | |
| 3756 | hence "factorcount G b = length as + length cs" by simp | |
| 3757 | with fca show ?thesis by simp | |
| 3758 | qed | |
| 3759 | ||
| 3760 | lemma (in factorial_monoid) associated_fcount: | |
| 3761 | assumes acarr: "a \<in> carrier G" and bcarr:"b \<in> carrier G" | |
| 3762 | and asc: "a \<sim> b" | |
| 3763 | shows "factorcount G a = factorcount G b" | |
| 3764 | apply (rule associatedE[OF asc]) | |
| 3765 | apply (drule divides_fcount[OF _ acarr bcarr]) | |
| 3766 | apply (drule divides_fcount[OF _ bcarr acarr]) | |
| 3767 | apply simp | |
| 3768 | done | |
| 3769 | ||
| 3770 | lemma (in factorial_monoid) properfactor_fcount: | |
| 3771 | assumes acarr: "a \<in> carrier G" and bcarr:"b \<in> carrier G" | |
| 3772 | and pf: "properfactor G a b" | |
| 3773 | shows "factorcount G a < factorcount G b" | |
| 3774 | apply (rule properfactorE[OF pf], elim dividesE) | |
| 3775 | proof - | |
| 3776 | fix c | |
| 3777 | from assms | |
| 3778 | have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a" by fast | |
| 3779 | from this obtain as | |
| 3780 | where ascarr: "set as \<subseteq> carrier G" | |
| 3781 | and afs: "wfactors G as a" | |
| 3782 | by auto | |
| 3783 | with acarr have fca: "factorcount G a = length as" by (intro factorcount_unique) | |
| 3784 | ||
| 3785 | assume ccarr: "c \<in> carrier G" | |
| 3786 | hence "\<exists>cs. set cs \<subseteq> carrier G \<and> wfactors G cs c" by fast | |
| 3787 | from this obtain cs | |
| 3788 | where cscarr: "set cs \<subseteq> carrier G" | |
| 3789 | and cfs: "wfactors G cs c" | |
| 3790 | by auto | |
| 3791 | ||
| 3792 | assume b: "b = a \<otimes> c" | |
| 3793 | ||
| 3794 | have "wfactors G (as@cs) (a \<otimes> c)" by (rule wfactors_mult) fact+ | |
| 3795 | with b | |
| 3796 | have "wfactors G (as@cs) b" by simp | |
| 3797 | with ascarr cscarr bcarr | |
| 3798 | have "factorcount G b = length (as@cs)" by (simp add: factorcount_unique) | |
| 3799 | hence fcb: "factorcount G b = length as + length cs" by simp | |
| 3800 | ||
| 3801 | assume nbdvda: "\<not> b divides a" | |
| 3802 | have "c \<notin> Units G" | |
| 3803 | proof (rule ccontr, simp) | |
| 3804 | assume cunit:"c \<in> Units G" | |
| 3805 | ||
| 3806 | have "b \<otimes> inv c = a \<otimes> c \<otimes> inv c" by (simp add: b) | |
| 3807 | also with ccarr acarr cunit | |
| 3808 | have "\<dots> = a \<otimes> (c \<otimes> inv c)" by (fast intro: m_assoc) | |
| 3809 | also with ccarr cunit | |
| 3810 | have "\<dots> = a \<otimes> \<one>" by (simp add: Units_r_inv) | |
| 3811 | also with acarr | |
| 3812 | have "\<dots> = a" by simp | |
| 3813 | finally have "a = b \<otimes> inv c" by simp | |
| 3814 | with ccarr cunit | |
| 3815 | have "b divides a" by (fast intro: dividesI[of "inv c"]) | |
| 3816 | with nbdvda show False by simp | |
| 3817 | qed | |
| 3818 | ||
| 3819 | with cfs have "length cs > 0" | |
| 3820 | apply - | |
| 3821 | apply (rule ccontr, simp) | |
| 3822 | proof - | |
| 3823 | assume "wfactors G [] c" | |
| 3824 | hence "\<one> \<sim> c" by (elim wfactorsE, simp) | |
| 3825 | with ccarr | |
| 3826 | have cunit: "c \<in> Units G" by (intro assoc_unit_r[of "\<one>" "c"], simp+) | |
| 3827 | assume "c \<notin> Units G" | |
| 3828 | with cunit show "False" by simp | |
| 3829 | qed | |
| 3830 | ||
| 3831 | with fca fcb show ?thesis by simp | |
| 3832 | qed | |
| 3833 | ||
| 29237 | 3834 | sublocale factorial_monoid \<subseteq> divisor_chain_condition_monoid | 
| 27701 | 3835 | apply unfold_locales | 
| 3836 | apply (rule wfUNIVI) | |
| 3837 | apply (rule measure_induct[of "factorcount G"]) | |
| 3838 | apply simp (* slow *) (* | |
| 3839 | [1]Applying congruence rule: | |
| 3840 | \<lbrakk>factorcount G y < factorcount G xa \<equiv> ?P'; ?P' \<Longrightarrow> P y \<equiv> ?Q'\<rbrakk> \<Longrightarrow> factorcount G y < factorcount G xa \<longrightarrow> P y \<equiv> ?P' \<longrightarrow> ?Q' | |
| 3841 | ||
| 3842 | trace_simp_depth_limit exceeded! | |
| 3843 | *) | |
| 3844 | proof - | |
| 3845 | fix P x | |
| 3846 | assume r1[rule_format]: | |
| 3847 | "\<forall>y. (\<forall>z. z \<in> carrier G \<and> y \<in> carrier G \<and> properfactor G z y \<longrightarrow> P z) \<longrightarrow> P y" | |
| 3848 | and r2[rule_format]: "\<forall>y. factorcount G y < factorcount G x \<longrightarrow> P y" | |
| 3849 | show "P x" | |
| 3850 | apply (rule r1) | |
| 3851 | apply (rule r2) | |
| 3852 | apply (rule properfactor_fcount, simp+) | |
| 3853 | done | |
| 3854 | qed | |
| 3855 | ||
| 29237 | 3856 | sublocale factorial_monoid \<subseteq> primeness_condition_monoid | 
| 28823 | 3857 | proof qed (rule irreducible_is_prime) | 
| 27701 | 3858 | |
| 3859 | ||
| 3860 | lemma (in factorial_monoid) primeness_condition: | |
| 3861 | shows "primeness_condition_monoid G" | |
| 28823 | 3862 | .. | 
| 27701 | 3863 | |
| 3864 | lemma (in factorial_monoid) gcd_condition [simp]: | |
| 3865 | shows "gcd_condition_monoid G" | |
| 28823 | 3866 | proof qed (rule gcdof_exists) | 
| 27701 | 3867 | |
| 29237 | 3868 | sublocale factorial_monoid \<subseteq> gcd_condition_monoid | 
| 28823 | 3869 | proof qed (rule gcdof_exists) | 
| 27701 | 3870 | |
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 3871 | lemma (in factorial_monoid) division_weak_lattice [simp]: | 
| 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 3872 | shows "weak_lattice (division_rel G)" | 
| 27701 | 3873 | proof - | 
| 29237 | 3874 | interpret weak_lower_semilattice "division_rel G" by simp | 
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 3875 | |
| 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 3876 | show "weak_lattice (division_rel G)" | 
| 27701 | 3877 | apply (unfold_locales, simp_all) | 
| 3878 | proof - | |
| 3879 | fix x y | |
| 3880 | assume carr: "x \<in> carrier G" "y \<in> carrier G" | |
| 3881 | ||
| 3882 | hence "\<exists>z. z \<in> carrier G \<and> z lcmof x y" by (rule lcmof_exists) | |
| 3883 | from this obtain z | |
| 3884 | where zcarr: "z \<in> carrier G" | |
| 3885 | and isgcd: "z lcmof x y" | |
| 3886 | by auto | |
| 3887 | with carr | |
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 3888 |     have "least (division_rel G) z (Upper (division_rel G) {x, y})"
 | 
| 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 3889 | by (simp add: lcmof_leastUpper[symmetric]) | 
| 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 3890 |     thus "\<exists>z. least (division_rel G) z (Upper (division_rel G) {x, y})" by fast
 | 
| 27701 | 3891 | qed | 
| 3892 | qed | |
| 3893 | ||
| 3894 | ||
| 27717 
21bbd410ba04
Generalised polynomial lemmas from cring to ring.
 ballarin parents: 
27713diff
changeset | 3895 | subsection {* Factoriality Theorems *}
 | 
| 27701 | 3896 | |
| 3897 | theorem factorial_condition_one: (* Jacobson theorem 2.21 *) | |
| 3898 | shows "(divisor_chain_condition_monoid G \<and> primeness_condition_monoid G) = | |
| 3899 | factorial_monoid G" | |
| 3900 | apply rule | |
| 3901 | proof clarify | |
| 3902 | assume dcc: "divisor_chain_condition_monoid G" | |
| 3903 | and pc: "primeness_condition_monoid G" | |
| 29237 | 3904 | interpret divisor_chain_condition_monoid "G" by (rule dcc) | 
| 3905 | interpret primeness_condition_monoid "G" by (rule pc) | |
| 27701 | 3906 | |
| 3907 | show "factorial_monoid G" | |
| 3908 | by (fast intro: factorial_monoidI wfactors_exist wfactors_unique) | |
| 3909 | next | |
| 3910 | assume fm: "factorial_monoid G" | |
| 29237 | 3911 | interpret factorial_monoid "G" by (rule fm) | 
| 27701 | 3912 | show "divisor_chain_condition_monoid G \<and> primeness_condition_monoid G" | 
| 3913 | by rule unfold_locales | |
| 3914 | qed | |
| 3915 | ||
| 3916 | theorem factorial_condition_two: (* Jacobson theorem 2.22 *) | |
| 3917 | shows "(divisor_chain_condition_monoid G \<and> gcd_condition_monoid G) = factorial_monoid G" | |
| 3918 | apply rule | |
| 3919 | proof clarify | |
| 3920 | assume dcc: "divisor_chain_condition_monoid G" | |
| 3921 | and gc: "gcd_condition_monoid G" | |
| 29237 | 3922 | interpret divisor_chain_condition_monoid "G" by (rule dcc) | 
| 3923 | interpret gcd_condition_monoid "G" by (rule gc) | |
| 27701 | 3924 | show "factorial_monoid G" | 
| 3925 | by (simp add: factorial_condition_one[symmetric], rule, unfold_locales) | |
| 3926 | next | |
| 3927 | assume fm: "factorial_monoid G" | |
| 29237 | 3928 | interpret factorial_monoid "G" by (rule fm) | 
| 27701 | 3929 | show "divisor_chain_condition_monoid G \<and> gcd_condition_monoid G" | 
| 3930 | by rule unfold_locales | |
| 3931 | qed | |
| 3932 | ||
| 3933 | end |