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