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