| author | wenzelm | 
| Sat, 04 Apr 2020 20:06:15 +0200 | |
| changeset 71687 | f17be1db8381 | 
| parent 70215 | 8371a25ca177 | 
| child 73297 | beaff25452d2 | 
| permissions | -rw-r--r-- | 
| 41959 | 1 | (* Title: HOL/Algebra/Divisibility.thy | 
| 2 | Author: Clemens Ballarin | |
| 3 | Author: Stephan Hohe | |
| 27701 | 4 | *) | 
| 5 | ||
| 61382 | 6 | section \<open>Divisibility in monoids and rings\<close> | 
| 41959 | 7 | |
| 27701 | 8 | theory Divisibility | 
| 66579 | 9 | imports "HOL-Library.Permutation" Coset Group | 
| 27701 | 10 | begin | 
| 11 | ||
| 61382 | 12 | section \<open>Factorial Monoids\<close> | 
| 13 | ||
| 14 | subsection \<open>Monoids with Cancellation Law\<close> | |
| 27701 | 15 | |
| 16 | locale monoid_cancel = monoid + | |
| 63832 | 17 | assumes l_cancel: "\<lbrakk>c \<otimes> a = c \<otimes> b; a \<in> carrier G; b \<in> carrier G; c \<in> carrier G\<rbrakk> \<Longrightarrow> a = b" | 
| 18 | and r_cancel: "\<lbrakk>a \<otimes> c = b \<otimes> c; a \<in> carrier G; b \<in> carrier G; c \<in> carrier G\<rbrakk> \<Longrightarrow> a = b" | |
| 27701 | 19 | |
| 20 | lemma (in monoid) monoid_cancelI: | |
| 63832 | 21 | assumes l_cancel: "\<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" | 
| 22 | and r_cancel: "\<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" | |
| 27701 | 23 | shows "monoid_cancel G" | 
| 61169 | 24 | by standard fact+ | 
| 27701 | 25 | |
| 63832 | 26 | lemma (in monoid_cancel) is_monoid_cancel: "monoid_cancel G" .. | 
| 27701 | 27 | |
| 29237 | 28 | sublocale group \<subseteq> monoid_cancel | 
| 61169 | 29 | by standard simp_all | 
| 27701 | 30 | |
| 31 | ||
| 32 | locale comm_monoid_cancel = monoid_cancel + comm_monoid | |
| 33 | ||
| 34 | lemma comm_monoid_cancelI: | |
| 28599 | 35 | fixes G (structure) | 
| 36 | assumes "comm_monoid G" | |
| 63832 | 37 | assumes cancel: "\<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" | 
| 27701 | 38 | shows "comm_monoid_cancel G" | 
| 28599 | 39 | proof - | 
| 29237 | 40 | interpret comm_monoid G by fact | 
| 28599 | 41 | show "comm_monoid_cancel G" | 
| 36278 | 42 | by unfold_locales (metis assms(2) m_ac(2))+ | 
| 28599 | 43 | qed | 
| 27701 | 44 | |
| 63832 | 45 | lemma (in comm_monoid_cancel) is_comm_monoid_cancel: "comm_monoid_cancel G" | 
| 28823 | 46 | by intro_locales | 
| 27701 | 47 | |
| 63832 | 48 | sublocale comm_group \<subseteq> comm_monoid_cancel .. | 
| 27701 | 49 | |
| 50 | ||
| 61382 | 51 | subsection \<open>Products of Units in Monoids\<close> | 
| 27701 | 52 | |
| 53 | lemma (in monoid) prod_unit_l: | |
| 63832 | 54 | assumes abunit[simp]: "a \<otimes> b \<in> Units G" | 
| 55 | and aunit[simp]: "a \<in> Units G" | |
| 27701 | 56 | and carr[simp]: "a \<in> carrier G" "b \<in> carrier G" | 
| 57 | shows "b \<in> Units G" | |
| 58 | proof - | |
| 59 | have c: "inv (a \<otimes> b) \<otimes> a \<in> carrier G" by simp | |
| 60 | ||
| 63832 | 61 | have "(inv (a \<otimes> b) \<otimes> a) \<otimes> b = inv (a \<otimes> b) \<otimes> (a \<otimes> b)" | 
| 62 | by (simp add: m_assoc) | |
| 57865 | 63 | also have "\<dots> = \<one>" by simp | 
| 27701 | 64 | finally have li: "(inv (a \<otimes> b) \<otimes> a) \<otimes> b = \<one>" . | 
| 65 | ||
| 66 | have "\<one> = inv a \<otimes> a" by (simp add: Units_l_inv[symmetric]) | |
| 67 | also have "\<dots> = inv a \<otimes> \<one> \<otimes> a" by simp | |
| 68 | also have "\<dots> = inv a \<otimes> ((a \<otimes> b) \<otimes> inv (a \<otimes> b)) \<otimes> a" | |
| 63832 | 69 | by (simp add: Units_r_inv[OF abunit, symmetric] del: Units_r_inv) | 
| 27701 | 70 | also have "\<dots> = ((inv a \<otimes> a) \<otimes> b) \<otimes> inv (a \<otimes> b) \<otimes> a" | 
| 71 | by (simp add: m_assoc del: Units_l_inv) | |
| 57865 | 72 | also have "\<dots> = b \<otimes> inv (a \<otimes> b) \<otimes> a" by simp | 
| 27701 | 73 | also have "\<dots> = b \<otimes> (inv (a \<otimes> b) \<otimes> a)" by (simp add: m_assoc) | 
| 74 | finally have ri: "b \<otimes> (inv (a \<otimes> b) \<otimes> a) = \<one> " by simp | |
| 75 | ||
| 63832 | 76 | from c li ri show "b \<in> Units G" by (auto simp: Units_def) | 
| 27701 | 77 | qed | 
| 78 | ||
| 79 | lemma (in monoid) prod_unit_r: | |
| 63832 | 80 | assumes abunit[simp]: "a \<otimes> b \<in> Units G" | 
| 81 | and bunit[simp]: "b \<in> Units G" | |
| 27701 | 82 | and carr[simp]: "a \<in> carrier G" "b \<in> carrier G" | 
| 83 | shows "a \<in> Units G" | |
| 84 | proof - | |
| 85 | have c: "b \<otimes> inv (a \<otimes> b) \<in> carrier G" by simp | |
| 86 | ||
| 87 | have "a \<otimes> (b \<otimes> inv (a \<otimes> b)) = (a \<otimes> b) \<otimes> inv (a \<otimes> b)" | |
| 88 | by (simp add: m_assoc del: Units_r_inv) | |
| 89 | also have "\<dots> = \<one>" by simp | |
| 90 | finally have li: "a \<otimes> (b \<otimes> inv (a \<otimes> b)) = \<one>" . | |
| 91 | ||
| 92 | have "\<one> = b \<otimes> inv b" by (simp add: Units_r_inv[symmetric]) | |
| 93 | also have "\<dots> = b \<otimes> \<one> \<otimes> inv b" by simp | |
| 63832 | 94 | also have "\<dots> = b \<otimes> (inv (a \<otimes> b) \<otimes> (a \<otimes> b)) \<otimes> inv b" | 
| 95 | by (simp add: Units_l_inv[OF abunit, symmetric] del: Units_l_inv) | |
| 27701 | 96 | also have "\<dots> = (b \<otimes> inv (a \<otimes> b) \<otimes> a) \<otimes> (b \<otimes> inv b)" | 
| 97 | by (simp add: m_assoc del: Units_l_inv) | |
| 98 | also have "\<dots> = b \<otimes> inv (a \<otimes> b) \<otimes> a" by simp | |
| 99 | finally have ri: "(b \<otimes> inv (a \<otimes> b)) \<otimes> a = \<one> " by simp | |
| 100 | ||
| 63832 | 101 | from c li ri show "a \<in> Units G" by (auto simp: Units_def) | 
| 27701 | 102 | qed | 
| 103 | ||
| 104 | lemma (in comm_monoid) unit_factor: | |
| 105 | assumes abunit: "a \<otimes> b \<in> Units G" | |
| 106 | and [simp]: "a \<in> carrier G" "b \<in> carrier G" | |
| 107 | shows "a \<in> Units G" | |
| 63832 | 108 | using abunit[simplified Units_def] | 
| 27701 | 109 | proof clarsimp | 
| 110 | fix i | |
| 111 | assume [simp]: "i \<in> carrier G" | |
| 112 | ||
| 113 | have carr': "b \<otimes> i \<in> carrier G" by simp | |
| 114 | ||
| 115 | have "(b \<otimes> i) \<otimes> a = (i \<otimes> b) \<otimes> a" by (simp add: m_comm) | |
| 116 | also have "\<dots> = i \<otimes> (b \<otimes> a)" by (simp add: m_assoc) | |
| 117 | also have "\<dots> = i \<otimes> (a \<otimes> b)" by (simp add: m_comm) | |
| 63832 | 118 | also assume "i \<otimes> (a \<otimes> b) = \<one>" | 
| 27701 | 119 | finally have li': "(b \<otimes> i) \<otimes> a = \<one>" . | 
| 120 | ||
| 121 | have "a \<otimes> (b \<otimes> i) = a \<otimes> b \<otimes> i" by (simp add: m_assoc) | |
| 63832 | 122 | also assume "a \<otimes> b \<otimes> i = \<one>" | 
| 27701 | 123 | finally have ri': "a \<otimes> (b \<otimes> i) = \<one>" . | 
| 124 | ||
| 125 | from carr' li' ri' | |
| 63832 | 126 | show "a \<in> Units G" by (simp add: Units_def, fast) | 
| 27701 | 127 | qed | 
| 128 | ||
| 35849 | 129 | |
| 61382 | 130 | subsection \<open>Divisibility and Association\<close> | 
| 131 | ||
| 132 | subsubsection \<open>Function definitions\<close> | |
| 27701 | 133 | |
| 63832 | 134 | definition factor :: "[_, 'a, 'a] \<Rightarrow> bool" (infix "divides\<index>" 65) | 
| 35848 
5443079512ea
slightly more uniform definitions -- eliminated old-style meta-equality;
 wenzelm parents: 
35847diff
changeset | 135 | where "a divides\<^bsub>G\<^esub> b \<longleftrightarrow> (\<exists>c\<in>carrier G. b = a \<otimes>\<^bsub>G\<^esub> c)" | 
| 35847 | 136 | |
| 63832 | 137 | definition associated :: "[_, 'a, 'a] \<Rightarrow> bool" (infix "\<sim>\<index>" 55) | 
| 35848 
5443079512ea
slightly more uniform definitions -- eliminated old-style meta-equality;
 wenzelm parents: 
35847diff
changeset | 138 | where "a \<sim>\<^bsub>G\<^esub> b \<longleftrightarrow> a divides\<^bsub>G\<^esub> b \<and> b divides\<^bsub>G\<^esub> a" | 
| 27701 | 139 | |
| 67399 | 140 | abbreviation "division_rel G \<equiv> \<lparr>carrier = carrier G, eq = (\<sim>\<^bsub>G\<^esub>), le = (divides\<^bsub>G\<^esub>)\<rparr>" | 
| 63832 | 141 | |
| 142 | definition properfactor :: "[_, 'a, 'a] \<Rightarrow> bool" | |
| 35848 
5443079512ea
slightly more uniform definitions -- eliminated old-style meta-equality;
 wenzelm parents: 
35847diff
changeset | 143 | where "properfactor G a b \<longleftrightarrow> a divides\<^bsub>G\<^esub> b \<and> \<not>(b divides\<^bsub>G\<^esub> a)" | 
| 35847 | 144 | |
| 63832 | 145 | definition irreducible :: "[_, 'a] \<Rightarrow> bool" | 
| 35848 
5443079512ea
slightly more uniform definitions -- eliminated old-style meta-equality;
 wenzelm parents: 
35847diff
changeset | 146 | 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 | 147 | |
| 63832 | 148 | definition prime :: "[_, 'a] \<Rightarrow> bool" | 
| 149 | where "prime G p \<longleftrightarrow> | |
| 150 | p \<notin> Units G \<and> | |
| 35847 | 151 | (\<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 | 152 | |
| 153 | ||
| 61382 | 154 | subsubsection \<open>Divisibility\<close> | 
| 27701 | 155 | |
| 156 | lemma dividesI: | |
| 157 | fixes G (structure) | |
| 158 | assumes carr: "c \<in> carrier G" | |
| 159 | and p: "b = a \<otimes> c" | |
| 160 | shows "a divides b" | |
| 63832 | 161 | unfolding factor_def using assms by fast | 
| 27701 | 162 | |
| 163 | lemma dividesI' [intro]: | |
| 63832 | 164 | fixes G (structure) | 
| 27701 | 165 | assumes p: "b = a \<otimes> c" | 
| 166 | and carr: "c \<in> carrier G" | |
| 167 | shows "a divides b" | |
| 63832 | 168 | using assms by (fast intro: dividesI) | 
| 27701 | 169 | |
| 170 | lemma dividesD: | |
| 171 | fixes G (structure) | |
| 172 | assumes "a divides b" | |
| 173 | shows "\<exists>c\<in>carrier G. b = a \<otimes> c" | |
| 63832 | 174 | using assms unfolding factor_def by fast | 
| 27701 | 175 | |
| 176 | lemma dividesE [elim]: | |
| 177 | fixes G (structure) | |
| 178 | assumes d: "a divides b" | |
| 179 | and elim: "\<And>c. \<lbrakk>b = a \<otimes> c; c \<in> carrier G\<rbrakk> \<Longrightarrow> P" | |
| 180 | shows "P" | |
| 181 | proof - | |
| 63846 | 182 | from dividesD[OF d] obtain c where "c \<in> carrier G" and "b = a \<otimes> c" by auto | 
| 63832 | 183 | then show P by (elim elim) | 
| 27701 | 184 | qed | 
| 185 | ||
| 186 | lemma (in monoid) divides_refl[simp, intro!]: | |
| 187 | assumes carr: "a \<in> carrier G" | |
| 188 | shows "a divides a" | |
| 63832 | 189 | by (intro dividesI[of "\<one>"]) (simp_all add: carr) | 
| 27701 | 190 | |
| 191 | lemma (in monoid) divides_trans [trans]: | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 192 | assumes dvds: "a divides b" "b divides c" | 
| 27701 | 193 | and acarr: "a \<in> carrier G" | 
| 194 | shows "a divides c" | |
| 63832 | 195 | using dvds[THEN dividesD] by (blast intro: dividesI m_assoc acarr) | 
| 27701 | 196 | |
| 197 | lemma (in monoid) divides_mult_lI [intro]: | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 198 | assumes "a divides b" "a \<in> carrier G" "c \<in> carrier G" | 
| 27701 | 199 | shows "(c \<otimes> a) divides (c \<otimes> b)" | 
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 200 | by (metis assms factor_def m_assoc) | 
| 27701 | 201 | |
| 202 | lemma (in monoid_cancel) divides_mult_l [simp]: | |
| 203 | assumes carr: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | |
| 204 | shows "(c \<otimes> a) divides (c \<otimes> b) = a divides b" | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 205 | proof | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 206 | show "c \<otimes> a divides c \<otimes> b \<Longrightarrow> a divides b" | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 207 | using carr monoid.m_assoc monoid_axioms monoid_cancel.l_cancel monoid_cancel_axioms by fastforce | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 208 | show "a divides b \<Longrightarrow> c \<otimes> a divides c \<otimes> b" | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 209 | using carr(1) carr(3) by blast | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 210 | qed | 
| 27701 | 211 | |
| 212 | lemma (in comm_monoid) divides_mult_rI [intro]: | |
| 213 | assumes ab: "a divides b" | |
| 214 | and carr: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | |
| 215 | shows "(a \<otimes> c) divides (b \<otimes> c)" | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 216 | using carr ab by (metis divides_mult_lI m_comm) | 
| 27701 | 217 | |
| 218 | lemma (in comm_monoid_cancel) divides_mult_r [simp]: | |
| 219 | assumes carr: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | |
| 220 | shows "(a \<otimes> c) divides (b \<otimes> c) = a divides b" | |
| 63832 | 221 | using carr by (simp add: m_comm[of a c] m_comm[of b c]) | 
| 27701 | 222 | |
| 223 | lemma (in monoid) divides_prod_r: | |
| 224 | assumes ab: "a divides b" | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 225 | and carr: "a \<in> carrier G" "c \<in> carrier G" | 
| 27701 | 226 | shows "a divides (b \<otimes> c)" | 
| 63832 | 227 | using ab carr by (fast intro: m_assoc) | 
| 27701 | 228 | |
| 229 | lemma (in comm_monoid) divides_prod_l: | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 230 | assumes "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" "a divides b" | 
| 27701 | 231 | shows "a divides (c \<otimes> b)" | 
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 232 | using assms by (simp add: divides_prod_r m_comm) | 
| 27701 | 233 | |
| 234 | lemma (in monoid) unit_divides: | |
| 235 | assumes uunit: "u \<in> Units G" | |
| 63832 | 236 | and acarr: "a \<in> carrier G" | 
| 27701 | 237 | shows "u divides a" | 
| 238 | proof (intro dividesI[of "(inv u) \<otimes> a"], fast intro: uunit acarr) | |
| 63832 | 239 | from uunit acarr have xcarr: "inv u \<otimes> a \<in> carrier G" by fast | 
| 240 | from uunit acarr have "u \<otimes> (inv u \<otimes> a) = (u \<otimes> inv u) \<otimes> a" | |
| 241 | by (fast intro: m_assoc[symmetric]) | |
| 27701 | 242 | also have "\<dots> = \<one> \<otimes> a" by (simp add: Units_r_inv[OF uunit]) | 
| 63832 | 243 | also from acarr have "\<dots> = a" by simp | 
| 244 | finally show "a = u \<otimes> (inv u \<otimes> a)" .. | |
| 27701 | 245 | qed | 
| 246 | ||
| 247 | lemma (in comm_monoid) divides_unit: | |
| 248 | assumes udvd: "a divides u" | |
| 63832 | 249 | and carr: "a \<in> carrier G" "u \<in> Units G" | 
| 27701 | 250 | shows "a \<in> Units G" | 
| 63832 | 251 | using udvd carr by (blast intro: unit_factor) | 
| 27701 | 252 | |
| 253 | lemma (in comm_monoid) Unit_eq_dividesone: | |
| 254 | assumes ucarr: "u \<in> carrier G" | |
| 255 | shows "u \<in> Units G = u divides \<one>" | |
| 63832 | 256 | using ucarr by (fast dest: divides_unit intro: unit_divides) | 
| 27701 | 257 | |
| 258 | ||
| 61382 | 259 | subsubsection \<open>Association\<close> | 
| 27701 | 260 | |
| 261 | lemma associatedI: | |
| 262 | fixes G (structure) | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 263 | assumes "a divides b" "b divides a" | 
| 27701 | 264 | shows "a \<sim> b" | 
| 63832 | 265 | using assms by (simp add: associated_def) | 
| 27701 | 266 | |
| 267 | lemma (in monoid) associatedI2: | |
| 268 | assumes uunit[simp]: "u \<in> Units G" | |
| 269 | and a: "a = b \<otimes> u" | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 270 | and bcarr: "b \<in> carrier G" | 
| 27701 | 271 | shows "a \<sim> b" | 
| 63832 | 272 | using uunit bcarr | 
| 273 | unfolding a | |
| 274 | apply (intro associatedI) | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 275 | apply (metis Units_closed divides_mult_lI one_closed r_one unit_divides) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 276 | by blast | 
| 27701 | 277 | |
| 278 | lemma (in monoid) associatedI2': | |
| 63832 | 279 | assumes "a = b \<otimes> u" | 
| 280 | and "u \<in> Units G" | |
| 281 | and "b \<in> carrier G" | |
| 27701 | 282 | shows "a \<sim> b" | 
| 63832 | 283 | using assms by (intro associatedI2) | 
| 27701 | 284 | |
| 285 | lemma associatedD: | |
| 286 | fixes G (structure) | |
| 287 | assumes "a \<sim> b" | |
| 288 | shows "a divides b" | |
| 63832 | 289 | using assms by (simp add: associated_def) | 
| 27701 | 290 | |
| 291 | lemma (in monoid_cancel) associatedD2: | |
| 292 | assumes assoc: "a \<sim> b" | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 293 | and carr: "a \<in> carrier G" "b \<in> carrier G" | 
| 27701 | 294 | shows "\<exists>u\<in>Units G. a = b \<otimes> u" | 
| 63832 | 295 | using assoc | 
| 296 | unfolding associated_def | |
| 27701 | 297 | proof clarify | 
| 298 | assume "b divides a" | |
| 63832 | 299 | then obtain u where ucarr: "u \<in> carrier G" and a: "a = b \<otimes> u" | 
| 63846 | 300 | by (rule dividesE) | 
| 27701 | 301 | |
| 302 | assume "a divides b" | |
| 63832 | 303 | then obtain u' where u'carr: "u' \<in> carrier G" and b: "b = a \<otimes> u'" | 
| 63846 | 304 | by (rule dividesE) | 
| 27701 | 305 | note carr = carr ucarr u'carr | 
| 306 | ||
| 63832 | 307 | from carr have "a \<otimes> \<one> = a" by simp | 
| 27701 | 308 | also have "\<dots> = b \<otimes> u" by (simp add: a) | 
| 309 | also have "\<dots> = a \<otimes> u' \<otimes> u" by (simp add: b) | |
| 63832 | 310 | also from carr have "\<dots> = a \<otimes> (u' \<otimes> u)" by (simp add: m_assoc) | 
| 311 | finally have "a \<otimes> \<one> = a \<otimes> (u' \<otimes> u)" . | |
| 312 | with carr have u1: "\<one> = u' \<otimes> u" by (fast dest: l_cancel) | |
| 313 | ||
| 314 | from carr have "b \<otimes> \<one> = b" by simp | |
| 27701 | 315 | also have "\<dots> = a \<otimes> u'" by (simp add: b) | 
| 316 | also have "\<dots> = b \<otimes> u \<otimes> u'" by (simp add: a) | |
| 63832 | 317 | also from carr have "\<dots> = b \<otimes> (u \<otimes> u')" by (simp add: m_assoc) | 
| 318 | finally have "b \<otimes> \<one> = b \<otimes> (u \<otimes> u')" . | |
| 319 | with carr have u2: "\<one> = u \<otimes> u'" by (fast dest: l_cancel) | |
| 320 | ||
| 321 | from u'carr u1[symmetric] u2[symmetric] have "\<exists>u'\<in>carrier G. u' \<otimes> u = \<one> \<and> u \<otimes> u' = \<one>" | |
| 322 | by fast | |
| 323 | then have "u \<in> Units G" | |
| 324 | by (simp add: Units_def ucarr) | |
| 325 | with ucarr a show "\<exists>u\<in>Units G. a = b \<otimes> u" by fast | |
| 27701 | 326 | qed | 
| 327 | ||
| 328 | lemma associatedE: | |
| 329 | fixes G (structure) | |
| 330 | assumes assoc: "a \<sim> b" | |
| 331 | and e: "\<lbrakk>a divides b; b divides a\<rbrakk> \<Longrightarrow> P" | |
| 332 | shows "P" | |
| 333 | proof - | |
| 63832 | 334 | from assoc have "a divides b" "b divides a" | 
| 335 | by (simp_all add: associated_def) | |
| 336 | then show P by (elim e) | |
| 27701 | 337 | qed | 
| 338 | ||
| 339 | lemma (in monoid_cancel) associatedE2: | |
| 340 | assumes assoc: "a \<sim> b" | |
| 341 | and e: "\<And>u. \<lbrakk>a = b \<otimes> u; u \<in> Units G\<rbrakk> \<Longrightarrow> P" | |
| 342 | and carr: "a \<in> carrier G" "b \<in> carrier G" | |
| 343 | shows "P" | |
| 344 | proof - | |
| 63832 | 345 | from assoc and carr have "\<exists>u\<in>Units G. a = b \<otimes> u" | 
| 346 | by (rule associatedD2) | |
| 347 | then obtain u where "u \<in> Units G" "a = b \<otimes> u" | |
| 348 | by auto | |
| 349 | then show P by (elim e) | |
| 27701 | 350 | qed | 
| 351 | ||
| 352 | lemma (in monoid) associated_refl [simp, intro!]: | |
| 353 | assumes "a \<in> carrier G" | |
| 354 | shows "a \<sim> a" | |
| 63832 | 355 | using assms by (fast intro: associatedI) | 
| 27701 | 356 | |
| 357 | lemma (in monoid) associated_sym [sym]: | |
| 358 | assumes "a \<sim> b" | |
| 359 | shows "b \<sim> a" | |
| 63832 | 360 | using assms by (iprover intro: associatedI elim: associatedE) | 
| 27701 | 361 | |
| 362 | lemma (in monoid) associated_trans [trans]: | |
| 363 | assumes "a \<sim> b" "b \<sim> c" | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 364 | and "a \<in> carrier G" "c \<in> carrier G" | 
| 27701 | 365 | shows "a \<sim> c" | 
| 63832 | 366 | using assms by (iprover intro: associatedI divides_trans elim: associatedE) | 
| 367 | ||
| 368 | lemma (in monoid) division_equiv [intro, simp]: "equivalence (division_rel G)" | |
| 27701 | 369 | apply unfold_locales | 
| 63832 | 370 | apply simp_all | 
| 371 | apply (metis associated_def) | |
| 27701 | 372 | apply (iprover intro: associated_trans) | 
| 373 | done | |
| 374 | ||
| 375 | ||
| 61382 | 376 | subsubsection \<open>Division and associativity\<close> | 
| 27701 | 377 | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 378 | lemmas divides_antisym = associatedI | 
| 27701 | 379 | |
| 380 | lemma (in monoid) divides_cong_l [trans]: | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 381 | assumes "x \<sim> x'" "x' divides y" "x \<in> carrier G" | 
| 27701 | 382 | shows "x divides y" | 
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 383 | by (meson assms associatedD divides_trans) | 
| 27701 | 384 | |
| 385 | lemma (in monoid) divides_cong_r [trans]: | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 386 | assumes "x divides y" "y \<sim> y'" "x \<in> carrier G" | 
| 27701 | 387 | shows "x divides y'" | 
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 388 | by (meson assms associatedD divides_trans) | 
| 27701 | 389 | |
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 390 | 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 | 391 | "weak_partial_order (division_rel G)" | 
| 27701 | 392 | apply unfold_locales | 
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 393 | apply (simp_all add: associated_sym divides_antisym) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 394 | apply (metis associated_trans) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 395 | apply (metis divides_trans) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 396 | by (meson associated_def divides_trans) | 
| 27701 | 397 | |
| 63832 | 398 | |
| 61382 | 399 | subsubsection \<open>Multiplication and associativity\<close> | 
| 27701 | 400 | |
| 70214 
58191e01f0b1
moving around some material from Algebraic_Closure
 paulson <lp15@cam.ac.uk> parents: 
69895diff
changeset | 401 | lemma (in monoid) mult_cong_r: | 
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 402 | assumes "b \<sim> b'" "a \<in> carrier G" "b \<in> carrier G" "b' \<in> carrier G" | 
| 27701 | 403 | shows "a \<otimes> b \<sim> a \<otimes> b'" | 
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 404 | by (meson assms associated_def divides_mult_lI) | 
| 27701 | 405 | |
| 70214 
58191e01f0b1
moving around some material from Algebraic_Closure
 paulson <lp15@cam.ac.uk> parents: 
69895diff
changeset | 406 | lemma (in comm_monoid) mult_cong_l: | 
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 407 | assumes "a \<sim> a'" "a \<in> carrier G" "a' \<in> carrier G" "b \<in> carrier G" | 
| 27701 | 408 | shows "a \<otimes> b \<sim> a' \<otimes> b" | 
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 409 | using assms m_comm mult_cong_r by auto | 
| 27701 | 410 | |
| 411 | lemma (in monoid_cancel) assoc_l_cancel: | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 412 | assumes "a \<in> carrier G" "b \<in> carrier G" "b' \<in> carrier G" "a \<otimes> b \<sim> a \<otimes> b'" | 
| 27701 | 413 | shows "b \<sim> b'" | 
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 414 | by (meson assms associated_def divides_mult_l) | 
| 27701 | 415 | |
| 416 | lemma (in comm_monoid_cancel) assoc_r_cancel: | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 417 | assumes "a \<otimes> b \<sim> a' \<otimes> b" "a \<in> carrier G" "a' \<in> carrier G" "b \<in> carrier G" | 
| 27701 | 418 | shows "a \<sim> a'" | 
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 419 | using assms assoc_l_cancel m_comm by presburger | 
| 27701 | 420 | |
| 421 | ||
| 61382 | 422 | subsubsection \<open>Units\<close> | 
| 27701 | 423 | |
| 424 | lemma (in monoid_cancel) assoc_unit_l [trans]: | |
| 63832 | 425 | assumes "a \<sim> b" | 
| 426 | and "b \<in> Units G" | |
| 427 | and "a \<in> carrier G" | |
| 27701 | 428 | shows "a \<in> Units G" | 
| 63832 | 429 | using assms by (fast elim: associatedE2) | 
| 27701 | 430 | |
| 431 | lemma (in monoid_cancel) assoc_unit_r [trans]: | |
| 63832 | 432 | assumes aunit: "a \<in> Units G" | 
| 433 | and asc: "a \<sim> b" | |
| 27701 | 434 | and bcarr: "b \<in> carrier G" | 
| 435 | shows "b \<in> Units G" | |
| 63832 | 436 | using aunit bcarr associated_sym[OF asc] by (blast intro: assoc_unit_l) | 
| 27701 | 437 | |
| 438 | lemma (in comm_monoid) Units_cong: | |
| 439 | assumes aunit: "a \<in> Units G" and asc: "a \<sim> b" | |
| 440 | and bcarr: "b \<in> carrier G" | |
| 441 | shows "b \<in> Units G" | |
| 63832 | 442 | using assms by (blast intro: divides_unit elim: associatedE) | 
| 27701 | 443 | |
| 444 | lemma (in monoid) Units_assoc: | |
| 445 | assumes units: "a \<in> Units G" "b \<in> Units G" | |
| 446 | shows "a \<sim> b" | |
| 63832 | 447 | using units by (fast intro: associatedI unit_divides) | 
| 448 | ||
| 449 | lemma (in monoid) Units_are_ones: "Units G {.=}\<^bsub>(division_rel G)\<^esub> {\<one>}"
 | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 450 | proof - | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 451 |   have "a .\<in>\<^bsub>division_rel G\<^esub> {\<one>}" if "a \<in> Units G" for a
 | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 452 | proof - | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 453 | have "a \<sim> \<one>" | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 454 | by (rule associatedI) (simp_all add: Units_closed that unit_divides) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 455 | then show ?thesis | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 456 | by (simp add: elem_def) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 457 | qed | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 458 | moreover have "\<one> .\<in>\<^bsub>division_rel G\<^esub> Units G" | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 459 | by (simp add: equivalence.mem_imp_elem) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 460 | ultimately show ?thesis | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 461 | by (auto simp: set_eq_def) | 
| 27701 | 462 | qed | 
| 463 | ||
| 63832 | 464 | lemma (in comm_monoid) Units_Lower: "Units G = Lower (division_rel G) (carrier G)" | 
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 465 | apply (auto simp add: Units_def Lower_def) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 466 | apply (metis Units_one_closed unit_divides unit_factor) | 
| 63832 | 467 | apply (metis Unit_eq_dividesone Units_r_inv_ex m_ac(2) one_closed) | 
| 468 | done | |
| 27701 | 469 | |
| 68664 
bd0df72c16d5
updated material concerning Algebra
 paulson <lp15@cam.ac.uk> parents: 
68604diff
changeset | 470 | lemma (in monoid_cancel) associated_iff: | 
| 
bd0df72c16d5
updated material concerning Algebra
 paulson <lp15@cam.ac.uk> parents: 
68604diff
changeset | 471 | assumes "a \<in> carrier G" "b \<in> carrier G" | 
| 
bd0df72c16d5
updated material concerning Algebra
 paulson <lp15@cam.ac.uk> parents: 
68604diff
changeset | 472 | shows "a \<sim> b \<longleftrightarrow> (\<exists>c \<in> Units G. a = b \<otimes> c)" | 
| 
bd0df72c16d5
updated material concerning Algebra
 paulson <lp15@cam.ac.uk> parents: 
68604diff
changeset | 473 | using assms associatedI2' associatedD2 by auto | 
| 
bd0df72c16d5
updated material concerning Algebra
 paulson <lp15@cam.ac.uk> parents: 
68604diff
changeset | 474 | |
| 27701 | 475 | |
| 61382 | 476 | subsubsection \<open>Proper factors\<close> | 
| 27701 | 477 | |
| 478 | lemma properfactorI: | |
| 479 | fixes G (structure) | |
| 480 | assumes "a divides b" | |
| 481 | and "\<not>(b divides a)" | |
| 482 | shows "properfactor G a b" | |
| 63832 | 483 | using assms unfolding properfactor_def by simp | 
| 27701 | 484 | |
| 485 | lemma properfactorI2: | |
| 486 | fixes G (structure) | |
| 487 | assumes advdb: "a divides b" | |
| 488 | and neq: "\<not>(a \<sim> b)" | |
| 489 | shows "properfactor G a b" | |
| 63846 | 490 | proof (rule properfactorI, rule advdb, rule notI) | 
| 27701 | 491 | assume "b divides a" | 
| 492 | with advdb have "a \<sim> b" by (rule associatedI) | |
| 493 | with neq show "False" by fast | |
| 494 | qed | |
| 495 | ||
| 496 | lemma (in comm_monoid_cancel) properfactorI3: | |
| 497 | assumes p: "p = a \<otimes> b" | |
| 498 | and nunit: "b \<notin> Units G" | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 499 | and carr: "a \<in> carrier G" "b \<in> carrier G" | 
| 27701 | 500 | shows "properfactor G a p" | 
| 63832 | 501 | unfolding p | 
| 502 | using carr | |
| 503 | apply (intro properfactorI, fast) | |
| 27701 | 504 | proof (clarsimp, elim dividesE) | 
| 505 | fix c | |
| 506 | assume ccarr: "c \<in> carrier G" | |
| 507 | note [simp] = carr ccarr | |
| 508 | ||
| 509 | have "a \<otimes> \<one> = a" by simp | |
| 510 | also assume "a = a \<otimes> b \<otimes> c" | |
| 511 | also have "\<dots> = a \<otimes> (b \<otimes> c)" by (simp add: m_assoc) | |
| 512 | finally have "a \<otimes> \<one> = a \<otimes> (b \<otimes> c)" . | |
| 513 | ||
| 63832 | 514 | then have rinv: "\<one> = b \<otimes> c" by (intro l_cancel[of "a" "\<one>" "b \<otimes> c"], simp+) | 
| 27701 | 515 | also have "\<dots> = c \<otimes> b" by (simp add: m_comm) | 
| 516 | finally have linv: "\<one> = c \<otimes> b" . | |
| 517 | ||
| 63832 | 518 | from ccarr linv[symmetric] rinv[symmetric] have "b \<in> Units G" | 
| 519 | unfolding Units_def by fastforce | |
| 520 | with nunit show False .. | |
| 27701 | 521 | qed | 
| 522 | ||
| 523 | lemma properfactorE: | |
| 524 | fixes G (structure) | |
| 525 | assumes pf: "properfactor G a b" | |
| 526 | and r: "\<lbrakk>a divides b; \<not>(b divides a)\<rbrakk> \<Longrightarrow> P" | |
| 527 | shows "P" | |
| 63832 | 528 | using pf unfolding properfactor_def by (fast intro: r) | 
| 27701 | 529 | |
| 530 | lemma properfactorE2: | |
| 531 | fixes G (structure) | |
| 532 | assumes pf: "properfactor G a b" | |
| 533 | and elim: "\<lbrakk>a divides b; \<not>(a \<sim> b)\<rbrakk> \<Longrightarrow> P" | |
| 534 | shows "P" | |
| 63832 | 535 | using pf unfolding properfactor_def by (fast elim: elim associatedE) | 
| 27701 | 536 | |
| 537 | lemma (in monoid) properfactor_unitE: | |
| 538 | assumes uunit: "u \<in> Units G" | |
| 539 | and pf: "properfactor G a u" | |
| 540 | and acarr: "a \<in> carrier G" | |
| 541 | shows "P" | |
| 63832 | 542 | using pf unit_divides[OF uunit acarr] by (fast elim: properfactorE) | 
| 27701 | 543 | |
| 544 | lemma (in monoid) properfactor_divides: | |
| 545 | assumes pf: "properfactor G a b" | |
| 546 | shows "a divides b" | |
| 63832 | 547 | using pf by (elim properfactorE) | 
| 27701 | 548 | |
| 549 | lemma (in monoid) properfactor_trans1 [trans]: | |
| 68684 | 550 | assumes "a divides b" "properfactor G b c" "a \<in> carrier G" "c \<in> carrier G" | 
| 27701 | 551 | shows "properfactor G a c" | 
| 68684 | 552 | by (meson divides_trans properfactorE properfactorI assms) | 
| 27701 | 553 | |
| 554 | lemma (in monoid) properfactor_trans2 [trans]: | |
| 68684 | 555 | assumes "properfactor G a b" "b divides c" "a \<in> carrier G" "b \<in> carrier G" | 
| 27701 | 556 | shows "properfactor G a c" | 
| 68684 | 557 | by (meson divides_trans properfactorE properfactorI assms) | 
| 27701 | 558 | |
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 559 | lemma properfactor_lless: | 
| 27701 | 560 | fixes G (structure) | 
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 561 | shows "properfactor G = lless (division_rel G)" | 
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 562 | by (force simp: lless_def properfactor_def associated_def) | 
| 27701 | 563 | |
| 564 | lemma (in monoid) properfactor_cong_l [trans]: | |
| 565 | assumes x'x: "x' \<sim> x" | |
| 566 | and pf: "properfactor G x y" | |
| 567 | and carr: "x \<in> carrier G" "x' \<in> carrier G" "y \<in> carrier G" | |
| 568 | shows "properfactor G x' y" | |
| 63832 | 569 | using pf | 
| 570 | unfolding properfactor_lless | |
| 27701 | 571 | proof - | 
| 29237 | 572 | interpret weak_partial_order "division_rel G" .. | 
| 63832 | 573 | from x'x have "x' .=\<^bsub>division_rel G\<^esub> x" by simp | 
| 27701 | 574 | also assume "x \<sqsubset>\<^bsub>division_rel G\<^esub> y" | 
| 63832 | 575 | finally show "x' \<sqsubset>\<^bsub>division_rel G\<^esub> y" by (simp add: carr) | 
| 27701 | 576 | qed | 
| 577 | ||
| 578 | lemma (in monoid) properfactor_cong_r [trans]: | |
| 579 | assumes pf: "properfactor G x y" | |
| 580 | and yy': "y \<sim> y'" | |
| 581 | and carr: "x \<in> carrier G" "y \<in> carrier G" "y' \<in> carrier G" | |
| 582 | shows "properfactor G x y'" | |
| 63832 | 583 | using pf | 
| 584 | unfolding properfactor_lless | |
| 27701 | 585 | proof - | 
| 29237 | 586 | interpret weak_partial_order "division_rel G" .. | 
| 27701 | 587 | assume "x \<sqsubset>\<^bsub>division_rel G\<^esub> y" | 
| 588 | also from yy' | |
| 63832 | 589 | have "y .=\<^bsub>division_rel G\<^esub> y'" by simp | 
| 590 | finally show "x \<sqsubset>\<^bsub>division_rel G\<^esub> y'" by (simp add: carr) | |
| 27701 | 591 | qed | 
| 592 | ||
| 593 | lemma (in monoid_cancel) properfactor_mult_lI [intro]: | |
| 594 | assumes ab: "properfactor G a b" | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 595 | and carr: "a \<in> carrier G" "c \<in> carrier G" | 
| 27701 | 596 | shows "properfactor G (c \<otimes> a) (c \<otimes> b)" | 
| 63832 | 597 | using ab carr by (fastforce elim: properfactorE intro: properfactorI) | 
| 27701 | 598 | |
| 599 | lemma (in monoid_cancel) properfactor_mult_l [simp]: | |
| 600 | assumes carr: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | |
| 601 | shows "properfactor G (c \<otimes> a) (c \<otimes> b) = properfactor G a b" | |
| 63832 | 602 | using carr by (fastforce elim: properfactorE intro: properfactorI) | 
| 27701 | 603 | |
| 604 | lemma (in comm_monoid_cancel) properfactor_mult_rI [intro]: | |
| 605 | assumes ab: "properfactor G a b" | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 606 | and carr: "a \<in> carrier G" "c \<in> carrier G" | 
| 27701 | 607 | shows "properfactor G (a \<otimes> c) (b \<otimes> c)" | 
| 63832 | 608 | using ab carr by (fastforce elim: properfactorE intro: properfactorI) | 
| 27701 | 609 | |
| 610 | lemma (in comm_monoid_cancel) properfactor_mult_r [simp]: | |
| 611 | assumes carr: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | |
| 612 | shows "properfactor G (a \<otimes> c) (b \<otimes> c) = properfactor G a b" | |
| 63832 | 613 | using carr by (fastforce elim: properfactorE intro: properfactorI) | 
| 27701 | 614 | |
| 615 | lemma (in monoid) properfactor_prod_r: | |
| 616 | assumes ab: "properfactor G a b" | |
| 617 | and carr[simp]: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | |
| 618 | shows "properfactor G a (b \<otimes> c)" | |
| 63832 | 619 | by (intro properfactor_trans2[OF ab] divides_prod_r) simp_all | 
| 27701 | 620 | |
| 621 | lemma (in comm_monoid) properfactor_prod_l: | |
| 622 | assumes ab: "properfactor G a b" | |
| 623 | and carr[simp]: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | |
| 624 | shows "properfactor G a (c \<otimes> b)" | |
| 63832 | 625 | by (intro properfactor_trans2[OF ab] divides_prod_l) simp_all | 
| 27701 | 626 | |
| 627 | ||
| 61382 | 628 | subsection \<open>Irreducible Elements and Primes\<close> | 
| 629 | ||
| 630 | subsubsection \<open>Irreducible elements\<close> | |
| 27701 | 631 | |
| 632 | lemma irreducibleI: | |
| 633 | fixes G (structure) | |
| 634 | assumes "a \<notin> Units G" | |
| 635 | and "\<And>b. \<lbrakk>b \<in> carrier G; properfactor G b a\<rbrakk> \<Longrightarrow> b \<in> Units G" | |
| 636 | shows "irreducible G a" | |
| 63832 | 637 | using assms unfolding irreducible_def by blast | 
| 27701 | 638 | |
| 639 | lemma irreducibleE: | |
| 640 | fixes G (structure) | |
| 641 | assumes irr: "irreducible G a" | |
| 63832 | 642 | 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" | 
| 27701 | 643 | shows "P" | 
| 63832 | 644 | using assms unfolding irreducible_def by blast | 
| 27701 | 645 | |
| 646 | lemma irreducibleD: | |
| 647 | fixes G (structure) | |
| 648 | assumes irr: "irreducible G a" | |
| 63832 | 649 | and pf: "properfactor G b a" | 
| 650 | and bcarr: "b \<in> carrier G" | |
| 27701 | 651 | shows "b \<in> Units G" | 
| 63832 | 652 | using assms by (fast elim: irreducibleE) | 
| 27701 | 653 | |
| 654 | lemma (in monoid_cancel) irreducible_cong [trans]: | |
| 68684 | 655 | assumes "irreducible G a" "a \<sim> a'" "a \<in> carrier G" "a' \<in> carrier G" | 
| 27701 | 656 | shows "irreducible G a'" | 
| 68684 | 657 | proof - | 
| 658 | have "a' divides a" | |
| 659 | by (meson \<open>a \<sim> a'\<close> associated_def) | |
| 660 | then show ?thesis | |
| 661 | by (metis (no_types) assms assoc_unit_l irreducibleE irreducibleI monoid.properfactor_trans2 monoid_axioms) | |
| 662 | qed | |
| 27701 | 663 | |
| 664 | lemma (in monoid) irreducible_prod_rI: | |
| 68684 | 665 | assumes "irreducible G a" "b \<in> Units G" "a \<in> carrier G" "b \<in> carrier G" | 
| 27701 | 666 | shows "irreducible G (a \<otimes> b)" | 
| 68684 | 667 | using assms | 
| 668 | by (metis (no_types, lifting) associatedI2' irreducible_def monoid.m_closed monoid_axioms prod_unit_r properfactor_cong_r) | |
| 27701 | 669 | |
| 670 | lemma (in comm_monoid) irreducible_prod_lI: | |
| 671 | assumes birr: "irreducible G b" | |
| 672 | and aunit: "a \<in> Units G" | |
| 673 | and carr [simp]: "a \<in> carrier G" "b \<in> carrier G" | |
| 674 | shows "irreducible G (a \<otimes> b)" | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 675 | by (metis aunit birr carr irreducible_prod_rI m_comm) | 
| 27701 | 676 | |
| 677 | lemma (in comm_monoid_cancel) irreducible_prodE [elim]: | |
| 678 | assumes irr: "irreducible G (a \<otimes> b)" | |
| 679 | and carr[simp]: "a \<in> carrier G" "b \<in> carrier G" | |
| 680 | and e1: "\<lbrakk>irreducible G a; b \<in> Units G\<rbrakk> \<Longrightarrow> P" | |
| 681 | and e2: "\<lbrakk>a \<in> Units G; irreducible G b\<rbrakk> \<Longrightarrow> P" | |
| 63832 | 682 | shows P | 
| 683 | using irr | |
| 27701 | 684 | proof (elim irreducibleE) | 
| 685 | assume abnunit: "a \<otimes> b \<notin> Units G" | |
| 686 | and isunit[rule_format]: "\<forall>ba. ba \<in> carrier G \<and> properfactor G ba (a \<otimes> b) \<longrightarrow> ba \<in> Units G" | |
| 63832 | 687 | show P | 
| 27701 | 688 | proof (cases "a \<in> Units G") | 
| 63832 | 689 | case aunit: True | 
| 27701 | 690 | have "irreducible G b" | 
| 63846 | 691 | proof (rule irreducibleI, rule notI) | 
| 27701 | 692 | assume "b \<in> Units G" | 
| 693 | with aunit have "(a \<otimes> b) \<in> Units G" by fast | |
| 694 | with abnunit show "False" .. | |
| 695 | next | |
| 696 | fix c | |
| 697 | assume ccarr: "c \<in> carrier G" | |
| 698 | and "properfactor G c b" | |
| 63832 | 699 | then have "properfactor G c (a \<otimes> b)" by (simp add: properfactor_prod_l[of c b a]) | 
| 700 | with ccarr show "c \<in> Units G" by (fast intro: isunit) | |
| 27701 | 701 | qed | 
| 63832 | 702 | with aunit show "P" by (rule e2) | 
| 27701 | 703 | next | 
| 63832 | 704 | case anunit: False | 
| 27701 | 705 | with carr have "properfactor G b (b \<otimes> a)" by (fast intro: properfactorI3) | 
| 63832 | 706 | then have bf: "properfactor G b (a \<otimes> b)" by (subst m_comm[of a b], simp+) | 
| 707 | then have bunit: "b \<in> Units G" by (intro isunit, simp) | |
| 27701 | 708 | |
| 709 | have "irreducible G a" | |
| 63846 | 710 | proof (rule irreducibleI, rule notI) | 
| 27701 | 711 | assume "a \<in> Units G" | 
| 712 | with bunit have "(a \<otimes> b) \<in> Units G" by fast | |
| 713 | with abnunit show "False" .. | |
| 714 | next | |
| 715 | fix c | |
| 716 | assume ccarr: "c \<in> carrier G" | |
| 717 | and "properfactor G c a" | |
| 63832 | 718 | then have "properfactor G c (a \<otimes> b)" | 
| 719 | by (simp add: properfactor_prod_r[of c a b]) | |
| 720 | with ccarr show "c \<in> Units G" by (fast intro: isunit) | |
| 27701 | 721 | qed | 
| 722 | from this bunit show "P" by (rule e1) | |
| 723 | qed | |
| 724 | qed | |
| 725 | ||
| 70214 
58191e01f0b1
moving around some material from Algebraic_Closure
 paulson <lp15@cam.ac.uk> parents: 
69895diff
changeset | 726 | lemma divides_irreducible_condition: | 
| 
58191e01f0b1
moving around some material from Algebraic_Closure
 paulson <lp15@cam.ac.uk> parents: 
69895diff
changeset | 727 | assumes "irreducible G r" and "a \<in> carrier G" | 
| 
58191e01f0b1
moving around some material from Algebraic_Closure
 paulson <lp15@cam.ac.uk> parents: 
69895diff
changeset | 728 | shows "a divides\<^bsub>G\<^esub> r \<Longrightarrow> a \<in> Units G \<or> a \<sim>\<^bsub>G\<^esub> r" | 
| 
58191e01f0b1
moving around some material from Algebraic_Closure
 paulson <lp15@cam.ac.uk> parents: 
69895diff
changeset | 729 | using assms unfolding irreducible_def properfactor_def associated_def | 
| 
58191e01f0b1
moving around some material from Algebraic_Closure
 paulson <lp15@cam.ac.uk> parents: 
69895diff
changeset | 730 | by (cases "r divides\<^bsub>G\<^esub> a", auto) | 
| 27701 | 731 | |
| 61382 | 732 | subsubsection \<open>Prime elements\<close> | 
| 27701 | 733 | |
| 734 | lemma primeI: | |
| 735 | fixes G (structure) | |
| 736 | assumes "p \<notin> Units G" | |
| 737 | 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" | |
| 738 | shows "prime G p" | |
| 63832 | 739 | using assms unfolding prime_def by blast | 
| 27701 | 740 | |
| 741 | lemma primeE: | |
| 742 | fixes G (structure) | |
| 743 | assumes pprime: "prime G p" | |
| 744 | and e: "\<lbrakk>p \<notin> Units G; \<forall>a\<in>carrier G. \<forall>b\<in>carrier G. | |
| 63832 | 745 | p divides a \<otimes> b \<longrightarrow> p divides a \<or> p divides b\<rbrakk> \<Longrightarrow> P" | 
| 27701 | 746 | shows "P" | 
| 63832 | 747 | using pprime unfolding prime_def by (blast dest: e) | 
| 27701 | 748 | |
| 749 | lemma (in comm_monoid_cancel) prime_divides: | |
| 750 | assumes carr: "a \<in> carrier G" "b \<in> carrier G" | |
| 751 | and pprime: "prime G p" | |
| 752 | and pdvd: "p divides a \<otimes> b" | |
| 753 | shows "p divides a \<or> p divides b" | |
| 63832 | 754 | using assms by (blast elim: primeE) | 
| 27701 | 755 | |
| 756 | lemma (in monoid_cancel) prime_cong [trans]: | |
| 68478 | 757 | assumes "prime G p" | 
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 758 | and pp': "p \<sim> p'" "p \<in> carrier G" "p' \<in> carrier G" | 
| 27701 | 759 | shows "prime G p'" | 
| 68478 | 760 | using assms | 
| 68684 | 761 | by (auto simp: prime_def assoc_unit_l) (metis pp' associated_sym divides_cong_l) | 
| 63832 | 762 | |
| 69895 
6b03a8cf092d
more formal contributors (with the help of the history);
 wenzelm parents: 
69700diff
changeset | 763 | lemma (in comm_monoid_cancel) prime_irreducible: \<^marker>\<open>contributor \<open>Paulo EmÃlio de Vilhena\<close>\<close> | 
| 68551 
b680e74eb6f2
More on Algebra by Paulo and Martin
 paulson <lp15@cam.ac.uk> parents: 
68488diff
changeset | 764 | assumes "prime G p" | 
| 
b680e74eb6f2
More on Algebra by Paulo and Martin
 paulson <lp15@cam.ac.uk> parents: 
68488diff
changeset | 765 | shows "irreducible G p" | 
| 
b680e74eb6f2
More on Algebra by Paulo and Martin
 paulson <lp15@cam.ac.uk> parents: 
68488diff
changeset | 766 | proof (rule irreducibleI) | 
| 
b680e74eb6f2
More on Algebra by Paulo and Martin
 paulson <lp15@cam.ac.uk> parents: 
68488diff
changeset | 767 | show "p \<notin> Units G" | 
| 
b680e74eb6f2
More on Algebra by Paulo and Martin
 paulson <lp15@cam.ac.uk> parents: 
68488diff
changeset | 768 | using assms unfolding prime_def by simp | 
| 
b680e74eb6f2
More on Algebra by Paulo and Martin
 paulson <lp15@cam.ac.uk> parents: 
68488diff
changeset | 769 | next | 
| 
b680e74eb6f2
More on Algebra by Paulo and Martin
 paulson <lp15@cam.ac.uk> parents: 
68488diff
changeset | 770 | fix b assume A: "b \<in> carrier G" "properfactor G b p" | 
| 
b680e74eb6f2
More on Algebra by Paulo and Martin
 paulson <lp15@cam.ac.uk> parents: 
68488diff
changeset | 771 | then obtain c where c: "c \<in> carrier G" "p = b \<otimes> c" | 
| 
b680e74eb6f2
More on Algebra by Paulo and Martin
 paulson <lp15@cam.ac.uk> parents: 
68488diff
changeset | 772 | unfolding properfactor_def factor_def by auto | 
| 
b680e74eb6f2
More on Algebra by Paulo and Martin
 paulson <lp15@cam.ac.uk> parents: 
68488diff
changeset | 773 | hence "p divides c" | 
| 
b680e74eb6f2
More on Algebra by Paulo and Martin
 paulson <lp15@cam.ac.uk> parents: 
68488diff
changeset | 774 | using A assms unfolding prime_def properfactor_def by auto | 
| 
b680e74eb6f2
More on Algebra by Paulo and Martin
 paulson <lp15@cam.ac.uk> parents: 
68488diff
changeset | 775 | then obtain b' where b': "b' \<in> carrier G" "c = p \<otimes> b'" | 
| 
b680e74eb6f2
More on Algebra by Paulo and Martin
 paulson <lp15@cam.ac.uk> parents: 
68488diff
changeset | 776 | unfolding factor_def by auto | 
| 
b680e74eb6f2
More on Algebra by Paulo and Martin
 paulson <lp15@cam.ac.uk> parents: 
68488diff
changeset | 777 | hence "\<one> = b \<otimes> b'" | 
| 
b680e74eb6f2
More on Algebra by Paulo and Martin
 paulson <lp15@cam.ac.uk> parents: 
68488diff
changeset | 778 | by (metis A(1) l_cancel m_closed m_lcomm one_closed r_one c) | 
| 
b680e74eb6f2
More on Algebra by Paulo and Martin
 paulson <lp15@cam.ac.uk> parents: 
68488diff
changeset | 779 | thus "b \<in> Units G" | 
| 
b680e74eb6f2
More on Algebra by Paulo and Martin
 paulson <lp15@cam.ac.uk> parents: 
68488diff
changeset | 780 | using A(1) Units_one_closed b'(1) unit_factor by presburger | 
| 
b680e74eb6f2
More on Algebra by Paulo and Martin
 paulson <lp15@cam.ac.uk> parents: 
68488diff
changeset | 781 | qed | 
| 
b680e74eb6f2
More on Algebra by Paulo and Martin
 paulson <lp15@cam.ac.uk> parents: 
68488diff
changeset | 782 | |
| 70215 
8371a25ca177
Algebraic closure: moving more theorems into their rightful places
 paulson <lp15@cam.ac.uk> parents: 
70214diff
changeset | 783 | lemma (in comm_monoid_cancel) prime_pow_divides_iff: | 
| 
8371a25ca177
Algebraic closure: moving more theorems into their rightful places
 paulson <lp15@cam.ac.uk> parents: 
70214diff
changeset | 784 | assumes "p \<in> carrier G" "a \<in> carrier G" "b \<in> carrier G" and "prime G p" and "\<not> (p divides a)" | 
| 
8371a25ca177
Algebraic closure: moving more theorems into their rightful places
 paulson <lp15@cam.ac.uk> parents: 
70214diff
changeset | 785 | shows "(p [^] (n :: nat)) divides (a \<otimes> b) \<longleftrightarrow> (p [^] n) divides b" | 
| 
8371a25ca177
Algebraic closure: moving more theorems into their rightful places
 paulson <lp15@cam.ac.uk> parents: 
70214diff
changeset | 786 | proof | 
| 
8371a25ca177
Algebraic closure: moving more theorems into their rightful places
 paulson <lp15@cam.ac.uk> parents: 
70214diff
changeset | 787 | assume "(p [^] n) divides b" thus "(p [^] n) divides (a \<otimes> b)" | 
| 
8371a25ca177
Algebraic closure: moving more theorems into their rightful places
 paulson <lp15@cam.ac.uk> parents: 
70214diff
changeset | 788 | using divides_prod_l[of "p [^] n" b a] assms by simp | 
| 
8371a25ca177
Algebraic closure: moving more theorems into their rightful places
 paulson <lp15@cam.ac.uk> parents: 
70214diff
changeset | 789 | next | 
| 
8371a25ca177
Algebraic closure: moving more theorems into their rightful places
 paulson <lp15@cam.ac.uk> parents: 
70214diff
changeset | 790 | assume "(p [^] n) divides (a \<otimes> b)" thus "(p [^] n) divides b" | 
| 
8371a25ca177
Algebraic closure: moving more theorems into their rightful places
 paulson <lp15@cam.ac.uk> parents: 
70214diff
changeset | 791 | proof (induction n) | 
| 
8371a25ca177
Algebraic closure: moving more theorems into their rightful places
 paulson <lp15@cam.ac.uk> parents: 
70214diff
changeset | 792 | case 0 with \<open>b \<in> carrier G\<close> show ?case | 
| 
8371a25ca177
Algebraic closure: moving more theorems into their rightful places
 paulson <lp15@cam.ac.uk> parents: 
70214diff
changeset | 793 | by (simp add: unit_divides) | 
| 
8371a25ca177
Algebraic closure: moving more theorems into their rightful places
 paulson <lp15@cam.ac.uk> parents: 
70214diff
changeset | 794 | next | 
| 
8371a25ca177
Algebraic closure: moving more theorems into their rightful places
 paulson <lp15@cam.ac.uk> parents: 
70214diff
changeset | 795 | case (Suc n) | 
| 
8371a25ca177
Algebraic closure: moving more theorems into their rightful places
 paulson <lp15@cam.ac.uk> parents: 
70214diff
changeset | 796 | hence "(p [^] n) divides (a \<otimes> b)" and "(p [^] n) divides b" | 
| 
8371a25ca177
Algebraic closure: moving more theorems into their rightful places
 paulson <lp15@cam.ac.uk> parents: 
70214diff
changeset | 797 | using assms(1) divides_prod_r by auto | 
| 
8371a25ca177
Algebraic closure: moving more theorems into their rightful places
 paulson <lp15@cam.ac.uk> parents: 
70214diff
changeset | 798 | with \<open>(p [^] (Suc n)) divides (a \<otimes> b)\<close> obtain c d | 
| 
8371a25ca177
Algebraic closure: moving more theorems into their rightful places
 paulson <lp15@cam.ac.uk> parents: 
70214diff
changeset | 799 | where c: "c \<in> carrier G" and "b = (p [^] n) \<otimes> c" | 
| 
8371a25ca177
Algebraic closure: moving more theorems into their rightful places
 paulson <lp15@cam.ac.uk> parents: 
70214diff
changeset | 800 | and d: "d \<in> carrier G" and "a \<otimes> b = (p [^] (Suc n)) \<otimes> d" | 
| 
8371a25ca177
Algebraic closure: moving more theorems into their rightful places
 paulson <lp15@cam.ac.uk> parents: 
70214diff
changeset | 801 | using assms by blast | 
| 
8371a25ca177
Algebraic closure: moving more theorems into their rightful places
 paulson <lp15@cam.ac.uk> parents: 
70214diff
changeset | 802 | hence "(p [^] n) \<otimes> (a \<otimes> c) = (p [^] n) \<otimes> (p \<otimes> d)" | 
| 
8371a25ca177
Algebraic closure: moving more theorems into their rightful places
 paulson <lp15@cam.ac.uk> parents: 
70214diff
changeset | 803 | using assms by (simp add: m_assoc m_lcomm) | 
| 
8371a25ca177
Algebraic closure: moving more theorems into their rightful places
 paulson <lp15@cam.ac.uk> parents: 
70214diff
changeset | 804 | hence "a \<otimes> c = p \<otimes> d" | 
| 
8371a25ca177
Algebraic closure: moving more theorems into their rightful places
 paulson <lp15@cam.ac.uk> parents: 
70214diff
changeset | 805 | using c d assms(1) assms(2) l_cancel by blast | 
| 
8371a25ca177
Algebraic closure: moving more theorems into their rightful places
 paulson <lp15@cam.ac.uk> parents: 
70214diff
changeset | 806 | with \<open>\<not> (p divides a)\<close> and \<open>prime G p\<close> have "p divides c" | 
| 
8371a25ca177
Algebraic closure: moving more theorems into their rightful places
 paulson <lp15@cam.ac.uk> parents: 
70214diff
changeset | 807 | by (metis assms(2) c d dividesI' prime_divides) | 
| 
8371a25ca177
Algebraic closure: moving more theorems into their rightful places
 paulson <lp15@cam.ac.uk> parents: 
70214diff
changeset | 808 | with \<open>b = (p [^] n) \<otimes> c\<close> show ?case | 
| 
8371a25ca177
Algebraic closure: moving more theorems into their rightful places
 paulson <lp15@cam.ac.uk> parents: 
70214diff
changeset | 809 | using assms(1) c by simp | 
| 
8371a25ca177
Algebraic closure: moving more theorems into their rightful places
 paulson <lp15@cam.ac.uk> parents: 
70214diff
changeset | 810 | qed | 
| 
8371a25ca177
Algebraic closure: moving more theorems into their rightful places
 paulson <lp15@cam.ac.uk> parents: 
70214diff
changeset | 811 | qed | 
| 
8371a25ca177
Algebraic closure: moving more theorems into their rightful places
 paulson <lp15@cam.ac.uk> parents: 
70214diff
changeset | 812 | |
| 27701 | 813 | |
| 61382 | 814 | subsection \<open>Factorization and Factorial Monoids\<close> | 
| 815 | ||
| 816 | subsubsection \<open>Function definitions\<close> | |
| 27701 | 817 | |
| 63832 | 818 | definition factors :: "[_, 'a list, 'a] \<Rightarrow> bool" | 
| 67399 | 819 | where "factors G fs a \<longleftrightarrow> (\<forall>x \<in> (set fs). irreducible G x) \<and> foldr (\<otimes>\<^bsub>G\<^esub>) fs \<one>\<^bsub>G\<^esub> = a" | 
| 35847 | 820 | |
| 63832 | 821 | definition wfactors ::"[_, 'a list, 'a] \<Rightarrow> bool" | 
| 67399 | 822 | where "wfactors G fs a \<longleftrightarrow> (\<forall>x \<in> (set fs). irreducible G x) \<and> foldr (\<otimes>\<^bsub>G\<^esub>) fs \<one>\<^bsub>G\<^esub> \<sim>\<^bsub>G\<^esub> a" | 
| 27701 | 823 | |
| 63832 | 824 | abbreviation list_assoc :: "('a,_) monoid_scheme \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> bool" (infix "[\<sim>]\<index>" 44)
 | 
| 67399 | 825 | where "list_assoc G \<equiv> list_all2 (\<sim>\<^bsub>G\<^esub>)" | 
| 63832 | 826 | |
| 827 | definition essentially_equal :: "[_, 'a list, 'a list] \<Rightarrow> bool" | |
| 35848 
5443079512ea
slightly more uniform definitions -- eliminated old-style meta-equality;
 wenzelm parents: 
35847diff
changeset | 828 | where "essentially_equal G fs1 fs2 \<longleftrightarrow> (\<exists>fs1'. fs1 <~~> fs1' \<and> fs1' [\<sim>]\<^bsub>G\<^esub> fs2)" | 
| 27701 | 829 | |
| 830 | ||
| 831 | locale factorial_monoid = comm_monoid_cancel + | |
| 63832 | 832 | assumes factors_exist: "\<lbrakk>a \<in> carrier G; a \<notin> Units G\<rbrakk> \<Longrightarrow> \<exists>fs. set fs \<subseteq> carrier G \<and> factors G fs a" | 
| 833 | and factors_unique: | |
| 834 | "\<lbrakk>factors G fs a; factors G fs' a; a \<in> carrier G; a \<notin> Units G; | |
| 835 | set fs \<subseteq> carrier G; set fs' \<subseteq> carrier G\<rbrakk> \<Longrightarrow> essentially_equal G fs fs'" | |
| 27701 | 836 | |
| 837 | ||
| 61382 | 838 | subsubsection \<open>Comparing lists of elements\<close> | 
| 839 | ||
| 840 | text \<open>Association on lists\<close> | |
| 27701 | 841 | |
| 842 | lemma (in monoid) listassoc_refl [simp, intro]: | |
| 843 | assumes "set as \<subseteq> carrier G" | |
| 844 | shows "as [\<sim>] as" | |
| 63832 | 845 | using assms by (induct as) simp_all | 
| 27701 | 846 | |
| 847 | lemma (in monoid) listassoc_sym [sym]: | |
| 848 | assumes "as [\<sim>] bs" | |
| 63832 | 849 | and "set as \<subseteq> carrier G" | 
| 850 | and "set bs \<subseteq> carrier G" | |
| 27701 | 851 | shows "bs [\<sim>] as" | 
| 63832 | 852 | using assms | 
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 853 | proof (induction as arbitrary: bs) | 
| 27701 | 854 | case Cons | 
| 63832 | 855 | then show ?case | 
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 856 | by (induction bs) (use associated_sym in auto) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 857 | qed auto | 
| 27701 | 858 | |
| 859 | lemma (in monoid) listassoc_trans [trans]: | |
| 860 | assumes "as [\<sim>] bs" and "bs [\<sim>] cs" | |
| 861 | and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G" and "set cs \<subseteq> carrier G" | |
| 862 | shows "as [\<sim>] cs" | |
| 63832 | 863 | using assms | 
| 864 | apply (simp add: list_all2_conv_all_nth set_conv_nth, safe) | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 865 | by (metis (mono_tags, lifting) associated_trans nth_mem subsetCE) | 
| 27701 | 866 | |
| 867 | lemma (in monoid_cancel) irrlist_listassoc_cong: | |
| 868 | assumes "\<forall>a\<in>set as. irreducible G a" | |
| 869 | and "as [\<sim>] bs" | |
| 870 | and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G" | |
| 871 | shows "\<forall>a\<in>set bs. irreducible G a" | |
| 63832 | 872 | using assms | 
| 68684 | 873 | by (fastforce simp add: list_all2_conv_all_nth set_conv_nth intro: irreducible_cong) | 
| 27701 | 874 | |
| 875 | ||
| 61382 | 876 | text \<open>Permutations\<close> | 
| 27701 | 877 | |
| 878 | lemma perm_map [intro]: | |
| 879 | assumes p: "a <~~> b" | |
| 880 | shows "map f a <~~> map f b" | |
| 63832 | 881 | using p by induct auto | 
| 27701 | 882 | |
| 883 | lemma perm_map_switch: | |
| 884 | assumes m: "map f a = map f b" and p: "b <~~> c" | |
| 885 | shows "\<exists>d. a <~~> d \<and> map f d = map f c" | |
| 63832 | 886 | using p m by (induct arbitrary: a) (simp, force, force, blast) | 
| 27701 | 887 | |
| 888 | lemma (in monoid) perm_assoc_switch: | |
| 63832 | 889 | assumes a:"as [\<sim>] bs" and p: "bs <~~> cs" | 
| 890 | shows "\<exists>bs'. as <~~> bs' \<and> bs' [\<sim>] cs" | |
| 891 | using p a | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 892 | proof (induction bs cs arbitrary: as) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 893 | case (swap y x l) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 894 | then show ?case | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 895 | by (metis (no_types, hide_lams) list_all2_Cons2 perm.swap) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 896 | next | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 897 | case (Cons xs ys z) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 898 | then show ?case | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 899 | by (metis list_all2_Cons2 perm.Cons) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 900 | next | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 901 | case (trans xs ys zs) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 902 | then show ?case | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 903 | by (meson perm.trans) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 904 | qed auto | 
| 27701 | 905 | |
| 906 | lemma (in monoid) perm_assoc_switch_r: | |
| 63832 | 907 | assumes p: "as <~~> bs" and a:"bs [\<sim>] cs" | 
| 908 | shows "\<exists>bs'. as [\<sim>] bs' \<and> bs' <~~> cs" | |
| 909 | using p a | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 910 | proof (induction as bs arbitrary: cs) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 911 | case Nil | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 912 | then show ?case | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 913 | by auto | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 914 | next | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 915 | case (swap y x l) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 916 | then show ?case | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 917 | by (metis (no_types, hide_lams) list_all2_Cons1 perm.swap) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 918 | next | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 919 | case (Cons xs ys z) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 920 | then show ?case | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 921 | by (metis list_all2_Cons1 perm.Cons) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 922 | next | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 923 | case (trans xs ys zs) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 924 | then show ?case | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 925 | by (blast intro: elim: ) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 926 | qed | 
| 27701 | 927 | |
| 928 | declare perm_sym [sym] | |
| 929 | ||
| 930 | lemma perm_setP: | |
| 931 | assumes perm: "as <~~> bs" | |
| 932 | and as: "P (set as)" | |
| 933 | shows "P (set bs)" | |
| 934 | proof - | |
| 63832 | 935 | from perm have "mset as = mset bs" | 
| 936 | by (simp add: mset_eq_perm) | |
| 937 | then have "set as = set bs" | |
| 938 | by (rule mset_eq_setD) | |
| 939 | with as show "P (set bs)" | |
| 940 | by simp | |
| 27701 | 941 | qed | 
| 942 | ||
| 63832 | 943 | lemmas (in monoid) perm_closed = perm_setP[of _ _ "\<lambda>as. as \<subseteq> carrier G"] | 
| 944 | ||
| 945 | lemmas (in monoid) irrlist_perm_cong = perm_setP[of _ _ "\<lambda>as. \<forall>a\<in>as. irreducible G a"] | |
| 27701 | 946 | |
| 947 | ||
| 61382 | 948 | text \<open>Essentially equal factorizations\<close> | 
| 27701 | 949 | |
| 950 | lemma (in monoid) essentially_equalI: | |
| 951 | assumes ex: "fs1 <~~> fs1'" "fs1' [\<sim>] fs2" | |
| 952 | shows "essentially_equal G fs1 fs2" | |
| 63832 | 953 | using ex unfolding essentially_equal_def by fast | 
| 27701 | 954 | |
| 955 | lemma (in monoid) essentially_equalE: | |
| 956 | assumes ee: "essentially_equal G fs1 fs2" | |
| 957 | and e: "\<And>fs1'. \<lbrakk>fs1 <~~> fs1'; fs1' [\<sim>] fs2\<rbrakk> \<Longrightarrow> P" | |
| 958 | shows "P" | |
| 63832 | 959 | using ee unfolding essentially_equal_def by (fast intro: e) | 
| 27701 | 960 | |
| 961 | lemma (in monoid) ee_refl [simp,intro]: | |
| 962 | assumes carr: "set as \<subseteq> carrier G" | |
| 963 | shows "essentially_equal G as as" | |
| 63832 | 964 | using carr by (fast intro: essentially_equalI) | 
| 27701 | 965 | |
| 966 | lemma (in monoid) ee_sym [sym]: | |
| 967 | assumes ee: "essentially_equal G as bs" | |
| 968 | and carr: "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" | |
| 969 | shows "essentially_equal G bs as" | |
| 63832 | 970 | using ee | 
| 27701 | 971 | proof (elim essentially_equalE) | 
| 972 | fix fs | |
| 973 | assume "as <~~> fs" "fs [\<sim>] bs" | |
| 63847 | 974 | from perm_assoc_switch_r [OF this] obtain fs' where a: "as [\<sim>] fs'" and p: "fs' <~~> bs" | 
| 975 | by blast | |
| 27701 | 976 | from p have "bs <~~> fs'" by (rule perm_sym) | 
| 63832 | 977 | with a[symmetric] carr show ?thesis | 
| 978 | by (iprover intro: essentially_equalI perm_closed) | |
| 27701 | 979 | qed | 
| 980 | ||
| 981 | lemma (in monoid) ee_trans [trans]: | |
| 982 | assumes ab: "essentially_equal G as bs" and bc: "essentially_equal G bs cs" | |
| 63832 | 983 | and ascarr: "set as \<subseteq> carrier G" | 
| 27701 | 984 | and bscarr: "set bs \<subseteq> carrier G" | 
| 985 | and cscarr: "set cs \<subseteq> carrier G" | |
| 986 | shows "essentially_equal G as cs" | |
| 63832 | 987 | using ab bc | 
| 27701 | 988 | proof (elim essentially_equalE) | 
| 989 | fix abs bcs | |
| 63847 | 990 | assume "abs [\<sim>] bs" and pb: "bs <~~> bcs" | 
| 991 | from perm_assoc_switch [OF this] obtain bs' where p: "abs <~~> bs'" and a: "bs' [\<sim>] bcs" | |
| 992 | by blast | |
| 27701 | 993 | assume "as <~~> abs" | 
| 63832 | 994 | with p have pp: "as <~~> bs'" by fast | 
| 27701 | 995 | from pp ascarr have c1: "set bs' \<subseteq> carrier G" by (rule perm_closed) | 
| 996 | from pb bscarr have c2: "set bcs \<subseteq> carrier G" by (rule perm_closed) | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 997 | assume "bcs [\<sim>] cs" | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 998 | then have "bs' [\<sim>] cs" | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 999 | using a c1 c2 cscarr listassoc_trans by blast | 
| 63832 | 1000 | with pp show ?thesis | 
| 1001 | by (rule essentially_equalI) | |
| 27701 | 1002 | qed | 
| 1003 | ||
| 1004 | ||
| 61382 | 1005 | subsubsection \<open>Properties of lists of elements\<close> | 
| 1006 | ||
| 1007 | text \<open>Multiplication of factors in a list\<close> | |
| 27701 | 1008 | |
| 1009 | lemma (in monoid) multlist_closed [simp, intro]: | |
| 1010 | assumes ascarr: "set fs \<subseteq> carrier G" | |
| 67399 | 1011 | shows "foldr (\<otimes>) fs \<one> \<in> carrier G" | 
| 63832 | 1012 | using ascarr by (induct fs) simp_all | 
| 27701 | 1013 | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1014 | lemma (in comm_monoid) multlist_dividesI: | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1015 | assumes "f \<in> set fs" and "set fs \<subseteq> carrier G" | 
| 67399 | 1016 | shows "f divides (foldr (\<otimes>) fs \<one>)" | 
| 63832 | 1017 | using assms | 
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1018 | proof (induction fs) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1019 | case (Cons a fs) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1020 | then have f: "f \<in> carrier G" | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1021 | by blast | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1022 | show ?case | 
| 68684 | 1023 | using Cons.IH Cons.prems(1) Cons.prems(2) divides_prod_l f by auto | 
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1024 | qed auto | 
| 27701 | 1025 | |
| 1026 | lemma (in comm_monoid_cancel) multlist_listassoc_cong: | |
| 1027 | assumes "fs [\<sim>] fs'" | |
| 1028 | and "set fs \<subseteq> carrier G" and "set fs' \<subseteq> carrier G" | |
| 67399 | 1029 | shows "foldr (\<otimes>) fs \<one> \<sim> foldr (\<otimes>) fs' \<one>" | 
| 63832 | 1030 | using assms | 
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1031 | proof (induct fs arbitrary: fs') | 
| 27701 | 1032 | case (Cons a as fs') | 
| 63832 | 1033 | then show ?case | 
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1034 | proof (induction fs') | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1035 | case (Cons b bs) | 
| 67399 | 1036 | then have p: "a \<otimes> foldr (\<otimes>) as \<one> \<sim> b \<otimes> foldr (\<otimes>) as \<one>" | 
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1037 | by (simp add: mult_cong_l) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1038 | then have "foldr (\<otimes>) as \<one> \<sim> foldr (\<otimes>) bs \<one>" | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1039 | using Cons by auto | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1040 | with Cons have "b \<otimes> foldr (\<otimes>) as \<one> \<sim> b \<otimes> foldr (\<otimes>) bs \<one>" | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1041 | by (simp add: mult_cong_r) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1042 | then show ?case | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1043 | using Cons.prems(3) Cons.prems(4) monoid.associated_trans monoid_axioms p by force | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1044 | qed auto | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1045 | qed auto | 
| 27701 | 1046 | |
| 1047 | lemma (in comm_monoid) multlist_perm_cong: | |
| 1048 | assumes prm: "as <~~> bs" | |
| 1049 | and ascarr: "set as \<subseteq> carrier G" | |
| 67399 | 1050 | shows "foldr (\<otimes>) as \<one> = foldr (\<otimes>) bs \<one>" | 
| 63832 | 1051 | using prm ascarr | 
| 68478 | 1052 | proof induction | 
| 1053 | case (swap y x l) then show ?case | |
| 1054 | by (simp add: m_lcomm) | |
| 1055 | next | |
| 1056 | case (trans xs ys zs) then show ?case | |
| 1057 | using perm_closed by auto | |
| 1058 | qed auto | |
| 27701 | 1059 | |
| 1060 | lemma (in comm_monoid_cancel) multlist_ee_cong: | |
| 1061 | assumes "essentially_equal G fs fs'" | |
| 1062 | and "set fs \<subseteq> carrier G" and "set fs' \<subseteq> carrier G" | |
| 67399 | 1063 | shows "foldr (\<otimes>) fs \<one> \<sim> foldr (\<otimes>) fs' \<one>" | 
| 63832 | 1064 | using assms | 
| 68684 | 1065 | by (metis essentially_equal_def multlist_listassoc_cong multlist_perm_cong perm_closed) | 
| 27701 | 1066 | |
| 1067 | ||
| 61382 | 1068 | subsubsection \<open>Factorization in irreducible elements\<close> | 
| 27701 | 1069 | |
| 1070 | lemma wfactorsI: | |
| 28599 | 1071 | fixes G (structure) | 
| 27701 | 1072 | assumes "\<forall>f\<in>set fs. irreducible G f" | 
| 67399 | 1073 | and "foldr (\<otimes>) fs \<one> \<sim> a" | 
| 27701 | 1074 | shows "wfactors G fs a" | 
| 63832 | 1075 | using assms unfolding wfactors_def by simp | 
| 27701 | 1076 | |
| 1077 | lemma wfactorsE: | |
| 28599 | 1078 | fixes G (structure) | 
| 27701 | 1079 | assumes wf: "wfactors G fs a" | 
| 67399 | 1080 | and e: "\<lbrakk>\<forall>f\<in>set fs. irreducible G f; foldr (\<otimes>) fs \<one> \<sim> a\<rbrakk> \<Longrightarrow> P" | 
| 27701 | 1081 | shows "P" | 
| 63832 | 1082 | using wf unfolding wfactors_def by (fast dest: e) | 
| 27701 | 1083 | |
| 1084 | lemma (in monoid) factorsI: | |
| 1085 | assumes "\<forall>f\<in>set fs. irreducible G f" | |
| 67399 | 1086 | and "foldr (\<otimes>) fs \<one> = a" | 
| 27701 | 1087 | shows "factors G fs a" | 
| 63832 | 1088 | using assms unfolding factors_def by simp | 
| 27701 | 1089 | |
| 1090 | lemma factorsE: | |
| 28599 | 1091 | fixes G (structure) | 
| 27701 | 1092 | assumes f: "factors G fs a" | 
| 67399 | 1093 | and e: "\<lbrakk>\<forall>f\<in>set fs. irreducible G f; foldr (\<otimes>) fs \<one> = a\<rbrakk> \<Longrightarrow> P" | 
| 27701 | 1094 | shows "P" | 
| 63832 | 1095 | using f unfolding factors_def by (simp add: e) | 
| 27701 | 1096 | |
| 1097 | lemma (in monoid) factors_wfactors: | |
| 1098 | assumes "factors G as a" and "set as \<subseteq> carrier G" | |
| 1099 | shows "wfactors G as a" | |
| 63832 | 1100 | using assms by (blast elim: factorsE intro: wfactorsI) | 
| 27701 | 1101 | |
| 1102 | lemma (in monoid) wfactors_factors: | |
| 1103 | assumes "wfactors G as a" and "set as \<subseteq> carrier G" | |
| 1104 | shows "\<exists>a'. factors G as a' \<and> a' \<sim> a" | |
| 63832 | 1105 | using assms by (blast elim: wfactorsE intro: factorsI) | 
| 27701 | 1106 | |
| 1107 | lemma (in monoid) factors_closed [dest]: | |
| 1108 | assumes "factors G fs a" and "set fs \<subseteq> carrier G" | |
| 1109 | shows "a \<in> carrier G" | |
| 63832 | 1110 | using assms by (elim factorsE, clarsimp) | 
| 27701 | 1111 | |
| 1112 | lemma (in monoid) nunit_factors: | |
| 1113 | assumes anunit: "a \<notin> Units G" | |
| 1114 | and fs: "factors G as a" | |
| 1115 | shows "length as > 0" | |
| 46129 | 1116 | proof - | 
| 1117 | from anunit Units_one_closed have "a \<noteq> \<one>" by auto | |
| 1118 | with fs show ?thesis by (auto elim: factorsE) | |
| 1119 | qed | |
| 27701 | 1120 | |
| 1121 | lemma (in monoid) unit_wfactors [simp]: | |
| 1122 | assumes aunit: "a \<in> Units G" | |
| 1123 | shows "wfactors G [] a" | |
| 63832 | 1124 | using aunit by (intro wfactorsI) (simp, simp add: Units_assoc) | 
| 27701 | 1125 | |
| 1126 | lemma (in comm_monoid_cancel) unit_wfactors_empty: | |
| 1127 | assumes aunit: "a \<in> Units G" | |
| 1128 | and wf: "wfactors G fs a" | |
| 1129 | and carr[simp]: "set fs \<subseteq> carrier G" | |
| 1130 | shows "fs = []" | |
| 63846 | 1131 | proof (cases fs) | 
| 1132 | case fs: (Cons f fs') | |
| 63832 | 1133 | from carr have fcarr[simp]: "f \<in> carrier G" and carr'[simp]: "set fs' \<subseteq> carrier G" | 
| 1134 | by (simp_all add: fs) | |
| 1135 | ||
| 1136 | from fs wf have "irreducible G f" by (simp add: wfactors_def) | |
| 1137 | then have fnunit: "f \<notin> Units G" by (fast elim: irreducibleE) | |
| 1138 | ||
| 67399 | 1139 | from fs wf have a: "f \<otimes> foldr (\<otimes>) fs' \<one> \<sim> a" by (simp add: wfactors_def) | 
| 27701 | 1140 | |
| 1141 | note aunit | |
| 1142 | also from fs wf | |
| 67399 | 1143 | have a: "f \<otimes> foldr (\<otimes>) fs' \<one> \<sim> a" by (simp add: wfactors_def) | 
| 1144 | have "a \<sim> f \<otimes> foldr (\<otimes>) fs' \<one>" | |
| 63832 | 1145 | by (simp add: Units_closed[OF aunit] a[symmetric]) | 
| 67399 | 1146 | finally have "f \<otimes> foldr (\<otimes>) fs' \<one> \<in> Units G" by simp | 
| 63832 | 1147 | then have "f \<in> Units G" by (intro unit_factor[of f], simp+) | 
| 63846 | 1148 | with fnunit show ?thesis by contradiction | 
| 27701 | 1149 | qed | 
| 1150 | ||
| 1151 | ||
| 61382 | 1152 | text \<open>Comparing wfactors\<close> | 
| 27701 | 1153 | |
| 1154 | lemma (in comm_monoid_cancel) wfactors_listassoc_cong_l: | |
| 1155 | assumes fact: "wfactors G fs a" | |
| 1156 | and asc: "fs [\<sim>] fs'" | |
| 1157 | and carr: "a \<in> carrier G" "set fs \<subseteq> carrier G" "set fs' \<subseteq> carrier G" | |
| 1158 | shows "wfactors G fs' a" | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1159 | proof - | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1160 |   { from asc[symmetric] have "foldr (\<otimes>) fs' \<one> \<sim> foldr (\<otimes>) fs \<one>"
 | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1161 | by (simp add: multlist_listassoc_cong carr) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1162 | also assume "foldr (\<otimes>) fs \<one> \<sim> a" | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1163 | finally have "foldr (\<otimes>) fs' \<one> \<sim> a" by (simp add: carr) } | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1164 | then show ?thesis | 
| 63832 | 1165 | using fact | 
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1166 | by (meson asc carr(2) carr(3) irrlist_listassoc_cong wfactors_def) | 
| 27701 | 1167 | qed | 
| 1168 | ||
| 1169 | lemma (in comm_monoid) wfactors_perm_cong_l: | |
| 1170 | assumes "wfactors G fs a" | |
| 1171 | and "fs <~~> fs'" | |
| 1172 | and "set fs \<subseteq> carrier G" | |
| 1173 | shows "wfactors G fs' a" | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1174 | using assms irrlist_perm_cong multlist_perm_cong wfactors_def by fastforce | 
| 27701 | 1175 | |
| 1176 | lemma (in comm_monoid_cancel) wfactors_ee_cong_l [trans]: | |
| 1177 | assumes ee: "essentially_equal G as bs" | |
| 1178 | and bfs: "wfactors G bs b" | |
| 1179 | and carr: "b \<in> carrier G" "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" | |
| 1180 | shows "wfactors G as b" | |
| 63832 | 1181 | using ee | 
| 27701 | 1182 | proof (elim essentially_equalE) | 
| 1183 | fix fs | |
| 1184 | assume prm: "as <~~> fs" | |
| 63832 | 1185 | with carr have fscarr: "set fs \<subseteq> carrier G" by (simp add: perm_closed) | 
| 27701 | 1186 | |
| 1187 | note bfs | |
| 1188 | also assume [symmetric]: "fs [\<sim>] bs" | |
| 1189 | also (wfactors_listassoc_cong_l) | |
| 63832 | 1190 | note prm[symmetric] | 
| 27701 | 1191 | finally (wfactors_perm_cong_l) | 
| 63832 | 1192 | show "wfactors G as b" by (simp add: carr fscarr) | 
| 27701 | 1193 | qed | 
| 1194 | ||
| 1195 | lemma (in monoid) wfactors_cong_r [trans]: | |
| 1196 | assumes fac: "wfactors G fs a" and aa': "a \<sim> a'" | |
| 1197 | and carr[simp]: "a \<in> carrier G" "a' \<in> carrier G" "set fs \<subseteq> carrier G" | |
| 1198 | shows "wfactors G fs a'" | |
| 63832 | 1199 | using fac | 
| 27701 | 1200 | proof (elim wfactorsE, intro wfactorsI) | 
| 67399 | 1201 | assume "foldr (\<otimes>) fs \<one> \<sim> a" also note aa' | 
| 1202 | finally show "foldr (\<otimes>) fs \<one> \<sim> a'" by simp | |
| 27701 | 1203 | qed | 
| 1204 | ||
| 1205 | ||
| 61382 | 1206 | subsubsection \<open>Essentially equal factorizations\<close> | 
| 27701 | 1207 | |
| 1208 | lemma (in comm_monoid_cancel) unitfactor_ee: | |
| 1209 | assumes uunit: "u \<in> Units G" | |
| 1210 | and carr: "set as \<subseteq> carrier G" | |
| 63832 | 1211 | shows "essentially_equal G (as[0 := (as!0 \<otimes> u)]) as" | 
| 1212 | (is "essentially_equal G ?as' as") | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1213 | proof - | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1214 | have "as[0 := as ! 0 \<otimes> u] [\<sim>] as" | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1215 | proof (cases as) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1216 | case (Cons a as') | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1217 | then show ?thesis | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1218 | using associatedI2 carr uunit by auto | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1219 | qed auto | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1220 | then show ?thesis | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1221 | using essentially_equal_def by blast | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1222 | qed | 
| 27701 | 1223 | |
| 1224 | lemma (in comm_monoid_cancel) factors_cong_unit: | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1225 | assumes u: "u \<in> Units G" | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1226 | and a: "a \<notin> Units G" | 
| 27701 | 1227 | and afs: "factors G as a" | 
| 1228 | and ascarr: "set as \<subseteq> carrier G" | |
| 63832 | 1229 | shows "factors G (as[0 := (as!0 \<otimes> u)]) (a \<otimes> u)" | 
| 1230 | (is "factors G ?as' ?a'") | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1231 | proof (cases as) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1232 | case Nil | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1233 | then show ?thesis | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1234 | using afs a nunit_factors by auto | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1235 | next | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1236 | case (Cons b bs) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1237 | have *: "\<forall>f\<in>set as. irreducible G f" "foldr (\<otimes>) as \<one> = a" | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1238 | using afs by (auto simp: factors_def) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1239 | show ?thesis | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1240 | proof (intro factorsI) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1241 | show "foldr (\<otimes>) (as[0 := as ! 0 \<otimes> u]) \<one> = a \<otimes> u" | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1242 | using Cons u ascarr * by (auto simp add: m_ac Units_closed) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1243 | show "\<forall>f\<in>set (as[0 := as ! 0 \<otimes> u]). irreducible G f" | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1244 | using Cons u ascarr * by (force intro: irreducible_prod_rI) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1245 | qed | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1246 | qed | 
| 27701 | 1247 | |
| 1248 | lemma (in comm_monoid) perm_wfactorsD: | |
| 1249 | assumes prm: "as <~~> bs" | |
| 63832 | 1250 | and afs: "wfactors G as a" | 
| 1251 | and bfs: "wfactors G bs b" | |
| 27701 | 1252 | and [simp]: "a \<in> carrier G" "b \<in> carrier G" | 
| 63832 | 1253 | and ascarr [simp]: "set as \<subseteq> carrier G" | 
| 27701 | 1254 | shows "a \<sim> b" | 
| 63832 | 1255 | using afs bfs | 
| 27701 | 1256 | proof (elim wfactorsE) | 
| 1257 | from prm have [simp]: "set bs \<subseteq> carrier G" by (simp add: perm_closed) | |
| 67399 | 1258 | assume "foldr (\<otimes>) as \<one> \<sim> a" | 
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1259 | then have "a \<sim> foldr (\<otimes>) as \<one>" | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1260 | by (simp add: associated_sym) | 
| 27701 | 1261 | also from prm | 
| 67399 | 1262 | have "foldr (\<otimes>) as \<one> = foldr (\<otimes>) bs \<one>" by (rule multlist_perm_cong, simp) | 
| 1263 | also assume "foldr (\<otimes>) bs \<one> \<sim> b" | |
| 63832 | 1264 | finally show "a \<sim> b" by simp | 
| 27701 | 1265 | qed | 
| 1266 | ||
| 1267 | lemma (in comm_monoid_cancel) listassoc_wfactorsD: | |
| 1268 | assumes assoc: "as [\<sim>] bs" | |
| 63832 | 1269 | and afs: "wfactors G as a" | 
| 1270 | and bfs: "wfactors G bs b" | |
| 27701 | 1271 | and [simp]: "a \<in> carrier G" "b \<in> carrier G" | 
| 1272 | and [simp]: "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" | |
| 1273 | shows "a \<sim> b" | |
| 63832 | 1274 | using afs bfs | 
| 27701 | 1275 | proof (elim wfactorsE) | 
| 67399 | 1276 | assume "foldr (\<otimes>) as \<one> \<sim> a" | 
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1277 | then have "a \<sim> foldr (\<otimes>) as \<one>" by (simp add: associated_sym) | 
| 27701 | 1278 | also from assoc | 
| 67399 | 1279 | have "foldr (\<otimes>) as \<one> \<sim> foldr (\<otimes>) bs \<one>" by (rule multlist_listassoc_cong, simp+) | 
| 1280 | also assume "foldr (\<otimes>) bs \<one> \<sim> b" | |
| 63832 | 1281 | finally show "a \<sim> b" by simp | 
| 27701 | 1282 | qed | 
| 1283 | ||
| 1284 | lemma (in comm_monoid_cancel) ee_wfactorsD: | |
| 1285 | assumes ee: "essentially_equal G as bs" | |
| 1286 | and afs: "wfactors G as a" and bfs: "wfactors G bs b" | |
| 1287 | and [simp]: "a \<in> carrier G" "b \<in> carrier G" | |
| 1288 | and ascarr[simp]: "set as \<subseteq> carrier G" and bscarr[simp]: "set bs \<subseteq> carrier G" | |
| 1289 | shows "a \<sim> b" | |
| 63832 | 1290 | using ee | 
| 27701 | 1291 | proof (elim essentially_equalE) | 
| 1292 | fix fs | |
| 1293 | assume prm: "as <~~> fs" | |
| 63832 | 1294 | then have as'carr[simp]: "set fs \<subseteq> carrier G" | 
| 1295 | by (simp add: perm_closed) | |
| 1296 | from afs prm have afs': "wfactors G fs a" | |
| 1297 | by (rule wfactors_perm_cong_l) simp | |
| 27701 | 1298 | assume "fs [\<sim>] bs" | 
| 63832 | 1299 | from this afs' bfs show "a \<sim> b" | 
| 1300 | by (rule listassoc_wfactorsD) simp_all | |
| 27701 | 1301 | qed | 
| 1302 | ||
| 1303 | lemma (in comm_monoid_cancel) ee_factorsD: | |
| 1304 | assumes ee: "essentially_equal G as bs" | |
| 1305 | and afs: "factors G as a" and bfs:"factors G bs b" | |
| 1306 | and "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" | |
| 1307 | shows "a \<sim> b" | |
| 63832 | 1308 | using assms by (blast intro: factors_wfactors dest: ee_wfactorsD) | 
| 27701 | 1309 | |
| 1310 | lemma (in factorial_monoid) ee_factorsI: | |
| 1311 | assumes ab: "a \<sim> b" | |
| 1312 | and afs: "factors G as a" and anunit: "a \<notin> Units G" | |
| 1313 | and bfs: "factors G bs b" and bnunit: "b \<notin> Units G" | |
| 1314 | and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G" | |
| 1315 | shows "essentially_equal G as bs" | |
| 1316 | proof - | |
| 1317 | note carr[simp] = factors_closed[OF afs ascarr] ascarr[THEN subsetD] | |
| 63832 | 1318 | factors_closed[OF bfs bscarr] bscarr[THEN subsetD] | 
| 1319 | ||
| 63847 | 1320 | from ab carr obtain u where uunit: "u \<in> Units G" and a: "a = b \<otimes> u" | 
| 1321 | by (elim associatedE2) | |
| 63832 | 1322 | |
| 1323 | from uunit bscarr have ee: "essentially_equal G (bs[0 := (bs!0 \<otimes> u)]) bs" | |
| 1324 | (is "essentially_equal G ?bs' bs") | |
| 1325 | by (rule unitfactor_ee) | |
| 1326 | ||
| 1327 | from bscarr uunit have bs'carr: "set ?bs' \<subseteq> carrier G" | |
| 1328 | by (cases bs) (simp_all add: Units_closed) | |
| 1329 | ||
| 1330 | from uunit bnunit bfs bscarr have fac: "factors G ?bs' (b \<otimes> u)" | |
| 1331 | by (rule factors_cong_unit) | |
| 27701 | 1332 | |
| 1333 | from afs fac[simplified a[symmetric]] ascarr bs'carr anunit | |
| 63832 | 1334 | have "essentially_equal G as ?bs'" | 
| 1335 | by (blast intro: factors_unique) | |
| 27701 | 1336 | also note ee | 
| 63832 | 1337 | finally show "essentially_equal G as bs" | 
| 1338 | by (simp add: ascarr bscarr bs'carr) | |
| 27701 | 1339 | qed | 
| 1340 | ||
| 1341 | lemma (in factorial_monoid) ee_wfactorsI: | |
| 1342 | assumes asc: "a \<sim> b" | |
| 1343 | and asf: "wfactors G as a" and bsf: "wfactors G bs b" | |
| 1344 | and acarr[simp]: "a \<in> carrier G" and bcarr[simp]: "b \<in> carrier G" | |
| 1345 | and ascarr[simp]: "set as \<subseteq> carrier G" and bscarr[simp]: "set bs \<subseteq> carrier G" | |
| 1346 | shows "essentially_equal G as bs" | |
| 63832 | 1347 | using assms | 
| 27701 | 1348 | proof (cases "a \<in> Units G") | 
| 63832 | 1349 | case aunit: True | 
| 27701 | 1350 | also note asc | 
| 1351 | finally have bunit: "b \<in> Units G" by simp | |
| 1352 | ||
| 63832 | 1353 | from aunit asf ascarr have e: "as = []" | 
| 1354 | by (rule unit_wfactors_empty) | |
| 1355 | from bunit bsf bscarr have e': "bs = []" | |
| 1356 | by (rule unit_wfactors_empty) | |
| 27701 | 1357 | |
| 1358 | have "essentially_equal G [] []" | |
| 63832 | 1359 | by (fast intro: essentially_equalI) | 
| 1360 | then show ?thesis | |
| 1361 | by (simp add: e e') | |
| 27701 | 1362 | next | 
| 63832 | 1363 | case anunit: False | 
| 27701 | 1364 | have bnunit: "b \<notin> Units G" | 
| 1365 | proof clarify | |
| 1366 | assume "b \<in> Units G" | |
| 1367 | also note asc[symmetric] | |
| 1368 | finally have "a \<in> Units G" by simp | |
| 63832 | 1369 | with anunit show False .. | 
| 27701 | 1370 | qed | 
| 1371 | ||
| 63847 | 1372 | from wfactors_factors[OF asf ascarr] obtain a' where fa': "factors G as a'" and a': "a' \<sim> a" | 
| 1373 | by blast | |
| 63832 | 1374 | from fa' ascarr have a'carr[simp]: "a' \<in> carrier G" | 
| 1375 | by fast | |
| 27701 | 1376 | |
| 1377 | have a'nunit: "a' \<notin> Units G" | |
| 63832 | 1378 | proof clarify | 
| 27701 | 1379 | assume "a' \<in> Units G" | 
| 1380 | also note a' | |
| 1381 | finally have "a \<in> Units G" by simp | |
| 1382 | with anunit | |
| 63832 | 1383 | show "False" .. | 
| 27701 | 1384 | qed | 
| 1385 | ||
| 63847 | 1386 | from wfactors_factors[OF bsf bscarr] obtain b' where fb': "factors G bs b'" and b': "b' \<sim> b" | 
| 1387 | by blast | |
| 63832 | 1388 | from fb' bscarr have b'carr[simp]: "b' \<in> carrier G" | 
| 1389 | by fast | |
| 27701 | 1390 | |
| 1391 | have b'nunit: "b' \<notin> Units G" | |
| 63832 | 1392 | proof clarify | 
| 27701 | 1393 | assume "b' \<in> Units G" | 
| 1394 | also note b' | |
| 1395 | finally have "b \<in> Units G" by simp | |
| 63832 | 1396 | with bnunit show False .. | 
| 27701 | 1397 | qed | 
| 1398 | ||
| 1399 | note a' | |
| 1400 | also note asc | |
| 1401 | also note b'[symmetric] | |
| 63832 | 1402 | finally have "a' \<sim> b'" by simp | 
| 1403 | from this fa' a'nunit fb' b'nunit ascarr bscarr show "essentially_equal G as bs" | |
| 1404 | by (rule ee_factorsI) | |
| 27701 | 1405 | qed | 
| 1406 | ||
| 1407 | lemma (in factorial_monoid) ee_wfactors: | |
| 1408 | assumes asf: "wfactors G as a" | |
| 1409 | and bsf: "wfactors G bs b" | |
| 1410 | and acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" | |
| 1411 | and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G" | |
| 1412 | shows asc: "a \<sim> b = essentially_equal G as bs" | |
| 63832 | 1413 | using assms by (fast intro: ee_wfactorsI ee_wfactorsD) | 
| 27701 | 1414 | |
| 1415 | lemma (in factorial_monoid) wfactors_exist [intro, simp]: | |
| 1416 | assumes acarr[simp]: "a \<in> carrier G" | |
| 1417 | shows "\<exists>fs. set fs \<subseteq> carrier G \<and> wfactors G fs a" | |
| 1418 | proof (cases "a \<in> Units G") | |
| 63832 | 1419 | case True | 
| 1420 | then have "wfactors G [] a" by (rule unit_wfactors) | |
| 1421 | then show ?thesis by (intro exI) force | |
| 27701 | 1422 | next | 
| 63832 | 1423 | case False | 
| 63847 | 1424 | with factors_exist [OF acarr] obtain fs where fscarr: "set fs \<subseteq> carrier G" and f: "factors G fs a" | 
| 1425 | by blast | |
| 27701 | 1426 | from f have "wfactors G fs a" by (rule factors_wfactors) fact | 
| 63832 | 1427 | with fscarr show ?thesis by fast | 
| 27701 | 1428 | qed | 
| 1429 | ||
| 1430 | lemma (in monoid) wfactors_prod_exists [intro, simp]: | |
| 1431 | assumes "\<forall>a \<in> set as. irreducible G a" and "set as \<subseteq> carrier G" | |
| 1432 | shows "\<exists>a. a \<in> carrier G \<and> wfactors G as a" | |
| 63832 | 1433 | unfolding wfactors_def using assms by blast | 
| 27701 | 1434 | |
| 1435 | lemma (in factorial_monoid) wfactors_unique: | |
| 63832 | 1436 | assumes "wfactors G fs a" | 
| 1437 | and "wfactors G fs' a" | |
| 27701 | 1438 | and "a \<in> carrier G" | 
| 63832 | 1439 | and "set fs \<subseteq> carrier G" | 
| 1440 | and "set fs' \<subseteq> carrier G" | |
| 27701 | 1441 | shows "essentially_equal G fs fs'" | 
| 63832 | 1442 | using assms by (fast intro: ee_wfactorsI[of a a]) | 
| 27701 | 1443 | |
| 1444 | lemma (in monoid) factors_mult_single: | |
| 1445 | assumes "irreducible G a" and "factors G fb b" and "a \<in> carrier G" | |
| 1446 | shows "factors G (a # fb) (a \<otimes> b)" | |
| 63832 | 1447 | using assms unfolding factors_def by simp | 
| 27701 | 1448 | |
| 1449 | lemma (in monoid_cancel) wfactors_mult_single: | |
| 1450 | assumes f: "irreducible G a" "wfactors G fb b" | |
| 63832 | 1451 | "a \<in> carrier G" "b \<in> carrier G" "set fb \<subseteq> carrier G" | 
| 27701 | 1452 | shows "wfactors G (a # fb) (a \<otimes> b)" | 
| 63832 | 1453 | using assms unfolding wfactors_def by (simp add: mult_cong_r) | 
| 27701 | 1454 | |
| 1455 | lemma (in monoid) factors_mult: | |
| 1456 | assumes factors: "factors G fa a" "factors G fb b" | |
| 63832 | 1457 | and ascarr: "set fa \<subseteq> carrier G" | 
| 1458 | and bscarr: "set fb \<subseteq> carrier G" | |
| 27701 | 1459 | shows "factors G (fa @ fb) (a \<otimes> b)" | 
| 68474 | 1460 | proof - | 
| 1461 | have "foldr (\<otimes>) (fa @ fb) \<one> = foldr (\<otimes>) fa \<one> \<otimes> foldr (\<otimes>) fb \<one>" if "set fa \<subseteq> carrier G" | |
| 1462 | "Ball (set fa) (irreducible G)" | |
| 1463 | using that bscarr by (induct fa) (simp_all add: m_assoc) | |
| 1464 | then show ?thesis | |
| 1465 | using assms unfolding factors_def by force | |
| 1466 | qed | |
| 27701 | 1467 | |
| 1468 | lemma (in comm_monoid_cancel) wfactors_mult [intro]: | |
| 1469 | assumes asf: "wfactors G as a" and bsf:"wfactors G bs b" | |
| 1470 | and acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" | |
| 1471 | and ascarr: "set as \<subseteq> carrier G" and bscarr:"set bs \<subseteq> carrier G" | |
| 1472 | shows "wfactors G (as @ bs) (a \<otimes> b)" | |
| 63832 | 1473 | using wfactors_factors[OF asf ascarr] and wfactors_factors[OF bsf bscarr] | 
| 1474 | proof clarsimp | |
| 27701 | 1475 | fix a' b' | 
| 1476 | assume asf': "factors G as a'" and a'a: "a' \<sim> a" | |
| 63832 | 1477 | and bsf': "factors G bs b'" and b'b: "b' \<sim> b" | 
| 27701 | 1478 | from asf' have a'carr: "a' \<in> carrier G" by (rule factors_closed) fact | 
| 1479 | from bsf' have b'carr: "b' \<in> carrier G" by (rule factors_closed) fact | |
| 1480 | ||
| 1481 | note carr = acarr bcarr a'carr b'carr ascarr bscarr | |
| 1482 | ||
| 63832 | 1483 | from asf' bsf' have "factors G (as @ bs) (a' \<otimes> b')" | 
| 1484 | by (rule factors_mult) fact+ | |
| 1485 | ||
| 1486 | with carr have abf': "wfactors G (as @ bs) (a' \<otimes> b')" | |
| 1487 | by (intro factors_wfactors) simp_all | |
| 1488 | also from b'b carr have trb: "a' \<otimes> b' \<sim> a' \<otimes> b" | |
| 1489 | by (intro mult_cong_r) | |
| 1490 | also from a'a carr have tra: "a' \<otimes> b \<sim> a \<otimes> b" | |
| 1491 | by (intro mult_cong_l) | |
| 1492 | finally show "wfactors G (as @ bs) (a \<otimes> b)" | |
| 1493 | by (simp add: carr) | |
| 27701 | 1494 | qed | 
| 1495 | ||
| 1496 | lemma (in comm_monoid) factors_dividesI: | |
| 63832 | 1497 | assumes "factors G fs a" | 
| 1498 | and "f \<in> set fs" | |
| 27701 | 1499 | and "set fs \<subseteq> carrier G" | 
| 1500 | shows "f divides a" | |
| 63832 | 1501 | using assms by (fast elim: factorsE intro: multlist_dividesI) | 
| 27701 | 1502 | |
| 1503 | lemma (in comm_monoid) wfactors_dividesI: | |
| 1504 | assumes p: "wfactors G fs a" | |
| 1505 | and fscarr: "set fs \<subseteq> carrier G" and acarr: "a \<in> carrier G" | |
| 1506 | and f: "f \<in> set fs" | |
| 1507 | shows "f divides a" | |
| 63832 | 1508 | using wfactors_factors[OF p fscarr] | 
| 1509 | proof clarsimp | |
| 27701 | 1510 | fix a' | 
| 63832 | 1511 | assume fsa': "factors G fs a'" and a'a: "a' \<sim> a" | 
| 1512 | with fscarr have a'carr: "a' \<in> carrier G" | |
| 1513 | by (simp add: factors_closed) | |
| 1514 | ||
| 1515 | from fsa' fscarr f have "f divides a'" | |
| 1516 | by (fast intro: factors_dividesI) | |
| 27701 | 1517 | also note a'a | 
| 63832 | 1518 | finally show "f divides a" | 
| 1519 | by (simp add: f fscarr[THEN subsetD] acarr a'carr) | |
| 27701 | 1520 | qed | 
| 1521 | ||
| 1522 | ||
| 61382 | 1523 | subsubsection \<open>Factorial monoids and wfactors\<close> | 
| 27701 | 1524 | |
| 1525 | lemma (in comm_monoid_cancel) factorial_monoidI: | |
| 68664 
bd0df72c16d5
updated material concerning Algebra
 paulson <lp15@cam.ac.uk> parents: 
68604diff
changeset | 1526 | assumes wfactors_exists: "\<And>a. \<lbrakk> a \<in> carrier G; a \<notin> Units G \<rbrakk> \<Longrightarrow> \<exists>fs. set fs \<subseteq> carrier G \<and> wfactors G fs a" | 
| 63832 | 1527 | and wfactors_unique: | 
| 1528 | "\<And>a fs fs'. \<lbrakk>a \<in> carrier G; set fs \<subseteq> carrier G; set fs' \<subseteq> carrier G; | |
| 1529 | wfactors G fs a; wfactors G fs' a\<rbrakk> \<Longrightarrow> essentially_equal G fs fs'" | |
| 27701 | 1530 | shows "factorial_monoid G" | 
| 28823 | 1531 | proof | 
| 27701 | 1532 | fix a | 
| 1533 | assume acarr: "a \<in> carrier G" and anunit: "a \<notin> Units G" | |
| 68664 
bd0df72c16d5
updated material concerning Algebra
 paulson <lp15@cam.ac.uk> parents: 
68604diff
changeset | 1534 | from wfactors_exists[OF acarr anunit] | 
| 63832 | 1535 | obtain as where ascarr: "set as \<subseteq> carrier G" and afs: "wfactors G as a" | 
| 63847 | 1536 | by blast | 
| 1537 | from wfactors_factors [OF afs ascarr] obtain a' where afs': "factors G as a'" and a'a: "a' \<sim> a" | |
| 1538 | by blast | |
| 63832 | 1539 | from afs' ascarr have a'carr: "a' \<in> carrier G" | 
| 1540 | by fast | |
| 27701 | 1541 | have a'nunit: "a' \<notin> Units G" | 
| 1542 | proof clarify | |
| 1543 | assume "a' \<in> Units G" | |
| 1544 | also note a'a | |
| 1545 | finally have "a \<in> Units G" by (simp add: acarr) | |
| 63832 | 1546 | with anunit show False .. | 
| 27701 | 1547 | qed | 
| 1548 | ||
| 63847 | 1549 | from a'carr acarr a'a obtain u where uunit: "u \<in> Units G" and a': "a' = a \<otimes> u" | 
| 63832 | 1550 | by (blast elim: associatedE2) | 
| 27701 | 1551 | |
| 1552 | note [simp] = acarr Units_closed[OF uunit] Units_inv_closed[OF uunit] | |
| 1553 | have "a = a \<otimes> \<one>" by simp | |
| 57865 | 1554 | also have "\<dots> = a \<otimes> (u \<otimes> inv u)" by (simp add: uunit) | 
| 27701 | 1555 | also have "\<dots> = a' \<otimes> inv u" by (simp add: m_assoc[symmetric] a'[symmetric]) | 
| 63832 | 1556 | finally have a: "a = a' \<otimes> inv u" . | 
| 1557 | ||
| 1558 | from ascarr uunit have cr: "set (as[0:=(as!0 \<otimes> inv u)]) \<subseteq> carrier G" | |
| 1559 | by (cases as) auto | |
| 1560 | from afs' uunit a'nunit acarr ascarr have "factors G (as[0:=(as!0 \<otimes> inv u)]) a" | |
| 1561 | by (simp add: a factors_cong_unit) | |
| 1562 | with cr show "\<exists>fs. set fs \<subseteq> carrier G \<and> factors G fs a" | |
| 1563 | by fast | |
| 27701 | 1564 | qed (blast intro: factors_wfactors wfactors_unique) | 
| 1565 | ||
| 1566 | ||
| 61382 | 1567 | subsection \<open>Factorizations as Multisets\<close> | 
| 1568 | ||
| 1569 | text \<open>Gives useful operations like intersection\<close> | |
| 27701 | 1570 | |
| 1571 | (* FIXME: use class_of x instead of closure_of {x} *)
 | |
| 1572 | ||
| 63832 | 1573 | abbreviation "assocs G x \<equiv> eq_closure_of (division_rel G) {x}"
 | 
| 1574 | ||
| 1575 | definition "fmset G as = mset (map (\<lambda>a. assocs G a) as)" | |
| 27701 | 1576 | |
| 1577 | ||
| 61382 | 1578 | text \<open>Helper lemmas\<close> | 
| 27701 | 1579 | |
| 1580 | lemma (in monoid) assocs_repr_independence: | |
| 68474 | 1581 | assumes "y \<in> assocs G x" "x \<in> carrier G" | 
| 27701 | 1582 | shows "assocs G x = assocs G y" | 
| 63832 | 1583 | using assms | 
| 68474 | 1584 | by (simp add: eq_closure_of_def elem_def) (use associated_sym associated_trans in \<open>blast+\<close>) | 
| 27701 | 1585 | |
| 1586 | lemma (in monoid) assocs_self: | |
| 1587 | assumes "x \<in> carrier G" | |
| 1588 | shows "x \<in> assocs G x" | |
| 63832 | 1589 | using assms by (fastforce intro: closure_ofI2) | 
| 27701 | 1590 | |
| 1591 | lemma (in monoid) assocs_repr_independenceD: | |
| 68474 | 1592 | assumes repr: "assocs G x = assocs G y" and ycarr: "y \<in> carrier G" | 
| 27701 | 1593 | shows "y \<in> assocs G x" | 
| 63832 | 1594 | unfolding repr using ycarr by (intro assocs_self) | 
| 27701 | 1595 | |
| 1596 | lemma (in comm_monoid) assocs_assoc: | |
| 68474 | 1597 | assumes "a \<in> assocs G b" "b \<in> carrier G" | 
| 27701 | 1598 | shows "a \<sim> b" | 
| 63832 | 1599 | using assms by (elim closure_ofE2) simp | 
| 1600 | ||
| 1601 | lemmas (in comm_monoid) assocs_eqD = assocs_repr_independenceD[THEN assocs_assoc] | |
| 27701 | 1602 | |
| 1603 | ||
| 61382 | 1604 | subsubsection \<open>Comparing multisets\<close> | 
| 27701 | 1605 | |
| 1606 | lemma (in monoid) fmset_perm_cong: | |
| 1607 | assumes prm: "as <~~> bs" | |
| 1608 | shows "fmset G as = fmset G bs" | |
| 63832 | 1609 | using perm_map[OF prm] unfolding mset_eq_perm fmset_def by blast | 
| 27701 | 1610 | |
| 1611 | lemma (in comm_monoid_cancel) eqc_listassoc_cong: | |
| 68474 | 1612 | assumes "as [\<sim>] bs" and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G" | 
| 27701 | 1613 | shows "map (assocs G) as = map (assocs G) bs" | 
| 63832 | 1614 | using assms | 
| 68474 | 1615 | proof (induction as arbitrary: bs) | 
| 1616 | case Nil | |
| 1617 | then show ?case by simp | |
| 27701 | 1618 | next | 
| 68474 | 1619 | case (Cons a as) | 
| 1620 | then show ?case | |
| 1621 | proof (clarsimp simp add: Cons_eq_map_conv list_all2_Cons1) | |
| 1622 | fix z zs | |
| 1623 | assume zzs: "a \<in> carrier G" "set as \<subseteq> carrier G" "bs = z # zs" "a \<sim> z" | |
| 1624 | "as [\<sim>] zs" "z \<in> carrier G" "set zs \<subseteq> carrier G" | |
| 1625 | then show "assocs G a = assocs G z" | |
| 1626 | apply (simp add: eq_closure_of_def elem_def) | |
| 1627 | using \<open>a \<in> carrier G\<close> \<open>z \<in> carrier G\<close> \<open>a \<sim> z\<close> associated_sym associated_trans by blast+ | |
| 1628 | qed | |
| 27701 | 1629 | qed | 
| 1630 | ||
| 1631 | lemma (in comm_monoid_cancel) fmset_listassoc_cong: | |
| 63832 | 1632 | assumes "as [\<sim>] bs" | 
| 27701 | 1633 | and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G" | 
| 1634 | shows "fmset G as = fmset G bs" | |
| 63832 | 1635 | using assms unfolding fmset_def by (simp add: eqc_listassoc_cong) | 
| 27701 | 1636 | |
| 1637 | lemma (in comm_monoid_cancel) ee_fmset: | |
| 63832 | 1638 | assumes ee: "essentially_equal G as bs" | 
| 27701 | 1639 | and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G" | 
| 1640 | shows "fmset G as = fmset G bs" | |
| 63832 | 1641 | using ee | 
| 27701 | 1642 | proof (elim essentially_equalE) | 
| 1643 | fix as' | |
| 1644 | assume prm: "as <~~> as'" | |
| 63832 | 1645 | from prm ascarr have as'carr: "set as' \<subseteq> carrier G" | 
| 1646 | by (rule perm_closed) | |
| 1647 | from prm have "fmset G as = fmset G as'" | |
| 1648 | by (rule fmset_perm_cong) | |
| 27701 | 1649 | also assume "as' [\<sim>] bs" | 
| 63832 | 1650 | with as'carr bscarr have "fmset G as' = fmset G bs" | 
| 1651 | by (simp add: fmset_listassoc_cong) | |
| 1652 | finally show "fmset G as = fmset G bs" . | |
| 27701 | 1653 | qed | 
| 1654 | ||
| 68474 | 1655 | lemma (in monoid_cancel) fmset_ee_aux: | 
| 1656 | assumes "cas <~~> cbs" "cas = map (assocs G) as" "cbs = map (assocs G) bs" | |
| 1657 | shows "\<exists>as'. as <~~> as' \<and> map (assocs G) as' = cbs" | |
| 1658 | using assms | |
| 1659 | proof (induction cas cbs arbitrary: as bs rule: perm.induct) | |
| 1660 | case (Cons xs ys z) | |
| 1661 | then show ?case | |
| 1662 | by (clarsimp simp add: map_eq_Cons_conv) blast | |
| 1663 | next | |
| 1664 | case (trans xs ys zs) | |
| 68604 | 1665 | then obtain as' where " as <~~> as' \<and> map (assocs G) as' = ys" | 
| 1666 | by (metis (no_types, lifting) ex_map_conv mset_eq_perm set_mset_mset) | |
| 68474 | 1667 | then show ?case | 
| 68604 | 1668 | using trans.IH(2) trans.prems(2) by blast | 
| 68474 | 1669 | qed auto | 
| 27701 | 1670 | |
| 1671 | lemma (in comm_monoid_cancel) fmset_ee: | |
| 1672 | assumes mset: "fmset G as = fmset G bs" | |
| 1673 | and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G" | |
| 1674 | shows "essentially_equal G as bs" | |
| 1675 | proof - | |
| 68474 | 1676 | from mset have "map (assocs G) as <~~> map (assocs G) bs" | 
| 63832 | 1677 | by (simp add: fmset_def mset_eq_perm del: mset_map) | 
| 1678 | then obtain as' where tp: "as <~~> as'" and tm: "map (assocs G) as' = map (assocs G) bs" | |
| 68474 | 1679 | using fmset_ee_aux by blast | 
| 63832 | 1680 | with ascarr have as'carr: "set as' \<subseteq> carrier G" | 
| 68474 | 1681 | using perm_closed by blast | 
| 63847 | 1682 | from tm as'carr[THEN subsetD] bscarr[THEN subsetD] have "as' [\<sim>] bs" | 
| 44890 
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
 nipkow parents: 
44655diff
changeset | 1683 | by (induct as' arbitrary: bs) (simp, fastforce dest: assocs_eqD[THEN associated_sym]) | 
| 63832 | 1684 | with tp show "essentially_equal G as bs" | 
| 1685 | by (fast intro: essentially_equalI) | |
| 27701 | 1686 | qed | 
| 1687 | ||
| 1688 | lemma (in comm_monoid_cancel) ee_is_fmset: | |
| 1689 | assumes "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G" | |
| 1690 | shows "essentially_equal G as bs = (fmset G as = fmset G bs)" | |
| 63832 | 1691 | using assms by (fast intro: ee_fmset fmset_ee) | 
| 27701 | 1692 | |
| 1693 | ||
| 61382 | 1694 | subsubsection \<open>Interpreting multisets as factorizations\<close> | 
| 27701 | 1695 | |
| 1696 | lemma (in monoid) mset_fmsetEx: | |
| 60495 | 1697 | assumes elems: "\<And>X. X \<in> set_mset Cs \<Longrightarrow> \<exists>x. P x \<and> X = assocs G x" | 
| 27701 | 1698 | shows "\<exists>cs. (\<forall>c \<in> set cs. P c) \<and> fmset G cs = Cs" | 
| 1699 | proof - | |
| 63847 | 1700 | from surjE[OF surj_mset] obtain Cs' where Cs: "Cs = mset Cs'" | 
| 1701 | by blast | |
| 60515 | 1702 | have "\<exists>cs. (\<forall>c \<in> set cs. P c) \<and> mset (map (assocs G) cs) = Cs" | 
| 68478 | 1703 | using elems unfolding Cs | 
| 1704 | proof (induction Cs') | |
| 1705 | case (Cons a Cs') | |
| 1706 | then obtain c cs where csP: "\<forall>x\<in>set cs. P x" and mset: "mset (map (assocs G) cs) = mset Cs'" | |
| 1707 | and cP: "P c" and a: "a = assocs G c" | |
| 1708 | by force | |
| 1709 | then have tP: "\<forall>x\<in>set (c#cs). P x" | |
| 63847 | 1710 | by simp | 
| 68478 | 1711 | show ?case | 
| 1712 | using tP mset a by fastforce | |
| 1713 | qed auto | |
| 63832 | 1714 | then show ?thesis by (simp add: fmset_def) | 
| 27701 | 1715 | qed | 
| 1716 | ||
| 1717 | lemma (in monoid) mset_wfactorsEx: | |
| 63832 | 1718 | assumes elems: "\<And>X. X \<in> set_mset Cs \<Longrightarrow> \<exists>x. (x \<in> carrier G \<and> irreducible G x) \<and> X = assocs G x" | 
| 27701 | 1719 | shows "\<exists>c cs. c \<in> carrier G \<and> set cs \<subseteq> carrier G \<and> wfactors G cs c \<and> fmset G cs = Cs" | 
| 1720 | proof - | |
| 1721 | have "\<exists>cs. (\<forall>c\<in>set cs. c \<in> carrier G \<and> irreducible G c) \<and> fmset G cs = Cs" | |
| 63832 | 1722 | by (intro mset_fmsetEx, rule elems) | 
| 1723 | then obtain cs where p[rule_format]: "\<forall>c\<in>set cs. c \<in> carrier G \<and> irreducible G c" | |
| 1724 | and Cs[symmetric]: "fmset G cs = Cs" by auto | |
| 1725 | from p have cscarr: "set cs \<subseteq> carrier G" by fast | |
| 1726 | from p have "\<exists>c. c \<in> carrier G \<and> wfactors G cs c" | |
| 1727 | by (intro wfactors_prod_exists) auto | |
| 1728 | then obtain c where ccarr: "c \<in> carrier G" and cfs: "wfactors G cs c" by auto | |
| 1729 | with cscarr Cs show ?thesis by fast | |
| 27701 | 1730 | qed | 
| 1731 | ||
| 1732 | ||
| 61382 | 1733 | subsubsection \<open>Multiplication on multisets\<close> | 
| 27701 | 1734 | |
| 1735 | lemma (in factorial_monoid) mult_wfactors_fmset: | |
| 63832 | 1736 | assumes afs: "wfactors G as a" | 
| 1737 | and bfs: "wfactors G bs b" | |
| 1738 | and cfs: "wfactors G cs (a \<otimes> b)" | |
| 27701 | 1739 | and carr: "a \<in> carrier G" "b \<in> carrier G" | 
| 1740 | "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" "set cs \<subseteq> carrier G" | |
| 1741 | shows "fmset G cs = fmset G as + fmset G bs" | |
| 1742 | proof - | |
| 63832 | 1743 | from assms have "wfactors G (as @ bs) (a \<otimes> b)" | 
| 1744 | by (intro wfactors_mult) | |
| 1745 | with carr cfs have "essentially_equal G cs (as@bs)" | |
| 1746 | by (intro ee_wfactorsI[of "a\<otimes>b" "a\<otimes>b"]) simp_all | |
| 1747 | with carr have "fmset G cs = fmset G (as@bs)" | |
| 1748 | by (intro ee_fmset) simp_all | |
| 1749 | also have "fmset G (as@bs) = fmset G as + fmset G bs" | |
| 1750 | by (simp add: fmset_def) | |
| 27701 | 1751 | finally show "fmset G cs = fmset G as + fmset G bs" . | 
| 1752 | qed | |
| 1753 | ||
| 1754 | lemma (in factorial_monoid) mult_factors_fmset: | |
| 63832 | 1755 | assumes afs: "factors G as a" | 
| 1756 | and bfs: "factors G bs b" | |
| 1757 | and cfs: "factors G cs (a \<otimes> b)" | |
| 27701 | 1758 | and "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" "set cs \<subseteq> carrier G" | 
| 1759 | shows "fmset G cs = fmset G as + fmset G bs" | |
| 63832 | 1760 | using assms by (blast intro: factors_wfactors mult_wfactors_fmset) | 
| 27701 | 1761 | |
| 1762 | lemma (in comm_monoid_cancel) fmset_wfactors_mult: | |
| 1763 | assumes mset: "fmset G cs = fmset G as + fmset G bs" | |
| 1764 | and carr: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | |
| 63832 | 1765 | "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" "set cs \<subseteq> carrier G" | 
| 27701 | 1766 | and fs: "wfactors G as a" "wfactors G bs b" "wfactors G cs c" | 
| 1767 | shows "c \<sim> a \<otimes> b" | |
| 1768 | proof - | |
| 63832 | 1769 | from carr fs have m: "wfactors G (as @ bs) (a \<otimes> b)" | 
| 1770 | by (intro wfactors_mult) | |
| 1771 | ||
| 1772 | from mset have "fmset G cs = fmset G (as@bs)" | |
| 1773 | by (simp add: fmset_def) | |
| 1774 | then have "essentially_equal G cs (as@bs)" | |
| 1775 | by (rule fmset_ee) (simp_all add: carr) | |
| 1776 | then show "c \<sim> a \<otimes> b" | |
| 1777 | by (rule ee_wfactorsD[of "cs" "as@bs"]) (simp_all add: assms m) | |
| 27701 | 1778 | qed | 
| 1779 | ||
| 1780 | ||
| 61382 | 1781 | subsubsection \<open>Divisibility on multisets\<close> | 
| 27701 | 1782 | |
| 1783 | lemma (in factorial_monoid) divides_fmsubset: | |
| 1784 | assumes ab: "a divides b" | |
| 63832 | 1785 | and afs: "wfactors G as a" | 
| 1786 | and bfs: "wfactors G bs b" | |
| 27701 | 1787 | and carr: "a \<in> carrier G" "b \<in> carrier G" "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" | 
| 64587 | 1788 | shows "fmset G as \<subseteq># fmset G bs" | 
| 63832 | 1789 | using ab | 
| 27701 | 1790 | proof (elim dividesE) | 
| 1791 | fix c | |
| 1792 | assume ccarr: "c \<in> carrier G" | |
| 63847 | 1793 | from wfactors_exist [OF this] | 
| 1794 | obtain cs where cscarr: "set cs \<subseteq> carrier G" and cfs: "wfactors G cs c" | |
| 1795 | by blast | |
| 27701 | 1796 | note carr = carr ccarr cscarr | 
| 1797 | ||
| 1798 | assume "b = a \<otimes> c" | |
| 63832 | 1799 | with afs bfs cfs carr have "fmset G bs = fmset G as + fmset G cs" | 
| 1800 | by (intro mult_wfactors_fmset[OF afs cfs]) simp_all | |
| 1801 | then show ?thesis by simp | |
| 27701 | 1802 | qed | 
| 1803 | ||
| 1804 | lemma (in comm_monoid_cancel) fmsubset_divides: | |
| 64587 | 1805 | assumes msubset: "fmset G as \<subseteq># fmset G bs" | 
| 63832 | 1806 | and afs: "wfactors G as a" | 
| 1807 | and bfs: "wfactors G bs b" | |
| 1808 | and acarr: "a \<in> carrier G" | |
| 1809 | and bcarr: "b \<in> carrier G" | |
| 1810 | and ascarr: "set as \<subseteq> carrier G" | |
| 1811 | and bscarr: "set bs \<subseteq> carrier G" | |
| 27701 | 1812 | shows "a divides b" | 
| 1813 | proof - | |
| 1814 | from afs have airr: "\<forall>a \<in> set as. irreducible G a" by (fast elim: wfactorsE) | |
| 1815 | from bfs have birr: "\<forall>b \<in> set bs. irreducible G b" by (fast elim: wfactorsE) | |
| 1816 | ||
| 1817 | 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" | |
| 1818 | proof (intro mset_wfactorsEx, simp) | |
| 1819 | fix X | |
| 62430 
9527ff088c15
more succint formulation of membership for multisets, similar to lists;
 haftmann parents: 
61382diff
changeset | 1820 | assume "X \<in># fmset G bs - fmset G as" | 
| 63832 | 1821 | then have "X \<in># fmset G bs" by (rule in_diffD) | 
| 1822 | then have "X \<in> set (map (assocs G) bs)" by (simp add: fmset_def) | |
| 1823 | then have "\<exists>x. x \<in> set bs \<and> X = assocs G x" by (induct bs) auto | |
| 1824 | then obtain x where xbs: "x \<in> set bs" and X: "X = assocs G x" by auto | |
| 27701 | 1825 | with bscarr have xcarr: "x \<in> carrier G" by fast | 
| 1826 | from xbs birr have xirr: "irreducible G x" by simp | |
| 1827 | ||
| 63832 | 1828 | from xcarr and xirr and X show "\<exists>x. x \<in> carrier G \<and> irreducible G x \<and> X = assocs G x" | 
| 1829 | by fast | |
| 27701 | 1830 | qed | 
| 63832 | 1831 | then obtain c cs | 
| 1832 | where ccarr: "c \<in> carrier G" | |
| 1833 | and cscarr: "set cs \<subseteq> carrier G" | |
| 27701 | 1834 | and csf: "wfactors G cs c" | 
| 1835 | and csmset: "fmset G cs = fmset G bs - fmset G as" by auto | |
| 1836 | ||
| 1837 | from csmset msubset | |
| 63832 | 1838 | have "fmset G bs = fmset G as + fmset G cs" | 
| 1839 | by (simp add: multiset_eq_iff subseteq_mset_def) | |
| 1840 | then have basc: "b \<sim> a \<otimes> c" | |
| 1841 | by (rule fmset_wfactors_mult) fact+ | |
| 1842 | then show ?thesis | |
| 27701 | 1843 | proof (elim associatedE2) | 
| 1844 | fix u | |
| 1845 | assume "u \<in> Units G" "b = a \<otimes> c \<otimes> u" | |
| 63832 | 1846 | with acarr ccarr show "a divides b" | 
| 1847 | by (fast intro: dividesI[of "c \<otimes> u"] m_assoc) | |
| 1848 | qed (simp_all add: acarr bcarr ccarr) | |
| 27701 | 1849 | qed | 
| 1850 | ||
| 1851 | lemma (in factorial_monoid) divides_as_fmsubset: | |
| 63832 | 1852 | assumes "wfactors G as a" | 
| 1853 | and "wfactors G bs b" | |
| 1854 | and "a \<in> carrier G" | |
| 1855 | and "b \<in> carrier G" | |
| 1856 | and "set as \<subseteq> carrier G" | |
| 1857 | and "set bs \<subseteq> carrier G" | |
| 64587 | 1858 | shows "a divides b = (fmset G as \<subseteq># fmset G bs)" | 
| 63832 | 1859 | using assms | 
| 1860 | by (blast intro: divides_fmsubset fmsubset_divides) | |
| 27701 | 1861 | |
| 1862 | ||
| 61382 | 1863 | text \<open>Proper factors on multisets\<close> | 
| 27701 | 1864 | |
| 1865 | lemma (in factorial_monoid) fmset_properfactor: | |
| 64587 | 1866 | assumes asubb: "fmset G as \<subseteq># fmset G bs" | 
| 27701 | 1867 | and anb: "fmset G as \<noteq> fmset G bs" | 
| 63832 | 1868 | and "wfactors G as a" | 
| 1869 | and "wfactors G bs b" | |
| 1870 | and "a \<in> carrier G" | |
| 1871 | and "b \<in> carrier G" | |
| 1872 | and "set as \<subseteq> carrier G" | |
| 1873 | and "set bs \<subseteq> carrier G" | |
| 27701 | 1874 | shows "properfactor G a b" | 
| 68478 | 1875 | proof (rule properfactorI) | 
| 1876 | show "a divides b" | |
| 1877 | using assms asubb fmsubset_divides by blast | |
| 1878 | show "\<not> b divides a" | |
| 1879 | by (meson anb assms asubb factorial_monoid.divides_fmsubset factorial_monoid_axioms subset_mset.antisym) | |
| 27701 | 1880 | qed | 
| 1881 | ||
| 1882 | lemma (in factorial_monoid) properfactor_fmset: | |
| 68684 | 1883 | assumes "properfactor G a b" | 
| 1884 | and "wfactors G as a" | |
| 1885 | and "wfactors G bs b" | |
| 1886 | and "a \<in> carrier G" | |
| 1887 | and "b \<in> carrier G" | |
| 1888 | and "set as \<subseteq> carrier G" | |
| 1889 | and "set bs \<subseteq> carrier G" | |
| 1890 | shows "fmset G as \<subseteq># fmset G bs" | |
| 1891 | using assms | |
| 1892 | by (meson divides_as_fmsubset properfactor_divides) | |
| 1893 | ||
| 1894 | lemma (in factorial_monoid) properfactor_fmset_ne: | |
| 27701 | 1895 | assumes pf: "properfactor G a b" | 
| 63832 | 1896 | and "wfactors G as a" | 
| 1897 | and "wfactors G bs b" | |
| 1898 | and "a \<in> carrier G" | |
| 1899 | and "b \<in> carrier G" | |
| 1900 | and "set as \<subseteq> carrier G" | |
| 1901 | and "set bs \<subseteq> carrier G" | |
| 68684 | 1902 | shows "fmset G as \<noteq> fmset G bs" | 
| 1903 | using properfactorE [OF pf] assms divides_as_fmsubset by force | |
| 27701 | 1904 | |
| 61382 | 1905 | subsection \<open>Irreducible Elements are Prime\<close> | 
| 27701 | 1906 | |
| 63633 | 1907 | lemma (in factorial_monoid) irreducible_prime: | 
| 68478 | 1908 | assumes pirr: "irreducible G p" and pcarr: "p \<in> carrier G" | 
| 27701 | 1909 | shows "prime G p" | 
| 63832 | 1910 | using pirr | 
| 27701 | 1911 | proof (elim irreducibleE, intro primeI) | 
| 1912 | fix a b | |
| 1913 | assume acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" | |
| 1914 | and pdvdab: "p divides (a \<otimes> b)" | |
| 1915 | and pnunit: "p \<notin> Units G" | |
| 1916 | assume irreduc[rule_format]: | |
| 63832 | 1917 | "\<forall>b. b \<in> carrier G \<and> properfactor G b p \<longrightarrow> b \<in> Units G" | 
| 63847 | 1918 | from pdvdab obtain c where ccarr: "c \<in> carrier G" and abpc: "a \<otimes> b = p \<otimes> c" | 
| 1919 | by (rule dividesE) | |
| 1920 | obtain as where ascarr: "set as \<subseteq> carrier G" and afs: "wfactors G as a" | |
| 68478 | 1921 | using wfactors_exist [OF acarr] by blast | 
| 63847 | 1922 | obtain bs where bscarr: "set bs \<subseteq> carrier G" and bfs: "wfactors G bs b" | 
| 68478 | 1923 | using wfactors_exist [OF bcarr] by blast | 
| 63847 | 1924 | obtain cs where cscarr: "set cs \<subseteq> carrier G" and cfs: "wfactors G cs c" | 
| 68478 | 1925 | using wfactors_exist [OF ccarr] by blast | 
| 27701 | 1926 | note carr[simp] = pcarr acarr bcarr ccarr ascarr bscarr cscarr | 
| 68478 | 1927 | from pirr cfs abpc have "wfactors G (p # cs) (a \<otimes> b)" | 
| 1928 | by (simp add: wfactors_mult_single) | |
| 1929 | moreover have "wfactors G (as @ bs) (a \<otimes> b)" | |
| 1930 | by (rule wfactors_mult [OF afs bfs]) fact+ | |
| 1931 | ultimately have "essentially_equal G (p # cs) (as @ bs)" | |
| 63832 | 1932 | by (rule wfactors_unique) simp+ | 
| 63847 | 1933 | then obtain ds where "p # cs <~~> ds" and dsassoc: "ds [\<sim>] (as @ bs)" | 
| 63832 | 1934 | by (fast elim: essentially_equalE) | 
| 27701 | 1935 | then have "p \<in> set ds" | 
| 63832 | 1936 | by (simp add: perm_set_eq[symmetric]) | 
| 63847 | 1937 | with dsassoc obtain p' where "p' \<in> set (as@bs)" and pp': "p \<sim> p'" | 
| 63832 | 1938 | unfolding list_all2_conv_all_nth set_conv_nth by force | 
| 1939 | then consider "p' \<in> set as" | "p' \<in> set bs" by auto | |
| 1940 | then show "p divides a \<or> p divides b" | |
| 68478 | 1941 | using afs bfs divides_cong_l pp' wfactors_dividesI | 
| 1942 | by (meson acarr ascarr bcarr bscarr pcarr) | |
| 27701 | 1943 | qed | 
| 1944 | ||
| 1945 | ||
| 69597 | 1946 | \<comment> \<open>A version using \<^const>\<open>factors\<close>, more complicated\<close> | 
| 63633 | 1947 | lemma (in factorial_monoid) factors_irreducible_prime: | 
| 68478 | 1948 | assumes pirr: "irreducible G p" and pcarr: "p \<in> carrier G" | 
| 27701 | 1949 | shows "prime G p" | 
| 68478 | 1950 | proof (rule primeI) | 
| 1951 | show "p \<notin> Units G" | |
| 1952 | by (meson irreducibleE pirr) | |
| 1953 | have irreduc: "\<And>b. \<lbrakk>b \<in> carrier G; properfactor G b p\<rbrakk> \<Longrightarrow> b \<in> Units G" | |
| 1954 | using pirr by (auto simp: irreducible_def) | |
| 1955 | show "p divides a \<or> p divides b" | |
| 1956 | if acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" and pdvdab: "p divides (a \<otimes> b)" for a b | |
| 1957 | proof - | |
| 1958 | from pdvdab obtain c where ccarr: "c \<in> carrier G" and abpc: "a \<otimes> b = p \<otimes> c" | |
| 1959 | by (rule dividesE) | |
| 1960 | note [simp] = pcarr acarr bcarr ccarr | |
| 1961 | ||
| 1962 | show "p divides a \<or> p divides b" | |
| 1963 | proof (cases "a \<in> Units G") | |
| 1964 | case True | |
| 1965 | then have "p divides b" | |
| 1966 | by (metis acarr associatedI2' associated_def bcarr divides_trans m_comm pcarr pdvdab) | |
| 63832 | 1967 | then show ?thesis .. | 
| 27701 | 1968 | next | 
| 68478 | 1969 | case anunit: False | 
| 1970 | show ?thesis | |
| 1971 | proof (cases "b \<in> Units G") | |
| 1972 | case True | |
| 1973 | then have "p divides a" | |
| 1974 | by (meson acarr bcarr divides_unit irreducible_prime pcarr pdvdab pirr prime_def) | |
| 63832 | 1975 | then show ?thesis .. | 
| 1976 | next | |
| 68478 | 1977 | case bnunit: False | 
| 1978 | then have cnunit: "c \<notin> Units G" | |
| 1979 | by (metis abpc acarr anunit bcarr ccarr irreducible_prodE irreducible_prod_rI pcarr pirr) | |
| 1980 | then have abnunit: "a \<otimes> b \<notin> Units G" | |
| 1981 | using acarr anunit bcarr unit_factor by blast | |
| 1982 | obtain as where ascarr: "set as \<subseteq> carrier G" and afac: "factors G as a" | |
| 1983 | using factors_exist [OF acarr anunit] by blast | |
| 1984 | obtain bs where bscarr: "set bs \<subseteq> carrier G" and bfac: "factors G bs b" | |
| 1985 | using factors_exist [OF bcarr bnunit] by blast | |
| 1986 | obtain cs where cscarr: "set cs \<subseteq> carrier G" and cfac: "factors G cs c" | |
| 1987 | using factors_exist [OF ccarr cnunit] by auto | |
| 1988 | note [simp] = ascarr bscarr cscarr | |
| 1989 | from pirr cfac abpc have abfac': "factors G (p # cs) (a \<otimes> b)" | |
| 1990 | by (simp add: factors_mult_single) | |
| 1991 | from afac and bfac have "factors G (as @ bs) (a \<otimes> b)" | |
| 1992 | by (rule factors_mult) fact+ | |
| 1993 | with abfac' have "essentially_equal G (p # cs) (as @ bs)" | |
| 1994 | using abnunit factors_unique by auto | |
| 1995 | then obtain ds where "p # cs <~~> ds" and dsassoc: "ds [\<sim>] (as @ bs)" | |
| 1996 | by (fast elim: essentially_equalE) | |
| 1997 | then have "p \<in> set ds" | |
| 1998 | by (simp add: perm_set_eq[symmetric]) | |
| 1999 | with dsassoc obtain p' where "p' \<in> set (as@bs)" and pp': "p \<sim> p'" | |
| 2000 | unfolding list_all2_conv_all_nth set_conv_nth by force | |
| 2001 | then consider "p' \<in> set as" | "p' \<in> set bs" by auto | |
| 2002 | then show "p divides a \<or> p divides b" | |
| 2003 | by (meson afac bfac divides_cong_l factors_dividesI pp' ascarr bscarr pcarr) | |
| 63832 | 2004 | qed | 
| 27701 | 2005 | qed | 
| 2006 | qed | |
| 2007 | qed | |
| 2008 | ||
| 2009 | ||
| 61382 | 2010 | subsection \<open>Greatest Common Divisors and Lowest Common Multiples\<close> | 
| 2011 | ||
| 2012 | subsubsection \<open>Definitions\<close> | |
| 27701 | 2013 | |
| 63832 | 2014 | definition 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 | 2015 | where "x gcdof\<^bsub>G\<^esub> a b \<longleftrightarrow> x divides\<^bsub>G\<^esub> a \<and> x divides\<^bsub>G\<^esub> b \<and> | 
| 35847 | 2016 | (\<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))" | 
| 2017 | ||
| 63832 | 2018 | definition 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 | 2019 | where "x lcmof\<^bsub>G\<^esub> a b \<longleftrightarrow> a divides\<^bsub>G\<^esub> x \<and> b divides\<^bsub>G\<^esub> x \<and> | 
| 35847 | 2020 | (\<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))" | 
| 2021 | ||
| 63832 | 2022 | definition 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 | 2023 | where "somegcd G a b = (SOME x. x \<in> carrier G \<and> x gcdof\<^bsub>G\<^esub> a b)" | 
| 35847 | 2024 | |
| 63832 | 2025 | definition 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 | 2026 | where "somelcm G a b = (SOME x. x \<in> carrier G \<and> x lcmof\<^bsub>G\<^esub> a b)" | 
| 35847 | 2027 | |
| 69700 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69597diff
changeset | 2028 | definition "SomeGcd G A = Lattice.inf (division_rel G) A" | 
| 27701 | 2029 | |
| 2030 | ||
| 2031 | locale gcd_condition_monoid = comm_monoid_cancel + | |
| 63832 | 2032 | assumes gcdof_exists: "\<lbrakk>a \<in> carrier G; b \<in> carrier G\<rbrakk> \<Longrightarrow> \<exists>c. c \<in> carrier G \<and> c gcdof a b" | 
| 27701 | 2033 | |
| 2034 | locale primeness_condition_monoid = comm_monoid_cancel + | |
| 63832 | 2035 | assumes irreducible_prime: "\<lbrakk>a \<in> carrier G; irreducible G a\<rbrakk> \<Longrightarrow> prime G a" | 
| 27701 | 2036 | |
| 2037 | locale divisor_chain_condition_monoid = comm_monoid_cancel + | |
| 63832 | 2038 |   assumes division_wellfounded: "wf {(x, y). x \<in> carrier G \<and> y \<in> carrier G \<and> properfactor G x y}"
 | 
| 27701 | 2039 | |
| 2040 | ||
| 61382 | 2041 | subsubsection \<open>Connections to \texttt{Lattice.thy}\<close>
 | 
| 27701 | 2042 | |
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2043 | lemma gcdof_greatestLower: | 
| 27701 | 2044 | fixes G (structure) | 
| 2045 | assumes carr[simp]: "a \<in> carrier G" "b \<in> carrier G" | |
| 63832 | 2046 |   shows "(x \<in> carrier G \<and> x gcdof a b) = greatest (division_rel G) x (Lower (division_rel G) {a, b})"
 | 
| 2047 | by (auto simp: isgcd_def greatest_def Lower_def elem_def) | |
| 27701 | 2048 | |
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2049 | lemma lcmof_leastUpper: | 
| 27701 | 2050 | fixes G (structure) | 
| 2051 | assumes carr[simp]: "a \<in> carrier G" "b \<in> carrier G" | |
| 63832 | 2052 |   shows "(x \<in> carrier G \<and> x lcmof a b) = least (division_rel G) x (Upper (division_rel G) {a, b})"
 | 
| 2053 | by (auto simp: islcm_def least_def Upper_def elem_def) | |
| 27701 | 2054 | |
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2055 | lemma somegcd_meet: | 
| 27701 | 2056 | fixes G (structure) | 
| 2057 | 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 | 2058 | shows "somegcd G a b = meet (division_rel G) a b" | 
| 63832 | 2059 | by (simp add: somegcd_def meet_def inf_def gcdof_greatestLower[OF carr]) | 
| 27701 | 2060 | |
| 2061 | lemma (in monoid) isgcd_divides_l: | |
| 2062 | assumes "a divides b" | |
| 2063 | and "a \<in> carrier G" "b \<in> carrier G" | |
| 2064 | shows "a gcdof a b" | |
| 63832 | 2065 | using assms unfolding isgcd_def by fast | 
| 27701 | 2066 | |
| 2067 | lemma (in monoid) isgcd_divides_r: | |
| 2068 | assumes "b divides a" | |
| 2069 | and "a \<in> carrier G" "b \<in> carrier G" | |
| 2070 | shows "b gcdof a b" | |
| 63832 | 2071 | using assms unfolding isgcd_def by fast | 
| 27701 | 2072 | |
| 2073 | ||
| 61382 | 2074 | subsubsection \<open>Existence of gcd and lcm\<close> | 
| 27701 | 2075 | |
| 2076 | lemma (in factorial_monoid) gcdof_exists: | |
| 63832 | 2077 | assumes acarr: "a \<in> carrier G" | 
| 2078 | and bcarr: "b \<in> carrier G" | |
| 27701 | 2079 | shows "\<exists>c. c \<in> carrier G \<and> c gcdof a b" | 
| 2080 | proof - | |
| 63847 | 2081 | from wfactors_exist [OF acarr] | 
| 2082 | obtain as where ascarr: "set as \<subseteq> carrier G" and afs: "wfactors G as a" | |
| 2083 | by blast | |
| 63832 | 2084 | from afs have airr: "\<forall>a \<in> set as. irreducible G a" | 
| 2085 | by (fast elim: wfactorsE) | |
| 2086 | ||
| 63847 | 2087 | from wfactors_exist [OF bcarr] | 
| 2088 | obtain bs where bscarr: "set bs \<subseteq> carrier G" and bfs: "wfactors G bs b" | |
| 2089 | by blast | |
| 63832 | 2090 | from bfs have birr: "\<forall>b \<in> set bs. irreducible G b" | 
| 2091 | by (fast elim: wfactorsE) | |
| 2092 | ||
| 2093 | have "\<exists>c cs. c \<in> carrier G \<and> set cs \<subseteq> carrier G \<and> wfactors G cs c \<and> | |
| 63919 
9aed2da07200
# after multiset intersection and union symbol
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63847diff
changeset | 2094 | fmset G cs = fmset G as \<inter># fmset G bs" | 
| 27701 | 2095 | proof (intro mset_wfactorsEx) | 
| 2096 | fix X | |
| 63919 
9aed2da07200
# after multiset intersection and union symbol
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63847diff
changeset | 2097 | assume "X \<in># fmset G as \<inter># fmset G bs" | 
| 63832 | 2098 | then have "X \<in># fmset G as" by simp | 
| 2099 | then have "X \<in> set (map (assocs G) as)" | |
| 2100 | by (simp add: fmset_def) | |
| 2101 | then have "\<exists>x. X = assocs G x \<and> x \<in> set as" | |
| 2102 | by (induct as) auto | |
| 2103 | then obtain x where X: "X = assocs G x" and xas: "x \<in> set as" | |
| 63847 | 2104 | by blast | 
| 63832 | 2105 | with ascarr have xcarr: "x \<in> carrier G" | 
| 63847 | 2106 | by blast | 
| 63832 | 2107 | from xas airr have xirr: "irreducible G x" | 
| 2108 | by simp | |
| 2109 | from xcarr and xirr and X show "\<exists>x. (x \<in> carrier G \<and> irreducible G x) \<and> X = assocs G x" | |
| 63847 | 2110 | by blast | 
| 27701 | 2111 | qed | 
| 63832 | 2112 | then obtain c cs | 
| 2113 | where ccarr: "c \<in> carrier G" | |
| 2114 | and cscarr: "set cs \<subseteq> carrier G" | |
| 27701 | 2115 | and csirr: "wfactors G cs c" | 
| 63919 
9aed2da07200
# after multiset intersection and union symbol
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63847diff
changeset | 2116 | and csmset: "fmset G cs = fmset G as \<inter># fmset G bs" | 
| 63832 | 2117 | by auto | 
| 27701 | 2118 | |
| 2119 | have "c gcdof a b" | |
| 2120 | proof (simp add: isgcd_def, safe) | |
| 2121 | from csmset | |
| 64587 | 2122 | have "fmset G cs \<subseteq># fmset G as" | 
| 63832 | 2123 | by (simp add: multiset_inter_def subset_mset_def) | 
| 2124 | then show "c divides a" by (rule fmsubset_divides) fact+ | |
| 27701 | 2125 | next | 
| 64587 | 2126 | from csmset have "fmset G cs \<subseteq># fmset G bs" | 
| 63832 | 2127 | by (simp add: multiset_inter_def subseteq_mset_def, force) | 
| 2128 | then show "c divides b" | |
| 2129 | by (rule fmsubset_divides) fact+ | |
| 27701 | 2130 | next | 
| 2131 | fix y | |
| 63847 | 2132 | assume "y \<in> carrier G" | 
| 2133 | from wfactors_exist [OF this] | |
| 2134 | obtain ys where yscarr: "set ys \<subseteq> carrier G" and yfs: "wfactors G ys y" | |
| 2135 | by blast | |
| 27701 | 2136 | |
| 2137 | assume "y divides a" | |
| 64587 | 2138 | then have ya: "fmset G ys \<subseteq># fmset G as" | 
| 63832 | 2139 | by (rule divides_fmsubset) fact+ | 
| 27701 | 2140 | |
| 2141 | assume "y divides b" | |
| 64587 | 2142 | then have yb: "fmset G ys \<subseteq># fmset G bs" | 
| 63832 | 2143 | by (rule divides_fmsubset) fact+ | 
| 2144 | ||
| 64587 | 2145 | from ya yb csmset have "fmset G ys \<subseteq># fmset G cs" | 
| 63832 | 2146 | by (simp add: subset_mset_def) | 
| 2147 | then show "y divides c" | |
| 2148 | by (rule fmsubset_divides) fact+ | |
| 27701 | 2149 | qed | 
| 63832 | 2150 | with ccarr show "\<exists>c. c \<in> carrier G \<and> c gcdof a b" | 
| 2151 | by fast | |
| 27701 | 2152 | qed | 
| 2153 | ||
| 2154 | lemma (in factorial_monoid) lcmof_exists: | |
| 63832 | 2155 | assumes acarr: "a \<in> carrier G" | 
| 2156 | and bcarr: "b \<in> carrier G" | |
| 27701 | 2157 | shows "\<exists>c. c \<in> carrier G \<and> c lcmof a b" | 
| 2158 | proof - | |
| 63847 | 2159 | from wfactors_exist [OF acarr] | 
| 2160 | obtain as where ascarr: "set as \<subseteq> carrier G" and afs: "wfactors G as a" | |
| 2161 | by blast | |
| 63832 | 2162 | from afs have airr: "\<forall>a \<in> set as. irreducible G a" | 
| 2163 | by (fast elim: wfactorsE) | |
| 2164 | ||
| 63847 | 2165 | from wfactors_exist [OF bcarr] | 
| 2166 | obtain bs where bscarr: "set bs \<subseteq> carrier G" and bfs: "wfactors G bs b" | |
| 2167 | by blast | |
| 63832 | 2168 | from bfs have birr: "\<forall>b \<in> set bs. irreducible G b" | 
| 2169 | by (fast elim: wfactorsE) | |
| 2170 | ||
| 2171 | have "\<exists>c cs. c \<in> carrier G \<and> set cs \<subseteq> carrier G \<and> wfactors G cs c \<and> | |
| 2172 | fmset G cs = (fmset G as - fmset G bs) + fmset G bs" | |
| 27701 | 2173 | proof (intro mset_wfactorsEx) | 
| 2174 | fix X | |
| 62430 
9527ff088c15
more succint formulation of membership for multisets, similar to lists;
 haftmann parents: 
61382diff
changeset | 2175 | assume "X \<in># (fmset G as - fmset G bs) + fmset G bs" | 
| 63832 | 2176 | then have "X \<in># fmset G as \<or> X \<in># fmset G bs" | 
| 62430 
9527ff088c15
more succint formulation of membership for multisets, similar to lists;
 haftmann parents: 
61382diff
changeset | 2177 | by (auto dest: in_diffD) | 
| 63832 | 2178 | then consider "X \<in> set_mset (fmset G as)" | "X \<in> set_mset (fmset G bs)" | 
| 2179 | by fast | |
| 2180 | then show "\<exists>x. (x \<in> carrier G \<and> irreducible G x) \<and> X = assocs G x" | |
| 2181 | proof cases | |
| 2182 | case 1 | |
| 2183 | then have "X \<in> set (map (assocs G) as)" by (simp add: fmset_def) | |
| 2184 | then have "\<exists>x. x \<in> set as \<and> X = assocs G x" by (induct as) auto | |
| 2185 | then obtain x where xas: "x \<in> set as" and X: "X = assocs G x" by auto | |
| 27701 | 2186 | with ascarr have xcarr: "x \<in> carrier G" by fast | 
| 2187 | from xas airr have xirr: "irreducible G x" by simp | |
| 63832 | 2188 | from xcarr and xirr and X show ?thesis by fast | 
| 2189 | next | |
| 2190 | case 2 | |
| 2191 | then have "X \<in> set (map (assocs G) bs)" by (simp add: fmset_def) | |
| 2192 | then have "\<exists>x. x \<in> set bs \<and> X = assocs G x" by (induct as) auto | |
| 2193 | then obtain x where xbs: "x \<in> set bs" and X: "X = assocs G x" by auto | |
| 27701 | 2194 | with bscarr have xcarr: "x \<in> carrier G" by fast | 
| 2195 | from xbs birr have xirr: "irreducible G x" by simp | |
| 63832 | 2196 | from xcarr and xirr and X show ?thesis by fast | 
| 2197 | qed | |
| 27701 | 2198 | qed | 
| 63832 | 2199 | then obtain c cs | 
| 2200 | where ccarr: "c \<in> carrier G" | |
| 2201 | and cscarr: "set cs \<subseteq> carrier G" | |
| 27701 | 2202 | and csirr: "wfactors G cs c" | 
| 63832 | 2203 | and csmset: "fmset G cs = fmset G as - fmset G bs + fmset G bs" | 
| 2204 | by auto | |
| 27701 | 2205 | |
| 2206 | have "c lcmof a b" | |
| 2207 | proof (simp add: islcm_def, safe) | |
| 64587 | 2208 | from csmset have "fmset G as \<subseteq># fmset G cs" | 
| 63832 | 2209 | by (simp add: subseteq_mset_def, force) | 
| 2210 | then show "a divides c" | |
| 2211 | by (rule fmsubset_divides) fact+ | |
| 27701 | 2212 | next | 
| 64587 | 2213 | from csmset have "fmset G bs \<subseteq># fmset G cs" | 
| 63832 | 2214 | by (simp add: subset_mset_def) | 
| 2215 | then show "b divides c" | |
| 2216 | by (rule fmsubset_divides) fact+ | |
| 27701 | 2217 | next | 
| 2218 | fix y | |
| 63847 | 2219 | assume "y \<in> carrier G" | 
| 2220 | from wfactors_exist [OF this] | |
| 2221 | obtain ys where yscarr: "set ys \<subseteq> carrier G" and yfs: "wfactors G ys y" | |
| 2222 | by blast | |
| 27701 | 2223 | |
| 2224 | assume "a divides y" | |
| 64587 | 2225 | then have ya: "fmset G as \<subseteq># fmset G ys" | 
| 63832 | 2226 | by (rule divides_fmsubset) fact+ | 
| 27701 | 2227 | |
| 2228 | assume "b divides y" | |
| 64587 | 2229 | then have yb: "fmset G bs \<subseteq># fmset G ys" | 
| 63832 | 2230 | by (rule divides_fmsubset) fact+ | 
| 2231 | ||
| 64587 | 2232 | from ya yb csmset have "fmset G cs \<subseteq># fmset G ys" | 
| 68474 | 2233 | using subset_eq_diff_conv subset_mset.le_diff_conv2 by fastforce | 
| 63832 | 2234 | then show "c divides y" | 
| 2235 | by (rule fmsubset_divides) fact+ | |
| 27701 | 2236 | qed | 
| 63832 | 2237 | with ccarr show "\<exists>c. c \<in> carrier G \<and> c lcmof a b" | 
| 2238 | by fast | |
| 27701 | 2239 | qed | 
| 2240 | ||
| 2241 | ||
| 61382 | 2242 | subsection \<open>Conditions for Factoriality\<close> | 
| 2243 | ||
| 2244 | subsubsection \<open>Gcd condition\<close> | |
| 27701 | 2245 | |
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2246 | lemma (in gcd_condition_monoid) division_weak_lower_semilattice [simp]: | 
| 63832 | 2247 | "weak_lower_semilattice (division_rel G)" | 
| 27701 | 2248 | proof - | 
| 29237 | 2249 | interpret weak_partial_order "division_rel G" .. | 
| 27701 | 2250 | show ?thesis | 
| 68474 | 2251 | proof (unfold_locales, simp_all) | 
| 27701 | 2252 | fix x y | 
| 2253 | assume carr: "x \<in> carrier G" "y \<in> carrier G" | |
| 63847 | 2254 | from gcdof_exists [OF this] obtain z where zcarr: "z \<in> carrier G" and isgcd: "z gcdof x y" | 
| 2255 | by blast | |
| 63832 | 2256 |     with carr have "greatest (division_rel G) z (Lower (division_rel G) {x, y})"
 | 
| 2257 | by (subst gcdof_greatestLower[symmetric], simp+) | |
| 2258 |     then show "\<exists>z. greatest (division_rel G) z (Lower (division_rel G) {x, y})"
 | |
| 2259 | by fast | |
| 27701 | 2260 | qed | 
| 2261 | qed | |
| 2262 | ||
| 2263 | lemma (in gcd_condition_monoid) gcdof_cong_l: | |
| 68684 | 2264 | assumes "a' \<sim> a" "a gcdof b c" "a' \<in> carrier G" and carr': "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | 
| 27701 | 2265 | shows "a' gcdof b c" | 
| 2266 | proof - | |
| 29237 | 2267 | interpret weak_lower_semilattice "division_rel G" by simp | 
| 68474 | 2268 |   have "is_glb (division_rel G) a' {b, c}"
 | 
| 68684 | 2269 | by (subst greatest_Lower_cong_l[of _ a]) (simp_all add: assms gcdof_greatestLower[symmetric]) | 
| 68474 | 2270 | then have "a' \<in> carrier G \<and> a' gcdof b c" | 
| 2271 | by (simp add: gcdof_greatestLower carr') | |
| 63832 | 2272 | then show ?thesis .. | 
| 27701 | 2273 | qed | 
| 2274 | ||
| 2275 | lemma (in gcd_condition_monoid) gcd_closed [simp]: | |
| 68684 | 2276 | assumes "a \<in> carrier G" "b \<in> carrier G" | 
| 27701 | 2277 | shows "somegcd G a b \<in> carrier G" | 
| 2278 | proof - | |
| 29237 | 2279 | interpret weak_lower_semilattice "division_rel G" by simp | 
| 27701 | 2280 | show ?thesis | 
| 68684 | 2281 | using assms meet_closed by (simp add: somegcd_meet) | 
| 27701 | 2282 | qed | 
| 2283 | ||
| 2284 | lemma (in gcd_condition_monoid) gcd_isgcd: | |
| 68684 | 2285 | assumes "a \<in> carrier G" "b \<in> carrier G" | 
| 27701 | 2286 | shows "(somegcd G a b) gcdof a b" | 
| 2287 | proof - | |
| 63832 | 2288 | interpret weak_lower_semilattice "division_rel G" | 
| 2289 | by simp | |
| 68684 | 2290 | from assms have "somegcd G a b \<in> carrier G \<and> (somegcd G a b) gcdof a b" | 
| 68474 | 2291 | by (simp add: gcdof_greatestLower inf_of_two_greatest meet_def somegcd_meet) | 
| 63832 | 2292 | then show "(somegcd G a b) gcdof a b" | 
| 2293 | by simp | |
| 27701 | 2294 | qed | 
| 2295 | ||
| 2296 | lemma (in gcd_condition_monoid) gcd_exists: | |
| 68684 | 2297 | assumes "a \<in> carrier G" "b \<in> carrier G" | 
| 27701 | 2298 | shows "\<exists>x\<in>carrier G. x = somegcd G a b" | 
| 2299 | proof - | |
| 63832 | 2300 | interpret weak_lower_semilattice "division_rel G" | 
| 2301 | by simp | |
| 27701 | 2302 | show ?thesis | 
| 68684 | 2303 | by (metis assms gcd_closed) | 
| 27701 | 2304 | qed | 
| 2305 | ||
| 2306 | lemma (in gcd_condition_monoid) gcd_divides_l: | |
| 68684 | 2307 | assumes "a \<in> carrier G" "b \<in> carrier G" | 
| 27701 | 2308 | shows "(somegcd G a b) divides a" | 
| 2309 | proof - | |
| 63832 | 2310 | interpret weak_lower_semilattice "division_rel G" | 
| 2311 | by simp | |
| 27701 | 2312 | show ?thesis | 
| 68684 | 2313 | by (metis assms gcd_isgcd isgcd_def) | 
| 27701 | 2314 | qed | 
| 2315 | ||
| 2316 | lemma (in gcd_condition_monoid) gcd_divides_r: | |
| 68684 | 2317 | assumes "a \<in> carrier G" "b \<in> carrier G" | 
| 27701 | 2318 | shows "(somegcd G a b) divides b" | 
| 2319 | proof - | |
| 63832 | 2320 | interpret weak_lower_semilattice "division_rel G" | 
| 2321 | by simp | |
| 27701 | 2322 | show ?thesis | 
| 68684 | 2323 | by (metis assms gcd_isgcd isgcd_def) | 
| 27701 | 2324 | qed | 
| 2325 | ||
| 2326 | lemma (in gcd_condition_monoid) gcd_divides: | |
| 68684 | 2327 | assumes "z divides x" "z divides y" | 
| 27701 | 2328 | and L: "x \<in> carrier G" "y \<in> carrier G" "z \<in> carrier G" | 
| 2329 | shows "z divides (somegcd G x y)" | |
| 2330 | proof - | |
| 63832 | 2331 | interpret weak_lower_semilattice "division_rel G" | 
| 2332 | by simp | |
| 27701 | 2333 | 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 | 2334 | by (metis gcd_isgcd isgcd_def assms) | 
| 27701 | 2335 | qed | 
| 2336 | ||
| 2337 | lemma (in gcd_condition_monoid) gcd_cong_l: | |
| 68684 | 2338 | assumes "x \<sim> x'" "x \<in> carrier G" "x' \<in> carrier G" "y \<in> carrier G" | 
| 27701 | 2339 | shows "somegcd G x y \<sim> somegcd G x' y" | 
| 2340 | proof - | |
| 63832 | 2341 | interpret weak_lower_semilattice "division_rel G" | 
| 2342 | by simp | |
| 27701 | 2343 | show ?thesis | 
| 68684 | 2344 | using somegcd_meet assms | 
| 2345 | by (metis eq_object.select_convs(1) meet_cong_l partial_object.select_convs(1)) | |
| 27701 | 2346 | qed | 
| 2347 | ||
| 2348 | lemma (in gcd_condition_monoid) gcd_cong_r: | |
| 68684 | 2349 | assumes "y \<sim> y'" "x \<in> carrier G" "y \<in> carrier G" "y' \<in> carrier G" | 
| 27701 | 2350 | shows "somegcd G x y \<sim> somegcd G x y'" | 
| 2351 | proof - | |
| 29237 | 2352 | interpret weak_lower_semilattice "division_rel G" by simp | 
| 27701 | 2353 | show ?thesis | 
| 68684 | 2354 | by (meson associated_def assms gcd_closed gcd_divides gcd_divides_l gcd_divides_r monoid.divides_trans monoid_axioms) | 
| 27701 | 2355 | qed | 
| 2356 | ||
| 2357 | lemma (in gcd_condition_monoid) gcdI: | |
| 2358 | assumes dvd: "a divides b" "a divides c" | |
| 68474 | 2359 | and others: "\<And>y. \<lbrakk>y\<in>carrier G; y divides b; y divides c\<rbrakk> \<Longrightarrow> y divides a" | 
| 27701 | 2360 | and acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" and ccarr: "c \<in> carrier G" | 
| 2361 | shows "a \<sim> somegcd G b c" | |
| 68474 | 2362 | proof - | 
| 2363 | have "\<exists>a. a \<in> carrier G \<and> a gcdof b c" | |
| 2364 | by (simp add: bcarr ccarr gcdof_exists) | |
| 2365 | moreover have "\<And>x. x \<in> carrier G \<and> x gcdof b c \<Longrightarrow> a \<sim> x" | |
| 2366 | by (simp add: acarr associated_def dvd isgcd_def others) | |
| 2367 | ultimately show ?thesis | |
| 2368 | unfolding somegcd_def by (blast intro: someI2_ex) | |
| 2369 | qed | |
| 27701 | 2370 | |
| 2371 | lemma (in gcd_condition_monoid) gcdI2: | |
| 63832 | 2372 | assumes "a gcdof b c" and "a \<in> carrier G" and "b \<in> carrier G" and "c \<in> carrier G" | 
| 27701 | 2373 | shows "a \<sim> somegcd G b c" | 
| 68474 | 2374 | using assms unfolding isgcd_def | 
| 2375 | by (simp add: gcdI) | |
| 27701 | 2376 | |
| 2377 | lemma (in gcd_condition_monoid) SomeGcd_ex: | |
| 2378 |   assumes "finite A"  "A \<subseteq> carrier G"  "A \<noteq> {}"
 | |
| 68684 | 2379 | shows "\<exists>x \<in> carrier G. x = SomeGcd G A" | 
| 27701 | 2380 | proof - | 
| 63832 | 2381 | interpret weak_lower_semilattice "division_rel G" | 
| 2382 | by simp | |
| 27701 | 2383 | show ?thesis | 
| 68684 | 2384 | using finite_inf_closed by (simp add: assms SomeGcd_def) | 
| 27701 | 2385 | qed | 
| 2386 | ||
| 2387 | lemma (in gcd_condition_monoid) gcd_assoc: | |
| 68684 | 2388 | assumes "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | 
| 27701 | 2389 | shows "somegcd G (somegcd G a b) c \<sim> somegcd G a (somegcd G b c)" | 
| 2390 | proof - | |
| 63832 | 2391 | interpret weak_lower_semilattice "division_rel G" | 
| 2392 | by simp | |
| 27701 | 2393 | show ?thesis | 
| 68488 
dfbd80c3d180
more modernisaton and de-applying
 paulson <lp15@cam.ac.uk> parents: 
68478diff
changeset | 2394 | unfolding associated_def | 
| 68684 | 2395 | by (meson assms divides_trans gcd_divides gcd_divides_l gcd_divides_r gcd_exists) | 
| 27701 | 2396 | qed | 
| 2397 | ||
| 2398 | lemma (in gcd_condition_monoid) gcd_mult: | |
| 2399 | assumes acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" and ccarr: "c \<in> carrier G" | |
| 2400 | shows "c \<otimes> somegcd G a b \<sim> somegcd G (c \<otimes> a) (c \<otimes> b)" | |
| 2401 | proof - (* following Jacobson, Basic Algebra, p.140 *) | |
| 2402 | let ?d = "somegcd G a b" | |
| 2403 | let ?e = "somegcd G (c \<otimes> a) (c \<otimes> b)" | |
| 2404 | note carr[simp] = acarr bcarr ccarr | |
| 2405 | have dcarr: "?d \<in> carrier G" by simp | |
| 2406 | have ecarr: "?e \<in> carrier G" by simp | |
| 2407 | note carr = carr dcarr ecarr | |
| 2408 | ||
| 2409 | have "?d divides a" by (simp add: gcd_divides_l) | |
| 63832 | 2410 | then have cd'ca: "c \<otimes> ?d divides (c \<otimes> a)" by (simp add: divides_mult_lI) | 
| 27701 | 2411 | |
| 2412 | have "?d divides b" by (simp add: gcd_divides_r) | |
| 63832 | 2413 | then have cd'cb: "c \<otimes> ?d divides (c \<otimes> b)" by (simp add: divides_mult_lI) | 
| 2414 | ||
| 2415 | from cd'ca cd'cb have cd'e: "c \<otimes> ?d divides ?e" | |
| 2416 | by (rule gcd_divides) simp_all | |
| 2417 | then obtain u where ucarr[simp]: "u \<in> carrier G" and e_cdu: "?e = c \<otimes> ?d \<otimes> u" | |
| 63847 | 2418 | by blast | 
| 27701 | 2419 | |
| 2420 | note carr = carr ucarr | |
| 2421 | ||
| 63832 | 2422 | have "?e divides c \<otimes> a" by (rule gcd_divides_l) simp_all | 
| 2423 | then obtain x where xcarr: "x \<in> carrier G" and ca_ex: "c \<otimes> a = ?e \<otimes> x" | |
| 63847 | 2424 | by blast | 
| 63832 | 2425 | with e_cdu have ca_cdux: "c \<otimes> a = c \<otimes> ?d \<otimes> u \<otimes> x" | 
| 2426 | by simp | |
| 2427 | ||
| 2428 | from ca_cdux xcarr have "c \<otimes> a = c \<otimes> (?d \<otimes> u \<otimes> x)" | |
| 2429 | by (simp add: m_assoc) | |
| 2430 | then have "a = ?d \<otimes> u \<otimes> x" | |
| 2431 | by (rule l_cancel[of c a]) (simp add: xcarr)+ | |
| 2432 | then have du'a: "?d \<otimes> u divides a" | |
| 2433 | by (rule dividesI[OF xcarr]) | |
| 2434 | ||
| 2435 | have "?e divides c \<otimes> b" by (intro gcd_divides_r) simp_all | |
| 2436 | then obtain x where xcarr: "x \<in> carrier G" and cb_ex: "c \<otimes> b = ?e \<otimes> x" | |
| 63847 | 2437 | by blast | 
| 63832 | 2438 | with e_cdu have cb_cdux: "c \<otimes> b = c \<otimes> ?d \<otimes> u \<otimes> x" | 
| 2439 | by simp | |
| 2440 | ||
| 2441 | from cb_cdux xcarr have "c \<otimes> b = c \<otimes> (?d \<otimes> u \<otimes> x)" | |
| 2442 | by (simp add: m_assoc) | |
| 2443 | with xcarr have "b = ?d \<otimes> u \<otimes> x" | |
| 2444 | by (intro l_cancel[of c b]) simp_all | |
| 2445 | then have du'b: "?d \<otimes> u divides b" | |
| 2446 | by (intro dividesI[OF xcarr]) | |
| 2447 | ||
| 2448 | from du'a du'b carr have du'd: "?d \<otimes> u divides ?d" | |
| 2449 | by (intro gcd_divides) simp_all | |
| 2450 | then have uunit: "u \<in> Units G" | |
| 27701 | 2451 | proof (elim dividesE) | 
| 2452 | fix v | |
| 2453 | assume vcarr[simp]: "v \<in> carrier G" | |
| 2454 | assume d: "?d = ?d \<otimes> u \<otimes> v" | |
| 2455 | have "?d \<otimes> \<one> = ?d \<otimes> u \<otimes> v" by simp fact | |
| 2456 | also have "?d \<otimes> u \<otimes> v = ?d \<otimes> (u \<otimes> v)" by (simp add: m_assoc) | |
| 2457 | finally have "?d \<otimes> \<one> = ?d \<otimes> (u \<otimes> v)" . | |
| 63832 | 2458 | then have i2: "\<one> = u \<otimes> v" by (rule l_cancel) simp_all | 
| 2459 | then have i1: "\<one> = v \<otimes> u" by (simp add: m_comm) | |
| 2460 | from vcarr i1[symmetric] i2[symmetric] show "u \<in> Units G" | |
| 2461 | by (auto simp: Units_def) | |
| 27701 | 2462 | qed | 
| 2463 | ||
| 63832 | 2464 | from e_cdu uunit have "somegcd G (c \<otimes> a) (c \<otimes> b) \<sim> c \<otimes> somegcd G a b" | 
| 2465 | by (intro associatedI2[of u]) simp_all | |
| 2466 | from this[symmetric] show "c \<otimes> somegcd G a b \<sim> somegcd G (c \<otimes> a) (c \<otimes> b)" | |
| 2467 | by simp | |
| 27701 | 2468 | qed | 
| 2469 | ||
| 2470 | lemma (in monoid) assoc_subst: | |
| 2471 | assumes ab: "a \<sim> b" | |
| 63832 | 2472 | and cP: "\<forall>a b. a \<in> carrier G \<and> b \<in> carrier G \<and> a \<sim> b | 
| 2473 | \<longrightarrow> f a \<in> carrier G \<and> f b \<in> carrier G \<and> f a \<sim> f b" | |
| 27701 | 2474 | and carr: "a \<in> carrier G" "b \<in> carrier G" | 
| 2475 | shows "f a \<sim> f b" | |
| 2476 | using assms by auto | |
| 2477 | ||
| 2478 | lemma (in gcd_condition_monoid) relprime_mult: | |
| 63832 | 2479 | assumes abrelprime: "somegcd G a b \<sim> \<one>" | 
| 2480 | and acrelprime: "somegcd G a c \<sim> \<one>" | |
| 27701 | 2481 | and carr[simp]: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | 
| 2482 | shows "somegcd G a (b \<otimes> c) \<sim> \<one>" | |
| 2483 | proof - | |
| 2484 | have "c = c \<otimes> \<one>" by simp | |
| 2485 | also from abrelprime[symmetric] | |
| 63832 | 2486 | have "\<dots> \<sim> c \<otimes> somegcd G a b" | 
| 2487 | by (rule assoc_subst) (simp add: mult_cong_r)+ | |
| 2488 | also have "\<dots> \<sim> somegcd G (c \<otimes> a) (c \<otimes> b)" | |
| 2489 | by (rule gcd_mult) fact+ | |
| 2490 | finally have c: "c \<sim> somegcd G (c \<otimes> a) (c \<otimes> b)" | |
| 2491 | by simp | |
| 2492 | ||
| 2493 | from carr have a: "a \<sim> somegcd G a (c \<otimes> a)" | |
| 2494 | by (fast intro: gcdI divides_prod_l) | |
| 2495 | ||
| 2496 | have "somegcd G a (b \<otimes> c) \<sim> somegcd G a (c \<otimes> b)" | |
| 2497 | by (simp add: m_comm) | |
| 2498 | also from a have "\<dots> \<sim> somegcd G (somegcd G a (c \<otimes> a)) (c \<otimes> b)" | |
| 2499 | by (rule assoc_subst) (simp add: gcd_cong_l)+ | |
| 2500 | also from gcd_assoc have "\<dots> \<sim> somegcd G a (somegcd G (c \<otimes> a) (c \<otimes> b))" | |
| 2501 | by (rule assoc_subst) simp+ | |
| 2502 | also from c[symmetric] have "\<dots> \<sim> somegcd G a c" | |
| 2503 | by (rule assoc_subst) (simp add: gcd_cong_r)+ | |
| 27701 | 2504 | also note acrelprime | 
| 63832 | 2505 | finally show "somegcd G a (b \<otimes> c) \<sim> \<one>" | 
| 2506 | by simp | |
| 27701 | 2507 | qed | 
| 2508 | ||
| 63832 | 2509 | lemma (in gcd_condition_monoid) primeness_condition: "primeness_condition_monoid G" | 
| 27701 | 2510 | proof - | 
| 68478 | 2511 | have *: "p divides a \<or> p divides b" | 
| 2512 | if pcarr[simp]: "p \<in> carrier G" and acarr[simp]: "a \<in> carrier G" and bcarr[simp]: "b \<in> carrier G" | |
| 2513 | and pirr: "irreducible G p" and pdvdab: "p divides a \<otimes> b" | |
| 2514 | for p a b | |
| 2515 | proof - | |
| 2516 | from pirr have pnunit: "p \<notin> Units G" | |
| 2517 | and r: "\<And>b. \<lbrakk>b \<in> carrier G; properfactor G b p\<rbrakk> \<Longrightarrow> b \<in> Units G" | |
| 2518 | by (fast elim: irreducibleE)+ | |
| 2519 | show "p divides a \<or> p divides b" | |
| 2520 | proof (rule ccontr, clarsimp) | |
| 2521 | assume npdvda: "\<not> p divides a" and npdvdb: "\<not> p divides b" | |
| 2522 | have "\<one> \<sim> somegcd G p a" | |
| 2523 | proof (intro gcdI unit_divides) | |
| 2524 | show "\<And>y. \<lbrakk>y \<in> carrier G; y divides p; y divides a\<rbrakk> \<Longrightarrow> y \<in> Units G" | |
| 2525 | by (meson divides_trans npdvda pcarr properfactorI r) | |
| 2526 | qed auto | |
| 2527 | with pcarr acarr have pa: "somegcd G p a \<sim> \<one>" | |
| 2528 | by (fast intro: associated_sym[of "\<one>"] gcd_closed) | |
| 2529 | have "\<one> \<sim> somegcd G p b" | |
| 2530 | proof (intro gcdI unit_divides) | |
| 2531 | show "\<And>y. \<lbrakk>y \<in> carrier G; y divides p; y divides b\<rbrakk> \<Longrightarrow> y \<in> Units G" | |
| 2532 | by (meson divides_trans npdvdb pcarr properfactorI r) | |
| 2533 | qed auto | |
| 2534 | with pcarr bcarr have pb: "somegcd G p b \<sim> \<one>" | |
| 2535 | by (fast intro: associated_sym[of "\<one>"] gcd_closed) | |
| 2536 | have "p \<sim> somegcd G p (a \<otimes> b)" | |
| 2537 | using pdvdab by (simp add: gcdI2 isgcd_divides_l) | |
| 2538 | also from pa pb pcarr acarr bcarr have "somegcd G p (a \<otimes> b) \<sim> \<one>" | |
| 2539 | by (rule relprime_mult) | |
| 2540 | finally have "p \<sim> \<one>" | |
| 2541 | by simp | |
| 2542 | with pcarr have "p \<in> Units G" | |
| 2543 | by (fast intro: assoc_unit_l) | |
| 2544 | with pnunit show False .. | |
| 2545 | qed | |
| 27701 | 2546 | qed | 
| 68478 | 2547 | show ?thesis | 
| 2548 | by unfold_locales (metis * primeI irreducibleE) | |
| 2549 | qed | |
| 2550 | ||
| 27701 | 2551 | |
| 29237 | 2552 | sublocale gcd_condition_monoid \<subseteq> primeness_condition_monoid | 
| 27701 | 2553 | by (rule primeness_condition) | 
| 2554 | ||
| 2555 | ||
| 61382 | 2556 | subsubsection \<open>Divisor chain condition\<close> | 
| 27701 | 2557 | |
| 2558 | lemma (in divisor_chain_condition_monoid) wfactors_exist: | |
| 2559 | assumes acarr: "a \<in> carrier G" | |
| 2560 | shows "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a" | |
| 2561 | proof - | |
| 68478 | 2562 | have r: "a \<in> carrier G \<Longrightarrow> (\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a)" | 
| 2563 | using division_wellfounded | |
| 2564 | proof (induction rule: wf_induct_rule) | |
| 2565 | case (less x) | |
| 2566 | then have xcarr: "x \<in> carrier G" | |
| 2567 | by auto | |
| 2568 | show ?case | |
| 2569 | proof (cases "x \<in> Units G") | |
| 2570 | case True | |
| 2571 | then show ?thesis | |
| 2572 | by (metis bot.extremum list.set(1) unit_wfactors) | |
| 2573 | next | |
| 2574 | case xnunit: False | |
| 2575 | show ?thesis | |
| 2576 | proof (cases "irreducible G x") | |
| 2577 | case True | |
| 2578 | then show ?thesis | |
| 2579 | by (rule_tac x="[x]" in exI) (simp add: wfactors_def xcarr) | |
| 2580 | next | |
| 2581 | case False | |
| 2582 | then obtain y where ycarr: "y \<in> carrier G" and ynunit: "y \<notin> Units G" and pfyx: "properfactor G y x" | |
| 2583 | by (meson irreducible_def xnunit) | |
| 2584 | obtain ys where yscarr: "set ys \<subseteq> carrier G" and yfs: "wfactors G ys y" | |
| 2585 | using less ycarr pfyx by blast | |
| 2586 | then obtain z where zcarr: "z \<in> carrier G" and x: "x = y \<otimes> z" | |
| 2587 | by (meson dividesE pfyx properfactorE2) | |
| 2588 | from zcarr ycarr have "properfactor G z x" | |
| 2589 | using m_comm properfactorI3 x ynunit by blast | |
| 2590 | with less zcarr obtain zs where zscarr: "set zs \<subseteq> carrier G" and zfs: "wfactors G zs z" | |
| 2591 | by blast | |
| 2592 | from yscarr zscarr have xscarr: "set (ys@zs) \<subseteq> carrier G" | |
| 2593 | by simp | |
| 2594 | have "wfactors G (ys@zs) (y\<otimes>z)" | |
| 2595 | using xscarr ycarr yfs zcarr zfs by auto | |
| 2596 | then have "wfactors G (ys@zs) x" | |
| 2597 | by (simp add: x) | |
| 2598 | with xscarr show "\<exists>xs. set xs \<subseteq> carrier G \<and> wfactors G xs x" | |
| 2599 | by fast | |
| 2600 | qed | |
| 27701 | 2601 | qed | 
| 2602 | qed | |
| 63832 | 2603 | from acarr show ?thesis by (rule r) | 
| 27701 | 2604 | qed | 
| 2605 | ||
| 2606 | ||
| 61382 | 2607 | subsubsection \<open>Primeness condition\<close> | 
| 27701 | 2608 | |
| 2609 | lemma (in comm_monoid_cancel) multlist_prime_pos: | |
| 68478 | 2610 | assumes aprime: "prime G a" and carr: "a \<in> carrier G" | 
| 2611 | and as: "set as \<subseteq> carrier G" "a divides (foldr (\<otimes>) as \<one>)" | |
| 2612 | shows "\<exists>i<length as. a divides (as!i)" | |
| 2613 | using as | |
| 2614 | proof (induction as) | |
| 2615 | case Nil | |
| 2616 | then show ?case | |
| 2617 | by simp (meson Units_one_closed aprime carr divides_unit primeE) | |
| 2618 | next | |
| 2619 | case (Cons x as) | |
| 2620 | then have "x \<in> carrier G" "set as \<subseteq> carrier G" and "a divides x \<otimes> foldr (\<otimes>) as \<one>" | |
| 2621 | by (auto simp: ) | |
| 2622 | with carr aprime have "a divides x \<or> a divides foldr (\<otimes>) as \<one>" | |
| 2623 | by (intro prime_divides) simp+ | |
| 2624 | then show ?case | |
| 2625 | using Cons.IH Cons.prems(1) by force | |
| 27701 | 2626 | qed | 
| 2627 | ||
| 68684 | 2628 | proposition (in primeness_condition_monoid) wfactors_unique: | 
| 2629 | assumes "wfactors G as a" "wfactors G as' a" | |
| 2630 | and "a \<in> carrier G" "set as \<subseteq> carrier G" "set as' \<subseteq> carrier G" | |
| 2631 | shows "essentially_equal G as as'" | |
| 2632 | using assms | |
| 2633 | proof (induct as arbitrary: a as') | |
| 63832 | 2634 | case Nil | 
| 68684 | 2635 | then have "a \<sim> \<one>" | 
| 2636 | by (meson Units_one_closed one_closed perm.Nil perm_wfactorsD unit_wfactors) | |
| 2637 | then have "as' = []" | |
| 2638 | using Nil.prems assoc_unit_l unit_wfactors_empty by blast | |
| 2639 | then show ?case | |
| 2640 | by auto | |
| 46129 | 2641 | next | 
| 63832 | 2642 | case (Cons ah as) | 
| 68684 | 2643 | then have ahdvda: "ah divides a" | 
| 2644 | using wfactors_dividesI by auto | |
| 63832 | 2645 | then obtain a' where a'carr: "a' \<in> carrier G" and a: "a = ah \<otimes> a'" | 
| 63847 | 2646 | by blast | 
| 68684 | 2647 | have carr_ah: "ah \<in> carrier G" "set as \<subseteq> carrier G" | 
| 2648 | using Cons.prems by fastforce+ | |
| 2649 | have "ah \<otimes> foldr (\<otimes>) as \<one> \<sim> a" | |
| 2650 | by (rule wfactorsE[OF \<open>wfactors G (ah # as) a\<close>]) auto | |
| 2651 | then have "foldr (\<otimes>) as \<one> \<sim> a'" | |
| 2652 | by (metis Cons.prems(4) a a'carr assoc_l_cancel insert_subset list.set(2) monoid.multlist_closed monoid_axioms) | |
| 2653 | then | |
| 46129 | 2654 | have a'fs: "wfactors G as a'" | 
| 68684 | 2655 | by (meson Cons.prems(1) set_subset_Cons subset_iff wfactorsE wfactorsI) | 
| 2656 | then have ahirr: "irreducible G ah" | |
| 2657 | by (meson Cons.prems(1) list.set_intros(1) wfactorsE) | |
| 2658 | with Cons have ahprime: "prime G ah" | |
| 2659 | by (simp add: irreducible_prime) | |
| 46129 | 2660 | note ahdvda | 
| 68684 | 2661 | also have "a divides (foldr (\<otimes>) as' \<one>)" | 
| 2662 | by (meson Cons.prems(2) associatedE wfactorsE) | |
| 67399 | 2663 | finally have "ah divides (foldr (\<otimes>) as' \<one>)" | 
| 68684 | 2664 | using Cons.prems(4) by auto | 
| 63832 | 2665 | with ahprime have "\<exists>i<length as'. ah divides as'!i" | 
| 68684 | 2666 | by (intro multlist_prime_pos) (use Cons.prems in auto) | 
| 63832 | 2667 | then obtain i where len: "i<length as'" and ahdvd: "ah divides as'!i" | 
| 63847 | 2668 | by blast | 
| 68684 | 2669 | then obtain x where "x \<in> carrier G" and asi: "as'!i = ah \<otimes> x" | 
| 63847 | 2670 | by blast | 
| 68684 | 2671 | have irrasi: "irreducible G (as'!i)" | 
| 2672 | using nth_mem[OF len] wfactorsE | |
| 2673 | by (metis Cons.prems(2)) | |
| 2674 | have asicarr[simp]: "as'!i \<in> carrier G" | |
| 2675 | using len \<open>set as' \<subseteq> carrier G\<close> nth_mem by blast | |
| 2676 | have asiah: "as'!i \<sim> ah" | |
| 2677 | by (metis \<open>ah \<in> carrier G\<close> \<open>x \<in> carrier G\<close> asi irrasi ahprime associatedI2 irreducible_prodE primeE) | |
| 46129 | 2678 | note setparts = set_take_subset[of i as'] set_drop_subset[of "Suc i" as'] | 
| 2679 | have "\<exists>aa_1. aa_1 \<in> carrier G \<and> wfactors G (take i as') aa_1" | |
| 68684 | 2680 | using Cons | 
| 2681 | by (metis setparts(1) subset_trans in_set_takeD wfactorsE wfactors_prod_exists) | |
| 2682 | then obtain aa_1 where aa1carr [simp]: "aa_1 \<in> carrier G" and aa1fs: "wfactors G (take i as') aa_1" | |
| 63832 | 2683 | by auto | 
| 68684 | 2684 | obtain aa_2 where aa2carr [simp]: "aa_2 \<in> carrier G" | 
| 63832 | 2685 | and aa2fs: "wfactors G (drop (Suc i) as') aa_2" | 
| 68684 | 2686 | by (metis Cons.prems(2) Cons.prems(5) subset_code(1) in_set_dropD wfactors_def wfactors_prod_exists) | 
| 2687 | ||
| 2688 | have set_drop: "set (drop (Suc i) as') \<subseteq> carrier G" | |
| 2689 | using Cons.prems(5) setparts(2) by blast | |
| 2690 | moreover have set_take: "set (take i as') \<subseteq> carrier G" | |
| 2691 | using Cons.prems(5) setparts by auto | |
| 2692 | moreover have v1: "wfactors G (take i as' @ drop (Suc i) as') (aa_1 \<otimes> aa_2)" | |
| 2693 | using aa1fs aa2fs \<open>set as' \<subseteq> carrier G\<close> by (force simp add: dest: in_set_takeD in_set_dropD) | |
| 2694 | ultimately have v1': "wfactors G (as'!i # take i as' @ drop (Suc i) as') (as'!i \<otimes> (aa_1 \<otimes> aa_2))" | |
| 2695 | using irrasi wfactors_mult_single | |
| 2696 | by (simp add: irrasi v1 wfactors_mult_single) | |
| 2697 | have "wfactors G (as'!i # drop (Suc i) as') (as'!i \<otimes> aa_2)" | |
| 2698 | by (simp add: aa2fs irrasi set_drop wfactors_mult_single) | |
| 2699 | with len aa1carr aa2carr aa1fs | |
| 63832 | 2700 | have v2: "wfactors G (take i as' @ as'!i # drop (Suc i) as') (aa_1 \<otimes> (as'!i \<otimes> aa_2))" | 
| 68684 | 2701 | using wfactors_mult by (simp add: set_take set_drop) | 
| 63832 | 2702 | from len have as': "as' = (take i as' @ as'!i # drop (Suc i) as')" | 
| 58247 
98d0f85d247f
enamed drop_Suc_conv_tl and nth_drop' to Cons_nth_drop_Suc
 nipkow parents: 
57865diff
changeset | 2703 | by (simp add: Cons_nth_drop_Suc) | 
| 68684 | 2704 | have eer: "essentially_equal G (take i as' @ as'!i # drop (Suc i) as') as'" | 
| 2705 | using Cons.prems(5) as' by auto | |
| 2706 | with v2 aa1carr aa2carr nth_mem[OF len] have "aa_1 \<otimes> (as'!i \<otimes> aa_2) \<sim> a" | |
| 2707 | using Cons.prems as' comm_monoid_cancel.ee_wfactorsD is_comm_monoid_cancel by fastforce | |
| 63832 | 2708 | then 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 | 2709 | by (metis aa1carr aa2carr asicarr m_lcomm) | 
| 68684 | 2710 | from asiah have "ah \<otimes> (aa_1 \<otimes> aa_2) \<sim> as'!i \<otimes> (aa_1 \<otimes> aa_2)" | 
| 2711 | by (simp add: \<open>ah \<in> carrier G\<close> associated_sym mult_cong_l) | |
| 46129 | 2712 | also note t1 | 
| 68684 | 2713 | finally have "ah \<otimes> (aa_1 \<otimes> aa_2) \<sim> a" | 
| 2714 | using Cons.prems(3) carr_ah aa1carr aa2carr by blast | |
| 2715 | with aa1carr aa2carr a'carr nth_mem[OF len] have a': "aa_1 \<otimes> aa_2 \<sim> a'" | |
| 2716 | using a assoc_l_cancel carr_ah(1) by blast | |
| 46129 | 2717 | note v1 | 
| 2718 | also note a' | |
| 63832 | 2719 | finally have "wfactors G (take i as' @ drop (Suc i) as') a'" | 
| 68684 | 2720 | by (simp add: a'carr set_drop set_take) | 
| 2721 | from a'fs this have "essentially_equal G as (take i as' @ drop (Suc i) as')" | |
| 2722 | using Cons.hyps a'carr carr_ah(2) set_drop set_take by auto | |
| 2723 | with carr_ah have ee1: "essentially_equal G (ah # as) (ah # take i as' @ drop (Suc i) as')" | |
| 2724 | by (auto simp: essentially_equal_def) | |
| 2725 | have ee2: "essentially_equal G (ah # take i as' @ drop (Suc i) as') | |
| 46129 | 2726 | (as' ! i # take i as' @ drop (Suc i) as')" | 
| 2727 | proof (intro essentially_equalI) | |
| 2728 | show "ah # take i as' @ drop (Suc i) as' <~~> ah # take i as' @ drop (Suc i) as'" | |
| 27701 | 2729 | by simp | 
| 46129 | 2730 | next | 
| 2731 | show "ah # take i as' @ drop (Suc i) as' [\<sim>] as' ! i # take i as' @ drop (Suc i) as'" | |
| 68684 | 2732 | by (simp add: asiah associated_sym set_drop set_take) | 
| 46129 | 2733 | qed | 
| 2734 | ||
| 2735 | note ee1 | |
| 2736 | also note ee2 | |
| 2737 | also have "essentially_equal G (as' ! i # take i as' @ drop (Suc i) as') | |
| 68488 
dfbd80c3d180
more modernisaton and de-applying
 paulson <lp15@cam.ac.uk> parents: 
68478diff
changeset | 2738 | (take i as' @ as' ! i # drop (Suc i) as')" | 
| 68684 | 2739 | by (metis Cons.prems(5) as' essentially_equalI listassoc_refl perm_append_Cons) | 
| 63832 | 2740 | finally have "essentially_equal G (ah # as) (take i as' @ as' ! i # drop (Suc i) as')" | 
| 68684 | 2741 | using Cons.prems(4) set_drop set_take by auto | 
| 2742 | then show ?case | |
| 2743 | using as' by auto | |
| 27701 | 2744 | qed | 
| 2745 | ||
| 2746 | ||
| 61382 | 2747 | subsubsection \<open>Application to factorial monoids\<close> | 
| 2748 | ||
| 2749 | text \<open>Number of factors for wellfoundedness\<close> | |
| 27701 | 2750 | |
| 63832 | 2751 | definition factorcount :: "_ \<Rightarrow> 'a \<Rightarrow> nat" | 
| 2752 | where "factorcount G a = | |
| 2753 | (THE c. \<forall>as. set as \<subseteq> carrier G \<and> wfactors G as a \<longrightarrow> c = length as)" | |
| 27701 | 2754 | |
| 2755 | lemma (in monoid) ee_length: | |
| 2756 | assumes ee: "essentially_equal G as bs" | |
| 2757 | shows "length as = length bs" | |
| 63832 | 2758 | by (rule essentially_equalE[OF ee]) (metis list_all2_conv_all_nth perm_length) | 
| 27701 | 2759 | |
| 2760 | lemma (in factorial_monoid) factorcount_exists: | |
| 2761 | assumes carr[simp]: "a \<in> carrier G" | |
| 63832 | 2762 | shows "\<exists>c. \<forall>as. set as \<subseteq> carrier G \<and> wfactors G as a \<longrightarrow> c = length as" | 
| 27701 | 2763 | proof - | 
| 63832 | 2764 | have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a" | 
| 2765 | by (intro wfactors_exist) simp | |
| 2766 | then obtain as where ascarr[simp]: "set as \<subseteq> carrier G" and afs: "wfactors G as a" | |
| 2767 | by (auto simp del: carr) | |
| 2768 | have "\<forall>as'. set as' \<subseteq> carrier G \<and> wfactors G as' a \<longrightarrow> length as = length as'" | |
| 36278 | 2769 | by (metis afs ascarr assms ee_length wfactors_unique) | 
| 63832 | 2770 | then show "\<exists>c. \<forall>as'. set as' \<subseteq> carrier G \<and> wfactors G as' a \<longrightarrow> c = length as'" .. | 
| 27701 | 2771 | qed | 
| 2772 | ||
| 2773 | lemma (in factorial_monoid) factorcount_unique: | |
| 2774 | assumes afs: "wfactors G as a" | |
| 68488 
dfbd80c3d180
more modernisaton and de-applying
 paulson <lp15@cam.ac.uk> parents: 
68478diff
changeset | 2775 | and acarr[simp]: "a \<in> carrier G" and ascarr: "set as \<subseteq> carrier G" | 
| 27701 | 2776 | shows "factorcount G a = length as" | 
| 2777 | proof - | |
| 63832 | 2778 | have "\<exists>ac. \<forall>as. set as \<subseteq> carrier G \<and> wfactors G as a \<longrightarrow> ac = length as" | 
| 2779 | by (rule factorcount_exists) simp | |
| 2780 | then obtain ac where alen: "\<forall>as. set as \<subseteq> carrier G \<and> wfactors G as a \<longrightarrow> ac = length as" | |
| 2781 | by auto | |
| 68488 
dfbd80c3d180
more modernisaton and de-applying
 paulson <lp15@cam.ac.uk> parents: 
68478diff
changeset | 2782 | then have ac: "ac = factorcount G a" | 
| 
dfbd80c3d180
more modernisaton and de-applying
 paulson <lp15@cam.ac.uk> parents: 
68478diff
changeset | 2783 | unfolding factorcount_def using ascarr by (blast intro: theI2 afs) | 
| 63832 | 2784 | from ascarr afs have "ac = length as" | 
| 68488 
dfbd80c3d180
more modernisaton and de-applying
 paulson <lp15@cam.ac.uk> parents: 
68478diff
changeset | 2785 | by (simp add: alen) | 
| 63832 | 2786 | with ac show ?thesis | 
| 2787 | by simp | |
| 27701 | 2788 | qed | 
| 2789 | ||
| 2790 | lemma (in factorial_monoid) divides_fcount: | |
| 2791 | assumes dvd: "a divides b" | |
| 63832 | 2792 | and acarr: "a \<in> carrier G" | 
| 2793 | and bcarr:"b \<in> carrier G" | |
| 2794 | shows "factorcount G a \<le> factorcount G b" | |
| 2795 | proof (rule dividesE[OF dvd]) | |
| 27701 | 2796 | fix c | 
| 63832 | 2797 | from assms have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a" | 
| 63847 | 2798 | by blast | 
| 63832 | 2799 | then obtain as where ascarr: "set as \<subseteq> carrier G" and afs: "wfactors G as a" | 
| 63847 | 2800 | by blast | 
| 63832 | 2801 | with acarr have fca: "factorcount G a = length as" | 
| 2802 | by (intro factorcount_unique) | |
| 27701 | 2803 | |
| 2804 | assume ccarr: "c \<in> carrier G" | |
| 63832 | 2805 | then have "\<exists>cs. set cs \<subseteq> carrier G \<and> wfactors G cs c" | 
| 63847 | 2806 | by blast | 
| 63832 | 2807 | then obtain cs where cscarr: "set cs \<subseteq> carrier G" and cfs: "wfactors G cs c" | 
| 63847 | 2808 | by blast | 
| 27701 | 2809 | |
| 2810 | note [simp] = acarr bcarr ccarr ascarr cscarr | |
| 2811 | assume b: "b = a \<otimes> c" | |
| 63832 | 2812 | from afs cfs have "wfactors G (as@cs) (a \<otimes> c)" | 
| 2813 | by (intro wfactors_mult) simp_all | |
| 2814 | with b have "wfactors G (as@cs) b" | |
| 2815 | by simp | |
| 2816 | then have "factorcount G b = length (as@cs)" | |
| 2817 | by (intro factorcount_unique) simp_all | |
| 2818 | then have "factorcount G b = length as + length cs" | |
| 2819 | by simp | |
| 2820 | with fca show ?thesis | |
| 2821 | by simp | |
| 27701 | 2822 | qed | 
| 2823 | ||
| 2824 | lemma (in factorial_monoid) associated_fcount: | |
| 63832 | 2825 | assumes acarr: "a \<in> carrier G" | 
| 2826 | and bcarr: "b \<in> carrier G" | |
| 27701 | 2827 | and asc: "a \<sim> b" | 
| 2828 | shows "factorcount G a = factorcount G b" | |
| 68488 
dfbd80c3d180
more modernisaton and de-applying
 paulson <lp15@cam.ac.uk> parents: 
68478diff
changeset | 2829 | using assms | 
| 
dfbd80c3d180
more modernisaton and de-applying
 paulson <lp15@cam.ac.uk> parents: 
68478diff
changeset | 2830 | by (auto simp: associated_def factorial_monoid.divides_fcount factorial_monoid_axioms le_antisym) | 
| 27701 | 2831 | |
| 2832 | lemma (in factorial_monoid) properfactor_fcount: | |
| 2833 | assumes acarr: "a \<in> carrier G" and bcarr:"b \<in> carrier G" | |
| 2834 | and pf: "properfactor G a b" | |
| 2835 | shows "factorcount G a < factorcount G b" | |
| 63832 | 2836 | proof (rule properfactorE[OF pf], elim dividesE) | 
| 27701 | 2837 | fix c | 
| 63832 | 2838 | from assms have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a" | 
| 63847 | 2839 | by blast | 
| 63832 | 2840 | then obtain as where ascarr: "set as \<subseteq> carrier G" and afs: "wfactors G as a" | 
| 63847 | 2841 | by blast | 
| 63832 | 2842 | with acarr have fca: "factorcount G a = length as" | 
| 2843 | by (intro factorcount_unique) | |
| 27701 | 2844 | |
| 2845 | assume ccarr: "c \<in> carrier G" | |
| 63832 | 2846 | then have "\<exists>cs. set cs \<subseteq> carrier G \<and> wfactors G cs c" | 
| 63847 | 2847 | by blast | 
| 63832 | 2848 | then obtain cs where cscarr: "set cs \<subseteq> carrier G" and cfs: "wfactors G cs c" | 
| 63847 | 2849 | by blast | 
| 27701 | 2850 | |
| 2851 | assume b: "b = a \<otimes> c" | |
| 2852 | ||
| 63832 | 2853 | have "wfactors G (as@cs) (a \<otimes> c)" | 
| 2854 | by (rule wfactors_mult) fact+ | |
| 2855 | with b have "wfactors G (as@cs) b" | |
| 2856 | by simp | |
| 2857 | with ascarr cscarr bcarr have "factorcount G b = length (as@cs)" | |
| 2858 | by (simp add: factorcount_unique) | |
| 2859 | then have fcb: "factorcount G b = length as + length cs" | |
| 2860 | by simp | |
| 27701 | 2861 | |
| 2862 | assume nbdvda: "\<not> b divides a" | |
| 2863 | have "c \<notin> Units G" | |
| 63846 | 2864 | proof | 
| 27701 | 2865 | assume cunit:"c \<in> Units G" | 
| 63832 | 2866 | have "b \<otimes> inv c = a \<otimes> c \<otimes> inv c" | 
| 2867 | by (simp add: b) | |
| 2868 | also from ccarr acarr cunit have "\<dots> = a \<otimes> (c \<otimes> inv c)" | |
| 2869 | by (fast intro: m_assoc) | |
| 2870 | also from ccarr cunit have "\<dots> = a \<otimes> \<one>" by simp | |
| 2871 | also from acarr have "\<dots> = a" by simp | |
| 27701 | 2872 | finally have "a = b \<otimes> inv c" by simp | 
| 63832 | 2873 | with ccarr cunit have "b divides a" | 
| 2874 | by (fast intro: dividesI[of "inv c"]) | |
| 27701 | 2875 | with nbdvda show False by simp | 
| 2876 | qed | |
| 2877 | with cfs have "length cs > 0" | |
| 68474 | 2878 | by (metis Units_one_closed assoc_unit_r ccarr foldr.simps(1) id_apply length_greater_0_conv wfactors_def) | 
| 63832 | 2879 | with fca fcb show ?thesis | 
| 2880 | by simp | |
| 27701 | 2881 | qed | 
| 2882 | ||
| 29237 | 2883 | sublocale factorial_monoid \<subseteq> divisor_chain_condition_monoid | 
| 63832 | 2884 | apply unfold_locales | 
| 2885 | apply (rule wfUNIVI) | |
| 2886 | apply (rule measure_induct[of "factorcount G"]) | |
| 68684 | 2887 | using properfactor_fcount by auto | 
| 27701 | 2888 | |
| 29237 | 2889 | sublocale factorial_monoid \<subseteq> primeness_condition_monoid | 
| 63633 | 2890 | by standard (rule irreducible_prime) | 
| 27701 | 2891 | |
| 2892 | ||
| 63832 | 2893 | lemma (in factorial_monoid) primeness_condition: "primeness_condition_monoid G" .. | 
| 2894 | ||
| 2895 | lemma (in factorial_monoid) gcd_condition [simp]: "gcd_condition_monoid G" | |
| 61169 | 2896 | by standard (rule gcdof_exists) | 
| 27701 | 2897 | |
| 29237 | 2898 | sublocale factorial_monoid \<subseteq> gcd_condition_monoid | 
| 61169 | 2899 | by standard (rule gcdof_exists) | 
| 27701 | 2900 | |
| 63832 | 2901 | lemma (in factorial_monoid) division_weak_lattice [simp]: "weak_lattice (division_rel G)" | 
| 27701 | 2902 | proof - | 
| 63832 | 2903 | interpret weak_lower_semilattice "division_rel G" | 
| 2904 | by simp | |
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2905 | show "weak_lattice (division_rel G)" | 
| 63832 | 2906 | proof (unfold_locales, simp_all) | 
| 27701 | 2907 | fix x y | 
| 2908 | assume carr: "x \<in> carrier G" "y \<in> carrier G" | |
| 63847 | 2909 | from lcmof_exists [OF this] obtain z where zcarr: "z \<in> carrier G" and isgcd: "z lcmof x y" | 
| 2910 | by blast | |
| 63832 | 2911 |     with carr have "least (division_rel G) z (Upper (division_rel G) {x, y})"
 | 
| 2912 | by (simp add: lcmof_leastUpper[symmetric]) | |
| 2913 |     then show "\<exists>z. least (division_rel G) z (Upper (division_rel G) {x, y})"
 | |
| 63847 | 2914 | by blast | 
| 27701 | 2915 | qed | 
| 2916 | qed | |
| 2917 | ||
| 2918 | ||
| 61382 | 2919 | subsection \<open>Factoriality Theorems\<close> | 
| 27701 | 2920 | |
| 2921 | theorem factorial_condition_one: (* Jacobson theorem 2.21 *) | |
| 63847 | 2922 | "divisor_chain_condition_monoid G \<and> primeness_condition_monoid G \<longleftrightarrow> factorial_monoid G" | 
| 2923 | proof (rule iffI, clarify) | |
| 27701 | 2924 | assume dcc: "divisor_chain_condition_monoid G" | 
| 63832 | 2925 | and pc: "primeness_condition_monoid G" | 
| 29237 | 2926 | interpret divisor_chain_condition_monoid "G" by (rule dcc) | 
| 2927 | interpret primeness_condition_monoid "G" by (rule pc) | |
| 27701 | 2928 | show "factorial_monoid G" | 
| 63832 | 2929 | by (fast intro: factorial_monoidI wfactors_exist wfactors_unique) | 
| 27701 | 2930 | next | 
| 63847 | 2931 | assume "factorial_monoid G" | 
| 2932 | then interpret factorial_monoid "G" . | |
| 27701 | 2933 | show "divisor_chain_condition_monoid G \<and> primeness_condition_monoid G" | 
| 63832 | 2934 | by rule unfold_locales | 
| 27701 | 2935 | qed | 
| 2936 | ||
| 2937 | theorem factorial_condition_two: (* Jacobson theorem 2.22 *) | |
| 63847 | 2938 | "divisor_chain_condition_monoid G \<and> gcd_condition_monoid G \<longleftrightarrow> factorial_monoid G" | 
| 2939 | proof (rule iffI, clarify) | |
| 57865 | 2940 | assume dcc: "divisor_chain_condition_monoid G" | 
| 63832 | 2941 | and gc: "gcd_condition_monoid G" | 
| 29237 | 2942 | interpret divisor_chain_condition_monoid "G" by (rule dcc) | 
| 2943 | interpret gcd_condition_monoid "G" by (rule gc) | |
| 27701 | 2944 | show "factorial_monoid G" | 
| 63832 | 2945 | by (simp add: factorial_condition_one[symmetric], rule, unfold_locales) | 
| 27701 | 2946 | next | 
| 63847 | 2947 | assume "factorial_monoid G" | 
| 2948 | then interpret factorial_monoid "G" . | |
| 27701 | 2949 | show "divisor_chain_condition_monoid G \<and> gcd_condition_monoid G" | 
| 63832 | 2950 | by rule unfold_locales | 
| 27701 | 2951 | qed | 
| 2952 | ||
| 2953 | end |