| author | wenzelm | 
| Sun, 20 Jul 2014 17:54:01 +0200 | |
| changeset 57581 | 74bbe9317aa4 | 
| parent 57492 | 74bf65a1910a | 
| child 57865 | dcfb33c26f50 | 
| 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" | |
| 44655 | 28 | by default 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 | 
| 44655 | 35 | by default simp_all | 
| 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)+ | |
| 50037 | 247 | apply (fast intro: carr) | 
| 27701 | 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] | |
| 44890 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 nipkow parents: 
44655diff
changeset | 653 | have "b \<in> Units G" unfolding Units_def by fastforce | 
| 27701 | 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 | 
| 44890 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 nipkow parents: 
44655diff
changeset | 713 | apply (fastforce elim: properfactorE2 intro: weak_llessI) | 
| 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 nipkow parents: 
44655diff
changeset | 714 | apply (fastforce 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 | |
| 44890 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 nipkow parents: 
44655diff
changeset | 754 | by (fastforce elim: properfactorE intro: properfactorI) | 
| 27701 | 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 | |
| 44890 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 nipkow parents: 
44655diff
changeset | 760 | by (fastforce elim: properfactorE intro: properfactorI) | 
| 27701 | 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 | |
| 44890 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 nipkow parents: 
44655diff
changeset | 767 | by (fastforce elim: properfactorE intro: properfactorI) | 
| 27701 | 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 | |
| 44890 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 nipkow parents: 
44655diff
changeset | 773 | by (fastforce elim: properfactorE intro: properfactorI) | 
| 27701 | 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" | |
| 46129 | 1286 | proof - | 
| 1287 | from anunit Units_one_closed have "a \<noteq> \<one>" by auto | |
| 1288 | with fs show ?thesis by (auto elim: factorsE) | |
| 1289 | qed | |
| 27701 | 1290 | |
| 1291 | lemma (in monoid) unit_wfactors [simp]: | |
| 1292 | assumes aunit: "a \<in> Units G" | |
| 1293 | shows "wfactors G [] a" | |
| 1294 | using aunit | |
| 1295 | by (intro wfactorsI) (simp, simp add: Units_assoc) | |
| 1296 | ||
| 1297 | lemma (in comm_monoid_cancel) unit_wfactors_empty: | |
| 1298 | assumes aunit: "a \<in> Units G" | |
| 1299 | and wf: "wfactors G fs a" | |
| 1300 | and carr[simp]: "set fs \<subseteq> carrier G" | |
| 1301 | shows "fs = []" | |
| 1302 | proof (rule ccontr, cases fs, simp) | |
| 1303 | fix f fs' | |
| 1304 | assume fs: "fs = f # fs'" | |
| 1305 | ||
| 1306 | from carr | |
| 1307 | have fcarr[simp]: "f \<in> carrier G" | |
| 1308 | and carr'[simp]: "set fs' \<subseteq> carrier G" | |
| 1309 | by (simp add: fs)+ | |
| 1310 | ||
| 1311 | from fs wf | |
| 1312 | have "irreducible G f" by (simp add: wfactors_def) | |
| 1313 | hence fnunit: "f \<notin> Units G" by (fast elim: irreducibleE) | |
| 1314 | ||
| 1315 | from fs wf | |
| 1316 | have a: "f \<otimes> foldr (op \<otimes>) fs' \<one> \<sim> a" by (simp add: wfactors_def) | |
| 1317 | ||
| 1318 | note aunit | |
| 1319 | also from fs wf | |
| 1320 | have a: "f \<otimes> foldr (op \<otimes>) fs' \<one> \<sim> a" by (simp add: wfactors_def) | |
| 1321 | have "a \<sim> f \<otimes> foldr (op \<otimes>) fs' \<one>" | |
| 1322 | by (simp add: Units_closed[OF aunit] a[symmetric]) | |
| 1323 | finally | |
| 1324 | have "f \<otimes> foldr (op \<otimes>) fs' \<one> \<in> Units G" by simp | |
| 1325 | hence "f \<in> Units G" by (intro unit_factor[of f], simp+) | |
| 1326 | ||
| 1327 | with fnunit show "False" by simp | |
| 1328 | qed | |
| 1329 | ||
| 1330 | ||
| 1331 | text {* Comparing wfactors *}
 | |
| 1332 | ||
| 1333 | lemma (in comm_monoid_cancel) wfactors_listassoc_cong_l: | |
| 1334 | assumes fact: "wfactors G fs a" | |
| 1335 | and asc: "fs [\<sim>] fs'" | |
| 1336 | and carr: "a \<in> carrier G" "set fs \<subseteq> carrier G" "set fs' \<subseteq> carrier G" | |
| 1337 | shows "wfactors G fs' a" | |
| 1338 | using fact | |
| 1339 | apply (elim wfactorsE, intro wfactorsI) | |
| 36278 | 1340 | apply (metis assms(2) assms(4) assms(5) irrlist_listassoc_cong) | 
| 27701 | 1341 | proof - | 
| 1342 | from asc[symmetric] | |
| 1343 | have "foldr op \<otimes> fs' \<one> \<sim> foldr op \<otimes> fs \<one>" | |
| 1344 | by (simp add: multlist_listassoc_cong carr) | |
| 1345 | also assume "foldr op \<otimes> fs \<one> \<sim> a" | |
| 1346 | finally | |
| 1347 | show "foldr op \<otimes> fs' \<one> \<sim> a" by (simp add: carr) | |
| 1348 | qed | |
| 1349 | ||
| 1350 | lemma (in comm_monoid) wfactors_perm_cong_l: | |
| 1351 | assumes "wfactors G fs a" | |
| 1352 | and "fs <~~> fs'" | |
| 1353 | and "set fs \<subseteq> carrier G" | |
| 1354 | shows "wfactors G fs' a" | |
| 1355 | using assms | |
| 1356 | apply (elim wfactorsE, intro wfactorsI) | |
| 1357 | apply (rule irrlist_perm_cong, assumption+) | |
| 1358 | apply (simp add: multlist_perm_cong[symmetric]) | |
| 1359 | done | |
| 1360 | ||
| 1361 | lemma (in comm_monoid_cancel) wfactors_ee_cong_l [trans]: | |
| 1362 | assumes ee: "essentially_equal G as bs" | |
| 1363 | and bfs: "wfactors G bs b" | |
| 1364 | and carr: "b \<in> carrier G" "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" | |
| 1365 | shows "wfactors G as b" | |
| 1366 | using ee | |
| 1367 | proof (elim essentially_equalE) | |
| 1368 | fix fs | |
| 1369 | assume prm: "as <~~> fs" | |
| 1370 | with carr | |
| 1371 | have fscarr: "set fs \<subseteq> carrier G" by (simp add: perm_closed) | |
| 1372 | ||
| 1373 | note bfs | |
| 1374 | also assume [symmetric]: "fs [\<sim>] bs" | |
| 1375 | also (wfactors_listassoc_cong_l) | |
| 1376 | note prm[symmetric] | |
| 1377 | finally (wfactors_perm_cong_l) | |
| 1378 | show "wfactors G as b" by (simp add: carr fscarr) | |
| 1379 | qed | |
| 1380 | ||
| 1381 | lemma (in monoid) wfactors_cong_r [trans]: | |
| 1382 | assumes fac: "wfactors G fs a" and aa': "a \<sim> a'" | |
| 1383 | and carr[simp]: "a \<in> carrier G" "a' \<in> carrier G" "set fs \<subseteq> carrier G" | |
| 1384 | shows "wfactors G fs a'" | |
| 1385 | using fac | |
| 1386 | proof (elim wfactorsE, intro wfactorsI) | |
| 1387 | assume "foldr op \<otimes> fs \<one> \<sim> a" also note aa' | |
| 1388 | finally show "foldr op \<otimes> fs \<one> \<sim> a'" by simp | |
| 1389 | qed | |
| 1390 | ||
| 1391 | ||
| 1392 | subsubsection {* Essentially equal factorizations *}
 | |
| 1393 | ||
| 1394 | lemma (in comm_monoid_cancel) unitfactor_ee: | |
| 1395 | assumes uunit: "u \<in> Units G" | |
| 1396 | and carr: "set as \<subseteq> carrier G" | |
| 1397 | shows "essentially_equal G (as[0 := (as!0 \<otimes> u)]) as" (is "essentially_equal G ?as' as") | |
| 1398 | using assms | |
| 1399 | apply (intro essentially_equalI[of _ ?as'], simp) | |
| 1400 | apply (cases as, simp) | |
| 1401 | apply (clarsimp, fast intro: associatedI2[of u]) | |
| 1402 | done | |
| 1403 | ||
| 1404 | lemma (in comm_monoid_cancel) factors_cong_unit: | |
| 1405 | assumes uunit: "u \<in> Units G" and anunit: "a \<notin> Units G" | |
| 1406 | and afs: "factors G as a" | |
| 1407 | and ascarr: "set as \<subseteq> carrier G" | |
| 1408 | shows "factors G (as[0 := (as!0 \<otimes> u)]) (a \<otimes> u)" (is "factors G ?as' ?a'") | |
| 1409 | using assms | |
| 1410 | apply (elim factorsE, clarify) | |
| 1411 | apply (cases as) | |
| 1412 | apply (simp add: nunit_factors) | |
| 1413 | apply clarsimp | |
| 1414 | apply (elim factorsE, intro factorsI) | |
| 1415 | apply (clarsimp, fast intro: irreducible_prod_rI) | |
| 1416 | apply (simp add: m_ac Units_closed) | |
| 1417 | done | |
| 1418 | ||
| 1419 | lemma (in comm_monoid) perm_wfactorsD: | |
| 1420 | assumes prm: "as <~~> bs" | |
| 1421 | and afs: "wfactors G as a" and bfs: "wfactors G bs b" | |
| 1422 | and [simp]: "a \<in> carrier G" "b \<in> carrier G" | |
| 1423 | and ascarr[simp]: "set as \<subseteq> carrier G" | |
| 1424 | shows "a \<sim> b" | |
| 1425 | using afs bfs | |
| 1426 | proof (elim wfactorsE) | |
| 1427 | from prm have [simp]: "set bs \<subseteq> carrier G" by (simp add: perm_closed) | |
| 1428 | assume "foldr op \<otimes> as \<one> \<sim> a" | |
| 1429 | hence "a \<sim> foldr op \<otimes> as \<one>" by (rule associated_sym, simp+) | |
| 1430 | also from prm | |
| 1431 | have "foldr op \<otimes> as \<one> = foldr op \<otimes> bs \<one>" by (rule multlist_perm_cong, simp) | |
| 1432 | also assume "foldr op \<otimes> bs \<one> \<sim> b" | |
| 1433 | finally | |
| 1434 | show "a \<sim> b" by simp | |
| 1435 | qed | |
| 1436 | ||
| 1437 | lemma (in comm_monoid_cancel) listassoc_wfactorsD: | |
| 1438 | assumes assoc: "as [\<sim>] bs" | |
| 1439 | and afs: "wfactors G as a" and bfs: "wfactors G bs b" | |
| 1440 | and [simp]: "a \<in> carrier G" "b \<in> carrier G" | |
| 1441 | and [simp]: "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" | |
| 1442 | shows "a \<sim> b" | |
| 1443 | using afs bfs | |
| 1444 | proof (elim wfactorsE) | |
| 1445 | assume "foldr op \<otimes> as \<one> \<sim> a" | |
| 1446 | hence "a \<sim> foldr op \<otimes> as \<one>" by (rule associated_sym, simp+) | |
| 1447 | also from assoc | |
| 1448 | have "foldr op \<otimes> as \<one> \<sim> foldr op \<otimes> bs \<one>" by (rule multlist_listassoc_cong, simp+) | |
| 1449 | also assume "foldr op \<otimes> bs \<one> \<sim> b" | |
| 1450 | finally | |
| 1451 | show "a \<sim> b" by simp | |
| 1452 | qed | |
| 1453 | ||
| 1454 | lemma (in comm_monoid_cancel) ee_wfactorsD: | |
| 1455 | assumes ee: "essentially_equal G as bs" | |
| 1456 | and afs: "wfactors G as a" and bfs: "wfactors G bs b" | |
| 1457 | and [simp]: "a \<in> carrier G" "b \<in> carrier G" | |
| 1458 | and ascarr[simp]: "set as \<subseteq> carrier G" and bscarr[simp]: "set bs \<subseteq> carrier G" | |
| 1459 | shows "a \<sim> b" | |
| 1460 | using ee | |
| 1461 | proof (elim essentially_equalE) | |
| 1462 | fix fs | |
| 1463 | assume prm: "as <~~> fs" | |
| 1464 | hence as'carr[simp]: "set fs \<subseteq> carrier G" by (simp add: perm_closed) | |
| 1465 | from afs prm | |
| 1466 | have afs': "wfactors G fs a" by (rule wfactors_perm_cong_l, simp) | |
| 1467 | assume "fs [\<sim>] bs" | |
| 1468 | from this afs' bfs | |
| 1469 | show "a \<sim> b" by (rule listassoc_wfactorsD, simp+) | |
| 1470 | qed | |
| 1471 | ||
| 1472 | lemma (in comm_monoid_cancel) ee_factorsD: | |
| 1473 | assumes ee: "essentially_equal G as bs" | |
| 1474 | and afs: "factors G as a" and bfs:"factors G bs b" | |
| 1475 | and "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" | |
| 1476 | shows "a \<sim> b" | |
| 1477 | using assms | |
| 1478 | by (blast intro: factors_wfactors dest: ee_wfactorsD) | |
| 1479 | ||
| 1480 | lemma (in factorial_monoid) ee_factorsI: | |
| 1481 | assumes ab: "a \<sim> b" | |
| 1482 | and afs: "factors G as a" and anunit: "a \<notin> Units G" | |
| 1483 | and bfs: "factors G bs b" and bnunit: "b \<notin> Units G" | |
| 1484 | and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G" | |
| 1485 | shows "essentially_equal G as bs" | |
| 1486 | proof - | |
| 1487 | note carr[simp] = factors_closed[OF afs ascarr] ascarr[THEN subsetD] | |
| 1488 | factors_closed[OF bfs bscarr] bscarr[THEN subsetD] | |
| 1489 | ||
| 1490 | from ab carr | |
| 1491 | have "\<exists>u\<in>Units G. a = b \<otimes> u" by (fast elim: associatedE2) | |
| 1492 | from this obtain u | |
| 1493 | where uunit: "u \<in> Units G" | |
| 1494 | and a: "a = b \<otimes> u" by auto | |
| 1495 | ||
| 1496 | from uunit bscarr | |
| 1497 | have ee: "essentially_equal G (bs[0 := (bs!0 \<otimes> u)]) bs" | |
| 1498 | (is "essentially_equal G ?bs' bs") | |
| 1499 | by (rule unitfactor_ee) | |
| 1500 | ||
| 1501 | from bscarr uunit | |
| 1502 | have bs'carr: "set ?bs' \<subseteq> carrier G" | |
| 1503 | by (cases bs) (simp add: Units_closed)+ | |
| 1504 | ||
| 1505 | from uunit bnunit bfs bscarr | |
| 1506 | have fac: "factors G ?bs' (b \<otimes> u)" | |
| 1507 | by (rule factors_cong_unit) | |
| 1508 | ||
| 1509 | from afs fac[simplified a[symmetric]] ascarr bs'carr anunit | |
| 1510 | have "essentially_equal G as ?bs'" | |
| 1511 | by (blast intro: factors_unique) | |
| 1512 | also note ee | |
| 1513 | finally | |
| 1514 | show "essentially_equal G as bs" by (simp add: ascarr bscarr bs'carr) | |
| 1515 | qed | |
| 1516 | ||
| 1517 | lemma (in factorial_monoid) ee_wfactorsI: | |
| 1518 | assumes asc: "a \<sim> b" | |
| 1519 | and asf: "wfactors G as a" and bsf: "wfactors G bs b" | |
| 1520 | and acarr[simp]: "a \<in> carrier G" and bcarr[simp]: "b \<in> carrier G" | |
| 1521 | and ascarr[simp]: "set as \<subseteq> carrier G" and bscarr[simp]: "set bs \<subseteq> carrier G" | |
| 1522 | shows "essentially_equal G as bs" | |
| 1523 | using assms | |
| 1524 | proof (cases "a \<in> Units G") | |
| 1525 | assume aunit: "a \<in> Units G" | |
| 1526 | also note asc | |
| 1527 | finally have bunit: "b \<in> Units G" by simp | |
| 1528 | ||
| 1529 | from aunit asf ascarr | |
| 1530 | have e: "as = []" by (rule unit_wfactors_empty) | |
| 1531 | from bunit bsf bscarr | |
| 1532 | have e': "bs = []" by (rule unit_wfactors_empty) | |
| 1533 | ||
| 1534 | have "essentially_equal G [] []" | |
| 1535 | by (fast intro: essentially_equalI) | |
| 1536 | thus ?thesis by (simp add: e e') | |
| 1537 | next | |
| 1538 | assume anunit: "a \<notin> Units G" | |
| 1539 | have bnunit: "b \<notin> Units G" | |
| 1540 | proof clarify | |
| 1541 | assume "b \<in> Units G" | |
| 1542 | also note asc[symmetric] | |
| 1543 | finally have "a \<in> Units G" by simp | |
| 1544 | with anunit | |
| 1545 | show "False" .. | |
| 1546 | qed | |
| 1547 | ||
| 1548 | have "\<exists>a'. factors G as a' \<and> a' \<sim> a" by (rule wfactors_factors[OF asf ascarr]) | |
| 1549 | from this obtain a' | |
| 1550 | where fa': "factors G as a'" | |
| 1551 | and a': "a' \<sim> a" | |
| 1552 | by auto | |
| 1553 | from fa' ascarr | |
| 1554 | have a'carr[simp]: "a' \<in> carrier G" by fast | |
| 1555 | ||
| 1556 | have a'nunit: "a' \<notin> Units G" | |
| 1557 | proof (clarify) | |
| 1558 | assume "a' \<in> Units G" | |
| 1559 | also note a' | |
| 1560 | finally have "a \<in> Units G" by simp | |
| 1561 | with anunit | |
| 1562 | show "False" .. | |
| 1563 | qed | |
| 1564 | ||
| 1565 | have "\<exists>b'. factors G bs b' \<and> b' \<sim> b" by (rule wfactors_factors[OF bsf bscarr]) | |
| 1566 | from this obtain b' | |
| 1567 | where fb': "factors G bs b'" | |
| 1568 | and b': "b' \<sim> b" | |
| 1569 | by auto | |
| 1570 | from fb' bscarr | |
| 1571 | have b'carr[simp]: "b' \<in> carrier G" by fast | |
| 1572 | ||
| 1573 | have b'nunit: "b' \<notin> Units G" | |
| 1574 | proof (clarify) | |
| 1575 | assume "b' \<in> Units G" | |
| 1576 | also note b' | |
| 1577 | finally have "b \<in> Units G" by simp | |
| 1578 | with bnunit | |
| 1579 | show "False" .. | |
| 1580 | qed | |
| 1581 | ||
| 1582 | note a' | |
| 1583 | also note asc | |
| 1584 | also note b'[symmetric] | |
| 1585 | finally | |
| 1586 | have "a' \<sim> b'" by simp | |
| 1587 | ||
| 1588 | from this fa' a'nunit fb' b'nunit ascarr bscarr | |
| 1589 | show "essentially_equal G as bs" | |
| 1590 | by (rule ee_factorsI) | |
| 1591 | qed | |
| 1592 | ||
| 1593 | lemma (in factorial_monoid) ee_wfactors: | |
| 1594 | assumes asf: "wfactors G as a" | |
| 1595 | and bsf: "wfactors G bs b" | |
| 1596 | and acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" | |
| 1597 | and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G" | |
| 1598 | shows asc: "a \<sim> b = essentially_equal G as bs" | |
| 1599 | using assms | |
| 1600 | by (fast intro: ee_wfactorsI ee_wfactorsD) | |
| 1601 | ||
| 1602 | lemma (in factorial_monoid) wfactors_exist [intro, simp]: | |
| 1603 | assumes acarr[simp]: "a \<in> carrier G" | |
| 1604 | shows "\<exists>fs. set fs \<subseteq> carrier G \<and> wfactors G fs a" | |
| 1605 | proof (cases "a \<in> Units G") | |
| 1606 | assume "a \<in> Units G" | |
| 1607 | hence "wfactors G [] a" by (rule unit_wfactors) | |
| 1608 | thus ?thesis by (intro exI) force | |
| 1609 | next | |
| 1610 | assume "a \<notin> Units G" | |
| 1611 | hence "\<exists>fs. set fs \<subseteq> carrier G \<and> factors G fs a" by (intro factors_exist acarr) | |
| 1612 | from this obtain fs | |
| 1613 | where fscarr: "set fs \<subseteq> carrier G" | |
| 1614 | and f: "factors G fs a" | |
| 1615 | by auto | |
| 1616 | from f have "wfactors G fs a" by (rule factors_wfactors) fact | |
| 1617 | from fscarr this | |
| 1618 | show ?thesis by fast | |
| 1619 | qed | |
| 1620 | ||
| 1621 | lemma (in monoid) wfactors_prod_exists [intro, simp]: | |
| 1622 | assumes "\<forall>a \<in> set as. irreducible G a" and "set as \<subseteq> carrier G" | |
| 1623 | shows "\<exists>a. a \<in> carrier G \<and> wfactors G as a" | |
| 1624 | unfolding wfactors_def | |
| 1625 | using assms | |
| 1626 | by blast | |
| 1627 | ||
| 1628 | lemma (in factorial_monoid) wfactors_unique: | |
| 1629 | assumes "wfactors G fs a" and "wfactors G fs' a" | |
| 1630 | and "a \<in> carrier G" | |
| 1631 | and "set fs \<subseteq> carrier G" and "set fs' \<subseteq> carrier G" | |
| 1632 | shows "essentially_equal G fs fs'" | |
| 1633 | using assms | |
| 1634 | by (fast intro: ee_wfactorsI[of a a]) | |
| 1635 | ||
| 1636 | lemma (in monoid) factors_mult_single: | |
| 1637 | assumes "irreducible G a" and "factors G fb b" and "a \<in> carrier G" | |
| 1638 | shows "factors G (a # fb) (a \<otimes> b)" | |
| 1639 | using assms | |
| 1640 | unfolding factors_def | |
| 1641 | by simp | |
| 1642 | ||
| 1643 | lemma (in monoid_cancel) wfactors_mult_single: | |
| 1644 | assumes f: "irreducible G a" "wfactors G fb b" | |
| 1645 | "a \<in> carrier G" "b \<in> carrier G" "set fb \<subseteq> carrier G" | |
| 1646 | shows "wfactors G (a # fb) (a \<otimes> b)" | |
| 1647 | using assms | |
| 1648 | unfolding wfactors_def | |
| 1649 | by (simp add: mult_cong_r) | |
| 1650 | ||
| 1651 | lemma (in monoid) factors_mult: | |
| 1652 | assumes factors: "factors G fa a" "factors G fb b" | |
| 1653 | and ascarr: "set fa \<subseteq> carrier G" and bscarr:"set fb \<subseteq> carrier G" | |
| 1654 | shows "factors G (fa @ fb) (a \<otimes> b)" | |
| 1655 | using assms | |
| 1656 | unfolding factors_def | |
| 1657 | apply (safe, force) | |
| 57492 
74bf65a1910a
Hypsubst preserves equality hypotheses
 Thomas Sewell <thomas.sewell@nicta.com.au> parents: 
55242diff
changeset | 1658 | apply hypsubst_thin | 
| 27701 | 1659 | apply (induct fa) | 
| 1660 | apply simp | |
| 1661 | apply (simp add: m_assoc) | |
| 1662 | done | |
| 1663 | ||
| 1664 | lemma (in comm_monoid_cancel) wfactors_mult [intro]: | |
| 1665 | assumes asf: "wfactors G as a" and bsf:"wfactors G bs b" | |
| 1666 | and acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" | |
| 1667 | and ascarr: "set as \<subseteq> carrier G" and bscarr:"set bs \<subseteq> carrier G" | |
| 1668 | shows "wfactors G (as @ bs) (a \<otimes> b)" | |
| 1669 | apply (insert wfactors_factors[OF asf ascarr]) | |
| 1670 | apply (insert wfactors_factors[OF bsf bscarr]) | |
| 1671 | proof (clarsimp) | |
| 1672 | fix a' b' | |
| 1673 | assume asf': "factors G as a'" and a'a: "a' \<sim> a" | |
| 1674 | and bsf': "factors G bs b'" and b'b: "b' \<sim> b" | |
| 1675 | from asf' have a'carr: "a' \<in> carrier G" by (rule factors_closed) fact | |
| 1676 | from bsf' have b'carr: "b' \<in> carrier G" by (rule factors_closed) fact | |
| 1677 | ||
| 1678 | note carr = acarr bcarr a'carr b'carr ascarr bscarr | |
| 1679 | ||
| 1680 | from asf' bsf' | |
| 1681 | have "factors G (as @ bs) (a' \<otimes> b')" by (rule factors_mult) fact+ | |
| 1682 | ||
| 1683 | with carr | |
| 1684 | have abf': "wfactors G (as @ bs) (a' \<otimes> b')" by (intro factors_wfactors) simp+ | |
| 1685 | also from b'b carr | |
| 1686 | have trb: "a' \<otimes> b' \<sim> a' \<otimes> b" by (intro mult_cong_r) | |
| 1687 | also from a'a carr | |
| 1688 | have tra: "a' \<otimes> b \<sim> a \<otimes> b" by (intro mult_cong_l) | |
| 1689 | finally | |
| 1690 | show "wfactors G (as @ bs) (a \<otimes> b)" | |
| 1691 | by (simp add: carr) | |
| 1692 | qed | |
| 1693 | ||
| 1694 | lemma (in comm_monoid) factors_dividesI: | |
| 1695 | assumes "factors G fs a" and "f \<in> set fs" | |
| 1696 | and "set fs \<subseteq> carrier G" | |
| 1697 | shows "f divides a" | |
| 1698 | using assms | |
| 1699 | by (fast elim: factorsE intro: multlist_dividesI) | |
| 1700 | ||
| 1701 | lemma (in comm_monoid) wfactors_dividesI: | |
| 1702 | assumes p: "wfactors G fs a" | |
| 1703 | and fscarr: "set fs \<subseteq> carrier G" and acarr: "a \<in> carrier G" | |
| 1704 | and f: "f \<in> set fs" | |
| 1705 | shows "f divides a" | |
| 1706 | apply (insert wfactors_factors[OF p fscarr], clarsimp) | |
| 1707 | proof - | |
| 1708 | fix a' | |
| 1709 | assume fsa': "factors G fs a'" | |
| 1710 | and a'a: "a' \<sim> a" | |
| 1711 | with fscarr | |
| 1712 | have a'carr: "a' \<in> carrier G" by (simp add: factors_closed) | |
| 1713 | ||
| 1714 | from fsa' fscarr f | |
| 1715 | have "f divides a'" by (fast intro: factors_dividesI) | |
| 1716 | also note a'a | |
| 1717 | finally | |
| 1718 | show "f divides a" by (simp add: f fscarr[THEN subsetD] acarr a'carr) | |
| 1719 | qed | |
| 1720 | ||
| 1721 | ||
| 1722 | subsubsection {* Factorial monoids and wfactors *}
 | |
| 1723 | ||
| 1724 | lemma (in comm_monoid_cancel) factorial_monoidI: | |
| 1725 | assumes wfactors_exists: | |
| 1726 | "\<And>a. a \<in> carrier G \<Longrightarrow> \<exists>fs. set fs \<subseteq> carrier G \<and> wfactors G fs a" | |
| 1727 | and wfactors_unique: | |
| 1728 | "\<And>a fs fs'. \<lbrakk>a \<in> carrier G; set fs \<subseteq> carrier G; set fs' \<subseteq> carrier G; | |
| 1729 | wfactors G fs a; wfactors G fs' a\<rbrakk> \<Longrightarrow> essentially_equal G fs fs'" | |
| 1730 | shows "factorial_monoid G" | |
| 28823 | 1731 | proof | 
| 27701 | 1732 | fix a | 
| 1733 | assume acarr: "a \<in> carrier G" and anunit: "a \<notin> Units G" | |
| 1734 | ||
| 1735 | from wfactors_exists[OF acarr] | |
| 1736 | obtain as | |
| 1737 | where ascarr: "set as \<subseteq> carrier G" | |
| 1738 | and afs: "wfactors G as a" | |
| 1739 | by auto | |
| 1740 | from afs ascarr | |
| 1741 | have "\<exists>a'. factors G as a' \<and> a' \<sim> a" by (rule wfactors_factors) | |
| 1742 | from this obtain a' | |
| 1743 | where afs': "factors G as a'" | |
| 1744 | and a'a: "a' \<sim> a" | |
| 1745 | by auto | |
| 1746 | from afs' ascarr | |
| 1747 | have a'carr: "a' \<in> carrier G" by fast | |
| 1748 | have a'nunit: "a' \<notin> Units G" | |
| 1749 | proof clarify | |
| 1750 | assume "a' \<in> Units G" | |
| 1751 | also note a'a | |
| 1752 | finally have "a \<in> Units G" by (simp add: acarr) | |
| 1753 | with anunit | |
| 1754 | show "False" .. | |
| 1755 | qed | |
| 1756 | ||
| 1757 | from a'carr acarr a'a | |
| 1758 | have "\<exists>u. u \<in> Units G \<and> a' = a \<otimes> u" by (blast elim: associatedE2) | |
| 1759 | from this obtain u | |
| 1760 | where uunit: "u \<in> Units G" | |
| 1761 | and a': "a' = a \<otimes> u" | |
| 1762 | by auto | |
| 1763 | ||
| 1764 | note [simp] = acarr Units_closed[OF uunit] Units_inv_closed[OF uunit] | |
| 1765 | ||
| 1766 | have "a = a \<otimes> \<one>" by simp | |
| 1767 | also have "\<dots> = a \<otimes> (u \<otimes> inv u)" by (simp add: Units_r_inv uunit) | |
| 1768 | also have "\<dots> = a' \<otimes> inv u" by (simp add: m_assoc[symmetric] a'[symmetric]) | |
| 1769 | finally | |
| 1770 | have a: "a = a' \<otimes> inv u" . | |
| 1771 | ||
| 1772 | from ascarr uunit | |
| 1773 | have cr: "set (as[0:=(as!0 \<otimes> inv u)]) \<subseteq> carrier G" | |
| 1774 | by (cases as, clarsimp+) | |
| 1775 | ||
| 1776 | from afs' uunit a'nunit acarr ascarr | |
| 1777 | have "factors G (as[0:=(as!0 \<otimes> inv u)]) a" | |
| 1778 | by (simp add: a factors_cong_unit) | |
| 1779 | ||
| 1780 | with cr | |
| 1781 | show "\<exists>fs. set fs \<subseteq> carrier G \<and> factors G fs a" by fast | |
| 1782 | qed (blast intro: factors_wfactors wfactors_unique) | |
| 1783 | ||
| 1784 | ||
| 27717 
21bbd410ba04
Generalised polynomial lemmas from cring to ring.
 ballarin parents: 
27713diff
changeset | 1785 | subsection {* Factorizations as Multisets *}
 | 
| 27701 | 1786 | |
| 1787 | text {* Gives useful operations like intersection *}
 | |
| 1788 | ||
| 1789 | (* FIXME: use class_of x instead of closure_of {x} *)
 | |
| 1790 | ||
| 1791 | abbreviation | |
| 1792 |   "assocs G x == eq_closure_of (division_rel G) {x}"
 | |
| 1793 | ||
| 35847 | 1794 | definition | 
| 35848 
5443079512ea
slightly more uniform definitions -- eliminated old-style meta-equality;
 wenzelm parents: 
35847diff
changeset | 1795 | "fmset G as = multiset_of (map (\<lambda>a. assocs G a) as)" | 
| 27701 | 1796 | |
| 1797 | ||
| 1798 | text {* Helper lemmas *}
 | |
| 1799 | ||
| 1800 | lemma (in monoid) assocs_repr_independence: | |
| 1801 | assumes "y \<in> assocs G x" | |
| 1802 | and "x \<in> carrier G" | |
| 1803 | shows "assocs G x = assocs G y" | |
| 1804 | using assms | |
| 1805 | apply safe | |
| 1806 | apply (elim closure_ofE2, intro closure_ofI2[of _ _ y]) | |
| 1807 | apply (clarsimp, iprover intro: associated_trans associated_sym, simp+) | |
| 1808 | apply (elim closure_ofE2, intro closure_ofI2[of _ _ x]) | |
| 1809 | apply (clarsimp, iprover intro: associated_trans, simp+) | |
| 1810 | done | |
| 1811 | ||
| 1812 | lemma (in monoid) assocs_self: | |
| 1813 | assumes "x \<in> carrier G" | |
| 1814 | shows "x \<in> assocs G x" | |
| 1815 | using assms | |
| 44890 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 nipkow parents: 
44655diff
changeset | 1816 | by (fastforce intro: closure_ofI2) | 
| 27701 | 1817 | |
| 1818 | lemma (in monoid) assocs_repr_independenceD: | |
| 1819 | assumes repr: "assocs G x = assocs G y" | |
| 1820 | and ycarr: "y \<in> carrier G" | |
| 1821 | shows "y \<in> assocs G x" | |
| 1822 | unfolding repr | |
| 1823 | using ycarr | |
| 1824 | by (intro assocs_self) | |
| 1825 | ||
| 1826 | lemma (in comm_monoid) assocs_assoc: | |
| 1827 | assumes "a \<in> assocs G b" | |
| 1828 | and "b \<in> carrier G" | |
| 1829 | shows "a \<sim> b" | |
| 1830 | using assms | |
| 1831 | by (elim closure_ofE2, simp) | |
| 1832 | ||
| 1833 | lemmas (in comm_monoid) assocs_eqD = | |
| 1834 | assocs_repr_independenceD[THEN assocs_assoc] | |
| 1835 | ||
| 1836 | ||
| 1837 | subsubsection {* Comparing multisets *}
 | |
| 1838 | ||
| 1839 | lemma (in monoid) fmset_perm_cong: | |
| 1840 | assumes prm: "as <~~> bs" | |
| 1841 | shows "fmset G as = fmset G bs" | |
| 1842 | using perm_map[OF prm] | |
| 1843 | by (simp add: multiset_of_eq_perm fmset_def) | |
| 1844 | ||
| 1845 | lemma (in comm_monoid_cancel) eqc_listassoc_cong: | |
| 1846 | assumes "as [\<sim>] bs" | |
| 1847 | and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G" | |
| 1848 | shows "map (assocs G) as = map (assocs G) bs" | |
| 1849 | using assms | |
| 1850 | apply (induct as arbitrary: bs, simp) | |
| 1851 | apply (clarsimp simp add: Cons_eq_map_conv list_all2_Cons1, safe) | |
| 1852 | apply (clarsimp elim!: closure_ofE2) defer 1 | |
| 1853 | apply (clarsimp elim!: closure_ofE2) defer 1 | |
| 1854 | proof - | |
| 1855 | fix a x z | |
| 1856 | assume carr[simp]: "a \<in> carrier G" "x \<in> carrier G" "z \<in> carrier G" | |
| 1857 | assume "x \<sim> a" | |
| 1858 | also assume "a \<sim> z" | |
| 1859 | finally have "x \<sim> z" by simp | |
| 1860 | with carr | |
| 1861 | show "x \<in> assocs G z" | |
| 1862 | by (intro closure_ofI2) simp+ | |
| 1863 | next | |
| 1864 | fix a x z | |
| 1865 | assume carr[simp]: "a \<in> carrier G" "x \<in> carrier G" "z \<in> carrier G" | |
| 1866 | assume "x \<sim> z" | |
| 1867 | also assume [symmetric]: "a \<sim> z" | |
| 1868 | finally have "x \<sim> a" by simp | |
| 1869 | with carr | |
| 1870 | show "x \<in> assocs G a" | |
| 1871 | by (intro closure_ofI2) simp+ | |
| 1872 | qed | |
| 1873 | ||
| 1874 | lemma (in comm_monoid_cancel) fmset_listassoc_cong: | |
| 1875 | assumes "as [\<sim>] bs" | |
| 1876 | and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G" | |
| 1877 | shows "fmset G as = fmset G bs" | |
| 1878 | using assms | |
| 1879 | unfolding fmset_def | |
| 1880 | by (simp add: eqc_listassoc_cong) | |
| 1881 | ||
| 1882 | lemma (in comm_monoid_cancel) ee_fmset: | |
| 1883 | assumes ee: "essentially_equal G as bs" | |
| 1884 | and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G" | |
| 1885 | shows "fmset G as = fmset G bs" | |
| 1886 | using ee | |
| 1887 | proof (elim essentially_equalE) | |
| 1888 | fix as' | |
| 1889 | assume prm: "as <~~> as'" | |
| 1890 | from prm ascarr | |
| 1891 | have as'carr: "set as' \<subseteq> carrier G" by (rule perm_closed) | |
| 1892 | ||
| 1893 | from prm | |
| 1894 | have "fmset G as = fmset G as'" by (rule fmset_perm_cong) | |
| 1895 | also assume "as' [\<sim>] bs" | |
| 1896 | with as'carr bscarr | |
| 1897 | have "fmset G as' = fmset G bs" by (simp add: fmset_listassoc_cong) | |
| 1898 | finally | |
| 1899 | show "fmset G as = fmset G bs" . | |
| 1900 | qed | |
| 1901 | ||
| 1902 | lemma (in monoid_cancel) fmset_ee__hlp_induct: | |
| 1903 | assumes prm: "cas <~~> cbs" | |
| 1904 | and cdef: "cas = map (assocs G) as" "cbs = map (assocs G) bs" | |
| 1905 | shows "\<forall>as bs. (cas <~~> cbs \<and> cas = map (assocs G) as \<and> | |
| 1906 | cbs = map (assocs G) bs) \<longrightarrow> (\<exists>as'. as <~~> as' \<and> map (assocs G) as' = cbs)" | |
| 1907 | apply (rule perm.induct[of cas cbs], rule prm) | |
| 1908 | apply safe apply simp_all | |
| 1909 | apply (simp add: map_eq_Cons_conv, blast) | |
| 1910 | apply force | |
| 1911 | proof - | |
| 1912 | fix ys as bs | |
| 1913 | assume p1: "map (assocs G) as <~~> ys" | |
| 1914 | and r1[rule_format]: | |
| 1915 | "\<forall>asa bs. map (assocs G) as = map (assocs G) asa \<and> | |
| 1916 | ys = map (assocs G) bs | |
| 1917 | \<longrightarrow> (\<exists>as'. asa <~~> as' \<and> map (assocs G) as' = map (assocs G) bs)" | |
| 1918 | and p2: "ys <~~> map (assocs G) bs" | |
| 1919 | and r2[rule_format]: | |
| 1920 | "\<forall>as bsa. ys = map (assocs G) as \<and> | |
| 1921 | map (assocs G) bs = map (assocs G) bsa | |
| 1922 | \<longrightarrow> (\<exists>as'. as <~~> as' \<and> map (assocs G) as' = map (assocs G) bsa)" | |
| 1923 | and p3: "map (assocs G) as <~~> map (assocs G) bs" | |
| 1924 | ||
| 1925 | from p1 | |
| 1926 | have "multiset_of (map (assocs G) as) = multiset_of ys" | |
| 1927 | by (simp add: multiset_of_eq_perm) | |
| 1928 | hence setys: "set (map (assocs G) as) = set ys" by (rule multiset_of_eq_setD) | |
| 1929 | ||
| 1930 |   have "set (map (assocs G) as) = { assocs G x | x. x \<in> set as}" by clarsimp fast
 | |
| 1931 |   with setys have "set ys \<subseteq> { assocs G x | x. x \<in> set as}" by simp
 | |
| 1932 | hence "\<exists>yy. ys = map (assocs G) yy" | |
| 1933 | apply (induct ys, simp, clarsimp) | |
| 1934 | proof - | |
| 1935 | fix yy x | |
| 1936 | show "\<exists>yya. (assocs G x) # map (assocs G) yy = | |
| 1937 | map (assocs G) yya" | |
| 1938 | by (rule exI[of _ "x#yy"], simp) | |
| 1939 | qed | |
| 1940 | from this obtain yy | |
| 1941 | where ys: "ys = map (assocs G) yy" | |
| 1942 | by auto | |
| 1943 | ||
| 1944 | from p1 ys | |
| 1945 | have "\<exists>as'. as <~~> as' \<and> map (assocs G) as' = map (assocs G) yy" | |
| 1946 | by (intro r1, simp) | |
| 1947 | from this obtain as' | |
| 1948 | where asas': "as <~~> as'" | |
| 1949 | and as'yy: "map (assocs G) as' = map (assocs G) yy" | |
| 1950 | by auto | |
| 1951 | ||
| 1952 | from p2 ys | |
| 1953 | have "\<exists>as'. yy <~~> as' \<and> map (assocs G) as' = map (assocs G) bs" | |
| 1954 | by (intro r2, simp) | |
| 1955 | from this obtain as'' | |
| 1956 | where yyas'': "yy <~~> as''" | |
| 1957 | and as''bs: "map (assocs G) as'' = map (assocs G) bs" | |
| 1958 | by auto | |
| 1959 | ||
| 1960 | from as'yy and yyas'' | |
| 1961 | have "\<exists>cs. as' <~~> cs \<and> map (assocs G) cs = map (assocs G) as''" | |
| 1962 | by (rule perm_map_switch) | |
| 1963 | from this obtain cs | |
| 1964 | where as'cs: "as' <~~> cs" | |
| 1965 | and csas'': "map (assocs G) cs = map (assocs G) as''" | |
| 1966 | by auto | |
| 1967 | ||
| 1968 | from asas' and as'cs | |
| 1969 | have ascs: "as <~~> cs" by fast | |
| 1970 | from csas'' and as''bs | |
| 1971 | have "map (assocs G) cs = map (assocs G) bs" by simp | |
| 1972 | from ascs and this | |
| 1973 | show "\<exists>as'. as <~~> as' \<and> map (assocs G) as' = map (assocs G) bs" by fast | |
| 1974 | qed | |
| 1975 | ||
| 1976 | lemma (in comm_monoid_cancel) fmset_ee: | |
| 1977 | assumes mset: "fmset G as = fmset G bs" | |
| 1978 | and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G" | |
| 1979 | shows "essentially_equal G as bs" | |
| 1980 | proof - | |
| 1981 | from mset | |
| 1982 | have mpp: "map (assocs G) as <~~> map (assocs G) bs" | |
| 1983 | by (simp add: fmset_def multiset_of_eq_perm) | |
| 1984 | ||
| 1985 | have "\<exists>cas. cas = map (assocs G) as" by simp | |
| 1986 | from this obtain cas where cas: "cas = map (assocs G) as" by simp | |
| 1987 | ||
| 1988 | have "\<exists>cbs. cbs = map (assocs G) bs" by simp | |
| 1989 | from this obtain cbs where cbs: "cbs = map (assocs G) bs" by simp | |
| 1990 | ||
| 1991 | from cas cbs mpp | |
| 1992 | have [rule_format]: | |
| 1993 | "\<forall>as bs. (cas <~~> cbs \<and> cas = map (assocs G) as \<and> | |
| 1994 | cbs = map (assocs G) bs) | |
| 1995 | \<longrightarrow> (\<exists>as'. as <~~> as' \<and> map (assocs G) as' = cbs)" | |
| 1996 | by (intro fmset_ee__hlp_induct, simp+) | |
| 1997 | with mpp cas cbs | |
| 1998 | have "\<exists>as'. as <~~> as' \<and> map (assocs G) as' = map (assocs G) bs" | |
| 1999 | by simp | |
| 2000 | ||
| 2001 | from this obtain as' | |
| 2002 | where tp: "as <~~> as'" | |
| 2003 | and tm: "map (assocs G) as' = map (assocs G) bs" | |
| 2004 | by auto | |
| 2005 | from tm have lene: "length as' = length bs" by (rule map_eq_imp_length_eq) | |
| 2006 | from tp have "set as = set as'" by (simp add: multiset_of_eq_perm multiset_of_eq_setD) | |
| 2007 | with ascarr | |
| 2008 | have as'carr: "set as' \<subseteq> carrier G" by simp | |
| 2009 | ||
| 2010 | from tm as'carr[THEN subsetD] bscarr[THEN subsetD] | |
| 2011 | have "as' [\<sim>] bs" | |
| 44890 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 nipkow parents: 
44655diff
changeset | 2012 | by (induct as' arbitrary: bs) (simp, fastforce dest: assocs_eqD[THEN associated_sym]) | 
| 27701 | 2013 | |
| 2014 | from tp and this | |
| 2015 | show "essentially_equal G as bs" by (fast intro: essentially_equalI) | |
| 2016 | qed | |
| 2017 | ||
| 2018 | lemma (in comm_monoid_cancel) ee_is_fmset: | |
| 2019 | assumes "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G" | |
| 2020 | shows "essentially_equal G as bs = (fmset G as = fmset G bs)" | |
| 2021 | using assms | |
| 2022 | by (fast intro: ee_fmset fmset_ee) | |
| 2023 | ||
| 2024 | ||
| 2025 | subsubsection {* Interpreting multisets as factorizations *}
 | |
| 2026 | ||
| 2027 | lemma (in monoid) mset_fmsetEx: | |
| 2028 | assumes elems: "\<And>X. X \<in> set_of Cs \<Longrightarrow> \<exists>x. P x \<and> X = assocs G x" | |
| 2029 | shows "\<exists>cs. (\<forall>c \<in> set cs. P c) \<and> fmset G cs = Cs" | |
| 2030 | proof - | |
| 2031 | have "\<exists>Cs'. Cs = multiset_of Cs'" | |
| 2032 | by (rule surjE[OF surj_multiset_of], fast) | |
| 2033 | from this obtain Cs' | |
| 2034 | where Cs: "Cs = multiset_of Cs'" | |
| 2035 | by auto | |
| 2036 | ||
| 2037 | have "\<exists>cs. (\<forall>c \<in> set cs. P c) \<and> multiset_of (map (assocs G) cs) = Cs" | |
| 2038 | using elems | |
| 2039 | unfolding Cs | |
| 2040 | apply (induct Cs', simp) | |
| 2041 | apply clarsimp | |
| 2042 | apply (subgoal_tac "\<exists>cs. (\<forall>x\<in>set cs. P x) \<and> | |
| 2043 | multiset_of (map (assocs G) cs) = multiset_of Cs'") | |
| 2044 | proof clarsimp | |
| 2045 | fix a Cs' cs | |
| 2046 | assume ih: "\<And>X. X = a \<or> X \<in> set Cs' \<Longrightarrow> \<exists>x. P x \<and> X = assocs G x" | |
| 2047 | and csP: "\<forall>x\<in>set cs. P x" | |
| 2048 | and mset: "multiset_of (map (assocs G) cs) = multiset_of Cs'" | |
| 2049 | from ih | |
| 2050 | have "\<exists>x. P x \<and> a = assocs G x" by fast | |
| 2051 | from this obtain c | |
| 2052 | where cP: "P c" | |
| 2053 | and a: "a = assocs G c" | |
| 2054 | by auto | |
| 2055 | from cP csP | |
| 2056 | have tP: "\<forall>x\<in>set (c#cs). P x" by simp | |
| 2057 | from mset a | |
| 2058 |     have "multiset_of (map (assocs G) (c#cs)) = multiset_of Cs' + {#a#}" by simp
 | |
| 2059 | from tP this | |
| 2060 | show "\<exists>cs. (\<forall>x\<in>set cs. P x) \<and> | |
| 2061 | multiset_of (map (assocs G) cs) = | |
| 2062 |                multiset_of Cs' + {#a#}" by fast
 | |
| 2063 | qed simp | |
| 2064 | thus ?thesis by (simp add: fmset_def) | |
| 2065 | qed | |
| 2066 | ||
| 2067 | lemma (in monoid) mset_wfactorsEx: | |
| 2068 | assumes elems: "\<And>X. X \<in> set_of Cs | |
| 2069 | \<Longrightarrow> \<exists>x. (x \<in> carrier G \<and> irreducible G x) \<and> X = assocs G x" | |
| 2070 | shows "\<exists>c cs. c \<in> carrier G \<and> set cs \<subseteq> carrier G \<and> wfactors G cs c \<and> fmset G cs = Cs" | |
| 2071 | proof - | |
| 2072 | have "\<exists>cs. (\<forall>c\<in>set cs. c \<in> carrier G \<and> irreducible G c) \<and> fmset G cs = Cs" | |
| 2073 | by (intro mset_fmsetEx, rule elems) | |
| 2074 | from this obtain cs | |
| 2075 | where p[rule_format]: "\<forall>c\<in>set cs. c \<in> carrier G \<and> irreducible G c" | |
| 2076 | and Cs[symmetric]: "fmset G cs = Cs" | |
| 2077 | by auto | |
| 2078 | ||
| 2079 | from p | |
| 2080 | have cscarr: "set cs \<subseteq> carrier G" by fast | |
| 2081 | ||
| 2082 | from p | |
| 2083 | have "\<exists>c. c \<in> carrier G \<and> wfactors G cs c" | |
| 2084 | by (intro wfactors_prod_exists) fast+ | |
| 2085 | from this obtain c | |
| 2086 | where ccarr: "c \<in> carrier G" | |
| 2087 | and cfs: "wfactors G cs c" | |
| 2088 | by auto | |
| 2089 | ||
| 2090 | with cscarr Cs | |
| 2091 | show ?thesis by fast | |
| 2092 | qed | |
| 2093 | ||
| 2094 | ||
| 2095 | subsubsection {* Multiplication on multisets *}
 | |
| 2096 | ||
| 2097 | lemma (in factorial_monoid) mult_wfactors_fmset: | |
| 2098 | assumes afs: "wfactors G as a" and bfs: "wfactors G bs b" and cfs: "wfactors G cs (a \<otimes> b)" | |
| 2099 | and carr: "a \<in> carrier G" "b \<in> carrier G" | |
| 2100 | "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" "set cs \<subseteq> carrier G" | |
| 2101 | shows "fmset G cs = fmset G as + fmset G bs" | |
| 2102 | proof - | |
| 2103 | from assms | |
| 2104 | have "wfactors G (as @ bs) (a \<otimes> b)" by (intro wfactors_mult) | |
| 2105 | with carr cfs | |
| 2106 | have "essentially_equal G cs (as@bs)" by (intro ee_wfactorsI[of "a\<otimes>b" "a\<otimes>b"], simp+) | |
| 2107 | with carr | |
| 2108 | have "fmset G cs = fmset G (as@bs)" by (intro ee_fmset, simp+) | |
| 2109 | also have "fmset G (as@bs) = fmset G as + fmset G bs" by (simp add: fmset_def) | |
| 2110 | finally show "fmset G cs = fmset G as + fmset G bs" . | |
| 2111 | qed | |
| 2112 | ||
| 2113 | lemma (in factorial_monoid) mult_factors_fmset: | |
| 2114 | assumes afs: "factors G as a" and bfs: "factors G bs b" and cfs: "factors G cs (a \<otimes> b)" | |
| 2115 | and "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" "set cs \<subseteq> carrier G" | |
| 2116 | shows "fmset G cs = fmset G as + fmset G bs" | |
| 2117 | using assms | |
| 2118 | by (blast intro: factors_wfactors mult_wfactors_fmset) | |
| 2119 | ||
| 2120 | lemma (in comm_monoid_cancel) fmset_wfactors_mult: | |
| 2121 | assumes mset: "fmset G cs = fmset G as + fmset G bs" | |
| 2122 | and carr: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | |
| 2123 | "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" "set cs \<subseteq> carrier G" | |
| 2124 | and fs: "wfactors G as a" "wfactors G bs b" "wfactors G cs c" | |
| 2125 | shows "c \<sim> a \<otimes> b" | |
| 2126 | proof - | |
| 2127 | from carr fs | |
| 2128 | have m: "wfactors G (as @ bs) (a \<otimes> b)" by (intro wfactors_mult) | |
| 2129 | ||
| 2130 | from mset | |
| 2131 | have "fmset G cs = fmset G (as@bs)" by (simp add: fmset_def) | |
| 2132 | then have "essentially_equal G cs (as@bs)" by (rule fmset_ee) (simp add: carr)+ | |
| 2133 | then show "c \<sim> a \<otimes> b" by (rule ee_wfactorsD[of "cs" "as@bs"]) (simp add: assms m)+ | |
| 2134 | qed | |
| 2135 | ||
| 2136 | ||
| 2137 | subsubsection {* Divisibility on multisets *}
 | |
| 2138 | ||
| 2139 | lemma (in factorial_monoid) divides_fmsubset: | |
| 2140 | assumes ab: "a divides b" | |
| 2141 | and afs: "wfactors G as a" and bfs: "wfactors G bs b" | |
| 2142 | 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 | 2143 | shows "fmset G as \<le> fmset G bs" | 
| 27701 | 2144 | using ab | 
| 2145 | proof (elim dividesE) | |
| 2146 | fix c | |
| 2147 | assume ccarr: "c \<in> carrier G" | |
| 2148 | hence "\<exists>cs. set cs \<subseteq> carrier G \<and> wfactors G cs c" by (rule wfactors_exist) | |
| 2149 | from this obtain cs | |
| 2150 | where cscarr: "set cs \<subseteq> carrier G" | |
| 2151 | and cfs: "wfactors G cs c" by auto | |
| 2152 | note carr = carr ccarr cscarr | |
| 2153 | ||
| 2154 | assume "b = a \<otimes> c" | |
| 2155 | with afs bfs cfs carr | |
| 2156 | have "fmset G bs = fmset G as + fmset G cs" | |
| 2157 | by (intro mult_wfactors_fmset[OF afs cfs]) simp+ | |
| 2158 | ||
| 2159 | thus ?thesis by simp | |
| 2160 | qed | |
| 2161 | ||
| 2162 | lemma (in comm_monoid_cancel) fmsubset_divides: | |
| 35272 
c283ae736bea
switched notations for pointwise and multiset order
 haftmann parents: 
32960diff
changeset | 2163 | assumes msubset: "fmset G as \<le> fmset G bs" | 
| 27701 | 2164 | and afs: "wfactors G as a" and bfs: "wfactors G bs b" | 
| 2165 | and acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" | |
| 2166 | and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G" | |
| 2167 | shows "a divides b" | |
| 2168 | proof - | |
| 2169 | from afs have airr: "\<forall>a \<in> set as. irreducible G a" by (fast elim: wfactorsE) | |
| 2170 | from bfs have birr: "\<forall>b \<in> set bs. irreducible G b" by (fast elim: wfactorsE) | |
| 2171 | ||
| 2172 | 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" | |
| 2173 | proof (intro mset_wfactorsEx, simp) | |
| 2174 | fix X | |
| 2175 | assume "count (fmset G as) X < count (fmset G bs) X" | |
| 2176 | hence "0 < count (fmset G bs) X" by simp | |
| 2177 | hence "X \<in> set_of (fmset G bs)" by simp | |
| 2178 | hence "X \<in> set (map (assocs G) bs)" by (simp add: fmset_def) | |
| 2179 | hence "\<exists>x. x \<in> set bs \<and> X = assocs G x" by (induct bs) auto | |
| 2180 | from this obtain x | |
| 2181 | where xbs: "x \<in> set bs" | |
| 2182 | and X: "X = assocs G x" | |
| 2183 | by auto | |
| 2184 | ||
| 2185 | with bscarr have xcarr: "x \<in> carrier G" by fast | |
| 2186 | from xbs birr have xirr: "irreducible G x" by simp | |
| 2187 | ||
| 2188 | from xcarr and xirr and X | |
| 2189 | show "\<exists>x. x \<in> carrier G \<and> irreducible G x \<and> X = assocs G x" by fast | |
| 2190 | qed | |
| 2191 | from this obtain c cs | |
| 2192 | where ccarr: "c \<in> carrier G" | |
| 2193 | and cscarr: "set cs \<subseteq> carrier G" | |
| 2194 | and csf: "wfactors G cs c" | |
| 2195 | and csmset: "fmset G cs = fmset G bs - fmset G as" by auto | |
| 2196 | ||
| 2197 | from csmset msubset | |
| 2198 | 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 | 2199 | by (simp add: multiset_eq_iff mset_le_def) | 
| 27701 | 2200 | hence basc: "b \<sim> a \<otimes> c" | 
| 2201 | by (rule fmset_wfactors_mult) fact+ | |
| 2202 | ||
| 2203 | thus ?thesis | |
| 2204 | proof (elim associatedE2) | |
| 2205 | fix u | |
| 2206 | assume "u \<in> Units G" "b = a \<otimes> c \<otimes> u" | |
| 2207 | with acarr ccarr | |
| 2208 | show "a divides b" by (fast intro: dividesI[of "c \<otimes> u"] m_assoc) | |
| 2209 | qed (simp add: acarr bcarr ccarr)+ | |
| 2210 | qed | |
| 2211 | ||
| 2212 | lemma (in factorial_monoid) divides_as_fmsubset: | |
| 2213 | assumes "wfactors G as a" and "wfactors G bs b" | |
| 2214 | and "a \<in> carrier G" and "b \<in> carrier G" | |
| 2215 | 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 | 2216 | shows "a divides b = (fmset G as \<le> fmset G bs)" | 
| 27701 | 2217 | using assms | 
| 2218 | by (blast intro: divides_fmsubset fmsubset_divides) | |
| 2219 | ||
| 2220 | ||
| 2221 | text {* Proper factors on multisets *}
 | |
| 2222 | ||
| 2223 | lemma (in factorial_monoid) fmset_properfactor: | |
| 35272 
c283ae736bea
switched notations for pointwise and multiset order
 haftmann parents: 
32960diff
changeset | 2224 | assumes asubb: "fmset G as \<le> fmset G bs" | 
| 27701 | 2225 | and anb: "fmset G as \<noteq> fmset G bs" | 
| 2226 | and "wfactors G as a" and "wfactors G bs b" | |
| 2227 | and "a \<in> carrier G" and "b \<in> carrier G" | |
| 2228 | and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G" | |
| 2229 | shows "properfactor G a b" | |
| 2230 | apply (rule properfactorI) | |
| 2231 | apply (rule fmsubset_divides[of as bs], fact+) | |
| 2232 | proof | |
| 2233 | assume "b divides a" | |
| 35272 
c283ae736bea
switched notations for pointwise and multiset order
 haftmann parents: 
32960diff
changeset | 2234 | hence "fmset G bs \<le> fmset G as" | 
| 27701 | 2235 | by (rule divides_fmsubset) fact+ | 
| 2236 | with asubb | |
| 35272 
c283ae736bea
switched notations for pointwise and multiset order
 haftmann parents: 
32960diff
changeset | 2237 | have "fmset G as = fmset G bs" by (rule order_antisym) | 
| 27701 | 2238 | with anb | 
| 2239 | show "False" .. | |
| 2240 | qed | |
| 2241 | ||
| 2242 | lemma (in factorial_monoid) properfactor_fmset: | |
| 2243 | assumes pf: "properfactor G a b" | |
| 2244 | and "wfactors G as a" and "wfactors G bs b" | |
| 2245 | and "a \<in> carrier G" and "b \<in> carrier G" | |
| 2246 | 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 | 2247 | shows "fmset G as \<le> fmset G bs \<and> fmset G as \<noteq> fmset G bs" | 
| 27701 | 2248 | using pf | 
| 2249 | apply (elim properfactorE) | |
| 2250 | apply rule | |
| 2251 | apply (intro divides_fmsubset, assumption) | |
| 2252 | apply (rule assms)+ | |
| 36278 | 2253 | apply (metis assms divides_fmsubset fmsubset_divides) | 
| 2254 | done | |
| 27701 | 2255 | |
| 27717 
21bbd410ba04
Generalised polynomial lemmas from cring to ring.
 ballarin parents: 
27713diff
changeset | 2256 | subsection {* Irreducible Elements are Prime *}
 | 
| 27701 | 2257 | |
| 2258 | lemma (in factorial_monoid) irreducible_is_prime: | |
| 2259 | assumes pirr: "irreducible G p" | |
| 2260 | and pcarr: "p \<in> carrier G" | |
| 2261 | shows "prime G p" | |
| 2262 | using pirr | |
| 2263 | proof (elim irreducibleE, intro primeI) | |
| 2264 | fix a b | |
| 2265 | assume acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" | |
| 2266 | and pdvdab: "p divides (a \<otimes> b)" | |
| 2267 | and pnunit: "p \<notin> Units G" | |
| 2268 | assume irreduc[rule_format]: | |
| 2269 | "\<forall>b. b \<in> carrier G \<and> properfactor G b p \<longrightarrow> b \<in> Units G" | |
| 2270 | from pdvdab | |
| 2271 | have "\<exists>c\<in>carrier G. a \<otimes> b = p \<otimes> c" by (rule dividesD) | |
| 2272 | from this obtain c | |
| 2273 | where ccarr: "c \<in> carrier G" | |
| 2274 | and abpc: "a \<otimes> b = p \<otimes> c" | |
| 2275 | by auto | |
| 2276 | ||
| 2277 | from acarr have "\<exists>fs. set fs \<subseteq> carrier G \<and> wfactors G fs a" by (rule wfactors_exist) | |
| 2278 | from this obtain as where ascarr: "set as \<subseteq> carrier G" and afs: "wfactors G as a" by auto | |
| 2279 | ||
| 2280 | from bcarr have "\<exists>fs. set fs \<subseteq> carrier G \<and> wfactors G fs b" by (rule wfactors_exist) | |
| 2281 | from this obtain bs where bscarr: "set bs \<subseteq> carrier G" and bfs: "wfactors G bs b" by auto | |
| 2282 | ||
| 2283 | from ccarr have "\<exists>fs. set fs \<subseteq> carrier G \<and> wfactors G fs c" by (rule wfactors_exist) | |
| 2284 | from this obtain cs where cscarr: "set cs \<subseteq> carrier G" and cfs: "wfactors G cs c" by auto | |
| 2285 | ||
| 2286 | note carr[simp] = pcarr acarr bcarr ccarr ascarr bscarr cscarr | |
| 2287 | ||
| 2288 | from afs and bfs | |
| 2289 | have abfs: "wfactors G (as @ bs) (a \<otimes> b)" by (rule wfactors_mult) fact+ | |
| 2290 | ||
| 2291 | from pirr cfs | |
| 2292 | have pcfs: "wfactors G (p # cs) (p \<otimes> c)" by (rule wfactors_mult_single) fact+ | |
| 2293 | with abpc | |
| 2294 | have abfs': "wfactors G (p # cs) (a \<otimes> b)" by simp | |
| 2295 | ||
| 2296 | from abfs' abfs | |
| 2297 | have "essentially_equal G (p # cs) (as @ bs)" | |
| 2298 | by (rule wfactors_unique) simp+ | |
| 2299 | ||
| 2300 | hence "\<exists>ds. p # cs <~~> ds \<and> ds [\<sim>] (as @ bs)" | |
| 2301 | by (fast elim: essentially_equalE) | |
| 2302 | from this obtain ds | |
| 2303 | where "p # cs <~~> ds" | |
| 2304 | and dsassoc: "ds [\<sim>] (as @ bs)" | |
| 2305 | by auto | |
| 2306 | ||
| 2307 | then have "p \<in> set ds" | |
| 2308 | by (simp add: perm_set_eq[symmetric]) | |
| 2309 | with dsassoc | |
| 2310 | have "\<exists>p'. p' \<in> set (as@bs) \<and> p \<sim> p'" | |
| 2311 | unfolding list_all2_conv_all_nth set_conv_nth | |
| 2312 | by force | |
| 2313 | ||
| 2314 | from this obtain p' | |
| 2315 | where "p' \<in> set (as@bs)" | |
| 2316 | and pp': "p \<sim> p'" | |
| 2317 | by auto | |
| 2318 | ||
| 2319 | hence "p' \<in> set as \<or> p' \<in> set bs" by simp | |
| 2320 | moreover | |
| 2321 |   {
 | |
| 2322 | assume p'elem: "p' \<in> set as" | |
| 2323 | with ascarr have [simp]: "p' \<in> carrier G" by fast | |
| 2324 | ||
| 2325 | note pp' | |
| 2326 | also from afs | |
| 2327 | have "p' divides a" by (rule wfactors_dividesI) fact+ | |
| 2328 | finally | |
| 2329 | have "p divides a" by simp | |
| 2330 | } | |
| 2331 | moreover | |
| 2332 |   {
 | |
| 2333 | assume p'elem: "p' \<in> set bs" | |
| 2334 | with bscarr have [simp]: "p' \<in> carrier G" by fast | |
| 2335 | ||
| 2336 | note pp' | |
| 2337 | also from bfs | |
| 2338 | have "p' divides b" by (rule wfactors_dividesI) fact+ | |
| 2339 | finally | |
| 2340 | have "p divides b" by simp | |
| 2341 | } | |
| 2342 | ultimately | |
| 2343 | show "p divides a \<or> p divides b" by fast | |
| 2344 | qed | |
| 2345 | ||
| 2346 | ||
| 2347 | --"A version using @{const factors}, more complicated"
 | |
| 2348 | lemma (in factorial_monoid) factors_irreducible_is_prime: | |
| 2349 | assumes pirr: "irreducible G p" | |
| 2350 | and pcarr: "p \<in> carrier G" | |
| 2351 | shows "prime G p" | |
| 2352 | using pirr | |
| 2353 | apply (elim irreducibleE, intro primeI) | |
| 2354 | apply assumption | |
| 2355 | proof - | |
| 2356 | fix a b | |
| 2357 | assume acarr: "a \<in> carrier G" | |
| 2358 | and bcarr: "b \<in> carrier G" | |
| 2359 | and pdvdab: "p divides (a \<otimes> b)" | |
| 2360 | assume irreduc[rule_format]: | |
| 2361 | "\<forall>b. b \<in> carrier G \<and> properfactor G b p \<longrightarrow> b \<in> Units G" | |
| 2362 | from pdvdab | |
| 2363 | have "\<exists>c\<in>carrier G. a \<otimes> b = p \<otimes> c" by (rule dividesD) | |
| 2364 | from this obtain c | |
| 2365 | where ccarr: "c \<in> carrier G" | |
| 2366 | and abpc: "a \<otimes> b = p \<otimes> c" | |
| 2367 | by auto | |
| 2368 | note [simp] = pcarr acarr bcarr ccarr | |
| 2369 | ||
| 2370 | show "p divides a \<or> p divides b" | |
| 2371 | proof (cases "a \<in> Units G") | |
| 2372 | assume aunit: "a \<in> Units G" | |
| 2373 | ||
| 2374 | note pdvdab | |
| 2375 | also have "a \<otimes> b = b \<otimes> a" by (simp add: m_comm) | |
| 2376 | also from aunit | |
| 2377 | have bab: "b \<otimes> a \<sim> b" | |
| 2378 | by (intro associatedI2[of "a"], simp+) | |
| 2379 | finally | |
| 2380 | have "p divides b" by simp | |
| 2381 | thus "p divides a \<or> p divides b" .. | |
| 2382 | next | |
| 2383 | assume anunit: "a \<notin> Units G" | |
| 2384 | ||
| 2385 | show "p divides a \<or> p divides b" | |
| 2386 | proof (cases "b \<in> Units G") | |
| 2387 | assume bunit: "b \<in> Units G" | |
| 2388 | ||
| 2389 | note pdvdab | |
| 2390 | also from bunit | |
| 2391 | have baa: "a \<otimes> b \<sim> a" | |
| 2392 | by (intro associatedI2[of "b"], simp+) | |
| 2393 | finally | |
| 2394 | have "p divides a" by simp | |
| 2395 | thus "p divides a \<or> p divides b" .. | |
| 2396 | next | |
| 2397 | assume bnunit: "b \<notin> Units G" | |
| 2398 | ||
| 2399 | have cnunit: "c \<notin> Units G" | |
| 2400 | proof (rule ccontr, simp) | |
| 2401 | assume cunit: "c \<in> Units G" | |
| 2402 | from bnunit | |
| 2403 | have "properfactor G a (a \<otimes> b)" | |
| 2404 | by (intro properfactorI3[of _ _ b], simp+) | |
| 2405 | also note abpc | |
| 2406 | also from cunit | |
| 2407 | have "p \<otimes> c \<sim> p" | |
| 2408 | by (intro associatedI2[of c], simp+) | |
| 2409 | finally | |
| 2410 | have "properfactor G a p" by simp | |
| 2411 | ||
| 2412 | with acarr | |
| 2413 | have "a \<in> Units G" by (fast intro: irreduc) | |
| 2414 | with anunit | |
| 2415 | show "False" .. | |
| 2416 | qed | |
| 2417 | ||
| 2418 | have abnunit: "a \<otimes> b \<notin> Units G" | |
| 2419 | proof clarsimp | |
| 2420 | assume abunit: "a \<otimes> b \<in> Units G" | |
| 2421 | hence "a \<in> Units G" by (rule unit_factor) fact+ | |
| 2422 | with anunit | |
| 2423 | show "False" .. | |
| 2424 | qed | |
| 2425 | ||
| 2426 | from acarr anunit have "\<exists>fs. set fs \<subseteq> carrier G \<and> factors G fs a" by (rule factors_exist) | |
| 2427 | then obtain as where ascarr: "set as \<subseteq> carrier G" and afac: "factors G as a" by auto | |
| 2428 | ||
| 2429 | from bcarr bnunit have "\<exists>fs. set fs \<subseteq> carrier G \<and> factors G fs b" by (rule factors_exist) | |
| 2430 | then obtain bs where bscarr: "set bs \<subseteq> carrier G" and bfac: "factors G bs b" by auto | |
| 2431 | ||
| 2432 | from ccarr cnunit have "\<exists>fs. set fs \<subseteq> carrier G \<and> factors G fs c" by (rule factors_exist) | |
| 2433 | then obtain cs where cscarr: "set cs \<subseteq> carrier G" and cfac: "factors G cs c" by auto | |
| 2434 | ||
| 2435 | note [simp] = ascarr bscarr cscarr | |
| 2436 | ||
| 2437 | from afac and bfac | |
| 2438 | have abfac: "factors G (as @ bs) (a \<otimes> b)" by (rule factors_mult) fact+ | |
| 2439 | ||
| 2440 | from pirr cfac | |
| 2441 | have pcfac: "factors G (p # cs) (p \<otimes> c)" by (rule factors_mult_single) fact+ | |
| 2442 | with abpc | |
| 2443 | have abfac': "factors G (p # cs) (a \<otimes> b)" by simp | |
| 2444 | ||
| 2445 | from abfac' abfac | |
| 2446 | have "essentially_equal G (p # cs) (as @ bs)" | |
| 2447 | by (rule factors_unique) (fact | simp)+ | |
| 2448 | ||
| 2449 | hence "\<exists>ds. p # cs <~~> ds \<and> ds [\<sim>] (as @ bs)" | |
| 2450 | by (fast elim: essentially_equalE) | |
| 2451 | from this obtain ds | |
| 2452 | where "p # cs <~~> ds" | |
| 2453 | and dsassoc: "ds [\<sim>] (as @ bs)" | |
| 2454 | by auto | |
| 2455 | ||
| 2456 | then have "p \<in> set ds" | |
| 2457 | by (simp add: perm_set_eq[symmetric]) | |
| 2458 | with dsassoc | |
| 2459 | have "\<exists>p'. p' \<in> set (as@bs) \<and> p \<sim> p'" | |
| 2460 | unfolding list_all2_conv_all_nth set_conv_nth | |
| 2461 | by force | |
| 2462 | ||
| 2463 | from this obtain p' | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2464 | where "p' \<in> set (as@bs)" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2465 | and pp': "p \<sim> p'" by auto | 
| 27701 | 2466 | |
| 2467 | hence "p' \<in> set as \<or> p' \<in> set bs" by simp | |
| 2468 | moreover | |
| 2469 |       {
 | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2470 | assume p'elem: "p' \<in> set as" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2471 | 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 | 2472 | |
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2473 | note pp' | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2474 | also from afac p'elem | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2475 | 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 | 2476 | finally | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2477 | have "p divides a" by simp | 
| 27701 | 2478 | } | 
| 2479 | moreover | |
| 2480 |       {
 | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2481 | assume p'elem: "p' \<in> set bs" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2482 | 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 | 2483 | |
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2484 | note pp' | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2485 | also from bfac | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2486 | 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 | 2487 | finally have "p divides b" by simp | 
| 27701 | 2488 | } | 
| 2489 | ultimately | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2490 | show "p divides a \<or> p divides b" by fast | 
| 27701 | 2491 | qed | 
| 2492 | qed | |
| 2493 | qed | |
| 2494 | ||
| 2495 | ||
| 27717 
21bbd410ba04
Generalised polynomial lemmas from cring to ring.
 ballarin parents: 
27713diff
changeset | 2496 | subsection {* Greatest Common Divisors and Lowest Common Multiples *}
 | 
| 27701 | 2497 | |
| 2498 | subsubsection {* Definitions *}
 | |
| 2499 | ||
| 35847 | 2500 | definition | 
| 27701 | 2501 |   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 | 2502 | where "x gcdof\<^bsub>G\<^esub> a b \<longleftrightarrow> x divides\<^bsub>G\<^esub> a \<and> x divides\<^bsub>G\<^esub> b \<and> | 
| 35847 | 2503 | (\<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))" | 
| 2504 | ||
| 2505 | definition | |
| 27701 | 2506 |   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 | 2507 | where "x lcmof\<^bsub>G\<^esub> a b \<longleftrightarrow> a divides\<^bsub>G\<^esub> x \<and> b divides\<^bsub>G\<^esub> x \<and> | 
| 35847 | 2508 | (\<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))" | 
| 2509 | ||
| 2510 | definition | |
| 27701 | 2511 |   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 | 2512 | where "somegcd G a b = (SOME x. x \<in> carrier G \<and> x gcdof\<^bsub>G\<^esub> a b)" | 
| 35847 | 2513 | |
| 2514 | definition | |
| 27701 | 2515 |   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 | 2516 | where "somelcm G a b = (SOME x. x \<in> carrier G \<and> x lcmof\<^bsub>G\<^esub> a b)" | 
| 35847 | 2517 | |
| 2518 | definition | |
| 35848 
5443079512ea
slightly more uniform definitions -- eliminated old-style meta-equality;
 wenzelm parents: 
35847diff
changeset | 2519 | "SomeGcd G A = inf (division_rel G) A" | 
| 27701 | 2520 | |
| 2521 | ||
| 2522 | locale gcd_condition_monoid = comm_monoid_cancel + | |
| 2523 | assumes gcdof_exists: | |
| 2524 | "\<lbrakk>a \<in> carrier G; b \<in> carrier G\<rbrakk> \<Longrightarrow> \<exists>c. c \<in> carrier G \<and> c gcdof a b" | |
| 2525 | ||
| 2526 | locale primeness_condition_monoid = comm_monoid_cancel + | |
| 2527 | assumes irreducible_prime: | |
| 2528 | "\<lbrakk>a \<in> carrier G; irreducible G a\<rbrakk> \<Longrightarrow> prime G a" | |
| 2529 | ||
| 2530 | locale divisor_chain_condition_monoid = comm_monoid_cancel + | |
| 2531 | assumes division_wellfounded: | |
| 2532 |           "wf {(x, y). x \<in> carrier G \<and> y \<in> carrier G \<and> properfactor G x y}"
 | |
| 2533 | ||
| 2534 | ||
| 2535 | subsubsection {* Connections to \texttt{Lattice.thy} *}
 | |
| 2536 | ||
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2537 | lemma gcdof_greatestLower: | 
| 27701 | 2538 | fixes G (structure) | 
| 2539 | assumes carr[simp]: "a \<in> carrier G" "b \<in> carrier G" | |
| 2540 | 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 | 2541 |          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 | 2542 | 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 | 2543 | by auto | 
| 27701 | 2544 | |
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2545 | lemma lcmof_leastUpper: | 
| 27701 | 2546 | fixes G (structure) | 
| 2547 | assumes carr[simp]: "a \<in> carrier G" "b \<in> carrier G" | |
| 2548 | 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 | 2549 |          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 | 2550 | 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 | 2551 | by auto | 
| 27701 | 2552 | |
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2553 | lemma somegcd_meet: | 
| 27701 | 2554 | fixes G (structure) | 
| 2555 | 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 | 2556 | 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 | 2557 | 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 | 2558 | by (simp add: gcdof_greatestLower[OF carr]) | 
| 27701 | 2559 | |
| 2560 | lemma (in monoid) isgcd_divides_l: | |
| 2561 | assumes "a divides b" | |
| 2562 | and "a \<in> carrier G" "b \<in> carrier G" | |
| 2563 | shows "a gcdof a b" | |
| 2564 | using assms | |
| 2565 | unfolding isgcd_def | |
| 2566 | by fast | |
| 2567 | ||
| 2568 | lemma (in monoid) isgcd_divides_r: | |
| 2569 | assumes "b divides a" | |
| 2570 | and "a \<in> carrier G" "b \<in> carrier G" | |
| 2571 | shows "b gcdof a b" | |
| 2572 | using assms | |
| 2573 | unfolding isgcd_def | |
| 2574 | by fast | |
| 2575 | ||
| 2576 | ||
| 2577 | subsubsection {* Existence of gcd and lcm *}
 | |
| 2578 | ||
| 2579 | lemma (in factorial_monoid) gcdof_exists: | |
| 2580 | assumes acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" | |
| 2581 | shows "\<exists>c. c \<in> carrier G \<and> c gcdof a b" | |
| 2582 | proof - | |
| 2583 | from acarr have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a" by (rule wfactors_exist) | |
| 2584 | from this obtain as | |
| 2585 | where ascarr: "set as \<subseteq> carrier G" | |
| 2586 | and afs: "wfactors G as a" | |
| 2587 | by auto | |
| 2588 | from afs have airr: "\<forall>a \<in> set as. irreducible G a" by (fast elim: wfactorsE) | |
| 2589 | ||
| 2590 | from bcarr have "\<exists>bs. set bs \<subseteq> carrier G \<and> wfactors G bs b" by (rule wfactors_exist) | |
| 2591 | from this obtain bs | |
| 2592 | where bscarr: "set bs \<subseteq> carrier G" | |
| 2593 | and bfs: "wfactors G bs b" | |
| 2594 | by auto | |
| 2595 | from bfs have birr: "\<forall>b \<in> set bs. irreducible G b" by (fast elim: wfactorsE) | |
| 2596 | ||
| 2597 | have "\<exists>c cs. c \<in> carrier G \<and> set cs \<subseteq> carrier G \<and> wfactors G cs c \<and> | |
| 2598 | fmset G cs = fmset G as #\<inter> fmset G bs" | |
| 2599 | proof (intro mset_wfactorsEx) | |
| 2600 | fix X | |
| 2601 | assume "X \<in> set_of (fmset G as #\<inter> fmset G bs)" | |
| 2602 | hence "X \<in> set_of (fmset G as)" by (simp add: multiset_inter_def) | |
| 2603 | hence "X \<in> set (map (assocs G) as)" by (simp add: fmset_def) | |
| 2604 | hence "\<exists>x. X = assocs G x \<and> x \<in> set as" by (induct as) auto | |
| 2605 | from this obtain x | |
| 2606 | where X: "X = assocs G x" | |
| 2607 | and xas: "x \<in> set as" | |
| 2608 | by auto | |
| 2609 | with ascarr have xcarr: "x \<in> carrier G" by fast | |
| 2610 | from xas airr have xirr: "irreducible G x" by simp | |
| 2611 | ||
| 2612 | from xcarr and xirr and X | |
| 2613 | show "\<exists>x. (x \<in> carrier G \<and> irreducible G x) \<and> X = assocs G x" by fast | |
| 2614 | qed | |
| 2615 | ||
| 2616 | from this obtain c cs | |
| 2617 | where ccarr: "c \<in> carrier G" | |
| 2618 | and cscarr: "set cs \<subseteq> carrier G" | |
| 2619 | and csirr: "wfactors G cs c" | |
| 2620 | and csmset: "fmset G cs = fmset G as #\<inter> fmset G bs" by auto | |
| 2621 | ||
| 2622 | have "c gcdof a b" | |
| 2623 | proof (simp add: isgcd_def, safe) | |
| 2624 | from csmset | |
| 35272 
c283ae736bea
switched notations for pointwise and multiset order
 haftmann parents: 
32960diff
changeset | 2625 | have "fmset G cs \<le> fmset G as" | 
| 27701 | 2626 | by (simp add: multiset_inter_def mset_le_def) | 
| 2627 | thus "c divides a" by (rule fmsubset_divides) fact+ | |
| 2628 | next | |
| 2629 | from csmset | |
| 35272 
c283ae736bea
switched notations for pointwise and multiset order
 haftmann parents: 
32960diff
changeset | 2630 | have "fmset G cs \<le> fmset G bs" | 
| 27701 | 2631 | by (simp add: multiset_inter_def mset_le_def, force) | 
| 2632 | thus "c divides b" by (rule fmsubset_divides) fact+ | |
| 2633 | next | |
| 2634 | fix y | |
| 2635 | assume ycarr: "y \<in> carrier G" | |
| 2636 | hence "\<exists>ys. set ys \<subseteq> carrier G \<and> wfactors G ys y" by (rule wfactors_exist) | |
| 2637 | from this obtain ys | |
| 2638 | where yscarr: "set ys \<subseteq> carrier G" | |
| 2639 | and yfs: "wfactors G ys y" | |
| 2640 | by auto | |
| 2641 | ||
| 2642 | assume "y divides a" | |
| 35272 
c283ae736bea
switched notations for pointwise and multiset order
 haftmann parents: 
32960diff
changeset | 2643 | hence ya: "fmset G ys \<le> fmset G as" by (rule divides_fmsubset) fact+ | 
| 27701 | 2644 | |
| 2645 | assume "y divides b" | |
| 35272 
c283ae736bea
switched notations for pointwise and multiset order
 haftmann parents: 
32960diff
changeset | 2646 | hence yb: "fmset G ys \<le> fmset G bs" by (rule divides_fmsubset) fact+ | 
| 27701 | 2647 | |
| 2648 | from ya yb csmset | |
| 35272 
c283ae736bea
switched notations for pointwise and multiset order
 haftmann parents: 
32960diff
changeset | 2649 | have "fmset G ys \<le> fmset G cs" by (simp add: mset_le_def multiset_inter_count) | 
| 27701 | 2650 | thus "y divides c" by (rule fmsubset_divides) fact+ | 
| 2651 | qed | |
| 2652 | ||
| 2653 | with ccarr | |
| 2654 | show "\<exists>c. c \<in> carrier G \<and> c gcdof a b" by fast | |
| 2655 | qed | |
| 2656 | ||
| 2657 | lemma (in factorial_monoid) lcmof_exists: | |
| 2658 | assumes acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" | |
| 2659 | shows "\<exists>c. c \<in> carrier G \<and> c lcmof a b" | |
| 2660 | proof - | |
| 2661 | from acarr have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a" by (rule wfactors_exist) | |
| 2662 | from this obtain as | |
| 2663 | where ascarr: "set as \<subseteq> carrier G" | |
| 2664 | and afs: "wfactors G as a" | |
| 2665 | by auto | |
| 2666 | from afs have airr: "\<forall>a \<in> set as. irreducible G a" by (fast elim: wfactorsE) | |
| 2667 | ||
| 2668 | from bcarr have "\<exists>bs. set bs \<subseteq> carrier G \<and> wfactors G bs b" by (rule wfactors_exist) | |
| 2669 | from this obtain bs | |
| 2670 | where bscarr: "set bs \<subseteq> carrier G" | |
| 2671 | and bfs: "wfactors G bs b" | |
| 2672 | by auto | |
| 2673 | from bfs have birr: "\<forall>b \<in> set bs. irreducible G b" by (fast elim: wfactorsE) | |
| 2674 | ||
| 2675 | have "\<exists>c cs. c \<in> carrier G \<and> set cs \<subseteq> carrier G \<and> wfactors G cs c \<and> | |
| 2676 | fmset G cs = (fmset G as - fmset G bs) + fmset G bs" | |
| 2677 | proof (intro mset_wfactorsEx) | |
| 2678 | fix X | |
| 2679 | assume "X \<in> set_of ((fmset G as - fmset G bs) + fmset G bs)" | |
| 2680 | hence "X \<in> set_of (fmset G as) \<or> X \<in> set_of (fmset G bs)" | |
| 2681 | by (cases "X :# fmset G bs", simp, simp) | |
| 2682 | moreover | |
| 2683 |     {
 | |
| 2684 | assume "X \<in> set_of (fmset G as)" | |
| 2685 | hence "X \<in> set (map (assocs G) as)" by (simp add: fmset_def) | |
| 2686 | hence "\<exists>x. x \<in> set as \<and> X = assocs G x" by (induct as) auto | |
| 2687 | from this obtain x | |
| 2688 | where xas: "x \<in> set as" | |
| 2689 | and X: "X = assocs G x" by auto | |
| 2690 | ||
| 2691 | with ascarr have xcarr: "x \<in> carrier G" by fast | |
| 2692 | from xas airr have xirr: "irreducible G x" by simp | |
| 2693 | ||
| 2694 | from xcarr and xirr and X | |
| 2695 | have "\<exists>x. (x \<in> carrier G \<and> irreducible G x) \<and> X = assocs G x" by fast | |
| 2696 | } | |
| 2697 | moreover | |
| 2698 |     {
 | |
| 2699 | assume "X \<in> set_of (fmset G bs)" | |
| 2700 | hence "X \<in> set (map (assocs G) bs)" by (simp add: fmset_def) | |
| 2701 | hence "\<exists>x. x \<in> set bs \<and> X = assocs G x" by (induct as) auto | |
| 2702 | from this obtain x | |
| 2703 | where xbs: "x \<in> set bs" | |
| 2704 | and X: "X = assocs G x" by auto | |
| 2705 | ||
| 2706 | with bscarr have xcarr: "x \<in> carrier G" by fast | |
| 2707 | from xbs birr have xirr: "irreducible G x" by simp | |
| 2708 | ||
| 2709 | from xcarr and xirr and X | |
| 2710 | have "\<exists>x. (x \<in> carrier G \<and> irreducible G x) \<and> X = assocs G x" by fast | |
| 2711 | } | |
| 2712 | ultimately | |
| 2713 | show "\<exists>x. (x \<in> carrier G \<and> irreducible G x) \<and> X = assocs G x" by fast | |
| 2714 | qed | |
| 2715 | ||
| 2716 | from this obtain c cs | |
| 2717 | where ccarr: "c \<in> carrier G" | |
| 2718 | and cscarr: "set cs \<subseteq> carrier G" | |
| 2719 | and csirr: "wfactors G cs c" | |
| 2720 | and csmset: "fmset G cs = fmset G as - fmset G bs + fmset G bs" by auto | |
| 2721 | ||
| 2722 | have "c lcmof a b" | |
| 2723 | proof (simp add: islcm_def, safe) | |
| 35272 
c283ae736bea
switched notations for pointwise and multiset order
 haftmann parents: 
32960diff
changeset | 2724 | from csmset have "fmset G as \<le> fmset G cs" by (simp add: mset_le_def, force) | 
| 27701 | 2725 | thus "a divides c" by (rule fmsubset_divides) fact+ | 
| 2726 | next | |
| 35272 
c283ae736bea
switched notations for pointwise and multiset order
 haftmann parents: 
32960diff
changeset | 2727 | from csmset have "fmset G bs \<le> fmset G cs" by (simp add: mset_le_def) | 
| 27701 | 2728 | thus "b divides c" by (rule fmsubset_divides) fact+ | 
| 2729 | next | |
| 2730 | fix y | |
| 2731 | assume ycarr: "y \<in> carrier G" | |
| 2732 | hence "\<exists>ys. set ys \<subseteq> carrier G \<and> wfactors G ys y" by (rule wfactors_exist) | |
| 2733 | from this obtain ys | |
| 2734 | where yscarr: "set ys \<subseteq> carrier G" | |
| 2735 | and yfs: "wfactors G ys y" | |
| 2736 | by auto | |
| 2737 | ||
| 2738 | assume "a divides y" | |
| 35272 
c283ae736bea
switched notations for pointwise and multiset order
 haftmann parents: 
32960diff
changeset | 2739 | hence ya: "fmset G as \<le> fmset G ys" by (rule divides_fmsubset) fact+ | 
| 27701 | 2740 | |
| 2741 | assume "b divides y" | |
| 35272 
c283ae736bea
switched notations for pointwise and multiset order
 haftmann parents: 
32960diff
changeset | 2742 | hence yb: "fmset G bs \<le> fmset G ys" by (rule divides_fmsubset) fact+ | 
| 27701 | 2743 | |
| 2744 | from ya yb csmset | |
| 35272 
c283ae736bea
switched notations for pointwise and multiset order
 haftmann parents: 
32960diff
changeset | 2745 | have "fmset G cs \<le> fmset G ys" | 
| 27701 | 2746 | apply (simp add: mset_le_def, clarify) | 
| 2747 | apply (case_tac "count (fmset G as) a < count (fmset G bs) a") | |
| 2748 | apply simp | |
| 2749 | apply simp | |
| 2750 | done | |
| 2751 | thus "c divides y" by (rule fmsubset_divides) fact+ | |
| 2752 | qed | |
| 2753 | ||
| 2754 | with ccarr | |
| 2755 | show "\<exists>c. c \<in> carrier G \<and> c lcmof a b" by fast | |
| 2756 | qed | |
| 2757 | ||
| 2758 | ||
| 27717 
21bbd410ba04
Generalised polynomial lemmas from cring to ring.
 ballarin parents: 
27713diff
changeset | 2759 | subsection {* Conditions for Factoriality *}
 | 
| 27701 | 2760 | |
| 2761 | subsubsection {* Gcd condition *}
 | |
| 2762 | ||
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2763 | 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 | 2764 | shows "weak_lower_semilattice (division_rel G)" | 
| 27701 | 2765 | proof - | 
| 29237 | 2766 | interpret weak_partial_order "division_rel G" .. | 
| 27701 | 2767 | show ?thesis | 
| 2768 | apply (unfold_locales, simp_all) | |
| 2769 | proof - | |
| 2770 | fix x y | |
| 2771 | assume carr: "x \<in> carrier G" "y \<in> carrier G" | |
| 2772 | hence "\<exists>z. z \<in> carrier G \<and> z gcdof x y" by (rule gcdof_exists) | |
| 2773 | from this obtain z | |
| 2774 | where zcarr: "z \<in> carrier G" | |
| 2775 | and isgcd: "z gcdof x y" | |
| 2776 | by auto | |
| 2777 | with carr | |
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2778 |     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 | 2779 | 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 | 2780 |     thus "\<exists>z. greatest (division_rel G) z (Lower (division_rel G) {x, y})" by fast
 | 
| 27701 | 2781 | qed | 
| 2782 | qed | |
| 2783 | ||
| 2784 | lemma (in gcd_condition_monoid) gcdof_cong_l: | |
| 2785 | assumes a'a: "a' \<sim> a" | |
| 2786 | and agcd: "a gcdof b c" | |
| 2787 | and a'carr: "a' \<in> carrier G" and carr': "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | |
| 2788 | shows "a' gcdof b c" | |
| 2789 | proof - | |
| 2790 | note carr = a'carr carr' | |
| 29237 | 2791 | interpret weak_lower_semilattice "division_rel G" by simp | 
| 27701 | 2792 | 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 | 2793 | 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 | 2794 | apply (subst greatest_Lower_cong_l[of _ a]) | 
| 27701 | 2795 | apply (simp add: a'a) | 
| 2796 | apply (simp add: carr) | |
| 2797 | apply (simp add: carr) | |
| 2798 | 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 | 2799 | apply (simp add: gcdof_greatestLower[symmetric] agcd carr) | 
| 27701 | 2800 | done | 
| 2801 | thus ?thesis .. | |
| 2802 | qed | |
| 2803 | ||
| 2804 | lemma (in gcd_condition_monoid) gcd_closed [simp]: | |
| 2805 | assumes carr: "a \<in> carrier G" "b \<in> carrier G" | |
| 2806 | shows "somegcd G a b \<in> carrier G" | |
| 2807 | proof - | |
| 29237 | 2808 | interpret weak_lower_semilattice "division_rel G" by simp | 
| 27701 | 2809 | show ?thesis | 
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2810 | 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 | 2811 | apply (rule meet_closed[simplified], fact+) | 
| 27701 | 2812 | done | 
| 2813 | qed | |
| 2814 | ||
| 2815 | lemma (in gcd_condition_monoid) gcd_isgcd: | |
| 2816 | assumes carr: "a \<in> carrier G" "b \<in> carrier G" | |
| 2817 | shows "(somegcd G a b) gcdof a b" | |
| 2818 | proof - | |
| 29237 | 2819 | interpret weak_lower_semilattice "division_rel G" by simp | 
| 27701 | 2820 | from carr | 
| 2821 | 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 | 2822 | 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 | 2823 | 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 | 2824 | apply (rule inf_of_two_greatest[simplified], assumption+) | 
| 27701 | 2825 | done | 
| 2826 | thus "(somegcd G a b) gcdof a b" by simp | |
| 2827 | qed | |
| 2828 | ||
| 2829 | lemma (in gcd_condition_monoid) gcd_exists: | |
| 2830 | assumes carr: "a \<in> carrier G" "b \<in> carrier G" | |
| 2831 | shows "\<exists>x\<in>carrier G. x = somegcd G a b" | |
| 2832 | proof - | |
| 29237 | 2833 | interpret weak_lower_semilattice "division_rel G" by simp | 
| 27701 | 2834 | show ?thesis | 
| 55242 
413ec965f95d
Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
 paulson <lp15@cam.ac.uk> parents: 
53374diff
changeset | 2835 | by (metis carr(1) carr(2) gcd_closed) | 
| 27701 | 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 | 
| 55242 
413ec965f95d
Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
 paulson <lp15@cam.ac.uk> parents: 
53374diff
changeset | 2844 | by (metis carr(1) carr(2) gcd_isgcd isgcd_def) | 
| 27701 | 2845 | qed | 
| 2846 | ||
| 2847 | lemma (in gcd_condition_monoid) gcd_divides_r: | |
| 2848 | assumes carr: "a \<in> carrier G" "b \<in> carrier G" | |
| 2849 | shows "(somegcd G a b) divides b" | |
| 2850 | proof - | |
| 29237 | 2851 | interpret weak_lower_semilattice "division_rel G" by simp | 
| 27701 | 2852 | show ?thesis | 
| 55242 
413ec965f95d
Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
 paulson <lp15@cam.ac.uk> parents: 
53374diff
changeset | 2853 | by (metis carr gcd_isgcd isgcd_def) | 
| 27701 | 2854 | qed | 
| 2855 | ||
| 2856 | lemma (in gcd_condition_monoid) gcd_divides: | |
| 2857 | assumes sub: "z divides x" "z divides y" | |
| 2858 | and L: "x \<in> carrier G" "y \<in> carrier G" "z \<in> carrier G" | |
| 2859 | shows "z divides (somegcd G x y)" | |
| 2860 | proof - | |
| 29237 | 2861 | interpret weak_lower_semilattice "division_rel G" by simp | 
| 27701 | 2862 | show ?thesis | 
| 55242 
413ec965f95d
Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
 paulson <lp15@cam.ac.uk> parents: 
53374diff
changeset | 2863 | by (metis gcd_isgcd isgcd_def assms) | 
| 27701 | 2864 | qed | 
| 2865 | ||
| 2866 | lemma (in gcd_condition_monoid) gcd_cong_l: | |
| 2867 | assumes xx': "x \<sim> x'" | |
| 2868 | and carr: "x \<in> carrier G" "x' \<in> carrier G" "y \<in> carrier G" | |
| 2869 | shows "somegcd G x y \<sim> somegcd G x' y" | |
| 2870 | proof - | |
| 29237 | 2871 | interpret weak_lower_semilattice "division_rel G" by simp | 
| 27701 | 2872 | show ?thesis | 
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2873 | 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 | 2874 | apply (rule meet_cong_l[simplified], fact+) | 
| 27701 | 2875 | done | 
| 2876 | qed | |
| 2877 | ||
| 2878 | lemma (in gcd_condition_monoid) gcd_cong_r: | |
| 2879 | assumes carr: "x \<in> carrier G" "y \<in> carrier G" "y' \<in> carrier G" | |
| 2880 | and yy': "y \<sim> y'" | |
| 2881 | shows "somegcd G x y \<sim> somegcd G x y'" | |
| 2882 | proof - | |
| 29237 | 2883 | interpret weak_lower_semilattice "division_rel G" by simp | 
| 27701 | 2884 | show ?thesis | 
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2885 | 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 | 2886 | apply (rule meet_cong_r[simplified], fact+) | 
| 27701 | 2887 | done | 
| 2888 | qed | |
| 2889 | ||
| 2890 | (* | |
| 2891 | lemma (in gcd_condition_monoid) asc_cong_gcd_l [intro]: | |
| 2892 | assumes carr: "b \<in> carrier G" | |
| 2893 | shows "asc_cong (\<lambda>a. somegcd G a b)" | |
| 2894 | using carr | |
| 2895 | unfolding CONG_def | |
| 2896 | by clarsimp (blast intro: gcd_cong_l) | |
| 2897 | ||
| 2898 | lemma (in gcd_condition_monoid) asc_cong_gcd_r [intro]: | |
| 2899 | assumes carr: "a \<in> carrier G" | |
| 2900 | shows "asc_cong (\<lambda>b. somegcd G a b)" | |
| 2901 | using carr | |
| 2902 | unfolding CONG_def | |
| 2903 | by clarsimp (blast intro: gcd_cong_r) | |
| 2904 | ||
| 2905 | lemmas (in gcd_condition_monoid) asc_cong_gcd_split [simp] = | |
| 2906 | assoc_split[OF _ asc_cong_gcd_l] assoc_split[OF _ asc_cong_gcd_r] | |
| 2907 | *) | |
| 2908 | ||
| 2909 | lemma (in gcd_condition_monoid) gcdI: | |
| 2910 | assumes dvd: "a divides b" "a divides c" | |
| 2911 | and others: "\<forall>y\<in>carrier G. y divides b \<and> y divides c \<longrightarrow> y divides a" | |
| 2912 | and acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" and ccarr: "c \<in> carrier G" | |
| 2913 | shows "a \<sim> somegcd G b c" | |
| 2914 | apply (simp add: somegcd_def) | |
| 2915 | apply (rule someI2_ex) | |
| 2916 | apply (rule exI[of _ a], simp add: isgcd_def) | |
| 2917 | apply (simp add: assms) | |
| 2918 | apply (simp add: isgcd_def assms, clarify) | |
| 2919 | apply (insert assms, blast intro: associatedI) | |
| 2920 | done | |
| 2921 | ||
| 2922 | lemma (in gcd_condition_monoid) gcdI2: | |
| 2923 | assumes "a gcdof b c" | |
| 2924 | and "a \<in> carrier G" and bcarr: "b \<in> carrier G" and ccarr: "c \<in> carrier G" | |
| 2925 | shows "a \<sim> somegcd G b c" | |
| 2926 | using assms | |
| 2927 | unfolding isgcd_def | |
| 2928 | by (blast intro: gcdI) | |
| 2929 | ||
| 2930 | lemma (in gcd_condition_monoid) SomeGcd_ex: | |
| 2931 |   assumes "finite A"  "A \<subseteq> carrier G"  "A \<noteq> {}"
 | |
| 2932 | shows "\<exists>x\<in> carrier G. x = SomeGcd G A" | |
| 2933 | proof - | |
| 29237 | 2934 | interpret weak_lower_semilattice "division_rel G" by simp | 
| 27701 | 2935 | show ?thesis | 
| 2936 | 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 | 2937 | apply (rule finite_inf_closed[simplified], fact+) | 
| 27701 | 2938 | done | 
| 2939 | qed | |
| 2940 | ||
| 2941 | lemma (in gcd_condition_monoid) gcd_assoc: | |
| 2942 | assumes carr: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | |
| 2943 | shows "somegcd G (somegcd G a b) c \<sim> somegcd G a (somegcd G b c)" | |
| 2944 | proof - | |
| 29237 | 2945 | interpret weak_lower_semilattice "division_rel G" by simp | 
| 27701 | 2946 | show ?thesis | 
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2947 | 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 | 2948 | 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 | 2949 | apply (rule weak_meet_assoc[simplified], fact+) | 
| 27701 | 2950 | done | 
| 2951 | qed | |
| 2952 | ||
| 2953 | lemma (in gcd_condition_monoid) gcd_mult: | |
| 2954 | assumes acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" and ccarr: "c \<in> carrier G" | |
| 2955 | shows "c \<otimes> somegcd G a b \<sim> somegcd G (c \<otimes> a) (c \<otimes> b)" | |
| 2956 | proof - (* following Jacobson, Basic Algebra, p.140 *) | |
| 2957 | let ?d = "somegcd G a b" | |
| 2958 | let ?e = "somegcd G (c \<otimes> a) (c \<otimes> b)" | |
| 2959 | note carr[simp] = acarr bcarr ccarr | |
| 2960 | have dcarr: "?d \<in> carrier G" by simp | |
| 2961 | have ecarr: "?e \<in> carrier G" by simp | |
| 2962 | note carr = carr dcarr ecarr | |
| 2963 | ||
| 2964 | have "?d divides a" by (simp add: gcd_divides_l) | |
| 2965 | hence cd'ca: "c \<otimes> ?d divides (c \<otimes> a)" by (simp add: divides_mult_lI) | |
| 2966 | ||
| 2967 | have "?d divides b" by (simp add: gcd_divides_r) | |
| 2968 | hence cd'cb: "c \<otimes> ?d divides (c \<otimes> b)" by (simp add: divides_mult_lI) | |
| 2969 | ||
| 2970 | from cd'ca cd'cb | |
| 2971 | have cd'e: "c \<otimes> ?d divides ?e" | |
| 2972 | by (rule gcd_divides) simp+ | |
| 2973 | ||
| 2974 | hence "\<exists>u. u \<in> carrier G \<and> ?e = c \<otimes> ?d \<otimes> u" | |
| 2975 | by (elim dividesE, fast) | |
| 2976 | from this obtain u | |
| 2977 | where ucarr[simp]: "u \<in> carrier G" | |
| 2978 | and e_cdu: "?e = c \<otimes> ?d \<otimes> u" | |
| 2979 | by auto | |
| 2980 | ||
| 2981 | note carr = carr ucarr | |
| 2982 | ||
| 2983 | have "?e divides c \<otimes> a" by (rule gcd_divides_l) simp+ | |
| 2984 | hence "\<exists>x. x \<in> carrier G \<and> c \<otimes> a = ?e \<otimes> x" | |
| 2985 | by (elim dividesE, fast) | |
| 2986 | from this obtain x | |
| 2987 | where xcarr: "x \<in> carrier G" | |
| 2988 | and ca_ex: "c \<otimes> a = ?e \<otimes> x" | |
| 2989 | by auto | |
| 2990 | with e_cdu | |
| 2991 | have ca_cdux: "c \<otimes> a = c \<otimes> ?d \<otimes> u \<otimes> x" by simp | |
| 2992 | ||
| 2993 | from ca_cdux xcarr | |
| 2994 | have "c \<otimes> a = c \<otimes> (?d \<otimes> u \<otimes> x)" by (simp add: m_assoc) | |
| 2995 | then have "a = ?d \<otimes> u \<otimes> x" by (rule l_cancel[of c a]) (simp add: xcarr)+ | |
| 2996 | hence du'a: "?d \<otimes> u divides a" by (rule dividesI[OF xcarr]) | |
| 2997 | ||
| 2998 | have "?e divides c \<otimes> b" by (intro gcd_divides_r, simp+) | |
| 2999 | hence "\<exists>x. x \<in> carrier G \<and> c \<otimes> b = ?e \<otimes> x" | |
| 3000 | by (elim dividesE, fast) | |
| 3001 | from this obtain x | |
| 3002 | where xcarr: "x \<in> carrier G" | |
| 3003 | and cb_ex: "c \<otimes> b = ?e \<otimes> x" | |
| 3004 | by auto | |
| 3005 | with e_cdu | |
| 3006 | have cb_cdux: "c \<otimes> b = c \<otimes> ?d \<otimes> u \<otimes> x" by simp | |
| 3007 | ||
| 3008 | from cb_cdux xcarr | |
| 3009 | have "c \<otimes> b = c \<otimes> (?d \<otimes> u \<otimes> x)" by (simp add: m_assoc) | |
| 3010 | with xcarr | |
| 3011 | have "b = ?d \<otimes> u \<otimes> x" by (intro l_cancel[of c b], simp+) | |
| 3012 | hence du'b: "?d \<otimes> u divides b" by (intro dividesI[OF xcarr]) | |
| 3013 | ||
| 3014 | from du'a du'b carr | |
| 3015 | have du'd: "?d \<otimes> u divides ?d" | |
| 3016 | by (intro gcd_divides, simp+) | |
| 3017 | hence uunit: "u \<in> Units G" | |
| 3018 | proof (elim dividesE) | |
| 3019 | fix v | |
| 3020 | assume vcarr[simp]: "v \<in> carrier G" | |
| 3021 | assume d: "?d = ?d \<otimes> u \<otimes> v" | |
| 3022 | have "?d \<otimes> \<one> = ?d \<otimes> u \<otimes> v" by simp fact | |
| 3023 | also have "?d \<otimes> u \<otimes> v = ?d \<otimes> (u \<otimes> v)" by (simp add: m_assoc) | |
| 3024 | finally have "?d \<otimes> \<one> = ?d \<otimes> (u \<otimes> v)" . | |
| 3025 | hence i2: "\<one> = u \<otimes> v" by (rule l_cancel) simp+ | |
| 3026 | hence i1: "\<one> = v \<otimes> u" by (simp add: m_comm) | |
| 3027 | from vcarr i1[symmetric] i2[symmetric] | |
| 3028 | show "u \<in> Units G" | |
| 3029 | by (unfold Units_def, simp, fast) | |
| 3030 | qed | |
| 3031 | ||
| 3032 | from e_cdu uunit | |
| 3033 | have "somegcd G (c \<otimes> a) (c \<otimes> b) \<sim> c \<otimes> somegcd G a b" | |
| 3034 | by (intro associatedI2[of u], simp+) | |
| 3035 | from this[symmetric] | |
| 3036 | show "c \<otimes> somegcd G a b \<sim> somegcd G (c \<otimes> a) (c \<otimes> b)" by simp | |
| 3037 | qed | |
| 3038 | ||
| 3039 | lemma (in monoid) assoc_subst: | |
| 3040 | assumes ab: "a \<sim> b" | |
| 3041 | and cP: "ALL a b. a : carrier G & b : carrier G & a \<sim> b | |
| 3042 | --> f a : carrier G & f b : carrier G & f a \<sim> f b" | |
| 3043 | and carr: "a \<in> carrier G" "b \<in> carrier G" | |
| 3044 | shows "f a \<sim> f b" | |
| 3045 | using assms by auto | |
| 3046 | ||
| 3047 | lemma (in gcd_condition_monoid) relprime_mult: | |
| 3048 | assumes abrelprime: "somegcd G a b \<sim> \<one>" and acrelprime: "somegcd G a c \<sim> \<one>" | |
| 3049 | and carr[simp]: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | |
| 3050 | shows "somegcd G a (b \<otimes> c) \<sim> \<one>" | |
| 3051 | proof - | |
| 3052 | have "c = c \<otimes> \<one>" by simp | |
| 3053 | also from abrelprime[symmetric] | |
| 3054 | 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 | 3055 | by (rule assoc_subst) (simp add: mult_cong_r)+ | 
| 27701 | 3056 | also have "\<dots> \<sim> somegcd G (c \<otimes> a) (c \<otimes> b)" by (rule gcd_mult) fact+ | 
| 3057 | finally | |
| 3058 | have c: "c \<sim> somegcd G (c \<otimes> a) (c \<otimes> b)" by simp | |
| 3059 | ||
| 3060 | from carr | |
| 3061 | have a: "a \<sim> somegcd G a (c \<otimes> a)" | |
| 3062 | by (fast intro: gcdI divides_prod_l) | |
| 3063 | ||
| 3064 | have "somegcd G a (b \<otimes> c) \<sim> somegcd G a (c \<otimes> b)" by (simp add: m_comm) | |
| 3065 | also from a | |
| 3066 | 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 | 3067 | by (rule assoc_subst) (simp add: gcd_cong_l)+ | 
| 27701 | 3068 | also from gcd_assoc | 
| 3069 | have "\<dots> \<sim> somegcd G a (somegcd G (c \<otimes> a) (c \<otimes> b))" | |
| 3070 | by (rule assoc_subst) simp+ | |
| 3071 | also from c[symmetric] | |
| 3072 | have "\<dots> \<sim> somegcd G a c" | |
| 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_r)+ | 
| 27701 | 3074 | also note acrelprime | 
| 3075 | finally | |
| 3076 | show "somegcd G a (b \<otimes> c) \<sim> \<one>" by simp | |
| 3077 | qed | |
| 3078 | ||
| 3079 | lemma (in gcd_condition_monoid) primeness_condition: | |
| 3080 | "primeness_condition_monoid G" | |
| 3081 | apply unfold_locales | |
| 3082 | apply (rule primeI) | |
| 3083 | apply (elim irreducibleE, assumption) | |
| 3084 | proof - | |
| 3085 | fix p a b | |
| 3086 | assume pcarr: "p \<in> carrier G" and acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" | |
| 3087 | and pirr: "irreducible G p" | |
| 3088 | and pdvdab: "p divides a \<otimes> b" | |
| 3089 | from pirr | |
| 3090 | have pnunit: "p \<notin> Units G" | |
| 3091 | and r[rule_format]: "\<forall>b. b \<in> carrier G \<and> properfactor G b p \<longrightarrow> b \<in> Units G" | |
| 3092 | by - (fast elim: irreducibleE)+ | |
| 3093 | ||
| 3094 | show "p divides a \<or> p divides b" | |
| 3095 | proof (rule ccontr, clarsimp) | |
| 3096 | assume npdvda: "\<not> p divides a" | |
| 3097 | with pcarr acarr | |
| 3098 | have "\<one> \<sim> somegcd G p a" | |
| 3099 | apply (intro gcdI, simp, simp, simp) | |
| 3100 | apply (fast intro: unit_divides) | |
| 3101 | apply (fast intro: unit_divides) | |
| 3102 | apply (clarsimp simp add: Unit_eq_dividesone[symmetric]) | |
| 3103 | apply (rule r, rule, assumption) | |
| 3104 | apply (rule properfactorI, assumption) | |
| 3105 | proof (rule ccontr, simp) | |
| 3106 | fix y | |
| 3107 | assume ycarr: "y \<in> carrier G" | |
| 3108 | assume "p divides y" | |
| 3109 | also assume "y divides a" | |
| 3110 | finally | |
| 3111 | have "p divides a" by (simp add: pcarr ycarr acarr) | |
| 3112 | with npdvda | |
| 3113 | show "False" .. | |
| 3114 | qed simp+ | |
| 3115 | with pcarr acarr | |
| 3116 | have pa: "somegcd G p a \<sim> \<one>" by (fast intro: associated_sym[of "\<one>"] gcd_closed) | |
| 3117 | ||
| 3118 | assume npdvdb: "\<not> p divides b" | |
| 3119 | with pcarr bcarr | |
| 3120 | have "\<one> \<sim> somegcd G p b" | |
| 3121 | apply (intro gcdI, simp, simp, simp) | |
| 3122 | apply (fast intro: unit_divides) | |
| 3123 | apply (fast intro: unit_divides) | |
| 3124 | apply (clarsimp simp add: Unit_eq_dividesone[symmetric]) | |
| 3125 | apply (rule r, rule, assumption) | |
| 3126 | apply (rule properfactorI, assumption) | |
| 3127 | proof (rule ccontr, simp) | |
| 3128 | fix y | |
| 3129 | assume ycarr: "y \<in> carrier G" | |
| 3130 | assume "p divides y" | |
| 3131 | also assume "y divides b" | |
| 3132 | finally have "p divides b" by (simp add: pcarr ycarr bcarr) | |
| 3133 | with npdvdb | |
| 3134 | show "False" .. | |
| 3135 | qed simp+ | |
| 3136 | with pcarr bcarr | |
| 3137 | have pb: "somegcd G p b \<sim> \<one>" by (fast intro: associated_sym[of "\<one>"] gcd_closed) | |
| 3138 | ||
| 3139 | from pcarr acarr bcarr pdvdab | |
| 3140 | have "p gcdof p (a \<otimes> b)" by (fast intro: isgcd_divides_l) | |
| 3141 | ||
| 3142 | with pcarr acarr bcarr | |
| 3143 | have "p \<sim> somegcd G p (a \<otimes> b)" by (fast intro: gcdI2) | |
| 3144 | also from pa pb pcarr acarr bcarr | |
| 3145 | have "somegcd G p (a \<otimes> b) \<sim> \<one>" by (rule relprime_mult) | |
| 3146 | finally have "p \<sim> \<one>" by (simp add: pcarr acarr bcarr) | |
| 3147 | ||
| 3148 | with pcarr | |
| 3149 | have "p \<in> Units G" by (fast intro: assoc_unit_l) | |
| 3150 | with pnunit | |
| 3151 | show "False" .. | |
| 3152 | qed | |
| 3153 | qed | |
| 3154 | ||
| 29237 | 3155 | sublocale gcd_condition_monoid \<subseteq> primeness_condition_monoid | 
| 27701 | 3156 | by (rule primeness_condition) | 
| 3157 | ||
| 3158 | ||
| 3159 | subsubsection {* Divisor chain condition *}
 | |
| 3160 | ||
| 3161 | lemma (in divisor_chain_condition_monoid) wfactors_exist: | |
| 3162 | assumes acarr: "a \<in> carrier G" | |
| 3163 | shows "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a" | |
| 3164 | proof - | |
| 3165 | have r[rule_format]: "a \<in> carrier G \<longrightarrow> (\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a)" | |
| 3166 | apply (rule wf_induct[OF division_wellfounded]) | |
| 3167 | proof - | |
| 3168 | fix x | |
| 3169 |     assume ih: "\<forall>y. (y, x) \<in> {(x, y). x \<in> carrier G \<and> y \<in> carrier G \<and> properfactor G x y}
 | |
| 3170 | \<longrightarrow> y \<in> carrier G \<longrightarrow> (\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as y)" | |
| 3171 | ||
| 3172 | show "x \<in> carrier G \<longrightarrow> (\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as x)" | |
| 3173 | apply clarify | |
| 3174 | apply (cases "x \<in> Units G") | |
| 3175 | apply (rule exI[of _ "[]"], simp) | |
| 3176 | apply (cases "irreducible G x") | |
| 3177 | apply (rule exI[of _ "[x]"], simp add: wfactors_def) | |
| 3178 | proof - | |
| 3179 | assume xcarr: "x \<in> carrier G" | |
| 3180 | and xnunit: "x \<notin> Units G" | |
| 3181 | and xnirr: "\<not> irreducible G x" | |
| 3182 | hence "\<exists>y. y \<in> carrier G \<and> properfactor G y x \<and> y \<notin> Units G" | |
| 3183 | apply - apply (rule ccontr, simp) | |
| 3184 | apply (subgoal_tac "irreducible G x", simp) | |
| 3185 | apply (rule irreducibleI, simp, simp) | |
| 3186 | done | |
| 3187 | from this obtain y | |
| 3188 | where ycarr: "y \<in> carrier G" | |
| 3189 | and ynunit: "y \<notin> Units G" | |
| 3190 | and pfyx: "properfactor G y x" | |
| 3191 | by auto | |
| 3192 | ||
| 3193 | have ih': | |
| 3194 | "\<And>y. \<lbrakk>y \<in> carrier G; properfactor G y x\<rbrakk> | |
| 3195 | \<Longrightarrow> \<exists>as. set as \<subseteq> carrier G \<and> wfactors G as y" | |
| 3196 | by (rule ih[rule_format, simplified]) (simp add: xcarr)+ | |
| 3197 | ||
| 3198 | from ycarr pfyx | |
| 3199 | have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as y" | |
| 3200 | by (rule ih') | |
| 3201 | from this obtain ys | |
| 3202 | where yscarr: "set ys \<subseteq> carrier G" | |
| 3203 | and yfs: "wfactors G ys y" | |
| 3204 | by auto | |
| 3205 | ||
| 3206 | from pfyx | |
| 3207 | have "y divides x" | |
| 3208 | and nyx: "\<not> y \<sim> x" | |
| 3209 | by - (fast elim: properfactorE2)+ | |
| 3210 | hence "\<exists>z. z \<in> carrier G \<and> x = y \<otimes> z" | |
| 3211 | by (fast elim: dividesE) | |
| 3212 | ||
| 3213 | from this obtain z | |
| 3214 | where zcarr: "z \<in> carrier G" | |
| 3215 | and x: "x = y \<otimes> z" | |
| 3216 | by auto | |
| 3217 | ||
| 3218 | from zcarr ycarr | |
| 3219 | have "properfactor G z x" | |
| 3220 | apply (subst x) | |
| 3221 | apply (intro properfactorI3[of _ _ y]) | |
| 3222 | apply (simp add: m_comm) | |
| 3223 | apply (simp add: ynunit)+ | |
| 3224 | done | |
| 3225 | with zcarr | |
| 3226 | have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as z" | |
| 3227 | by (rule ih') | |
| 3228 | from this obtain zs | |
| 3229 | where zscarr: "set zs \<subseteq> carrier G" | |
| 3230 | and zfs: "wfactors G zs z" | |
| 3231 | by auto | |
| 3232 | ||
| 3233 | from yscarr zscarr | |
| 3234 | have xscarr: "set (ys@zs) \<subseteq> carrier G" by simp | |
| 3235 | from yfs zfs ycarr zcarr yscarr zscarr | |
| 3236 | have "wfactors G (ys@zs) (y\<otimes>z)" by (rule wfactors_mult) | |
| 3237 | hence "wfactors G (ys@zs) x" by (simp add: x) | |
| 3238 | ||
| 3239 | from xscarr this | |
| 3240 | show "\<exists>xs. set xs \<subseteq> carrier G \<and> wfactors G xs x" by fast | |
| 3241 | qed | |
| 3242 | qed | |
| 3243 | ||
| 3244 | from acarr | |
| 3245 | show ?thesis by (rule r) | |
| 3246 | qed | |
| 3247 | ||
| 3248 | ||
| 3249 | subsubsection {* Primeness condition *}
 | |
| 3250 | ||
| 3251 | lemma (in comm_monoid_cancel) multlist_prime_pos: | |
| 3252 | assumes carr: "a \<in> carrier G" "set as \<subseteq> carrier G" | |
| 3253 | and aprime: "prime G a" | |
| 3254 | and "a divides (foldr (op \<otimes>) as \<one>)" | |
| 3255 | shows "\<exists>i<length as. a divides (as!i)" | |
| 3256 | proof - | |
| 3257 | have r[rule_format]: | |
| 3258 | "set as \<subseteq> carrier G \<and> a divides (foldr (op \<otimes>) as \<one>) | |
| 3259 | \<longrightarrow> (\<exists>i. i < length as \<and> a divides (as!i))" | |
| 3260 | apply (induct as) | |
| 3261 | apply clarsimp defer 1 | |
| 3262 | apply clarsimp defer 1 | |
| 3263 | proof - | |
| 3264 | assume "a divides \<one>" | |
| 3265 | with carr | |
| 3266 | have "a \<in> Units G" | |
| 3267 | by (fast intro: divides_unit[of a \<one>]) | |
| 3268 | with aprime | |
| 3269 | show "False" by (elim primeE, simp) | |
| 3270 | next | |
| 3271 | fix aa as | |
| 3272 | assume ih[rule_format]: "a divides foldr op \<otimes> as \<one> \<longrightarrow> (\<exists>i<length as. a divides as ! i)" | |
| 3273 | and carr': "aa \<in> carrier G" "set as \<subseteq> carrier G" | |
| 3274 | and "a divides aa \<otimes> foldr op \<otimes> as \<one>" | |
| 3275 | with carr aprime | |
| 3276 | have "a divides aa \<or> a divides foldr op \<otimes> as \<one>" | |
| 3277 | by (intro prime_divides) simp+ | |
| 3278 |     moreover {
 | |
| 3279 | assume "a divides aa" | |
| 3280 | hence p1: "a divides (aa#as)!0" by simp | |
| 3281 | have "0 < Suc (length as)" by simp | |
| 3282 | with p1 have "\<exists>i<Suc (length as). a divides (aa # as) ! i" by fast | |
| 3283 | } | |
| 3284 |     moreover {
 | |
| 3285 | assume "a divides foldr op \<otimes> as \<one>" | |
| 3286 | hence "\<exists>i. i < length as \<and> a divides as ! i" by (rule ih) | |
| 3287 | from this obtain i where "a divides as ! i" and len: "i < length as" by auto | |
| 3288 | hence p1: "a divides (aa#as) ! (Suc i)" by simp | |
| 3289 | from len have "Suc i < Suc (length as)" by simp | |
| 3290 | with p1 have "\<exists>i<Suc (length as). a divides (aa # as) ! i" by force | |
| 3291 | } | |
| 3292 | ultimately | |
| 3293 | show "\<exists>i<Suc (length as). a divides (aa # as) ! i" by fast | |
| 3294 | qed | |
| 3295 | ||
| 3296 | from assms | |
| 3297 | show ?thesis | |
| 3298 | by (intro r, safe) | |
| 3299 | qed | |
| 3300 | ||
| 3301 | lemma (in primeness_condition_monoid) wfactors_unique__hlp_induct: | |
| 3302 | "\<forall>a as'. a \<in> carrier G \<and> set as \<subseteq> carrier G \<and> set as' \<subseteq> carrier G \<and> | |
| 3303 | wfactors G as a \<and> wfactors G as' a \<longrightarrow> essentially_equal G as as'" | |
| 46129 | 3304 | proof (induct as) | 
| 3305 | case Nil show ?case apply auto | |
| 3306 | proof - | |
| 3307 | fix a as' | |
| 3308 | assume a: "a \<in> carrier G" | |
| 3309 | assume "wfactors G [] a" | |
| 3310 | then obtain "\<one> \<sim> a" by (auto elim: wfactorsE) | |
| 3311 | with a have "a \<in> Units G" by (auto intro: assoc_unit_r) | |
| 3312 | moreover assume "wfactors G as' a" | |
| 3313 | moreover assume "set as' \<subseteq> carrier G" | |
| 3314 | ultimately have "as' = []" by (rule unit_wfactors_empty) | |
| 3315 | then show "essentially_equal G [] as'" by simp | |
| 3316 | qed | |
| 3317 | next | |
| 3318 | case (Cons ah as) then show ?case apply clarsimp | |
| 3319 | proof - | |
| 3320 | fix a as' | |
| 3321 | assume ih [rule_format]: | |
| 3322 | "\<forall>a as'. a \<in> carrier G \<and> set as' \<subseteq> carrier G \<and> wfactors G as a \<and> | |
| 3323 | wfactors G as' a \<longrightarrow> essentially_equal G as as'" | |
| 3324 | and acarr: "a \<in> carrier G" and ahcarr: "ah \<in> carrier G" | |
| 3325 | and ascarr: "set as \<subseteq> carrier G" and as'carr: "set as' \<subseteq> carrier G" | |
| 3326 | and afs: "wfactors G (ah # as) a" | |
| 3327 | and afs': "wfactors G as' a" | |
| 3328 | hence ahdvda: "ah divides a" | |
| 27701 | 3329 | by (intro wfactors_dividesI[of "ah#as" "a"], simp+) | 
| 46129 | 3330 | hence "\<exists>a'\<in> carrier G. a = ah \<otimes> a'" by (fast elim: dividesE) | 
| 3331 | from this obtain a' | |
| 27701 | 3332 | where a'carr: "a' \<in> carrier G" | 
| 3333 | and a: "a = ah \<otimes> a'" | |
| 3334 | by auto | |
| 46129 | 3335 | have a'fs: "wfactors G as a'" | 
| 3336 | apply (rule wfactorsE[OF afs], rule wfactorsI, simp) | |
| 3337 | apply (simp add: a, insert ascarr a'carr) | |
| 3338 | apply (intro assoc_l_cancel[of ah _ a'] multlist_closed ahcarr, assumption+) | |
| 3339 | done | |
| 3340 | from afs have ahirr: "irreducible G ah" by (elim wfactorsE, simp) | |
| 3341 | with ascarr have ahprime: "prime G ah" by (intro irreducible_prime ahcarr) | |
| 3342 | ||
| 3343 | note carr [simp] = acarr ahcarr ascarr as'carr a'carr | |
| 3344 | ||
| 3345 | note ahdvda | |
| 3346 | also from afs' | |
| 3347 | have "a divides (foldr (op \<otimes>) as' \<one>)" | |
| 3348 | by (elim wfactorsE associatedE, simp) | |
| 3349 | finally have "ah divides (foldr (op \<otimes>) as' \<one>)" by simp | |
| 3350 | ||
| 3351 | with ahprime | |
| 27701 | 3352 | have "\<exists>i<length as'. ah divides as'!i" | 
| 3353 | by (intro multlist_prime_pos, simp+) | |
| 46129 | 3354 | from this obtain i | 
| 27701 | 3355 | where len: "i<length as'" and ahdvd: "ah divides as'!i" | 
| 3356 | by auto | |
| 46129 | 3357 | from afs' carr have irrasi: "irreducible G (as'!i)" | 
| 27701 | 3358 | by (fast intro: nth_mem[OF len] elim: wfactorsE) | 
| 46129 | 3359 | from len carr | 
| 27701 | 3360 | have asicarr[simp]: "as'!i \<in> carrier G" by (unfold set_conv_nth, force) | 
| 46129 | 3361 | note carr = carr asicarr | 
| 3362 | ||
| 3363 | from ahdvd have "\<exists>x \<in> carrier G. as'!i = ah \<otimes> x" by (fast elim: dividesE) | |
| 3364 | from this obtain x where "x \<in> carrier G" and asi: "as'!i = ah \<otimes> x" by auto | |
| 3365 | ||
| 3366 | with carr irrasi[simplified asi] | |
| 27701 | 3367 | have asiah: "as'!i \<sim> ah" apply - | 
| 46129 | 3368 | apply (elim irreducible_prodE[of "ah" "x"], assumption+) | 
| 3369 | apply (rule associatedI2[of x], assumption+) | |
| 3370 | apply (rule irreducibleE[OF ahirr], simp) | |
| 3371 | done | |
| 3372 | ||
| 3373 | note setparts = set_take_subset[of i as'] set_drop_subset[of "Suc i" as'] | |
| 3374 | note partscarr [simp] = setparts[THEN subset_trans[OF _ as'carr]] | |
| 3375 | note carr = carr partscarr | |
| 3376 | ||
| 3377 | have "\<exists>aa_1. aa_1 \<in> carrier G \<and> wfactors G (take i as') aa_1" | |
| 3378 | apply (intro wfactors_prod_exists) | |
| 3379 | using setparts afs' by (fast elim: wfactorsE, simp) | |
| 3380 | from this obtain aa_1 | |
| 3381 | where aa1carr: "aa_1 \<in> carrier G" | |
| 3382 | and aa1fs: "wfactors G (take i as') aa_1" | |
| 3383 | by auto | |
| 3384 | ||
| 3385 | have "\<exists>aa_2. aa_2 \<in> carrier G \<and> wfactors G (drop (Suc i) as') aa_2" | |
| 3386 | apply (intro wfactors_prod_exists) | |
| 3387 | using setparts afs' by (fast elim: wfactorsE, simp) | |
| 3388 | from this obtain aa_2 | |
| 3389 | where aa2carr: "aa_2 \<in> carrier G" | |
| 3390 | and aa2fs: "wfactors G (drop (Suc i) as') aa_2" | |
| 3391 | by auto | |
| 3392 | ||
| 3393 | note carr = carr aa1carr[simp] aa2carr[simp] | |
| 3394 | ||
| 3395 | from aa1fs aa2fs | |
| 27701 | 3396 | have v1: "wfactors G (take i as' @ drop (Suc i) as') (aa_1 \<otimes> aa_2)" | 
| 3397 | by (intro wfactors_mult, simp+) | |
| 46129 | 3398 | hence v1': "wfactors G (as'!i # take i as' @ drop (Suc i) as') (as'!i \<otimes> (aa_1 \<otimes> aa_2))" | 
| 27701 | 3399 | apply (intro wfactors_mult_single) | 
| 3400 | using setparts afs' | |
| 3401 | by (fast intro: nth_mem[OF len] elim: wfactorsE, simp+) | |
| 3402 | ||
| 46129 | 3403 | from aa2carr carr aa1fs aa2fs | 
| 27701 | 3404 | have "wfactors G (as'!i # drop (Suc i) as') (as'!i \<otimes> aa_2)" | 
| 55242 
413ec965f95d
Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
 paulson <lp15@cam.ac.uk> parents: 
53374diff
changeset | 3405 | by (metis irrasi wfactors_mult_single) | 
| 46129 | 3406 | with len carr aa1carr aa2carr aa1fs | 
| 27701 | 3407 | have v2: "wfactors G (take i as' @ as'!i # drop (Suc i) as') (aa_1 \<otimes> (as'!i \<otimes> aa_2))" | 
| 46129 | 3408 | apply (intro wfactors_mult) | 
| 3409 | apply fast | |
| 3410 | apply (simp, (fast intro: nth_mem[OF len])?)+ | |
| 3411 | done | |
| 3412 | ||
| 3413 | from len | |
| 27701 | 3414 | have as': "as' = (take i as' @ as'!i # drop (Suc i) as')" | 
| 3415 | by (simp add: drop_Suc_conv_tl) | |
| 46129 | 3416 | with carr | 
| 27701 | 3417 | have eer: "essentially_equal G (take i as' @ as'!i # drop (Suc i) as') as'" | 
| 3418 | by simp | |
| 46129 | 3419 | with v2 afs' carr aa1carr aa2carr nth_mem[OF len] | 
| 27701 | 3420 | have "aa_1 \<otimes> (as'!i \<otimes> aa_2) \<sim> a" | 
| 55242 
413ec965f95d
Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
 paulson <lp15@cam.ac.uk> parents: 
53374diff
changeset | 3421 | by (metis as' ee_wfactorsD m_closed) | 
| 46129 | 3422 | then | 
| 3423 | have t1: "as'!i \<otimes> (aa_1 \<otimes> aa_2) \<sim> a" | |
| 55242 
413ec965f95d
Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
 paulson <lp15@cam.ac.uk> parents: 
53374diff
changeset | 3424 | by (metis aa1carr aa2carr asicarr m_lcomm) | 
| 46129 | 3425 | from carr asiah | 
| 3426 | have "ah \<otimes> (aa_1 \<otimes> aa_2) \<sim> as'!i \<otimes> (aa_1 \<otimes> aa_2)" | |
| 55242 
413ec965f95d
Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
 paulson <lp15@cam.ac.uk> parents: 
53374diff
changeset | 3427 | by (metis associated_sym m_closed mult_cong_l) | 
| 46129 | 3428 | also note t1 | 
| 3429 | finally | |
| 27701 | 3430 | have "ah \<otimes> (aa_1 \<otimes> aa_2) \<sim> a" by simp | 
| 3431 | ||
| 46129 | 3432 | with carr aa1carr aa2carr a'carr nth_mem[OF len] | 
| 27701 | 3433 | have a': "aa_1 \<otimes> aa_2 \<sim> a'" | 
| 3434 | by (simp add: a, fast intro: assoc_l_cancel[of ah _ a']) | |
| 3435 | ||
| 46129 | 3436 | note v1 | 
| 3437 | also note a' | |
| 3438 | finally have "wfactors G (take i as' @ drop (Suc i) as') a'" by simp | |
| 3439 | ||
| 3440 | from a'fs this carr | |
| 27701 | 3441 | have "essentially_equal G as (take i as' @ drop (Suc i) as')" | 
| 3442 | by (intro ih[of a']) simp | |
| 3443 | ||
| 46129 | 3444 | hence ee1: "essentially_equal G (ah # as) (ah # take i as' @ drop (Suc i) as')" | 
| 3445 | apply (elim essentially_equalE) apply (fastforce intro: essentially_equalI) | |
| 3446 | done | |
| 3447 | ||
| 3448 | from carr | |
| 3449 | have ee2: "essentially_equal G (ah # take i as' @ drop (Suc i) as') | |
| 3450 | (as' ! i # take i as' @ drop (Suc i) as')" | |
| 3451 | proof (intro essentially_equalI) | |
| 3452 | show "ah # take i as' @ drop (Suc i) as' <~~> ah # take i as' @ drop (Suc i) as'" | |
| 27701 | 3453 | by simp | 
| 46129 | 3454 | next | 
| 3455 | show "ah # take i as' @ drop (Suc i) as' [\<sim>] as' ! i # take i as' @ drop (Suc i) as'" | |
| 3456 | apply (simp add: list_all2_append) | |
| 3457 | apply (simp add: asiah[symmetric] ahcarr asicarr) | |
| 3458 | done | |
| 3459 | qed | |
| 3460 | ||
| 3461 | note ee1 | |
| 3462 | also note ee2 | |
| 3463 | also have "essentially_equal G (as' ! i # take i as' @ drop (Suc i) as') | |
| 3464 | (take i as' @ as' ! i # drop (Suc i) as')" | |
| 3465 | apply (intro essentially_equalI) | |
| 3466 | apply (subgoal_tac "as' ! i # take i as' @ drop (Suc i) as' <~~> | |
| 3467 | take i as' @ as' ! i # drop (Suc i) as'") | |
| 3468 | apply simp | |
| 3469 | apply (rule perm_append_Cons) | |
| 3470 | apply simp | |
| 27701 | 3471 | done | 
| 46129 | 3472 | finally | 
| 3473 | have "essentially_equal G (ah # as) (take i as' @ as' ! i # drop (Suc i) as')" by simp | |
| 3474 | then show "essentially_equal G (ah # as) as'" by (subst as', assumption) | |
| 27701 | 3475 | qed | 
| 3476 | qed | |
| 3477 | ||
| 3478 | lemma (in primeness_condition_monoid) wfactors_unique: | |
| 3479 | assumes "wfactors G as a" "wfactors G as' a" | |
| 3480 | and "a \<in> carrier G" "set as \<subseteq> carrier G" "set as' \<subseteq> carrier G" | |
| 3481 | shows "essentially_equal G as as'" | |
| 3482 | apply (rule wfactors_unique__hlp_induct[rule_format, of a]) | |
| 3483 | apply (simp add: assms) | |
| 3484 | done | |
| 3485 | ||
| 3486 | ||
| 3487 | subsubsection {* Application to factorial monoids *}
 | |
| 3488 | ||
| 3489 | text {* Number of factors for wellfoundedness *}
 | |
| 3490 | ||
| 35848 
5443079512ea
slightly more uniform definitions -- eliminated old-style meta-equality;
 wenzelm parents: 
35847diff
changeset | 3491 | definition | 
| 
5443079512ea
slightly more uniform definitions -- eliminated old-style meta-equality;
 wenzelm parents: 
35847diff
changeset | 3492 | factorcount :: "_ \<Rightarrow> 'a \<Rightarrow> nat" where | 
| 
5443079512ea
slightly more uniform definitions -- eliminated old-style meta-equality;
 wenzelm parents: 
35847diff
changeset | 3493 | "factorcount G a = | 
| 
5443079512ea
slightly more uniform definitions -- eliminated old-style meta-equality;
 wenzelm parents: 
35847diff
changeset | 3494 | (THE c. (ALL as. set as \<subseteq> carrier G \<and> wfactors G as a \<longrightarrow> c = length as))" | 
| 27701 | 3495 | |
| 3496 | lemma (in monoid) ee_length: | |
| 3497 | assumes ee: "essentially_equal G as bs" | |
| 3498 | shows "length as = length bs" | |
| 3499 | apply (rule essentially_equalE[OF ee]) | |
| 36278 | 3500 | apply (metis list_all2_conv_all_nth perm_length) | 
| 27701 | 3501 | done | 
| 3502 | ||
| 3503 | lemma (in factorial_monoid) factorcount_exists: | |
| 3504 | assumes carr[simp]: "a \<in> carrier G" | |
| 3505 | shows "EX c. ALL as. set as \<subseteq> carrier G \<and> wfactors G as a \<longrightarrow> c = length as" | |
| 3506 | proof - | |
| 3507 | have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a" by (intro wfactors_exist, simp) | |
| 3508 | from this obtain as | |
| 3509 | where ascarr[simp]: "set as \<subseteq> carrier G" | |
| 3510 | and afs: "wfactors G as a" | |
| 3511 | by (auto simp del: carr) | |
| 3512 | have "ALL as'. set as' \<subseteq> carrier G \<and> wfactors G as' a \<longrightarrow> length as = length as'" | |
| 36278 | 3513 | by (metis afs ascarr assms ee_length wfactors_unique) | 
| 27701 | 3514 | thus "EX c. ALL as'. set as' \<subseteq> carrier G \<and> wfactors G as' a \<longrightarrow> c = length as'" .. | 
| 3515 | qed | |
| 3516 | ||
| 3517 | lemma (in factorial_monoid) factorcount_unique: | |
| 3518 | assumes afs: "wfactors G as a" | |
| 3519 | and acarr[simp]: "a \<in> carrier G" and ascarr[simp]: "set as \<subseteq> carrier G" | |
| 3520 | shows "factorcount G a = length as" | |
| 3521 | proof - | |
| 3522 | have "EX ac. ALL as. set as \<subseteq> carrier G \<and> wfactors G as a \<longrightarrow> ac = length as" by (rule factorcount_exists, simp) | |
| 3523 | from this obtain ac where | |
| 3524 | alen: "ALL as. set as \<subseteq> carrier G \<and> wfactors G as a \<longrightarrow> ac = length as" | |
| 3525 | by auto | |
| 3526 | have ac: "ac = factorcount G a" | |
| 3527 | apply (simp add: factorcount_def) | |
| 3528 | apply (rule theI2) | |
| 3529 | apply (rule alen) | |
| 55242 
413ec965f95d
Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
 paulson <lp15@cam.ac.uk> parents: 
53374diff
changeset | 3530 | apply (metis afs alen ascarr)+ | 
| 27701 | 3531 | done | 
| 3532 | ||
| 3533 | from ascarr afs have "ac = length as" by (iprover intro: alen[rule_format]) | |
| 3534 | with ac show ?thesis by simp | |
| 3535 | qed | |
| 3536 | ||
| 3537 | lemma (in factorial_monoid) divides_fcount: | |
| 3538 | assumes dvd: "a divides b" | |
| 3539 | and acarr: "a \<in> carrier G" and bcarr:"b \<in> carrier G" | |
| 3540 | shows "factorcount G a <= factorcount G b" | |
| 3541 | apply (rule dividesE[OF dvd]) | |
| 3542 | proof - | |
| 3543 | fix c | |
| 3544 | from assms | |
| 3545 | have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a" by fast | |
| 3546 | from this obtain as | |
| 3547 | where ascarr: "set as \<subseteq> carrier G" | |
| 3548 | and afs: "wfactors G as a" | |
| 3549 | by auto | |
| 3550 | with acarr have fca: "factorcount G a = length as" by (intro factorcount_unique) | |
| 3551 | ||
| 3552 | assume ccarr: "c \<in> carrier G" | |
| 3553 | hence "\<exists>cs. set cs \<subseteq> carrier G \<and> wfactors G cs c" by fast | |
| 3554 | from this obtain cs | |
| 3555 | where cscarr: "set cs \<subseteq> carrier G" | |
| 3556 | and cfs: "wfactors G cs c" | |
| 3557 | by auto | |
| 3558 | ||
| 3559 | note [simp] = acarr bcarr ccarr ascarr cscarr | |
| 3560 | ||
| 3561 | assume b: "b = a \<otimes> c" | |
| 3562 | from afs cfs | |
| 3563 | have "wfactors G (as@cs) (a \<otimes> c)" by (intro wfactors_mult, simp+) | |
| 3564 | with b have "wfactors G (as@cs) b" by simp | |
| 3565 | hence "factorcount G b = length (as@cs)" by (intro factorcount_unique, simp+) | |
| 3566 | hence "factorcount G b = length as + length cs" by simp | |
| 3567 | with fca show ?thesis by simp | |
| 3568 | qed | |
| 3569 | ||
| 3570 | lemma (in factorial_monoid) associated_fcount: | |
| 3571 | assumes acarr: "a \<in> carrier G" and bcarr:"b \<in> carrier G" | |
| 3572 | and asc: "a \<sim> b" | |
| 3573 | shows "factorcount G a = factorcount G b" | |
| 3574 | apply (rule associatedE[OF asc]) | |
| 3575 | apply (drule divides_fcount[OF _ acarr bcarr]) | |
| 3576 | apply (drule divides_fcount[OF _ bcarr acarr]) | |
| 3577 | apply simp | |
| 3578 | done | |
| 3579 | ||
| 3580 | lemma (in factorial_monoid) properfactor_fcount: | |
| 3581 | assumes acarr: "a \<in> carrier G" and bcarr:"b \<in> carrier G" | |
| 3582 | and pf: "properfactor G a b" | |
| 3583 | shows "factorcount G a < factorcount G b" | |
| 3584 | apply (rule properfactorE[OF pf], elim dividesE) | |
| 3585 | proof - | |
| 3586 | fix c | |
| 3587 | from assms | |
| 3588 | have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a" by fast | |
| 3589 | from this obtain as | |
| 3590 | where ascarr: "set as \<subseteq> carrier G" | |
| 3591 | and afs: "wfactors G as a" | |
| 3592 | by auto | |
| 3593 | with acarr have fca: "factorcount G a = length as" by (intro factorcount_unique) | |
| 3594 | ||
| 3595 | assume ccarr: "c \<in> carrier G" | |
| 3596 | hence "\<exists>cs. set cs \<subseteq> carrier G \<and> wfactors G cs c" by fast | |
| 3597 | from this obtain cs | |
| 3598 | where cscarr: "set cs \<subseteq> carrier G" | |
| 3599 | and cfs: "wfactors G cs c" | |
| 3600 | by auto | |
| 3601 | ||
| 3602 | assume b: "b = a \<otimes> c" | |
| 3603 | ||
| 3604 | have "wfactors G (as@cs) (a \<otimes> c)" by (rule wfactors_mult) fact+ | |
| 3605 | with b | |
| 3606 | have "wfactors G (as@cs) b" by simp | |
| 3607 | with ascarr cscarr bcarr | |
| 3608 | have "factorcount G b = length (as@cs)" by (simp add: factorcount_unique) | |
| 3609 | hence fcb: "factorcount G b = length as + length cs" by simp | |
| 3610 | ||
| 3611 | assume nbdvda: "\<not> b divides a" | |
| 3612 | have "c \<notin> Units G" | |
| 3613 | proof (rule ccontr, simp) | |
| 3614 | assume cunit:"c \<in> Units G" | |
| 3615 | ||
| 3616 | have "b \<otimes> inv c = a \<otimes> c \<otimes> inv c" by (simp add: b) | |
| 53374 
a14d2a854c02
tuned proofs -- clarified flow of facts wrt. calculation;
 wenzelm parents: 
50037diff
changeset | 3617 | also from ccarr acarr cunit | 
| 27701 | 3618 | have "\<dots> = a \<otimes> (c \<otimes> inv c)" by (fast intro: m_assoc) | 
| 53374 
a14d2a854c02
tuned proofs -- clarified flow of facts wrt. calculation;
 wenzelm parents: 
50037diff
changeset | 3619 | also from ccarr cunit | 
| 27701 | 3620 | have "\<dots> = a \<otimes> \<one>" by (simp add: Units_r_inv) | 
| 53374 
a14d2a854c02
tuned proofs -- clarified flow of facts wrt. calculation;
 wenzelm parents: 
50037diff
changeset | 3621 | also from acarr | 
| 27701 | 3622 | have "\<dots> = a" by simp | 
| 3623 | finally have "a = b \<otimes> inv c" by simp | |
| 3624 | with ccarr cunit | |
| 3625 | have "b divides a" by (fast intro: dividesI[of "inv c"]) | |
| 3626 | with nbdvda show False by simp | |
| 3627 | qed | |
| 3628 | ||
| 3629 | with cfs have "length cs > 0" | |
| 36278 | 3630 | apply - | 
| 3631 | apply (rule ccontr, simp) | |
| 3632 | apply (metis Units_one_closed ccarr cscarr l_one one_closed properfactorI3 properfactor_fmset unit_wfactors) | |
| 3633 | done | |
| 27701 | 3634 | with fca fcb show ?thesis by simp | 
| 3635 | qed | |
| 3636 | ||
| 29237 | 3637 | sublocale factorial_monoid \<subseteq> divisor_chain_condition_monoid | 
| 27701 | 3638 | apply unfold_locales | 
| 3639 | apply (rule wfUNIVI) | |
| 3640 | apply (rule measure_induct[of "factorcount G"]) | |
| 36278 | 3641 | apply simp | 
| 3642 | apply (metis properfactor_fcount) | |
| 3643 | done | |
| 27701 | 3644 | |
| 29237 | 3645 | sublocale factorial_monoid \<subseteq> primeness_condition_monoid | 
| 44655 | 3646 | by default (rule irreducible_is_prime) | 
| 27701 | 3647 | |
| 3648 | ||
| 3649 | lemma (in factorial_monoid) primeness_condition: | |
| 3650 | shows "primeness_condition_monoid G" | |
| 28823 | 3651 | .. | 
| 27701 | 3652 | |
| 3653 | lemma (in factorial_monoid) gcd_condition [simp]: | |
| 3654 | shows "gcd_condition_monoid G" | |
| 44655 | 3655 | by default (rule gcdof_exists) | 
| 27701 | 3656 | |
| 29237 | 3657 | sublocale factorial_monoid \<subseteq> gcd_condition_monoid | 
| 44655 | 3658 | by default (rule gcdof_exists) | 
| 27701 | 3659 | |
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 3660 | 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 | 3661 | shows "weak_lattice (division_rel G)" | 
| 27701 | 3662 | proof - | 
| 29237 | 3663 | 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 | 3664 | |
| 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 3665 | show "weak_lattice (division_rel G)" | 
| 27701 | 3666 | apply (unfold_locales, simp_all) | 
| 3667 | proof - | |
| 3668 | fix x y | |
| 3669 | assume carr: "x \<in> carrier G" "y \<in> carrier G" | |
| 3670 | ||
| 3671 | hence "\<exists>z. z \<in> carrier G \<and> z lcmof x y" by (rule lcmof_exists) | |
| 3672 | from this obtain z | |
| 3673 | where zcarr: "z \<in> carrier G" | |
| 3674 | and isgcd: "z lcmof x y" | |
| 3675 | by auto | |
| 3676 | with carr | |
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 3677 |     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 | 3678 | 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 | 3679 |     thus "\<exists>z. least (division_rel G) z (Upper (division_rel G) {x, y})" by fast
 | 
| 27701 | 3680 | qed | 
| 3681 | qed | |
| 3682 | ||
| 3683 | ||
| 27717 
21bbd410ba04
Generalised polynomial lemmas from cring to ring.
 ballarin parents: 
27713diff
changeset | 3684 | subsection {* Factoriality Theorems *}
 | 
| 27701 | 3685 | |
| 3686 | theorem factorial_condition_one: (* Jacobson theorem 2.21 *) | |
| 3687 | shows "(divisor_chain_condition_monoid G \<and> primeness_condition_monoid G) = | |
| 3688 | factorial_monoid G" | |
| 3689 | apply rule | |
| 3690 | proof clarify | |
| 3691 | assume dcc: "divisor_chain_condition_monoid G" | |
| 3692 | and pc: "primeness_condition_monoid G" | |
| 29237 | 3693 | interpret divisor_chain_condition_monoid "G" by (rule dcc) | 
| 3694 | interpret primeness_condition_monoid "G" by (rule pc) | |
| 27701 | 3695 | |
| 3696 | show "factorial_monoid G" | |
| 3697 | by (fast intro: factorial_monoidI wfactors_exist wfactors_unique) | |
| 3698 | next | |
| 3699 | assume fm: "factorial_monoid G" | |
| 29237 | 3700 | interpret factorial_monoid "G" by (rule fm) | 
| 27701 | 3701 | show "divisor_chain_condition_monoid G \<and> primeness_condition_monoid G" | 
| 3702 | by rule unfold_locales | |
| 3703 | qed | |
| 3704 | ||
| 3705 | theorem factorial_condition_two: (* Jacobson theorem 2.22 *) | |
| 3706 | shows "(divisor_chain_condition_monoid G \<and> gcd_condition_monoid G) = factorial_monoid G" | |
| 3707 | apply rule | |
| 3708 | proof clarify | |
| 3709 | assume dcc: "divisor_chain_condition_monoid G" | |
| 3710 | and gc: "gcd_condition_monoid G" | |
| 29237 | 3711 | interpret divisor_chain_condition_monoid "G" by (rule dcc) | 
| 3712 | interpret gcd_condition_monoid "G" by (rule gc) | |
| 27701 | 3713 | show "factorial_monoid G" | 
| 3714 | by (simp add: factorial_condition_one[symmetric], rule, unfold_locales) | |
| 3715 | next | |
| 3716 | assume fm: "factorial_monoid G" | |
| 29237 | 3717 | interpret factorial_monoid "G" by (rule fm) | 
| 27701 | 3718 | show "divisor_chain_condition_monoid G \<and> gcd_condition_monoid G" | 
| 3719 | by rule unfold_locales | |
| 3720 | qed | |
| 3721 | ||
| 3722 | end |