| author | wenzelm | 
| Fri, 24 Nov 2023 20:58:12 +0100 | |
| changeset 79053 | badb3da19ac6 | 
| parent 75455 | 91c16c5ad3e9 | 
| child 80914 | d97fdabd9e2b | 
| 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 | 
| 73477 | 9 | imports "HOL-Combinatorics.List_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 | |
| 73350 | 818 | definition factors :: "('a, _) monoid_scheme \<Rightarrow> 'a list \<Rightarrow> '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 | |
| 73350 | 821 | definition wfactors ::"('a, _) monoid_scheme \<Rightarrow> 'a list \<Rightarrow> '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 | |
| 73350 | 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 | |
| 73350 | 827 | definition essentially_equal :: "('a, _) monoid_scheme \<Rightarrow> 'a list \<Rightarrow> '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" | |
| 73706 | 881 | using p by simp | 
| 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" | |
| 73350 | 886 | proof - | 
| 887 | from m have \<open>length a = length b\<close> | |
| 888 | by (rule map_eq_imp_length_eq) | |
| 889 | from p have \<open>mset c = mset b\<close> | |
| 73706 | 890 | by simp | 
| 73350 | 891 |   then obtain p where \<open>p permutes {..<length b}\<close> \<open>permute_list p b = c\<close>
 | 
| 892 | by (rule mset_eq_permutation) | |
| 893 |   with \<open>length a = length b\<close> have \<open>p permutes {..<length a}\<close>
 | |
| 894 | by simp | |
| 895 | moreover define d where \<open>d = permute_list p a\<close> | |
| 896 | ultimately have \<open>mset a = mset d\<close> \<open>map f d = map f c\<close> | |
| 897 |     using m \<open>p permutes {..<length b}\<close> \<open>permute_list p b = c\<close>
 | |
| 898 | by (auto simp flip: permute_list_map) | |
| 899 | then show ?thesis | |
| 73706 | 900 | by auto | 
| 73350 | 901 | qed | 
| 27701 | 902 | |
| 903 | lemma (in monoid) perm_assoc_switch: | |
| 63832 | 904 | assumes a:"as [\<sim>] bs" and p: "bs <~~> cs" | 
| 905 | shows "\<exists>bs'. as <~~> bs' \<and> bs' [\<sim>] cs" | |
| 73706 | 906 | proof - | 
| 907 | from p have \<open>mset cs = mset bs\<close> | |
| 908 | by simp | |
| 909 |   then obtain p where \<open>p permutes {..<length bs}\<close> \<open>permute_list p bs = cs\<close>
 | |
| 910 | by (rule mset_eq_permutation) | |
| 911 | moreover define bs' where \<open>bs' = permute_list p as\<close> | |
| 912 | ultimately have \<open>as <~~> bs'\<close> and \<open>bs' [\<sim>] cs\<close> | |
| 913 | using a by (auto simp add: list_all2_permute_list_iff list_all2_lengthD) | |
| 914 | then show ?thesis by blast | |
| 915 | qed | |
| 27701 | 916 | |
| 917 | lemma (in monoid) perm_assoc_switch_r: | |
| 63832 | 918 | assumes p: "as <~~> bs" and a:"bs [\<sim>] cs" | 
| 919 | shows "\<exists>bs'. as [\<sim>] bs' \<and> bs' <~~> cs" | |
| 73706 | 920 | using a p by (rule list_all2_reorder_left_invariance) | 
| 27701 | 921 | |
| 922 | declare perm_sym [sym] | |
| 923 | ||
| 924 | lemma perm_setP: | |
| 925 | assumes perm: "as <~~> bs" | |
| 926 | and as: "P (set as)" | |
| 927 | shows "P (set bs)" | |
| 73706 | 928 | using assms by (metis set_mset_mset) | 
| 27701 | 929 | |
| 63832 | 930 | lemmas (in monoid) perm_closed = perm_setP[of _ _ "\<lambda>as. as \<subseteq> carrier G"] | 
| 931 | ||
| 932 | lemmas (in monoid) irrlist_perm_cong = perm_setP[of _ _ "\<lambda>as. \<forall>a\<in>as. irreducible G a"] | |
| 27701 | 933 | |
| 934 | ||
| 61382 | 935 | text \<open>Essentially equal factorizations\<close> | 
| 27701 | 936 | |
| 937 | lemma (in monoid) essentially_equalI: | |
| 938 | assumes ex: "fs1 <~~> fs1'" "fs1' [\<sim>] fs2" | |
| 939 | shows "essentially_equal G fs1 fs2" | |
| 63832 | 940 | using ex unfolding essentially_equal_def by fast | 
| 27701 | 941 | |
| 942 | lemma (in monoid) essentially_equalE: | |
| 943 | assumes ee: "essentially_equal G fs1 fs2" | |
| 944 | and e: "\<And>fs1'. \<lbrakk>fs1 <~~> fs1'; fs1' [\<sim>] fs2\<rbrakk> \<Longrightarrow> P" | |
| 945 | shows "P" | |
| 63832 | 946 | using ee unfolding essentially_equal_def by (fast intro: e) | 
| 27701 | 947 | |
| 948 | lemma (in monoid) ee_refl [simp,intro]: | |
| 949 | assumes carr: "set as \<subseteq> carrier G" | |
| 950 | shows "essentially_equal G as as" | |
| 63832 | 951 | using carr by (fast intro: essentially_equalI) | 
| 27701 | 952 | |
| 953 | lemma (in monoid) ee_sym [sym]: | |
| 954 | assumes ee: "essentially_equal G as bs" | |
| 955 | and carr: "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" | |
| 956 | shows "essentially_equal G bs as" | |
| 63832 | 957 | using ee | 
| 27701 | 958 | proof (elim essentially_equalE) | 
| 959 | fix fs | |
| 960 | assume "as <~~> fs" "fs [\<sim>] bs" | |
| 63847 | 961 | from perm_assoc_switch_r [OF this] obtain fs' where a: "as [\<sim>] fs'" and p: "fs' <~~> bs" | 
| 962 | by blast | |
| 27701 | 963 | from p have "bs <~~> fs'" by (rule perm_sym) | 
| 63832 | 964 | with a[symmetric] carr show ?thesis | 
| 965 | by (iprover intro: essentially_equalI perm_closed) | |
| 27701 | 966 | qed | 
| 967 | ||
| 968 | lemma (in monoid) ee_trans [trans]: | |
| 969 | assumes ab: "essentially_equal G as bs" and bc: "essentially_equal G bs cs" | |
| 63832 | 970 | and ascarr: "set as \<subseteq> carrier G" | 
| 27701 | 971 | and bscarr: "set bs \<subseteq> carrier G" | 
| 972 | and cscarr: "set cs \<subseteq> carrier G" | |
| 973 | shows "essentially_equal G as cs" | |
| 63832 | 974 | using ab bc | 
| 27701 | 975 | proof (elim essentially_equalE) | 
| 976 | fix abs bcs | |
| 63847 | 977 | assume "abs [\<sim>] bs" and pb: "bs <~~> bcs" | 
| 978 | from perm_assoc_switch [OF this] obtain bs' where p: "abs <~~> bs'" and a: "bs' [\<sim>] bcs" | |
| 979 | by blast | |
| 27701 | 980 | assume "as <~~> abs" | 
| 73706 | 981 | with p have pp: "as <~~> bs'" by simp | 
| 27701 | 982 | from pp ascarr have c1: "set bs' \<subseteq> carrier G" by (rule perm_closed) | 
| 983 | 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 | 984 | assume "bcs [\<sim>] cs" | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 985 | then have "bs' [\<sim>] cs" | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 986 | using a c1 c2 cscarr listassoc_trans by blast | 
| 63832 | 987 | with pp show ?thesis | 
| 988 | by (rule essentially_equalI) | |
| 27701 | 989 | qed | 
| 990 | ||
| 991 | ||
| 61382 | 992 | subsubsection \<open>Properties of lists of elements\<close> | 
| 993 | ||
| 994 | text \<open>Multiplication of factors in a list\<close> | |
| 27701 | 995 | |
| 996 | lemma (in monoid) multlist_closed [simp, intro]: | |
| 997 | assumes ascarr: "set fs \<subseteq> carrier G" | |
| 67399 | 998 | shows "foldr (\<otimes>) fs \<one> \<in> carrier G" | 
| 63832 | 999 | using ascarr by (induct fs) simp_all | 
| 27701 | 1000 | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1001 | lemma (in comm_monoid) multlist_dividesI: | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1002 | assumes "f \<in> set fs" and "set fs \<subseteq> carrier G" | 
| 67399 | 1003 | shows "f divides (foldr (\<otimes>) fs \<one>)" | 
| 63832 | 1004 | using assms | 
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1005 | proof (induction fs) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1006 | case (Cons a fs) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1007 | then have f: "f \<in> carrier G" | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1008 | by blast | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1009 | show ?case | 
| 68684 | 1010 | 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 | 1011 | qed auto | 
| 27701 | 1012 | |
| 1013 | lemma (in comm_monoid_cancel) multlist_listassoc_cong: | |
| 1014 | assumes "fs [\<sim>] fs'" | |
| 1015 | and "set fs \<subseteq> carrier G" and "set fs' \<subseteq> carrier G" | |
| 67399 | 1016 | shows "foldr (\<otimes>) fs \<one> \<sim> 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 (induct fs arbitrary: fs') | 
| 27701 | 1019 | case (Cons a as fs') | 
| 63832 | 1020 | then show ?case | 
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1021 | proof (induction fs') | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1022 | case (Cons b bs) | 
| 67399 | 1023 | 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 | 1024 | by (simp add: mult_cong_l) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1025 | 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 | 1026 | using Cons by auto | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1027 | 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 | 1028 | by (simp add: mult_cong_r) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1029 | then show ?case | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1030 | 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 | 1031 | qed auto | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1032 | qed auto | 
| 27701 | 1033 | |
| 1034 | lemma (in comm_monoid) multlist_perm_cong: | |
| 1035 | assumes prm: "as <~~> bs" | |
| 1036 | and ascarr: "set as \<subseteq> carrier G" | |
| 67399 | 1037 | shows "foldr (\<otimes>) as \<one> = foldr (\<otimes>) bs \<one>" | 
| 73706 | 1038 | proof - | 
| 1039 | from prm have \<open>mset (rev as) = mset (rev bs)\<close> | |
| 1040 | by simp | |
| 1041 | moreover note one_closed | |
| 1042 | ultimately have \<open>fold (\<otimes>) (rev as) \<one> = fold (\<otimes>) (rev bs) \<one>\<close> | |
| 1043 | by (rule fold_permuted_eq) (use ascarr in \<open>auto intro: m_lcomm\<close>) | |
| 1044 | then show ?thesis | |
| 1045 | by (simp add: foldr_conv_fold) | |
| 1046 | qed | |
| 27701 | 1047 | |
| 1048 | lemma (in comm_monoid_cancel) multlist_ee_cong: | |
| 1049 | assumes "essentially_equal G fs fs'" | |
| 1050 | and "set fs \<subseteq> carrier G" and "set fs' \<subseteq> carrier G" | |
| 67399 | 1051 | shows "foldr (\<otimes>) fs \<one> \<sim> foldr (\<otimes>) fs' \<one>" | 
| 63832 | 1052 | using assms | 
| 68684 | 1053 | by (metis essentially_equal_def multlist_listassoc_cong multlist_perm_cong perm_closed) | 
| 27701 | 1054 | |
| 1055 | ||
| 61382 | 1056 | subsubsection \<open>Factorization in irreducible elements\<close> | 
| 27701 | 1057 | |
| 1058 | lemma wfactorsI: | |
| 28599 | 1059 | fixes G (structure) | 
| 27701 | 1060 | assumes "\<forall>f\<in>set fs. irreducible G f" | 
| 67399 | 1061 | and "foldr (\<otimes>) fs \<one> \<sim> a" | 
| 27701 | 1062 | shows "wfactors G fs a" | 
| 63832 | 1063 | using assms unfolding wfactors_def by simp | 
| 27701 | 1064 | |
| 1065 | lemma wfactorsE: | |
| 28599 | 1066 | fixes G (structure) | 
| 27701 | 1067 | assumes wf: "wfactors G fs a" | 
| 67399 | 1068 | and e: "\<lbrakk>\<forall>f\<in>set fs. irreducible G f; foldr (\<otimes>) fs \<one> \<sim> a\<rbrakk> \<Longrightarrow> P" | 
| 27701 | 1069 | shows "P" | 
| 63832 | 1070 | using wf unfolding wfactors_def by (fast dest: e) | 
| 27701 | 1071 | |
| 1072 | lemma (in monoid) factorsI: | |
| 1073 | assumes "\<forall>f\<in>set fs. irreducible G f" | |
| 67399 | 1074 | and "foldr (\<otimes>) fs \<one> = a" | 
| 27701 | 1075 | shows "factors G fs a" | 
| 63832 | 1076 | using assms unfolding factors_def by simp | 
| 27701 | 1077 | |
| 1078 | lemma factorsE: | |
| 28599 | 1079 | fixes G (structure) | 
| 27701 | 1080 | assumes f: "factors G fs a" | 
| 67399 | 1081 | and e: "\<lbrakk>\<forall>f\<in>set fs. irreducible G f; foldr (\<otimes>) fs \<one> = a\<rbrakk> \<Longrightarrow> P" | 
| 27701 | 1082 | shows "P" | 
| 63832 | 1083 | using f unfolding factors_def by (simp add: e) | 
| 27701 | 1084 | |
| 1085 | lemma (in monoid) factors_wfactors: | |
| 1086 | assumes "factors G as a" and "set as \<subseteq> carrier G" | |
| 1087 | shows "wfactors G as a" | |
| 63832 | 1088 | using assms by (blast elim: factorsE intro: wfactorsI) | 
| 27701 | 1089 | |
| 1090 | lemma (in monoid) wfactors_factors: | |
| 1091 | assumes "wfactors G as a" and "set as \<subseteq> carrier G" | |
| 1092 | shows "\<exists>a'. factors G as a' \<and> a' \<sim> a" | |
| 63832 | 1093 | using assms by (blast elim: wfactorsE intro: factorsI) | 
| 27701 | 1094 | |
| 1095 | lemma (in monoid) factors_closed [dest]: | |
| 1096 | assumes "factors G fs a" and "set fs \<subseteq> carrier G" | |
| 1097 | shows "a \<in> carrier G" | |
| 63832 | 1098 | using assms by (elim factorsE, clarsimp) | 
| 27701 | 1099 | |
| 1100 | lemma (in monoid) nunit_factors: | |
| 1101 | assumes anunit: "a \<notin> Units G" | |
| 1102 | and fs: "factors G as a" | |
| 1103 | shows "length as > 0" | |
| 46129 | 1104 | proof - | 
| 1105 | from anunit Units_one_closed have "a \<noteq> \<one>" by auto | |
| 1106 | with fs show ?thesis by (auto elim: factorsE) | |
| 1107 | qed | |
| 27701 | 1108 | |
| 1109 | lemma (in monoid) unit_wfactors [simp]: | |
| 1110 | assumes aunit: "a \<in> Units G" | |
| 1111 | shows "wfactors G [] a" | |
| 63832 | 1112 | using aunit by (intro wfactorsI) (simp, simp add: Units_assoc) | 
| 27701 | 1113 | |
| 1114 | lemma (in comm_monoid_cancel) unit_wfactors_empty: | |
| 1115 | assumes aunit: "a \<in> Units G" | |
| 1116 | and wf: "wfactors G fs a" | |
| 1117 | and carr[simp]: "set fs \<subseteq> carrier G" | |
| 1118 | shows "fs = []" | |
| 63846 | 1119 | proof (cases fs) | 
| 1120 | case fs: (Cons f fs') | |
| 63832 | 1121 | from carr have fcarr[simp]: "f \<in> carrier G" and carr'[simp]: "set fs' \<subseteq> carrier G" | 
| 1122 | by (simp_all add: fs) | |
| 1123 | ||
| 1124 | from fs wf have "irreducible G f" by (simp add: wfactors_def) | |
| 1125 | then have fnunit: "f \<notin> Units G" by (fast elim: irreducibleE) | |
| 1126 | ||
| 67399 | 1127 | from fs wf have a: "f \<otimes> foldr (\<otimes>) fs' \<one> \<sim> a" by (simp add: wfactors_def) | 
| 27701 | 1128 | |
| 1129 | note aunit | |
| 1130 | also from fs wf | |
| 67399 | 1131 | have a: "f \<otimes> foldr (\<otimes>) fs' \<one> \<sim> a" by (simp add: wfactors_def) | 
| 1132 | have "a \<sim> f \<otimes> foldr (\<otimes>) fs' \<one>" | |
| 63832 | 1133 | by (simp add: Units_closed[OF aunit] a[symmetric]) | 
| 67399 | 1134 | finally have "f \<otimes> foldr (\<otimes>) fs' \<one> \<in> Units G" by simp | 
| 63832 | 1135 | then have "f \<in> Units G" by (intro unit_factor[of f], simp+) | 
| 63846 | 1136 | with fnunit show ?thesis by contradiction | 
| 27701 | 1137 | qed | 
| 1138 | ||
| 1139 | ||
| 61382 | 1140 | text \<open>Comparing wfactors\<close> | 
| 27701 | 1141 | |
| 1142 | lemma (in comm_monoid_cancel) wfactors_listassoc_cong_l: | |
| 1143 | assumes fact: "wfactors G fs a" | |
| 1144 | and asc: "fs [\<sim>] fs'" | |
| 1145 | and carr: "a \<in> carrier G" "set fs \<subseteq> carrier G" "set fs' \<subseteq> carrier G" | |
| 1146 | shows "wfactors G fs' a" | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1147 | proof - | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1148 |   { 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 | 1149 | by (simp add: multlist_listassoc_cong carr) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1150 | also assume "foldr (\<otimes>) fs \<one> \<sim> a" | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1151 | 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 | 1152 | then show ?thesis | 
| 63832 | 1153 | using fact | 
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1154 | by (meson asc carr(2) carr(3) irrlist_listassoc_cong wfactors_def) | 
| 27701 | 1155 | qed | 
| 1156 | ||
| 1157 | lemma (in comm_monoid) wfactors_perm_cong_l: | |
| 1158 | assumes "wfactors G fs a" | |
| 1159 | and "fs <~~> fs'" | |
| 1160 | and "set fs \<subseteq> carrier G" | |
| 1161 | shows "wfactors G fs' a" | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1162 | using assms irrlist_perm_cong multlist_perm_cong wfactors_def by fastforce | 
| 27701 | 1163 | |
| 1164 | lemma (in comm_monoid_cancel) wfactors_ee_cong_l [trans]: | |
| 1165 | assumes ee: "essentially_equal G as bs" | |
| 1166 | and bfs: "wfactors G bs b" | |
| 1167 | and carr: "b \<in> carrier G" "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" | |
| 1168 | shows "wfactors G as b" | |
| 63832 | 1169 | using ee | 
| 27701 | 1170 | proof (elim essentially_equalE) | 
| 1171 | fix fs | |
| 1172 | assume prm: "as <~~> fs" | |
| 73706 | 1173 | with carr have fscarr: "set fs \<subseteq> carrier G" | 
| 1174 | using perm_closed by blast | |
| 27701 | 1175 | |
| 1176 | note bfs | |
| 1177 | also assume [symmetric]: "fs [\<sim>] bs" | |
| 1178 | also (wfactors_listassoc_cong_l) | |
| 73706 | 1179 | have \<open>mset fs = mset as\<close> using prm by simp | 
| 27701 | 1180 | finally (wfactors_perm_cong_l) | 
| 63832 | 1181 | show "wfactors G as b" by (simp add: carr fscarr) | 
| 27701 | 1182 | qed | 
| 1183 | ||
| 1184 | lemma (in monoid) wfactors_cong_r [trans]: | |
| 1185 | assumes fac: "wfactors G fs a" and aa': "a \<sim> a'" | |
| 1186 | and carr[simp]: "a \<in> carrier G" "a' \<in> carrier G" "set fs \<subseteq> carrier G" | |
| 1187 | shows "wfactors G fs a'" | |
| 63832 | 1188 | using fac | 
| 27701 | 1189 | proof (elim wfactorsE, intro wfactorsI) | 
| 67399 | 1190 | assume "foldr (\<otimes>) fs \<one> \<sim> a" also note aa' | 
| 1191 | finally show "foldr (\<otimes>) fs \<one> \<sim> a'" by simp | |
| 27701 | 1192 | qed | 
| 1193 | ||
| 1194 | ||
| 61382 | 1195 | subsubsection \<open>Essentially equal factorizations\<close> | 
| 27701 | 1196 | |
| 1197 | lemma (in comm_monoid_cancel) unitfactor_ee: | |
| 1198 | assumes uunit: "u \<in> Units G" | |
| 1199 | and carr: "set as \<subseteq> carrier G" | |
| 63832 | 1200 | shows "essentially_equal G (as[0 := (as!0 \<otimes> u)]) as" | 
| 1201 | (is "essentially_equal G ?as' as") | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1202 | proof - | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1203 | have "as[0 := as ! 0 \<otimes> u] [\<sim>] as" | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1204 | proof (cases as) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1205 | case (Cons a as') | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1206 | then show ?thesis | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1207 | using associatedI2 carr uunit by auto | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1208 | qed auto | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1209 | then show ?thesis | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1210 | using essentially_equal_def by blast | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1211 | qed | 
| 27701 | 1212 | |
| 1213 | lemma (in comm_monoid_cancel) factors_cong_unit: | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1214 | assumes u: "u \<in> Units G" | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1215 | and a: "a \<notin> Units G" | 
| 27701 | 1216 | and afs: "factors G as a" | 
| 1217 | and ascarr: "set as \<subseteq> carrier G" | |
| 63832 | 1218 | shows "factors G (as[0 := (as!0 \<otimes> u)]) (a \<otimes> u)" | 
| 1219 | (is "factors G ?as' ?a'") | |
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1220 | proof (cases as) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1221 | case Nil | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1222 | then show ?thesis | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1223 | using afs a nunit_factors by auto | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1224 | next | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1225 | case (Cons b bs) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1226 | 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 | 1227 | using afs by (auto simp: factors_def) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1228 | show ?thesis | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1229 | proof (intro factorsI) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1230 | 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 | 1231 | 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 | 1232 | 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 | 1233 | using Cons u ascarr * by (force intro: irreducible_prod_rI) | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1234 | qed | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1235 | qed | 
| 27701 | 1236 | |
| 1237 | lemma (in comm_monoid) perm_wfactorsD: | |
| 1238 | assumes prm: "as <~~> bs" | |
| 63832 | 1239 | and afs: "wfactors G as a" | 
| 1240 | and bfs: "wfactors G bs b" | |
| 27701 | 1241 | and [simp]: "a \<in> carrier G" "b \<in> carrier G" | 
| 63832 | 1242 | and ascarr [simp]: "set as \<subseteq> carrier G" | 
| 27701 | 1243 | shows "a \<sim> b" | 
| 63832 | 1244 | using afs bfs | 
| 27701 | 1245 | proof (elim wfactorsE) | 
| 1246 | from prm have [simp]: "set bs \<subseteq> carrier G" by (simp add: perm_closed) | |
| 67399 | 1247 | assume "foldr (\<otimes>) as \<one> \<sim> a" | 
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1248 | then have "a \<sim> foldr (\<otimes>) as \<one>" | 
| 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1249 | by (simp add: associated_sym) | 
| 27701 | 1250 | also from prm | 
| 67399 | 1251 | have "foldr (\<otimes>) as \<one> = foldr (\<otimes>) bs \<one>" by (rule multlist_perm_cong, simp) | 
| 1252 | also assume "foldr (\<otimes>) bs \<one> \<sim> b" | |
| 63832 | 1253 | finally show "a \<sim> b" by simp | 
| 27701 | 1254 | qed | 
| 1255 | ||
| 1256 | lemma (in comm_monoid_cancel) listassoc_wfactorsD: | |
| 1257 | assumes assoc: "as [\<sim>] bs" | |
| 63832 | 1258 | and afs: "wfactors G as a" | 
| 1259 | and bfs: "wfactors G bs b" | |
| 27701 | 1260 | and [simp]: "a \<in> carrier G" "b \<in> carrier G" | 
| 1261 | and [simp]: "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" | |
| 1262 | shows "a \<sim> b" | |
| 63832 | 1263 | using afs bfs | 
| 27701 | 1264 | proof (elim wfactorsE) | 
| 67399 | 1265 | assume "foldr (\<otimes>) as \<one> \<sim> a" | 
| 68470 
7ddcce75c3ee
Partial de-apply of Divisibility
 paulson <lp15@cam.ac.uk> parents: 
68399diff
changeset | 1266 | then have "a \<sim> foldr (\<otimes>) as \<one>" by (simp add: associated_sym) | 
| 27701 | 1267 | also from assoc | 
| 67399 | 1268 | have "foldr (\<otimes>) as \<one> \<sim> foldr (\<otimes>) bs \<one>" by (rule multlist_listassoc_cong, simp+) | 
| 1269 | also assume "foldr (\<otimes>) bs \<one> \<sim> b" | |
| 63832 | 1270 | finally show "a \<sim> b" by simp | 
| 27701 | 1271 | qed | 
| 1272 | ||
| 1273 | lemma (in comm_monoid_cancel) ee_wfactorsD: | |
| 1274 | assumes ee: "essentially_equal G as bs" | |
| 1275 | and afs: "wfactors G as a" and bfs: "wfactors G bs b" | |
| 1276 | and [simp]: "a \<in> carrier G" "b \<in> carrier G" | |
| 1277 | and ascarr[simp]: "set as \<subseteq> carrier G" and bscarr[simp]: "set bs \<subseteq> carrier G" | |
| 1278 | shows "a \<sim> b" | |
| 63832 | 1279 | using ee | 
| 27701 | 1280 | proof (elim essentially_equalE) | 
| 1281 | fix fs | |
| 1282 | assume prm: "as <~~> fs" | |
| 63832 | 1283 | then have as'carr[simp]: "set fs \<subseteq> carrier G" | 
| 1284 | by (simp add: perm_closed) | |
| 1285 | from afs prm have afs': "wfactors G fs a" | |
| 1286 | by (rule wfactors_perm_cong_l) simp | |
| 27701 | 1287 | assume "fs [\<sim>] bs" | 
| 63832 | 1288 | from this afs' bfs show "a \<sim> b" | 
| 1289 | by (rule listassoc_wfactorsD) simp_all | |
| 27701 | 1290 | qed | 
| 1291 | ||
| 1292 | lemma (in comm_monoid_cancel) ee_factorsD: | |
| 1293 | assumes ee: "essentially_equal G as bs" | |
| 1294 | and afs: "factors G as a" and bfs:"factors G bs b" | |
| 1295 | and "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" | |
| 1296 | shows "a \<sim> b" | |
| 63832 | 1297 | using assms by (blast intro: factors_wfactors dest: ee_wfactorsD) | 
| 27701 | 1298 | |
| 1299 | lemma (in factorial_monoid) ee_factorsI: | |
| 1300 | assumes ab: "a \<sim> b" | |
| 1301 | and afs: "factors G as a" and anunit: "a \<notin> Units G" | |
| 1302 | and bfs: "factors G bs b" and bnunit: "b \<notin> Units G" | |
| 1303 | and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G" | |
| 1304 | shows "essentially_equal G as bs" | |
| 1305 | proof - | |
| 1306 | note carr[simp] = factors_closed[OF afs ascarr] ascarr[THEN subsetD] | |
| 63832 | 1307 | factors_closed[OF bfs bscarr] bscarr[THEN subsetD] | 
| 1308 | ||
| 63847 | 1309 | from ab carr obtain u where uunit: "u \<in> Units G" and a: "a = b \<otimes> u" | 
| 1310 | by (elim associatedE2) | |
| 63832 | 1311 | |
| 1312 | from uunit bscarr have ee: "essentially_equal G (bs[0 := (bs!0 \<otimes> u)]) bs" | |
| 1313 | (is "essentially_equal G ?bs' bs") | |
| 1314 | by (rule unitfactor_ee) | |
| 1315 | ||
| 1316 | from bscarr uunit have bs'carr: "set ?bs' \<subseteq> carrier G" | |
| 1317 | by (cases bs) (simp_all add: Units_closed) | |
| 1318 | ||
| 1319 | from uunit bnunit bfs bscarr have fac: "factors G ?bs' (b \<otimes> u)" | |
| 1320 | by (rule factors_cong_unit) | |
| 27701 | 1321 | |
| 1322 | from afs fac[simplified a[symmetric]] ascarr bs'carr anunit | |
| 63832 | 1323 | have "essentially_equal G as ?bs'" | 
| 1324 | by (blast intro: factors_unique) | |
| 27701 | 1325 | also note ee | 
| 63832 | 1326 | finally show "essentially_equal G as bs" | 
| 1327 | by (simp add: ascarr bscarr bs'carr) | |
| 27701 | 1328 | qed | 
| 1329 | ||
| 1330 | lemma (in factorial_monoid) ee_wfactorsI: | |
| 1331 | assumes asc: "a \<sim> b" | |
| 1332 | and asf: "wfactors G as a" and bsf: "wfactors G bs b" | |
| 1333 | and acarr[simp]: "a \<in> carrier G" and bcarr[simp]: "b \<in> carrier G" | |
| 1334 | and ascarr[simp]: "set as \<subseteq> carrier G" and bscarr[simp]: "set bs \<subseteq> carrier G" | |
| 1335 | shows "essentially_equal G as bs" | |
| 63832 | 1336 | using assms | 
| 27701 | 1337 | proof (cases "a \<in> Units G") | 
| 63832 | 1338 | case aunit: True | 
| 27701 | 1339 | also note asc | 
| 1340 | finally have bunit: "b \<in> Units G" by simp | |
| 1341 | ||
| 63832 | 1342 | from aunit asf ascarr have e: "as = []" | 
| 1343 | by (rule unit_wfactors_empty) | |
| 1344 | from bunit bsf bscarr have e': "bs = []" | |
| 1345 | by (rule unit_wfactors_empty) | |
| 27701 | 1346 | |
| 1347 | have "essentially_equal G [] []" | |
| 63832 | 1348 | by (fast intro: essentially_equalI) | 
| 1349 | then show ?thesis | |
| 1350 | by (simp add: e e') | |
| 27701 | 1351 | next | 
| 63832 | 1352 | case anunit: False | 
| 27701 | 1353 | have bnunit: "b \<notin> Units G" | 
| 1354 | proof clarify | |
| 1355 | assume "b \<in> Units G" | |
| 1356 | also note asc[symmetric] | |
| 1357 | finally have "a \<in> Units G" by simp | |
| 63832 | 1358 | with anunit show False .. | 
| 27701 | 1359 | qed | 
| 1360 | ||
| 63847 | 1361 | from wfactors_factors[OF asf ascarr] obtain a' where fa': "factors G as a'" and a': "a' \<sim> a" | 
| 1362 | by blast | |
| 63832 | 1363 | from fa' ascarr have a'carr[simp]: "a' \<in> carrier G" | 
| 1364 | by fast | |
| 27701 | 1365 | |
| 1366 | have a'nunit: "a' \<notin> Units G" | |
| 63832 | 1367 | proof clarify | 
| 27701 | 1368 | assume "a' \<in> Units G" | 
| 1369 | also note a' | |
| 1370 | finally have "a \<in> Units G" by simp | |
| 1371 | with anunit | |
| 63832 | 1372 | show "False" .. | 
| 27701 | 1373 | qed | 
| 1374 | ||
| 63847 | 1375 | from wfactors_factors[OF bsf bscarr] obtain b' where fb': "factors G bs b'" and b': "b' \<sim> b" | 
| 1376 | by blast | |
| 63832 | 1377 | from fb' bscarr have b'carr[simp]: "b' \<in> carrier G" | 
| 1378 | by fast | |
| 27701 | 1379 | |
| 1380 | have b'nunit: "b' \<notin> Units G" | |
| 63832 | 1381 | proof clarify | 
| 27701 | 1382 | assume "b' \<in> Units G" | 
| 1383 | also note b' | |
| 1384 | finally have "b \<in> Units G" by simp | |
| 63832 | 1385 | with bnunit show False .. | 
| 27701 | 1386 | qed | 
| 1387 | ||
| 1388 | note a' | |
| 1389 | also note asc | |
| 1390 | also note b'[symmetric] | |
| 63832 | 1391 | finally have "a' \<sim> b'" by simp | 
| 1392 | from this fa' a'nunit fb' b'nunit ascarr bscarr show "essentially_equal G as bs" | |
| 1393 | by (rule ee_factorsI) | |
| 27701 | 1394 | qed | 
| 1395 | ||
| 1396 | lemma (in factorial_monoid) ee_wfactors: | |
| 1397 | assumes asf: "wfactors G as a" | |
| 1398 | and bsf: "wfactors G bs b" | |
| 1399 | and acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" | |
| 1400 | and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G" | |
| 1401 | shows asc: "a \<sim> b = essentially_equal G as bs" | |
| 63832 | 1402 | using assms by (fast intro: ee_wfactorsI ee_wfactorsD) | 
| 27701 | 1403 | |
| 1404 | lemma (in factorial_monoid) wfactors_exist [intro, simp]: | |
| 1405 | assumes acarr[simp]: "a \<in> carrier G" | |
| 1406 | shows "\<exists>fs. set fs \<subseteq> carrier G \<and> wfactors G fs a" | |
| 1407 | proof (cases "a \<in> Units G") | |
| 63832 | 1408 | case True | 
| 1409 | then have "wfactors G [] a" by (rule unit_wfactors) | |
| 1410 | then show ?thesis by (intro exI) force | |
| 27701 | 1411 | next | 
| 63832 | 1412 | case False | 
| 63847 | 1413 | with factors_exist [OF acarr] obtain fs where fscarr: "set fs \<subseteq> carrier G" and f: "factors G fs a" | 
| 1414 | by blast | |
| 27701 | 1415 | from f have "wfactors G fs a" by (rule factors_wfactors) fact | 
| 63832 | 1416 | with fscarr show ?thesis by fast | 
| 27701 | 1417 | qed | 
| 1418 | ||
| 1419 | lemma (in monoid) wfactors_prod_exists [intro, simp]: | |
| 1420 | assumes "\<forall>a \<in> set as. irreducible G a" and "set as \<subseteq> carrier G" | |
| 1421 | shows "\<exists>a. a \<in> carrier G \<and> wfactors G as a" | |
| 63832 | 1422 | unfolding wfactors_def using assms by blast | 
| 27701 | 1423 | |
| 1424 | lemma (in factorial_monoid) wfactors_unique: | |
| 63832 | 1425 | assumes "wfactors G fs a" | 
| 1426 | and "wfactors G fs' a" | |
| 27701 | 1427 | and "a \<in> carrier G" | 
| 63832 | 1428 | and "set fs \<subseteq> carrier G" | 
| 1429 | and "set fs' \<subseteq> carrier G" | |
| 27701 | 1430 | shows "essentially_equal G fs fs'" | 
| 63832 | 1431 | using assms by (fast intro: ee_wfactorsI[of a a]) | 
| 27701 | 1432 | |
| 1433 | lemma (in monoid) factors_mult_single: | |
| 1434 | assumes "irreducible G a" and "factors G fb b" and "a \<in> carrier G" | |
| 1435 | shows "factors G (a # fb) (a \<otimes> b)" | |
| 63832 | 1436 | using assms unfolding factors_def by simp | 
| 27701 | 1437 | |
| 1438 | lemma (in monoid_cancel) wfactors_mult_single: | |
| 1439 | assumes f: "irreducible G a" "wfactors G fb b" | |
| 63832 | 1440 | "a \<in> carrier G" "b \<in> carrier G" "set fb \<subseteq> carrier G" | 
| 27701 | 1441 | shows "wfactors G (a # fb) (a \<otimes> b)" | 
| 63832 | 1442 | using assms unfolding wfactors_def by (simp add: mult_cong_r) | 
| 27701 | 1443 | |
| 1444 | lemma (in monoid) factors_mult: | |
| 1445 | assumes factors: "factors G fa a" "factors G fb b" | |
| 63832 | 1446 | and ascarr: "set fa \<subseteq> carrier G" | 
| 1447 | and bscarr: "set fb \<subseteq> carrier G" | |
| 27701 | 1448 | shows "factors G (fa @ fb) (a \<otimes> b)" | 
| 68474 | 1449 | proof - | 
| 1450 | have "foldr (\<otimes>) (fa @ fb) \<one> = foldr (\<otimes>) fa \<one> \<otimes> foldr (\<otimes>) fb \<one>" if "set fa \<subseteq> carrier G" | |
| 1451 | "Ball (set fa) (irreducible G)" | |
| 1452 | using that bscarr by (induct fa) (simp_all add: m_assoc) | |
| 1453 | then show ?thesis | |
| 1454 | using assms unfolding factors_def by force | |
| 1455 | qed | |
| 27701 | 1456 | |
| 1457 | lemma (in comm_monoid_cancel) wfactors_mult [intro]: | |
| 1458 | assumes asf: "wfactors G as a" and bsf:"wfactors G bs b" | |
| 1459 | and acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" | |
| 1460 | and ascarr: "set as \<subseteq> carrier G" and bscarr:"set bs \<subseteq> carrier G" | |
| 1461 | shows "wfactors G (as @ bs) (a \<otimes> b)" | |
| 63832 | 1462 | using wfactors_factors[OF asf ascarr] and wfactors_factors[OF bsf bscarr] | 
| 1463 | proof clarsimp | |
| 27701 | 1464 | fix a' b' | 
| 1465 | assume asf': "factors G as a'" and a'a: "a' \<sim> a" | |
| 63832 | 1466 | and bsf': "factors G bs b'" and b'b: "b' \<sim> b" | 
| 27701 | 1467 | from asf' have a'carr: "a' \<in> carrier G" by (rule factors_closed) fact | 
| 1468 | from bsf' have b'carr: "b' \<in> carrier G" by (rule factors_closed) fact | |
| 1469 | ||
| 1470 | note carr = acarr bcarr a'carr b'carr ascarr bscarr | |
| 1471 | ||
| 63832 | 1472 | from asf' bsf' have "factors G (as @ bs) (a' \<otimes> b')" | 
| 1473 | by (rule factors_mult) fact+ | |
| 1474 | ||
| 1475 | with carr have abf': "wfactors G (as @ bs) (a' \<otimes> b')" | |
| 1476 | by (intro factors_wfactors) simp_all | |
| 1477 | also from b'b carr have trb: "a' \<otimes> b' \<sim> a' \<otimes> b" | |
| 1478 | by (intro mult_cong_r) | |
| 1479 | also from a'a carr have tra: "a' \<otimes> b \<sim> a \<otimes> b" | |
| 1480 | by (intro mult_cong_l) | |
| 1481 | finally show "wfactors G (as @ bs) (a \<otimes> b)" | |
| 1482 | by (simp add: carr) | |
| 27701 | 1483 | qed | 
| 1484 | ||
| 1485 | lemma (in comm_monoid) factors_dividesI: | |
| 63832 | 1486 | assumes "factors G fs a" | 
| 1487 | and "f \<in> set fs" | |
| 27701 | 1488 | and "set fs \<subseteq> carrier G" | 
| 1489 | shows "f divides a" | |
| 63832 | 1490 | using assms by (fast elim: factorsE intro: multlist_dividesI) | 
| 27701 | 1491 | |
| 1492 | lemma (in comm_monoid) wfactors_dividesI: | |
| 1493 | assumes p: "wfactors G fs a" | |
| 1494 | and fscarr: "set fs \<subseteq> carrier G" and acarr: "a \<in> carrier G" | |
| 1495 | and f: "f \<in> set fs" | |
| 1496 | shows "f divides a" | |
| 63832 | 1497 | using wfactors_factors[OF p fscarr] | 
| 1498 | proof clarsimp | |
| 27701 | 1499 | fix a' | 
| 63832 | 1500 | assume fsa': "factors G fs a'" and a'a: "a' \<sim> a" | 
| 1501 | with fscarr have a'carr: "a' \<in> carrier G" | |
| 1502 | by (simp add: factors_closed) | |
| 1503 | ||
| 1504 | from fsa' fscarr f have "f divides a'" | |
| 1505 | by (fast intro: factors_dividesI) | |
| 27701 | 1506 | also note a'a | 
| 63832 | 1507 | finally show "f divides a" | 
| 1508 | by (simp add: f fscarr[THEN subsetD] acarr a'carr) | |
| 27701 | 1509 | qed | 
| 1510 | ||
| 1511 | ||
| 61382 | 1512 | subsubsection \<open>Factorial monoids and wfactors\<close> | 
| 27701 | 1513 | |
| 1514 | lemma (in comm_monoid_cancel) factorial_monoidI: | |
| 68664 
bd0df72c16d5
updated material concerning Algebra
 paulson <lp15@cam.ac.uk> parents: 
68604diff
changeset | 1515 | 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 | 1516 | and wfactors_unique: | 
| 1517 | "\<And>a fs fs'. \<lbrakk>a \<in> carrier G; set fs \<subseteq> carrier G; set fs' \<subseteq> carrier G; | |
| 1518 | wfactors G fs a; wfactors G fs' a\<rbrakk> \<Longrightarrow> essentially_equal G fs fs'" | |
| 27701 | 1519 | shows "factorial_monoid G" | 
| 28823 | 1520 | proof | 
| 27701 | 1521 | fix a | 
| 1522 | 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 | 1523 | from wfactors_exists[OF acarr anunit] | 
| 63832 | 1524 | obtain as where ascarr: "set as \<subseteq> carrier G" and afs: "wfactors G as a" | 
| 63847 | 1525 | by blast | 
| 1526 | from wfactors_factors [OF afs ascarr] obtain a' where afs': "factors G as a'" and a'a: "a' \<sim> a" | |
| 1527 | by blast | |
| 63832 | 1528 | from afs' ascarr have a'carr: "a' \<in> carrier G" | 
| 1529 | by fast | |
| 27701 | 1530 | have a'nunit: "a' \<notin> Units G" | 
| 1531 | proof clarify | |
| 1532 | assume "a' \<in> Units G" | |
| 1533 | also note a'a | |
| 1534 | finally have "a \<in> Units G" by (simp add: acarr) | |
| 63832 | 1535 | with anunit show False .. | 
| 27701 | 1536 | qed | 
| 1537 | ||
| 63847 | 1538 | from a'carr acarr a'a obtain u where uunit: "u \<in> Units G" and a': "a' = a \<otimes> u" | 
| 63832 | 1539 | by (blast elim: associatedE2) | 
| 27701 | 1540 | |
| 1541 | note [simp] = acarr Units_closed[OF uunit] Units_inv_closed[OF uunit] | |
| 1542 | have "a = a \<otimes> \<one>" by simp | |
| 57865 | 1543 | also have "\<dots> = a \<otimes> (u \<otimes> inv u)" by (simp add: uunit) | 
| 27701 | 1544 | also have "\<dots> = a' \<otimes> inv u" by (simp add: m_assoc[symmetric] a'[symmetric]) | 
| 63832 | 1545 | finally have a: "a = a' \<otimes> inv u" . | 
| 1546 | ||
| 1547 | from ascarr uunit have cr: "set (as[0:=(as!0 \<otimes> inv u)]) \<subseteq> carrier G" | |
| 1548 | by (cases as) auto | |
| 1549 | from afs' uunit a'nunit acarr ascarr have "factors G (as[0:=(as!0 \<otimes> inv u)]) a" | |
| 1550 | by (simp add: a factors_cong_unit) | |
| 1551 | with cr show "\<exists>fs. set fs \<subseteq> carrier G \<and> factors G fs a" | |
| 1552 | by fast | |
| 27701 | 1553 | qed (blast intro: factors_wfactors wfactors_unique) | 
| 1554 | ||
| 1555 | ||
| 61382 | 1556 | subsection \<open>Factorizations as Multisets\<close> | 
| 1557 | ||
| 1558 | text \<open>Gives useful operations like intersection\<close> | |
| 27701 | 1559 | |
| 1560 | (* FIXME: use class_of x instead of closure_of {x} *)
 | |
| 1561 | ||
| 63832 | 1562 | abbreviation "assocs G x \<equiv> eq_closure_of (division_rel G) {x}"
 | 
| 1563 | ||
| 73350 | 1564 | definition "fmset G as = mset (map (assocs G) as)" | 
| 27701 | 1565 | |
| 1566 | ||
| 61382 | 1567 | text \<open>Helper lemmas\<close> | 
| 27701 | 1568 | |
| 1569 | lemma (in monoid) assocs_repr_independence: | |
| 68474 | 1570 | assumes "y \<in> assocs G x" "x \<in> carrier G" | 
| 27701 | 1571 | shows "assocs G x = assocs G y" | 
| 63832 | 1572 | using assms | 
| 68474 | 1573 | by (simp add: eq_closure_of_def elem_def) (use associated_sym associated_trans in \<open>blast+\<close>) | 
| 27701 | 1574 | |
| 1575 | lemma (in monoid) assocs_self: | |
| 1576 | assumes "x \<in> carrier G" | |
| 1577 | shows "x \<in> assocs G x" | |
| 63832 | 1578 | using assms by (fastforce intro: closure_ofI2) | 
| 27701 | 1579 | |
| 1580 | lemma (in monoid) assocs_repr_independenceD: | |
| 68474 | 1581 | assumes repr: "assocs G x = assocs G y" and ycarr: "y \<in> carrier G" | 
| 27701 | 1582 | shows "y \<in> assocs G x" | 
| 63832 | 1583 | unfolding repr using ycarr by (intro assocs_self) | 
| 27701 | 1584 | |
| 1585 | lemma (in comm_monoid) assocs_assoc: | |
| 68474 | 1586 | assumes "a \<in> assocs G b" "b \<in> carrier G" | 
| 27701 | 1587 | shows "a \<sim> b" | 
| 63832 | 1588 | using assms by (elim closure_ofE2) simp | 
| 1589 | ||
| 1590 | lemmas (in comm_monoid) assocs_eqD = assocs_repr_independenceD[THEN assocs_assoc] | |
| 27701 | 1591 | |
| 1592 | ||
| 61382 | 1593 | subsubsection \<open>Comparing multisets\<close> | 
| 27701 | 1594 | |
| 1595 | lemma (in monoid) fmset_perm_cong: | |
| 1596 | assumes prm: "as <~~> bs" | |
| 1597 | shows "fmset G as = fmset G bs" | |
| 73706 | 1598 | using perm_map[OF prm] unfolding fmset_def by blast | 
| 27701 | 1599 | |
| 1600 | lemma (in comm_monoid_cancel) eqc_listassoc_cong: | |
| 68474 | 1601 | assumes "as [\<sim>] bs" and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G" | 
| 27701 | 1602 | shows "map (assocs G) as = map (assocs G) bs" | 
| 63832 | 1603 | using assms | 
| 68474 | 1604 | proof (induction as arbitrary: bs) | 
| 1605 | case Nil | |
| 1606 | then show ?case by simp | |
| 27701 | 1607 | next | 
| 68474 | 1608 | case (Cons a as) | 
| 1609 | then show ?case | |
| 1610 | proof (clarsimp simp add: Cons_eq_map_conv list_all2_Cons1) | |
| 1611 | fix z zs | |
| 1612 | assume zzs: "a \<in> carrier G" "set as \<subseteq> carrier G" "bs = z # zs" "a \<sim> z" | |
| 1613 | "as [\<sim>] zs" "z \<in> carrier G" "set zs \<subseteq> carrier G" | |
| 1614 | then show "assocs G a = assocs G z" | |
| 1615 | apply (simp add: eq_closure_of_def elem_def) | |
| 1616 | using \<open>a \<in> carrier G\<close> \<open>z \<in> carrier G\<close> \<open>a \<sim> z\<close> associated_sym associated_trans by blast+ | |
| 1617 | qed | |
| 27701 | 1618 | qed | 
| 1619 | ||
| 1620 | lemma (in comm_monoid_cancel) fmset_listassoc_cong: | |
| 63832 | 1621 | assumes "as [\<sim>] bs" | 
| 27701 | 1622 | and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G" | 
| 1623 | shows "fmset G as = fmset G bs" | |
| 63832 | 1624 | using assms unfolding fmset_def by (simp add: eqc_listassoc_cong) | 
| 27701 | 1625 | |
| 1626 | lemma (in comm_monoid_cancel) ee_fmset: | |
| 63832 | 1627 | assumes ee: "essentially_equal G as bs" | 
| 27701 | 1628 | and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G" | 
| 1629 | shows "fmset G as = fmset G bs" | |
| 63832 | 1630 | using ee | 
| 73350 | 1631 | thm essentially_equal_def | 
| 27701 | 1632 | proof (elim essentially_equalE) | 
| 1633 | fix as' | |
| 1634 | assume prm: "as <~~> as'" | |
| 63832 | 1635 | from prm ascarr have as'carr: "set as' \<subseteq> carrier G" | 
| 1636 | by (rule perm_closed) | |
| 1637 | from prm have "fmset G as = fmset G as'" | |
| 1638 | by (rule fmset_perm_cong) | |
| 27701 | 1639 | also assume "as' [\<sim>] bs" | 
| 63832 | 1640 | with as'carr bscarr have "fmset G as' = fmset G bs" | 
| 1641 | by (simp add: fmset_listassoc_cong) | |
| 1642 | finally show "fmset G as = fmset G bs" . | |
| 27701 | 1643 | qed | 
| 1644 | ||
| 1645 | lemma (in comm_monoid_cancel) fmset_ee: | |
| 1646 | assumes mset: "fmset G as = fmset G bs" | |
| 1647 | and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G" | |
| 1648 | shows "essentially_equal G as bs" | |
| 1649 | proof - | |
| 73350 | 1650 | from mset have "mset (map (assocs G) bs) = mset (map (assocs G) as)" | 
| 1651 | by (simp add: fmset_def) | |
| 1652 |   then obtain p where \<open>p permutes {..<length (map (assocs G) as)}\<close>
 | |
| 1653 | \<open>permute_list p (map (assocs G) as) = map (assocs G) bs\<close> | |
| 1654 | by (rule mset_eq_permutation) | |
| 1655 |   then have \<open>p permutes {..<length as}\<close>
 | |
| 1656 | \<open>map (assocs G) (permute_list p as) = map (assocs G) bs\<close> | |
| 1657 | by (simp_all add: permute_list_map) | |
| 1658 | moreover define as' where \<open>as' = permute_list p as\<close> | |
| 1659 | ultimately have tp: "as <~~> as'" and tm: "map (assocs G) as' = map (assocs G) bs" | |
| 73706 | 1660 | by simp_all | 
| 73350 | 1661 | from tp show ?thesis | 
| 1662 | proof (rule essentially_equalI) | |
| 1663 | from tm tp ascarr have as'carr: "set as' \<subseteq> carrier G" | |
| 1664 | using perm_closed by blast | |
| 1665 | from tm as'carr[THEN subsetD] bscarr[THEN subsetD] show "as' [\<sim>] bs" | |
| 1666 | by (induct as' arbitrary: bs) (simp, fastforce dest: assocs_eqD[THEN associated_sym]) | |
| 1667 | qed | |
| 27701 | 1668 | qed | 
| 1669 | ||
| 1670 | lemma (in comm_monoid_cancel) ee_is_fmset: | |
| 1671 | assumes "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G" | |
| 1672 | shows "essentially_equal G as bs = (fmset G as = fmset G bs)" | |
| 63832 | 1673 | using assms by (fast intro: ee_fmset fmset_ee) | 
| 27701 | 1674 | |
| 1675 | ||
| 61382 | 1676 | subsubsection \<open>Interpreting multisets as factorizations\<close> | 
| 27701 | 1677 | |
| 1678 | lemma (in monoid) mset_fmsetEx: | |
| 60495 | 1679 | assumes elems: "\<And>X. X \<in> set_mset Cs \<Longrightarrow> \<exists>x. P x \<and> X = assocs G x" | 
| 27701 | 1680 | shows "\<exists>cs. (\<forall>c \<in> set cs. P c) \<and> fmset G cs = Cs" | 
| 1681 | proof - | |
| 63847 | 1682 | from surjE[OF surj_mset] obtain Cs' where Cs: "Cs = mset Cs'" | 
| 1683 | by blast | |
| 60515 | 1684 | have "\<exists>cs. (\<forall>c \<in> set cs. P c) \<and> mset (map (assocs G) cs) = Cs" | 
| 68478 | 1685 | using elems unfolding Cs | 
| 1686 | proof (induction Cs') | |
| 1687 | case (Cons a Cs') | |
| 1688 | then obtain c cs where csP: "\<forall>x\<in>set cs. P x" and mset: "mset (map (assocs G) cs) = mset Cs'" | |
| 1689 | and cP: "P c" and a: "a = assocs G c" | |
| 1690 | by force | |
| 1691 | then have tP: "\<forall>x\<in>set (c#cs). P x" | |
| 63847 | 1692 | by simp | 
| 68478 | 1693 | show ?case | 
| 1694 | using tP mset a by fastforce | |
| 1695 | qed auto | |
| 63832 | 1696 | then show ?thesis by (simp add: fmset_def) | 
| 27701 | 1697 | qed | 
| 1698 | ||
| 1699 | lemma (in monoid) mset_wfactorsEx: | |
| 63832 | 1700 | 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 | 1701 | shows "\<exists>c cs. c \<in> carrier G \<and> set cs \<subseteq> carrier G \<and> wfactors G cs c \<and> fmset G cs = Cs" | 
| 1702 | proof - | |
| 1703 | have "\<exists>cs. (\<forall>c\<in>set cs. c \<in> carrier G \<and> irreducible G c) \<and> fmset G cs = Cs" | |
| 63832 | 1704 | by (intro mset_fmsetEx, rule elems) | 
| 1705 | then obtain cs where p[rule_format]: "\<forall>c\<in>set cs. c \<in> carrier G \<and> irreducible G c" | |
| 1706 | and Cs[symmetric]: "fmset G cs = Cs" by auto | |
| 1707 | from p have cscarr: "set cs \<subseteq> carrier G" by fast | |
| 1708 | from p have "\<exists>c. c \<in> carrier G \<and> wfactors G cs c" | |
| 1709 | by (intro wfactors_prod_exists) auto | |
| 1710 | then obtain c where ccarr: "c \<in> carrier G" and cfs: "wfactors G cs c" by auto | |
| 1711 | with cscarr Cs show ?thesis by fast | |
| 27701 | 1712 | qed | 
| 1713 | ||
| 1714 | ||
| 61382 | 1715 | subsubsection \<open>Multiplication on multisets\<close> | 
| 27701 | 1716 | |
| 1717 | lemma (in factorial_monoid) mult_wfactors_fmset: | |
| 63832 | 1718 | assumes afs: "wfactors G as a" | 
| 1719 | and bfs: "wfactors G bs b" | |
| 1720 | and cfs: "wfactors G cs (a \<otimes> b)" | |
| 27701 | 1721 | and carr: "a \<in> carrier G" "b \<in> carrier G" | 
| 1722 | "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" "set cs \<subseteq> carrier G" | |
| 1723 | shows "fmset G cs = fmset G as + fmset G bs" | |
| 1724 | proof - | |
| 63832 | 1725 | from assms have "wfactors G (as @ bs) (a \<otimes> b)" | 
| 1726 | by (intro wfactors_mult) | |
| 1727 | with carr cfs have "essentially_equal G cs (as@bs)" | |
| 1728 | by (intro ee_wfactorsI[of "a\<otimes>b" "a\<otimes>b"]) simp_all | |
| 1729 | with carr have "fmset G cs = fmset G (as@bs)" | |
| 1730 | by (intro ee_fmset) simp_all | |
| 1731 | also have "fmset G (as@bs) = fmset G as + fmset G bs" | |
| 1732 | by (simp add: fmset_def) | |
| 27701 | 1733 | finally show "fmset G cs = fmset G as + fmset G bs" . | 
| 1734 | qed | |
| 1735 | ||
| 1736 | lemma (in factorial_monoid) mult_factors_fmset: | |
| 63832 | 1737 | assumes afs: "factors G as a" | 
| 1738 | and bfs: "factors G bs b" | |
| 1739 | and cfs: "factors G cs (a \<otimes> b)" | |
| 27701 | 1740 | and "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" | |
| 63832 | 1742 | using assms by (blast intro: factors_wfactors mult_wfactors_fmset) | 
| 27701 | 1743 | |
| 1744 | lemma (in comm_monoid_cancel) fmset_wfactors_mult: | |
| 1745 | assumes mset: "fmset G cs = fmset G as + fmset G bs" | |
| 1746 | and carr: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | |
| 63832 | 1747 | "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" "set cs \<subseteq> carrier G" | 
| 27701 | 1748 | and fs: "wfactors G as a" "wfactors G bs b" "wfactors G cs c" | 
| 1749 | shows "c \<sim> a \<otimes> b" | |
| 1750 | proof - | |
| 63832 | 1751 | from carr fs have m: "wfactors G (as @ bs) (a \<otimes> b)" | 
| 1752 | by (intro wfactors_mult) | |
| 1753 | ||
| 1754 | from mset have "fmset G cs = fmset G (as@bs)" | |
| 1755 | by (simp add: fmset_def) | |
| 1756 | then have "essentially_equal G cs (as@bs)" | |
| 1757 | by (rule fmset_ee) (simp_all add: carr) | |
| 1758 | then show "c \<sim> a \<otimes> b" | |
| 1759 | by (rule ee_wfactorsD[of "cs" "as@bs"]) (simp_all add: assms m) | |
| 27701 | 1760 | qed | 
| 1761 | ||
| 1762 | ||
| 61382 | 1763 | subsubsection \<open>Divisibility on multisets\<close> | 
| 27701 | 1764 | |
| 1765 | lemma (in factorial_monoid) divides_fmsubset: | |
| 1766 | assumes ab: "a divides b" | |
| 63832 | 1767 | and afs: "wfactors G as a" | 
| 1768 | and bfs: "wfactors G bs b" | |
| 27701 | 1769 | and carr: "a \<in> carrier G" "b \<in> carrier G" "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" | 
| 64587 | 1770 | shows "fmset G as \<subseteq># fmset G bs" | 
| 63832 | 1771 | using ab | 
| 27701 | 1772 | proof (elim dividesE) | 
| 1773 | fix c | |
| 1774 | assume ccarr: "c \<in> carrier G" | |
| 63847 | 1775 | from wfactors_exist [OF this] | 
| 1776 | obtain cs where cscarr: "set cs \<subseteq> carrier G" and cfs: "wfactors G cs c" | |
| 1777 | by blast | |
| 27701 | 1778 | note carr = carr ccarr cscarr | 
| 1779 | ||
| 1780 | assume "b = a \<otimes> c" | |
| 63832 | 1781 | with afs bfs cfs carr have "fmset G bs = fmset G as + fmset G cs" | 
| 1782 | by (intro mult_wfactors_fmset[OF afs cfs]) simp_all | |
| 1783 | then show ?thesis by simp | |
| 27701 | 1784 | qed | 
| 1785 | ||
| 1786 | lemma (in comm_monoid_cancel) fmsubset_divides: | |
| 64587 | 1787 | assumes msubset: "fmset G as \<subseteq># fmset G bs" | 
| 63832 | 1788 | and afs: "wfactors G as a" | 
| 1789 | and bfs: "wfactors G bs b" | |
| 1790 | and acarr: "a \<in> carrier G" | |
| 1791 | and bcarr: "b \<in> carrier G" | |
| 1792 | and ascarr: "set as \<subseteq> carrier G" | |
| 1793 | and bscarr: "set bs \<subseteq> carrier G" | |
| 27701 | 1794 | shows "a divides b" | 
| 1795 | proof - | |
| 1796 | from afs have airr: "\<forall>a \<in> set as. irreducible G a" by (fast elim: wfactorsE) | |
| 1797 | from bfs have birr: "\<forall>b \<in> set bs. irreducible G b" by (fast elim: wfactorsE) | |
| 1798 | ||
| 1799 | 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" | |
| 1800 | proof (intro mset_wfactorsEx, simp) | |
| 1801 | fix X | |
| 62430 
9527ff088c15
more succint formulation of membership for multisets, similar to lists;
 haftmann parents: 
61382diff
changeset | 1802 | assume "X \<in># fmset G bs - fmset G as" | 
| 63832 | 1803 | then have "X \<in># fmset G bs" by (rule in_diffD) | 
| 1804 | then have "X \<in> set (map (assocs G) bs)" by (simp add: fmset_def) | |
| 1805 | then have "\<exists>x. x \<in> set bs \<and> X = assocs G x" by (induct bs) auto | |
| 1806 | then obtain x where xbs: "x \<in> set bs" and X: "X = assocs G x" by auto | |
| 27701 | 1807 | with bscarr have xcarr: "x \<in> carrier G" by fast | 
| 1808 | from xbs birr have xirr: "irreducible G x" by simp | |
| 1809 | ||
| 63832 | 1810 | from xcarr and xirr and X show "\<exists>x. x \<in> carrier G \<and> irreducible G x \<and> X = assocs G x" | 
| 1811 | by fast | |
| 27701 | 1812 | qed | 
| 63832 | 1813 | then obtain c cs | 
| 1814 | where ccarr: "c \<in> carrier G" | |
| 1815 | and cscarr: "set cs \<subseteq> carrier G" | |
| 27701 | 1816 | and csf: "wfactors G cs c" | 
| 1817 | and csmset: "fmset G cs = fmset G bs - fmset G as" by auto | |
| 1818 | ||
| 1819 | from csmset msubset | |
| 63832 | 1820 | have "fmset G bs = fmset G as + fmset G cs" | 
| 1821 | by (simp add: multiset_eq_iff subseteq_mset_def) | |
| 1822 | then have basc: "b \<sim> a \<otimes> c" | |
| 1823 | by (rule fmset_wfactors_mult) fact+ | |
| 1824 | then show ?thesis | |
| 27701 | 1825 | proof (elim associatedE2) | 
| 1826 | fix u | |
| 1827 | assume "u \<in> Units G" "b = a \<otimes> c \<otimes> u" | |
| 63832 | 1828 | with acarr ccarr show "a divides b" | 
| 1829 | by (fast intro: dividesI[of "c \<otimes> u"] m_assoc) | |
| 1830 | qed (simp_all add: acarr bcarr ccarr) | |
| 27701 | 1831 | qed | 
| 1832 | ||
| 1833 | lemma (in factorial_monoid) divides_as_fmsubset: | |
| 63832 | 1834 | assumes "wfactors G as a" | 
| 1835 | and "wfactors G bs b" | |
| 1836 | and "a \<in> carrier G" | |
| 1837 | and "b \<in> carrier G" | |
| 1838 | and "set as \<subseteq> carrier G" | |
| 1839 | and "set bs \<subseteq> carrier G" | |
| 64587 | 1840 | shows "a divides b = (fmset G as \<subseteq># fmset G bs)" | 
| 63832 | 1841 | using assms | 
| 1842 | by (blast intro: divides_fmsubset fmsubset_divides) | |
| 27701 | 1843 | |
| 1844 | ||
| 61382 | 1845 | text \<open>Proper factors on multisets\<close> | 
| 27701 | 1846 | |
| 1847 | lemma (in factorial_monoid) fmset_properfactor: | |
| 64587 | 1848 | assumes asubb: "fmset G as \<subseteq># fmset G bs" | 
| 27701 | 1849 | and anb: "fmset G as \<noteq> fmset G bs" | 
| 63832 | 1850 | and "wfactors G as a" | 
| 1851 | and "wfactors G bs b" | |
| 1852 | and "a \<in> carrier G" | |
| 1853 | and "b \<in> carrier G" | |
| 1854 | and "set as \<subseteq> carrier G" | |
| 1855 | and "set bs \<subseteq> carrier G" | |
| 27701 | 1856 | shows "properfactor G a b" | 
| 68478 | 1857 | proof (rule properfactorI) | 
| 1858 | show "a divides b" | |
| 1859 | using assms asubb fmsubset_divides by blast | |
| 1860 | show "\<not> b divides a" | |
| 1861 | by (meson anb assms asubb factorial_monoid.divides_fmsubset factorial_monoid_axioms subset_mset.antisym) | |
| 27701 | 1862 | qed | 
| 1863 | ||
| 1864 | lemma (in factorial_monoid) properfactor_fmset: | |
| 68684 | 1865 | assumes "properfactor G a b" | 
| 1866 | and "wfactors G as a" | |
| 1867 | and "wfactors G bs b" | |
| 1868 | and "a \<in> carrier G" | |
| 1869 | and "b \<in> carrier G" | |
| 1870 | and "set as \<subseteq> carrier G" | |
| 1871 | and "set bs \<subseteq> carrier G" | |
| 1872 | shows "fmset G as \<subseteq># fmset G bs" | |
| 1873 | using assms | |
| 1874 | by (meson divides_as_fmsubset properfactor_divides) | |
| 1875 | ||
| 1876 | lemma (in factorial_monoid) properfactor_fmset_ne: | |
| 27701 | 1877 | assumes pf: "properfactor G a b" | 
| 63832 | 1878 | and "wfactors G as a" | 
| 1879 | and "wfactors G bs b" | |
| 1880 | and "a \<in> carrier G" | |
| 1881 | and "b \<in> carrier G" | |
| 1882 | and "set as \<subseteq> carrier G" | |
| 1883 | and "set bs \<subseteq> carrier G" | |
| 68684 | 1884 | shows "fmset G as \<noteq> fmset G bs" | 
| 1885 | using properfactorE [OF pf] assms divides_as_fmsubset by force | |
| 27701 | 1886 | |
| 61382 | 1887 | subsection \<open>Irreducible Elements are Prime\<close> | 
| 27701 | 1888 | |
| 63633 | 1889 | lemma (in factorial_monoid) irreducible_prime: | 
| 68478 | 1890 | assumes pirr: "irreducible G p" and pcarr: "p \<in> carrier G" | 
| 27701 | 1891 | shows "prime G p" | 
| 63832 | 1892 | using pirr | 
| 27701 | 1893 | proof (elim irreducibleE, intro primeI) | 
| 1894 | fix a b | |
| 1895 | assume acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" | |
| 1896 | and pdvdab: "p divides (a \<otimes> b)" | |
| 1897 | and pnunit: "p \<notin> Units G" | |
| 1898 | assume irreduc[rule_format]: | |
| 63832 | 1899 | "\<forall>b. b \<in> carrier G \<and> properfactor G b p \<longrightarrow> b \<in> Units G" | 
| 63847 | 1900 | from pdvdab obtain c where ccarr: "c \<in> carrier G" and abpc: "a \<otimes> b = p \<otimes> c" | 
| 1901 | by (rule dividesE) | |
| 1902 | obtain as where ascarr: "set as \<subseteq> carrier G" and afs: "wfactors G as a" | |
| 68478 | 1903 | using wfactors_exist [OF acarr] by blast | 
| 63847 | 1904 | obtain bs where bscarr: "set bs \<subseteq> carrier G" and bfs: "wfactors G bs b" | 
| 68478 | 1905 | using wfactors_exist [OF bcarr] by blast | 
| 63847 | 1906 | obtain cs where cscarr: "set cs \<subseteq> carrier G" and cfs: "wfactors G cs c" | 
| 68478 | 1907 | using wfactors_exist [OF ccarr] by blast | 
| 27701 | 1908 | note carr[simp] = pcarr acarr bcarr ccarr ascarr bscarr cscarr | 
| 68478 | 1909 | from pirr cfs abpc have "wfactors G (p # cs) (a \<otimes> b)" | 
| 1910 | by (simp add: wfactors_mult_single) | |
| 1911 | moreover have "wfactors G (as @ bs) (a \<otimes> b)" | |
| 1912 | by (rule wfactors_mult [OF afs bfs]) fact+ | |
| 1913 | ultimately have "essentially_equal G (p # cs) (as @ bs)" | |
| 63832 | 1914 | by (rule wfactors_unique) simp+ | 
| 63847 | 1915 | then obtain ds where "p # cs <~~> ds" and dsassoc: "ds [\<sim>] (as @ bs)" | 
| 63832 | 1916 | by (fast elim: essentially_equalE) | 
| 27701 | 1917 | then have "p \<in> set ds" | 
| 73706 | 1918 | by (metis \<open>mset (p # cs) = mset ds\<close> insert_iff list.set(2) perm_set_eq) | 
| 63847 | 1919 | with dsassoc obtain p' where "p' \<in> set (as@bs)" and pp': "p \<sim> p'" | 
| 63832 | 1920 | unfolding list_all2_conv_all_nth set_conv_nth by force | 
| 1921 | then consider "p' \<in> set as" | "p' \<in> set bs" by auto | |
| 1922 | then show "p divides a \<or> p divides b" | |
| 68478 | 1923 | using afs bfs divides_cong_l pp' wfactors_dividesI | 
| 1924 | by (meson acarr ascarr bcarr bscarr pcarr) | |
| 27701 | 1925 | qed | 
| 1926 | ||
| 1927 | ||
| 69597 | 1928 | \<comment> \<open>A version using \<^const>\<open>factors\<close>, more complicated\<close> | 
| 63633 | 1929 | lemma (in factorial_monoid) factors_irreducible_prime: | 
| 68478 | 1930 | assumes pirr: "irreducible G p" and pcarr: "p \<in> carrier G" | 
| 27701 | 1931 | shows "prime G p" | 
| 68478 | 1932 | proof (rule primeI) | 
| 1933 | show "p \<notin> Units G" | |
| 1934 | by (meson irreducibleE pirr) | |
| 1935 | have irreduc: "\<And>b. \<lbrakk>b \<in> carrier G; properfactor G b p\<rbrakk> \<Longrightarrow> b \<in> Units G" | |
| 1936 | using pirr by (auto simp: irreducible_def) | |
| 1937 | show "p divides a \<or> p divides b" | |
| 1938 | if acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" and pdvdab: "p divides (a \<otimes> b)" for a b | |
| 1939 | proof - | |
| 1940 | from pdvdab obtain c where ccarr: "c \<in> carrier G" and abpc: "a \<otimes> b = p \<otimes> c" | |
| 1941 | by (rule dividesE) | |
| 1942 | note [simp] = pcarr acarr bcarr ccarr | |
| 1943 | ||
| 1944 | show "p divides a \<or> p divides b" | |
| 1945 | proof (cases "a \<in> Units G") | |
| 1946 | case True | |
| 1947 | then have "p divides b" | |
| 1948 | by (metis acarr associatedI2' associated_def bcarr divides_trans m_comm pcarr pdvdab) | |
| 63832 | 1949 | then show ?thesis .. | 
| 27701 | 1950 | next | 
| 68478 | 1951 | case anunit: False | 
| 1952 | show ?thesis | |
| 1953 | proof (cases "b \<in> Units G") | |
| 1954 | case True | |
| 1955 | then have "p divides a" | |
| 1956 | by (meson acarr bcarr divides_unit irreducible_prime pcarr pdvdab pirr prime_def) | |
| 63832 | 1957 | then show ?thesis .. | 
| 1958 | next | |
| 68478 | 1959 | case bnunit: False | 
| 1960 | then have cnunit: "c \<notin> Units G" | |
| 1961 | by (metis abpc acarr anunit bcarr ccarr irreducible_prodE irreducible_prod_rI pcarr pirr) | |
| 1962 | then have abnunit: "a \<otimes> b \<notin> Units G" | |
| 1963 | using acarr anunit bcarr unit_factor by blast | |
| 1964 | obtain as where ascarr: "set as \<subseteq> carrier G" and afac: "factors G as a" | |
| 1965 | using factors_exist [OF acarr anunit] by blast | |
| 1966 | obtain bs where bscarr: "set bs \<subseteq> carrier G" and bfac: "factors G bs b" | |
| 1967 | using factors_exist [OF bcarr bnunit] by blast | |
| 1968 | obtain cs where cscarr: "set cs \<subseteq> carrier G" and cfac: "factors G cs c" | |
| 1969 | using factors_exist [OF ccarr cnunit] by auto | |
| 1970 | note [simp] = ascarr bscarr cscarr | |
| 1971 | from pirr cfac abpc have abfac': "factors G (p # cs) (a \<otimes> b)" | |
| 1972 | by (simp add: factors_mult_single) | |
| 1973 | from afac and bfac have "factors G (as @ bs) (a \<otimes> b)" | |
| 1974 | by (rule factors_mult) fact+ | |
| 1975 | with abfac' have "essentially_equal G (p # cs) (as @ bs)" | |
| 1976 | using abnunit factors_unique by auto | |
| 1977 | then obtain ds where "p # cs <~~> ds" and dsassoc: "ds [\<sim>] (as @ bs)" | |
| 1978 | by (fast elim: essentially_equalE) | |
| 1979 | then have "p \<in> set ds" | |
| 73706 | 1980 | by (metis list.set_intros(1) set_mset_mset) | 
| 68478 | 1981 | with dsassoc obtain p' where "p' \<in> set (as@bs)" and pp': "p \<sim> p'" | 
| 1982 | unfolding list_all2_conv_all_nth set_conv_nth by force | |
| 1983 | then consider "p' \<in> set as" | "p' \<in> set bs" by auto | |
| 1984 | then show "p divides a \<or> p divides b" | |
| 1985 | by (meson afac bfac divides_cong_l factors_dividesI pp' ascarr bscarr pcarr) | |
| 63832 | 1986 | qed | 
| 27701 | 1987 | qed | 
| 1988 | qed | |
| 1989 | qed | |
| 1990 | ||
| 1991 | ||
| 61382 | 1992 | subsection \<open>Greatest Common Divisors and Lowest Common Multiples\<close> | 
| 1993 | ||
| 1994 | subsubsection \<open>Definitions\<close> | |
| 27701 | 1995 | |
| 63832 | 1996 | 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 | 1997 | where "x gcdof\<^bsub>G\<^esub> a b \<longleftrightarrow> x divides\<^bsub>G\<^esub> a \<and> x divides\<^bsub>G\<^esub> b \<and> | 
| 35847 | 1998 | (\<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))" | 
| 1999 | ||
| 63832 | 2000 | 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 | 2001 | where "x lcmof\<^bsub>G\<^esub> a b \<longleftrightarrow> a divides\<^bsub>G\<^esub> x \<and> b divides\<^bsub>G\<^esub> x \<and> | 
| 35847 | 2002 | (\<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))" | 
| 2003 | ||
| 63832 | 2004 | 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 | 2005 | where "somegcd G a b = (SOME x. x \<in> carrier G \<and> x gcdof\<^bsub>G\<^esub> a b)" | 
| 35847 | 2006 | |
| 63832 | 2007 | 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 | 2008 | where "somelcm G a b = (SOME x. x \<in> carrier G \<and> x lcmof\<^bsub>G\<^esub> a b)" | 
| 35847 | 2009 | |
| 69700 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69597diff
changeset | 2010 | definition "SomeGcd G A = Lattice.inf (division_rel G) A" | 
| 27701 | 2011 | |
| 2012 | ||
| 2013 | locale gcd_condition_monoid = comm_monoid_cancel + | |
| 63832 | 2014 | 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 | 2015 | |
| 2016 | locale primeness_condition_monoid = comm_monoid_cancel + | |
| 63832 | 2017 | assumes irreducible_prime: "\<lbrakk>a \<in> carrier G; irreducible G a\<rbrakk> \<Longrightarrow> prime G a" | 
| 27701 | 2018 | |
| 2019 | locale divisor_chain_condition_monoid = comm_monoid_cancel + | |
| 63832 | 2020 |   assumes division_wellfounded: "wf {(x, y). x \<in> carrier G \<and> y \<in> carrier G \<and> properfactor G x y}"
 | 
| 27701 | 2021 | |
| 2022 | ||
| 61382 | 2023 | subsubsection \<open>Connections to \texttt{Lattice.thy}\<close>
 | 
| 27701 | 2024 | |
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2025 | lemma gcdof_greatestLower: | 
| 27701 | 2026 | fixes G (structure) | 
| 2027 | assumes carr[simp]: "a \<in> carrier G" "b \<in> carrier G" | |
| 63832 | 2028 |   shows "(x \<in> carrier G \<and> x gcdof a b) = greatest (division_rel G) x (Lower (division_rel G) {a, b})"
 | 
| 2029 | by (auto simp: isgcd_def greatest_def Lower_def elem_def) | |
| 27701 | 2030 | |
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2031 | lemma lcmof_leastUpper: | 
| 27701 | 2032 | fixes G (structure) | 
| 2033 | assumes carr[simp]: "a \<in> carrier G" "b \<in> carrier G" | |
| 63832 | 2034 |   shows "(x \<in> carrier G \<and> x lcmof a b) = least (division_rel G) x (Upper (division_rel G) {a, b})"
 | 
| 2035 | by (auto simp: islcm_def least_def Upper_def elem_def) | |
| 27701 | 2036 | |
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2037 | lemma somegcd_meet: | 
| 27701 | 2038 | fixes G (structure) | 
| 2039 | 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 | 2040 | shows "somegcd G a b = meet (division_rel G) a b" | 
| 63832 | 2041 | by (simp add: somegcd_def meet_def inf_def gcdof_greatestLower[OF carr]) | 
| 27701 | 2042 | |
| 2043 | lemma (in monoid) isgcd_divides_l: | |
| 2044 | assumes "a divides b" | |
| 2045 | and "a \<in> carrier G" "b \<in> carrier G" | |
| 2046 | shows "a gcdof a b" | |
| 63832 | 2047 | using assms unfolding isgcd_def by fast | 
| 27701 | 2048 | |
| 2049 | lemma (in monoid) isgcd_divides_r: | |
| 2050 | assumes "b divides a" | |
| 2051 | and "a \<in> carrier G" "b \<in> carrier G" | |
| 2052 | shows "b gcdof a b" | |
| 63832 | 2053 | using assms unfolding isgcd_def by fast | 
| 27701 | 2054 | |
| 2055 | ||
| 61382 | 2056 | subsubsection \<open>Existence of gcd and lcm\<close> | 
| 27701 | 2057 | |
| 2058 | lemma (in factorial_monoid) gcdof_exists: | |
| 63832 | 2059 | assumes acarr: "a \<in> carrier G" | 
| 2060 | and bcarr: "b \<in> carrier G" | |
| 27701 | 2061 | shows "\<exists>c. c \<in> carrier G \<and> c gcdof a b" | 
| 2062 | proof - | |
| 63847 | 2063 | from wfactors_exist [OF acarr] | 
| 2064 | obtain as where ascarr: "set as \<subseteq> carrier G" and afs: "wfactors G as a" | |
| 2065 | by blast | |
| 63832 | 2066 | from afs have airr: "\<forall>a \<in> set as. irreducible G a" | 
| 2067 | by (fast elim: wfactorsE) | |
| 2068 | ||
| 63847 | 2069 | from wfactors_exist [OF bcarr] | 
| 2070 | obtain bs where bscarr: "set bs \<subseteq> carrier G" and bfs: "wfactors G bs b" | |
| 2071 | by blast | |
| 63832 | 2072 | from bfs have birr: "\<forall>b \<in> set bs. irreducible G b" | 
| 2073 | by (fast elim: wfactorsE) | |
| 2074 | ||
| 2075 | 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 | 2076 | fmset G cs = fmset G as \<inter># fmset G bs" | 
| 27701 | 2077 | proof (intro mset_wfactorsEx) | 
| 2078 | fix X | |
| 63919 
9aed2da07200
# after multiset intersection and union symbol
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63847diff
changeset | 2079 | assume "X \<in># fmset G as \<inter># fmset G bs" | 
| 63832 | 2080 | then have "X \<in># fmset G as" by simp | 
| 2081 | then have "X \<in> set (map (assocs G) as)" | |
| 2082 | by (simp add: fmset_def) | |
| 2083 | then have "\<exists>x. X = assocs G x \<and> x \<in> set as" | |
| 2084 | by (induct as) auto | |
| 2085 | then obtain x where X: "X = assocs G x" and xas: "x \<in> set as" | |
| 63847 | 2086 | by blast | 
| 63832 | 2087 | with ascarr have xcarr: "x \<in> carrier G" | 
| 63847 | 2088 | by blast | 
| 63832 | 2089 | from xas airr have xirr: "irreducible G x" | 
| 2090 | by simp | |
| 2091 | from xcarr and xirr and X show "\<exists>x. (x \<in> carrier G \<and> irreducible G x) \<and> X = assocs G x" | |
| 63847 | 2092 | by blast | 
| 27701 | 2093 | qed | 
| 63832 | 2094 | then obtain c cs | 
| 2095 | where ccarr: "c \<in> carrier G" | |
| 2096 | and cscarr: "set cs \<subseteq> carrier G" | |
| 27701 | 2097 | and csirr: "wfactors G cs c" | 
| 63919 
9aed2da07200
# after multiset intersection and union symbol
 fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
63847diff
changeset | 2098 | and csmset: "fmset G cs = fmset G as \<inter># fmset G bs" | 
| 63832 | 2099 | by auto | 
| 27701 | 2100 | |
| 2101 | have "c gcdof a b" | |
| 2102 | proof (simp add: isgcd_def, safe) | |
| 2103 | from csmset | |
| 64587 | 2104 | have "fmset G cs \<subseteq># fmset G as" | 
| 73393 | 2105 | by simp | 
| 63832 | 2106 | then show "c divides a" by (rule fmsubset_divides) fact+ | 
| 27701 | 2107 | next | 
| 64587 | 2108 | from csmset have "fmset G cs \<subseteq># fmset G bs" | 
| 73393 | 2109 | by simp | 
| 63832 | 2110 | then show "c divides b" | 
| 2111 | by (rule fmsubset_divides) fact+ | |
| 27701 | 2112 | next | 
| 2113 | fix y | |
| 63847 | 2114 | assume "y \<in> carrier G" | 
| 2115 | from wfactors_exist [OF this] | |
| 2116 | obtain ys where yscarr: "set ys \<subseteq> carrier G" and yfs: "wfactors G ys y" | |
| 2117 | by blast | |
| 27701 | 2118 | |
| 2119 | assume "y divides a" | |
| 64587 | 2120 | then have ya: "fmset G ys \<subseteq># fmset G as" | 
| 63832 | 2121 | by (rule divides_fmsubset) fact+ | 
| 27701 | 2122 | |
| 2123 | assume "y divides b" | |
| 64587 | 2124 | then have yb: "fmset G ys \<subseteq># fmset G bs" | 
| 63832 | 2125 | by (rule divides_fmsubset) fact+ | 
| 2126 | ||
| 64587 | 2127 | from ya yb csmset have "fmset G ys \<subseteq># fmset G cs" | 
| 63832 | 2128 | by (simp add: subset_mset_def) | 
| 2129 | then show "y divides c" | |
| 2130 | by (rule fmsubset_divides) fact+ | |
| 27701 | 2131 | qed | 
| 63832 | 2132 | with ccarr show "\<exists>c. c \<in> carrier G \<and> c gcdof a b" | 
| 2133 | by fast | |
| 27701 | 2134 | qed | 
| 2135 | ||
| 2136 | lemma (in factorial_monoid) lcmof_exists: | |
| 63832 | 2137 | assumes acarr: "a \<in> carrier G" | 
| 2138 | and bcarr: "b \<in> carrier G" | |
| 27701 | 2139 | shows "\<exists>c. c \<in> carrier G \<and> c lcmof a b" | 
| 2140 | proof - | |
| 63847 | 2141 | from wfactors_exist [OF acarr] | 
| 2142 | obtain as where ascarr: "set as \<subseteq> carrier G" and afs: "wfactors G as a" | |
| 2143 | by blast | |
| 63832 | 2144 | from afs have airr: "\<forall>a \<in> set as. irreducible G a" | 
| 2145 | by (fast elim: wfactorsE) | |
| 2146 | ||
| 63847 | 2147 | from wfactors_exist [OF bcarr] | 
| 2148 | obtain bs where bscarr: "set bs \<subseteq> carrier G" and bfs: "wfactors G bs b" | |
| 2149 | by blast | |
| 63832 | 2150 | from bfs have birr: "\<forall>b \<in> set bs. irreducible G b" | 
| 2151 | by (fast elim: wfactorsE) | |
| 2152 | ||
| 2153 | have "\<exists>c cs. c \<in> carrier G \<and> set cs \<subseteq> carrier G \<and> wfactors G cs c \<and> | |
| 2154 | fmset G cs = (fmset G as - fmset G bs) + fmset G bs" | |
| 27701 | 2155 | proof (intro mset_wfactorsEx) | 
| 2156 | fix X | |
| 62430 
9527ff088c15
more succint formulation of membership for multisets, similar to lists;
 haftmann parents: 
61382diff
changeset | 2157 | assume "X \<in># (fmset G as - fmset G bs) + fmset G bs" | 
| 63832 | 2158 | 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 | 2159 | by (auto dest: in_diffD) | 
| 63832 | 2160 | then consider "X \<in> set_mset (fmset G as)" | "X \<in> set_mset (fmset G bs)" | 
| 2161 | by fast | |
| 2162 | then show "\<exists>x. (x \<in> carrier G \<and> irreducible G x) \<and> X = assocs G x" | |
| 2163 | proof cases | |
| 2164 | case 1 | |
| 2165 | then have "X \<in> set (map (assocs G) as)" by (simp add: fmset_def) | |
| 2166 | then have "\<exists>x. x \<in> set as \<and> X = assocs G x" by (induct as) auto | |
| 2167 | then obtain x where xas: "x \<in> set as" and X: "X = assocs G x" by auto | |
| 27701 | 2168 | with ascarr have xcarr: "x \<in> carrier G" by fast | 
| 2169 | from xas airr have xirr: "irreducible G x" by simp | |
| 63832 | 2170 | from xcarr and xirr and X show ?thesis by fast | 
| 2171 | next | |
| 2172 | case 2 | |
| 2173 | then have "X \<in> set (map (assocs G) bs)" by (simp add: fmset_def) | |
| 2174 | then have "\<exists>x. x \<in> set bs \<and> X = assocs G x" by (induct as) auto | |
| 2175 | then obtain x where xbs: "x \<in> set bs" and X: "X = assocs G x" by auto | |
| 27701 | 2176 | with bscarr have xcarr: "x \<in> carrier G" by fast | 
| 2177 | from xbs birr have xirr: "irreducible G x" by simp | |
| 63832 | 2178 | from xcarr and xirr and X show ?thesis by fast | 
| 2179 | qed | |
| 27701 | 2180 | qed | 
| 63832 | 2181 | then obtain c cs | 
| 2182 | where ccarr: "c \<in> carrier G" | |
| 2183 | and cscarr: "set cs \<subseteq> carrier G" | |
| 27701 | 2184 | and csirr: "wfactors G cs c" | 
| 63832 | 2185 | and csmset: "fmset G cs = fmset G as - fmset G bs + fmset G bs" | 
| 2186 | by auto | |
| 27701 | 2187 | |
| 2188 | have "c lcmof a b" | |
| 2189 | proof (simp add: islcm_def, safe) | |
| 64587 | 2190 | from csmset have "fmset G as \<subseteq># fmset G cs" | 
| 63832 | 2191 | by (simp add: subseteq_mset_def, force) | 
| 2192 | then show "a divides c" | |
| 2193 | by (rule fmsubset_divides) fact+ | |
| 27701 | 2194 | next | 
| 64587 | 2195 | from csmset have "fmset G bs \<subseteq># fmset G cs" | 
| 63832 | 2196 | by (simp add: subset_mset_def) | 
| 2197 | then show "b divides c" | |
| 2198 | by (rule fmsubset_divides) fact+ | |
| 27701 | 2199 | next | 
| 2200 | fix y | |
| 63847 | 2201 | assume "y \<in> carrier G" | 
| 2202 | from wfactors_exist [OF this] | |
| 2203 | obtain ys where yscarr: "set ys \<subseteq> carrier G" and yfs: "wfactors G ys y" | |
| 2204 | by blast | |
| 27701 | 2205 | |
| 2206 | assume "a divides y" | |
| 64587 | 2207 | then have ya: "fmset G as \<subseteq># fmset G ys" | 
| 63832 | 2208 | by (rule divides_fmsubset) fact+ | 
| 27701 | 2209 | |
| 2210 | assume "b divides y" | |
| 64587 | 2211 | then have yb: "fmset G bs \<subseteq># fmset G ys" | 
| 63832 | 2212 | by (rule divides_fmsubset) fact+ | 
| 2213 | ||
| 64587 | 2214 | from ya yb csmset have "fmset G cs \<subseteq># fmset G ys" | 
| 68474 | 2215 | using subset_eq_diff_conv subset_mset.le_diff_conv2 by fastforce | 
| 63832 | 2216 | then show "c divides y" | 
| 2217 | by (rule fmsubset_divides) fact+ | |
| 27701 | 2218 | qed | 
| 63832 | 2219 | with ccarr show "\<exists>c. c \<in> carrier G \<and> c lcmof a b" | 
| 2220 | by fast | |
| 27701 | 2221 | qed | 
| 2222 | ||
| 2223 | ||
| 61382 | 2224 | subsection \<open>Conditions for Factoriality\<close> | 
| 2225 | ||
| 2226 | subsubsection \<open>Gcd condition\<close> | |
| 27701 | 2227 | |
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2228 | lemma (in gcd_condition_monoid) division_weak_lower_semilattice [simp]: | 
| 63832 | 2229 | "weak_lower_semilattice (division_rel G)" | 
| 27701 | 2230 | proof - | 
| 29237 | 2231 | interpret weak_partial_order "division_rel G" .. | 
| 27701 | 2232 | show ?thesis | 
| 68474 | 2233 | proof (unfold_locales, simp_all) | 
| 27701 | 2234 | fix x y | 
| 2235 | assume carr: "x \<in> carrier G" "y \<in> carrier G" | |
| 63847 | 2236 | from gcdof_exists [OF this] obtain z where zcarr: "z \<in> carrier G" and isgcd: "z gcdof x y" | 
| 2237 | by blast | |
| 63832 | 2238 |     with carr have "greatest (division_rel G) z (Lower (division_rel G) {x, y})"
 | 
| 2239 | by (subst gcdof_greatestLower[symmetric], simp+) | |
| 2240 |     then show "\<exists>z. greatest (division_rel G) z (Lower (division_rel G) {x, y})"
 | |
| 2241 | by fast | |
| 27701 | 2242 | qed | 
| 2243 | qed | |
| 2244 | ||
| 2245 | lemma (in gcd_condition_monoid) gcdof_cong_l: | |
| 68684 | 2246 | 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 | 2247 | shows "a' gcdof b c" | 
| 2248 | proof - | |
| 29237 | 2249 | interpret weak_lower_semilattice "division_rel G" by simp | 
| 68474 | 2250 |   have "is_glb (division_rel G) a' {b, c}"
 | 
| 68684 | 2251 | by (subst greatest_Lower_cong_l[of _ a]) (simp_all add: assms gcdof_greatestLower[symmetric]) | 
| 68474 | 2252 | then have "a' \<in> carrier G \<and> a' gcdof b c" | 
| 2253 | by (simp add: gcdof_greatestLower carr') | |
| 63832 | 2254 | then show ?thesis .. | 
| 27701 | 2255 | qed | 
| 2256 | ||
| 2257 | lemma (in gcd_condition_monoid) gcd_closed [simp]: | |
| 68684 | 2258 | assumes "a \<in> carrier G" "b \<in> carrier G" | 
| 27701 | 2259 | shows "somegcd G a b \<in> carrier G" | 
| 2260 | proof - | |
| 29237 | 2261 | interpret weak_lower_semilattice "division_rel G" by simp | 
| 27701 | 2262 | show ?thesis | 
| 68684 | 2263 | using assms meet_closed by (simp add: somegcd_meet) | 
| 27701 | 2264 | qed | 
| 2265 | ||
| 2266 | lemma (in gcd_condition_monoid) gcd_isgcd: | |
| 68684 | 2267 | assumes "a \<in> carrier G" "b \<in> carrier G" | 
| 27701 | 2268 | shows "(somegcd G a b) gcdof a b" | 
| 2269 | proof - | |
| 63832 | 2270 | interpret weak_lower_semilattice "division_rel G" | 
| 2271 | by simp | |
| 68684 | 2272 | from assms have "somegcd G a b \<in> carrier G \<and> (somegcd G a b) gcdof a b" | 
| 68474 | 2273 | by (simp add: gcdof_greatestLower inf_of_two_greatest meet_def somegcd_meet) | 
| 63832 | 2274 | then show "(somegcd G a b) gcdof a b" | 
| 2275 | by simp | |
| 27701 | 2276 | qed | 
| 2277 | ||
| 2278 | lemma (in gcd_condition_monoid) gcd_exists: | |
| 68684 | 2279 | assumes "a \<in> carrier G" "b \<in> carrier G" | 
| 27701 | 2280 | shows "\<exists>x\<in>carrier G. x = somegcd G a b" | 
| 2281 | proof - | |
| 63832 | 2282 | interpret weak_lower_semilattice "division_rel G" | 
| 2283 | by simp | |
| 27701 | 2284 | show ?thesis | 
| 68684 | 2285 | by (metis assms gcd_closed) | 
| 27701 | 2286 | qed | 
| 2287 | ||
| 2288 | lemma (in gcd_condition_monoid) gcd_divides_l: | |
| 68684 | 2289 | assumes "a \<in> carrier G" "b \<in> carrier G" | 
| 27701 | 2290 | shows "(somegcd G a b) divides a" | 
| 2291 | proof - | |
| 63832 | 2292 | interpret weak_lower_semilattice "division_rel G" | 
| 2293 | by simp | |
| 27701 | 2294 | show ?thesis | 
| 68684 | 2295 | by (metis assms gcd_isgcd isgcd_def) | 
| 27701 | 2296 | qed | 
| 2297 | ||
| 2298 | lemma (in gcd_condition_monoid) gcd_divides_r: | |
| 68684 | 2299 | assumes "a \<in> carrier G" "b \<in> carrier G" | 
| 27701 | 2300 | shows "(somegcd G a b) divides b" | 
| 2301 | proof - | |
| 63832 | 2302 | interpret weak_lower_semilattice "division_rel G" | 
| 2303 | by simp | |
| 27701 | 2304 | show ?thesis | 
| 68684 | 2305 | by (metis assms gcd_isgcd isgcd_def) | 
| 27701 | 2306 | qed | 
| 2307 | ||
| 2308 | lemma (in gcd_condition_monoid) gcd_divides: | |
| 68684 | 2309 | assumes "z divides x" "z divides y" | 
| 27701 | 2310 | and L: "x \<in> carrier G" "y \<in> carrier G" "z \<in> carrier G" | 
| 2311 | shows "z divides (somegcd G x y)" | |
| 2312 | proof - | |
| 63832 | 2313 | interpret weak_lower_semilattice "division_rel G" | 
| 2314 | by simp | |
| 27701 | 2315 | 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 | 2316 | by (metis gcd_isgcd isgcd_def assms) | 
| 27701 | 2317 | qed | 
| 2318 | ||
| 2319 | lemma (in gcd_condition_monoid) gcd_cong_l: | |
| 68684 | 2320 | assumes "x \<sim> x'" "x \<in> carrier G" "x' \<in> carrier G" "y \<in> carrier G" | 
| 27701 | 2321 | shows "somegcd G x y \<sim> somegcd G x' y" | 
| 2322 | proof - | |
| 63832 | 2323 | interpret weak_lower_semilattice "division_rel G" | 
| 2324 | by simp | |
| 27701 | 2325 | show ?thesis | 
| 68684 | 2326 | using somegcd_meet assms | 
| 2327 | by (metis eq_object.select_convs(1) meet_cong_l partial_object.select_convs(1)) | |
| 27701 | 2328 | qed | 
| 2329 | ||
| 2330 | lemma (in gcd_condition_monoid) gcd_cong_r: | |
| 68684 | 2331 | assumes "y \<sim> y'" "x \<in> carrier G" "y \<in> carrier G" "y' \<in> carrier G" | 
| 27701 | 2332 | shows "somegcd G x y \<sim> somegcd G x y'" | 
| 2333 | proof - | |
| 29237 | 2334 | interpret weak_lower_semilattice "division_rel G" by simp | 
| 27701 | 2335 | show ?thesis | 
| 68684 | 2336 | by (meson associated_def assms gcd_closed gcd_divides gcd_divides_l gcd_divides_r monoid.divides_trans monoid_axioms) | 
| 27701 | 2337 | qed | 
| 2338 | ||
| 2339 | lemma (in gcd_condition_monoid) gcdI: | |
| 2340 | assumes dvd: "a divides b" "a divides c" | |
| 68474 | 2341 | and others: "\<And>y. \<lbrakk>y\<in>carrier G; y divides b; y divides c\<rbrakk> \<Longrightarrow> y divides a" | 
| 27701 | 2342 | and acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" and ccarr: "c \<in> carrier G" | 
| 2343 | shows "a \<sim> somegcd G b c" | |
| 68474 | 2344 | proof - | 
| 2345 | have "\<exists>a. a \<in> carrier G \<and> a gcdof b c" | |
| 2346 | by (simp add: bcarr ccarr gcdof_exists) | |
| 2347 | moreover have "\<And>x. x \<in> carrier G \<and> x gcdof b c \<Longrightarrow> a \<sim> x" | |
| 2348 | by (simp add: acarr associated_def dvd isgcd_def others) | |
| 2349 | ultimately show ?thesis | |
| 2350 | unfolding somegcd_def by (blast intro: someI2_ex) | |
| 2351 | qed | |
| 27701 | 2352 | |
| 2353 | lemma (in gcd_condition_monoid) gcdI2: | |
| 63832 | 2354 | assumes "a gcdof b c" and "a \<in> carrier G" and "b \<in> carrier G" and "c \<in> carrier G" | 
| 27701 | 2355 | shows "a \<sim> somegcd G b c" | 
| 68474 | 2356 | using assms unfolding isgcd_def | 
| 2357 | by (simp add: gcdI) | |
| 27701 | 2358 | |
| 2359 | lemma (in gcd_condition_monoid) SomeGcd_ex: | |
| 2360 |   assumes "finite A"  "A \<subseteq> carrier G"  "A \<noteq> {}"
 | |
| 68684 | 2361 | shows "\<exists>x \<in> carrier G. x = SomeGcd G A" | 
| 27701 | 2362 | proof - | 
| 63832 | 2363 | interpret weak_lower_semilattice "division_rel G" | 
| 2364 | by simp | |
| 27701 | 2365 | show ?thesis | 
| 68684 | 2366 | using finite_inf_closed by (simp add: assms SomeGcd_def) | 
| 27701 | 2367 | qed | 
| 2368 | ||
| 2369 | lemma (in gcd_condition_monoid) gcd_assoc: | |
| 68684 | 2370 | assumes "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | 
| 27701 | 2371 | shows "somegcd G (somegcd G a b) c \<sim> somegcd G a (somegcd G b c)" | 
| 2372 | proof - | |
| 63832 | 2373 | interpret weak_lower_semilattice "division_rel G" | 
| 2374 | by simp | |
| 27701 | 2375 | show ?thesis | 
| 68488 
dfbd80c3d180
more modernisaton and de-applying
 paulson <lp15@cam.ac.uk> parents: 
68478diff
changeset | 2376 | unfolding associated_def | 
| 68684 | 2377 | by (meson assms divides_trans gcd_divides gcd_divides_l gcd_divides_r gcd_exists) | 
| 27701 | 2378 | qed | 
| 2379 | ||
| 2380 | lemma (in gcd_condition_monoid) gcd_mult: | |
| 2381 | assumes acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" and ccarr: "c \<in> carrier G" | |
| 2382 | shows "c \<otimes> somegcd G a b \<sim> somegcd G (c \<otimes> a) (c \<otimes> b)" | |
| 2383 | proof - (* following Jacobson, Basic Algebra, p.140 *) | |
| 2384 | let ?d = "somegcd G a b" | |
| 2385 | let ?e = "somegcd G (c \<otimes> a) (c \<otimes> b)" | |
| 2386 | note carr[simp] = acarr bcarr ccarr | |
| 2387 | have dcarr: "?d \<in> carrier G" by simp | |
| 2388 | have ecarr: "?e \<in> carrier G" by simp | |
| 2389 | note carr = carr dcarr ecarr | |
| 2390 | ||
| 2391 | have "?d divides a" by (simp add: gcd_divides_l) | |
| 63832 | 2392 | then have cd'ca: "c \<otimes> ?d divides (c \<otimes> a)" by (simp add: divides_mult_lI) | 
| 27701 | 2393 | |
| 2394 | have "?d divides b" by (simp add: gcd_divides_r) | |
| 63832 | 2395 | then have cd'cb: "c \<otimes> ?d divides (c \<otimes> b)" by (simp add: divides_mult_lI) | 
| 2396 | ||
| 2397 | from cd'ca cd'cb have cd'e: "c \<otimes> ?d divides ?e" | |
| 2398 | by (rule gcd_divides) simp_all | |
| 2399 | then obtain u where ucarr[simp]: "u \<in> carrier G" and e_cdu: "?e = c \<otimes> ?d \<otimes> u" | |
| 63847 | 2400 | by blast | 
| 27701 | 2401 | |
| 2402 | note carr = carr ucarr | |
| 2403 | ||
| 63832 | 2404 | have "?e divides c \<otimes> a" by (rule gcd_divides_l) simp_all | 
| 2405 | then obtain x where xcarr: "x \<in> carrier G" and ca_ex: "c \<otimes> a = ?e \<otimes> x" | |
| 63847 | 2406 | by blast | 
| 63832 | 2407 | with e_cdu have ca_cdux: "c \<otimes> a = c \<otimes> ?d \<otimes> u \<otimes> x" | 
| 2408 | by simp | |
| 2409 | ||
| 2410 | from ca_cdux xcarr have "c \<otimes> a = c \<otimes> (?d \<otimes> u \<otimes> x)" | |
| 2411 | by (simp add: m_assoc) | |
| 2412 | then have "a = ?d \<otimes> u \<otimes> x" | |
| 2413 | by (rule l_cancel[of c a]) (simp add: xcarr)+ | |
| 2414 | then have du'a: "?d \<otimes> u divides a" | |
| 2415 | by (rule dividesI[OF xcarr]) | |
| 2416 | ||
| 2417 | have "?e divides c \<otimes> b" by (intro gcd_divides_r) simp_all | |
| 2418 | then obtain x where xcarr: "x \<in> carrier G" and cb_ex: "c \<otimes> b = ?e \<otimes> x" | |
| 63847 | 2419 | by blast | 
| 63832 | 2420 | with e_cdu have cb_cdux: "c \<otimes> b = c \<otimes> ?d \<otimes> u \<otimes> x" | 
| 2421 | by simp | |
| 2422 | ||
| 2423 | from cb_cdux xcarr have "c \<otimes> b = c \<otimes> (?d \<otimes> u \<otimes> x)" | |
| 2424 | by (simp add: m_assoc) | |
| 2425 | with xcarr have "b = ?d \<otimes> u \<otimes> x" | |
| 2426 | by (intro l_cancel[of c b]) simp_all | |
| 2427 | then have du'b: "?d \<otimes> u divides b" | |
| 2428 | by (intro dividesI[OF xcarr]) | |
| 2429 | ||
| 2430 | from du'a du'b carr have du'd: "?d \<otimes> u divides ?d" | |
| 2431 | by (intro gcd_divides) simp_all | |
| 2432 | then have uunit: "u \<in> Units G" | |
| 27701 | 2433 | proof (elim dividesE) | 
| 2434 | fix v | |
| 2435 | assume vcarr[simp]: "v \<in> carrier G" | |
| 2436 | assume d: "?d = ?d \<otimes> u \<otimes> v" | |
| 2437 | have "?d \<otimes> \<one> = ?d \<otimes> u \<otimes> v" by simp fact | |
| 2438 | also have "?d \<otimes> u \<otimes> v = ?d \<otimes> (u \<otimes> v)" by (simp add: m_assoc) | |
| 2439 | finally have "?d \<otimes> \<one> = ?d \<otimes> (u \<otimes> v)" . | |
| 63832 | 2440 | then have i2: "\<one> = u \<otimes> v" by (rule l_cancel) simp_all | 
| 2441 | then have i1: "\<one> = v \<otimes> u" by (simp add: m_comm) | |
| 2442 | from vcarr i1[symmetric] i2[symmetric] show "u \<in> Units G" | |
| 2443 | by (auto simp: Units_def) | |
| 27701 | 2444 | qed | 
| 2445 | ||
| 63832 | 2446 | from e_cdu uunit have "somegcd G (c \<otimes> a) (c \<otimes> b) \<sim> c \<otimes> somegcd G a b" | 
| 2447 | by (intro associatedI2[of u]) simp_all | |
| 2448 | from this[symmetric] show "c \<otimes> somegcd G a b \<sim> somegcd G (c \<otimes> a) (c \<otimes> b)" | |
| 2449 | by simp | |
| 27701 | 2450 | qed | 
| 2451 | ||
| 2452 | lemma (in monoid) assoc_subst: | |
| 2453 | assumes ab: "a \<sim> b" | |
| 63832 | 2454 | and cP: "\<forall>a b. a \<in> carrier G \<and> b \<in> carrier G \<and> a \<sim> b | 
| 2455 | \<longrightarrow> f a \<in> carrier G \<and> f b \<in> carrier G \<and> f a \<sim> f b" | |
| 27701 | 2456 | and carr: "a \<in> carrier G" "b \<in> carrier G" | 
| 2457 | shows "f a \<sim> f b" | |
| 2458 | using assms by auto | |
| 2459 | ||
| 2460 | lemma (in gcd_condition_monoid) relprime_mult: | |
| 63832 | 2461 | assumes abrelprime: "somegcd G a b \<sim> \<one>" | 
| 2462 | and acrelprime: "somegcd G a c \<sim> \<one>" | |
| 27701 | 2463 | and carr[simp]: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" | 
| 2464 | shows "somegcd G a (b \<otimes> c) \<sim> \<one>" | |
| 2465 | proof - | |
| 2466 | have "c = c \<otimes> \<one>" by simp | |
| 2467 | also from abrelprime[symmetric] | |
| 63832 | 2468 | have "\<dots> \<sim> c \<otimes> somegcd G a b" | 
| 2469 | by (rule assoc_subst) (simp add: mult_cong_r)+ | |
| 2470 | also have "\<dots> \<sim> somegcd G (c \<otimes> a) (c \<otimes> b)" | |
| 2471 | by (rule gcd_mult) fact+ | |
| 2472 | finally have c: "c \<sim> somegcd G (c \<otimes> a) (c \<otimes> b)" | |
| 2473 | by simp | |
| 2474 | ||
| 2475 | from carr have a: "a \<sim> somegcd G a (c \<otimes> a)" | |
| 2476 | by (fast intro: gcdI divides_prod_l) | |
| 2477 | ||
| 2478 | have "somegcd G a (b \<otimes> c) \<sim> somegcd G a (c \<otimes> b)" | |
| 2479 | by (simp add: m_comm) | |
| 2480 | also from a have "\<dots> \<sim> somegcd G (somegcd G a (c \<otimes> a)) (c \<otimes> b)" | |
| 2481 | by (rule assoc_subst) (simp add: gcd_cong_l)+ | |
| 2482 | also from gcd_assoc have "\<dots> \<sim> somegcd G a (somegcd G (c \<otimes> a) (c \<otimes> b))" | |
| 2483 | by (rule assoc_subst) simp+ | |
| 2484 | also from c[symmetric] have "\<dots> \<sim> somegcd G a c" | |
| 2485 | by (rule assoc_subst) (simp add: gcd_cong_r)+ | |
| 27701 | 2486 | also note acrelprime | 
| 63832 | 2487 | finally show "somegcd G a (b \<otimes> c) \<sim> \<one>" | 
| 2488 | by simp | |
| 27701 | 2489 | qed | 
| 2490 | ||
| 63832 | 2491 | lemma (in gcd_condition_monoid) primeness_condition: "primeness_condition_monoid G" | 
| 27701 | 2492 | proof - | 
| 68478 | 2493 | have *: "p divides a \<or> p divides b" | 
| 2494 | if pcarr[simp]: "p \<in> carrier G" and acarr[simp]: "a \<in> carrier G" and bcarr[simp]: "b \<in> carrier G" | |
| 2495 | and pirr: "irreducible G p" and pdvdab: "p divides a \<otimes> b" | |
| 2496 | for p a b | |
| 2497 | proof - | |
| 2498 | from pirr have pnunit: "p \<notin> Units G" | |
| 2499 | and r: "\<And>b. \<lbrakk>b \<in> carrier G; properfactor G b p\<rbrakk> \<Longrightarrow> b \<in> Units G" | |
| 2500 | by (fast elim: irreducibleE)+ | |
| 2501 | show "p divides a \<or> p divides b" | |
| 2502 | proof (rule ccontr, clarsimp) | |
| 2503 | assume npdvda: "\<not> p divides a" and npdvdb: "\<not> p divides b" | |
| 2504 | have "\<one> \<sim> somegcd G p a" | |
| 2505 | proof (intro gcdI unit_divides) | |
| 2506 | show "\<And>y. \<lbrakk>y \<in> carrier G; y divides p; y divides a\<rbrakk> \<Longrightarrow> y \<in> Units G" | |
| 2507 | by (meson divides_trans npdvda pcarr properfactorI r) | |
| 2508 | qed auto | |
| 2509 | with pcarr acarr have pa: "somegcd G p a \<sim> \<one>" | |
| 2510 | by (fast intro: associated_sym[of "\<one>"] gcd_closed) | |
| 2511 | have "\<one> \<sim> somegcd G p b" | |
| 2512 | proof (intro gcdI unit_divides) | |
| 2513 | show "\<And>y. \<lbrakk>y \<in> carrier G; y divides p; y divides b\<rbrakk> \<Longrightarrow> y \<in> Units G" | |
| 2514 | by (meson divides_trans npdvdb pcarr properfactorI r) | |
| 2515 | qed auto | |
| 2516 | with pcarr bcarr have pb: "somegcd G p b \<sim> \<one>" | |
| 2517 | by (fast intro: associated_sym[of "\<one>"] gcd_closed) | |
| 2518 | have "p \<sim> somegcd G p (a \<otimes> b)" | |
| 2519 | using pdvdab by (simp add: gcdI2 isgcd_divides_l) | |
| 2520 | also from pa pb pcarr acarr bcarr have "somegcd G p (a \<otimes> b) \<sim> \<one>" | |
| 2521 | by (rule relprime_mult) | |
| 2522 | finally have "p \<sim> \<one>" | |
| 2523 | by simp | |
| 2524 | with pcarr have "p \<in> Units G" | |
| 2525 | by (fast intro: assoc_unit_l) | |
| 2526 | with pnunit show False .. | |
| 2527 | qed | |
| 27701 | 2528 | qed | 
| 68478 | 2529 | show ?thesis | 
| 2530 | by unfold_locales (metis * primeI irreducibleE) | |
| 2531 | qed | |
| 2532 | ||
| 27701 | 2533 | |
| 29237 | 2534 | sublocale gcd_condition_monoid \<subseteq> primeness_condition_monoid | 
| 27701 | 2535 | by (rule primeness_condition) | 
| 2536 | ||
| 2537 | ||
| 61382 | 2538 | subsubsection \<open>Divisor chain condition\<close> | 
| 27701 | 2539 | |
| 2540 | lemma (in divisor_chain_condition_monoid) wfactors_exist: | |
| 2541 | assumes acarr: "a \<in> carrier G" | |
| 2542 | shows "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a" | |
| 2543 | proof - | |
| 68478 | 2544 | have r: "a \<in> carrier G \<Longrightarrow> (\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a)" | 
| 2545 | using division_wellfounded | |
| 2546 | proof (induction rule: wf_induct_rule) | |
| 2547 | case (less x) | |
| 2548 | then have xcarr: "x \<in> carrier G" | |
| 2549 | by auto | |
| 2550 | show ?case | |
| 2551 | proof (cases "x \<in> Units G") | |
| 2552 | case True | |
| 2553 | then show ?thesis | |
| 2554 | by (metis bot.extremum list.set(1) unit_wfactors) | |
| 2555 | next | |
| 2556 | case xnunit: False | |
| 2557 | show ?thesis | |
| 2558 | proof (cases "irreducible G x") | |
| 2559 | case True | |
| 2560 | then show ?thesis | |
| 2561 | by (rule_tac x="[x]" in exI) (simp add: wfactors_def xcarr) | |
| 2562 | next | |
| 2563 | case False | |
| 2564 | then obtain y where ycarr: "y \<in> carrier G" and ynunit: "y \<notin> Units G" and pfyx: "properfactor G y x" | |
| 2565 | by (meson irreducible_def xnunit) | |
| 2566 | obtain ys where yscarr: "set ys \<subseteq> carrier G" and yfs: "wfactors G ys y" | |
| 2567 | using less ycarr pfyx by blast | |
| 2568 | then obtain z where zcarr: "z \<in> carrier G" and x: "x = y \<otimes> z" | |
| 2569 | by (meson dividesE pfyx properfactorE2) | |
| 2570 | from zcarr ycarr have "properfactor G z x" | |
| 2571 | using m_comm properfactorI3 x ynunit by blast | |
| 2572 | with less zcarr obtain zs where zscarr: "set zs \<subseteq> carrier G" and zfs: "wfactors G zs z" | |
| 2573 | by blast | |
| 2574 | from yscarr zscarr have xscarr: "set (ys@zs) \<subseteq> carrier G" | |
| 2575 | by simp | |
| 2576 | have "wfactors G (ys@zs) (y\<otimes>z)" | |
| 2577 | using xscarr ycarr yfs zcarr zfs by auto | |
| 2578 | then have "wfactors G (ys@zs) x" | |
| 2579 | by (simp add: x) | |
| 2580 | with xscarr show "\<exists>xs. set xs \<subseteq> carrier G \<and> wfactors G xs x" | |
| 2581 | by fast | |
| 2582 | qed | |
| 27701 | 2583 | qed | 
| 2584 | qed | |
| 63832 | 2585 | from acarr show ?thesis by (rule r) | 
| 27701 | 2586 | qed | 
| 2587 | ||
| 2588 | ||
| 61382 | 2589 | subsubsection \<open>Primeness condition\<close> | 
| 27701 | 2590 | |
| 2591 | lemma (in comm_monoid_cancel) multlist_prime_pos: | |
| 68478 | 2592 | assumes aprime: "prime G a" and carr: "a \<in> carrier G" | 
| 2593 | and as: "set as \<subseteq> carrier G" "a divides (foldr (\<otimes>) as \<one>)" | |
| 2594 | shows "\<exists>i<length as. a divides (as!i)" | |
| 2595 | using as | |
| 2596 | proof (induction as) | |
| 2597 | case Nil | |
| 2598 | then show ?case | |
| 2599 | by simp (meson Units_one_closed aprime carr divides_unit primeE) | |
| 2600 | next | |
| 2601 | case (Cons x as) | |
| 2602 | then have "x \<in> carrier G" "set as \<subseteq> carrier G" and "a divides x \<otimes> foldr (\<otimes>) as \<one>" | |
| 75455 
91c16c5ad3e9
tidied auto / simp with null arguments
 paulson <lp15@cam.ac.uk> parents: 
73706diff
changeset | 2603 | by auto | 
| 68478 | 2604 | with carr aprime have "a divides x \<or> a divides foldr (\<otimes>) as \<one>" | 
| 2605 | by (intro prime_divides) simp+ | |
| 2606 | then show ?case | |
| 2607 | using Cons.IH Cons.prems(1) by force | |
| 27701 | 2608 | qed | 
| 2609 | ||
| 68684 | 2610 | proposition (in primeness_condition_monoid) wfactors_unique: | 
| 2611 | assumes "wfactors G as a" "wfactors G as' a" | |
| 2612 | and "a \<in> carrier G" "set as \<subseteq> carrier G" "set as' \<subseteq> carrier G" | |
| 2613 | shows "essentially_equal G as as'" | |
| 2614 | using assms | |
| 2615 | proof (induct as arbitrary: a as') | |
| 63832 | 2616 | case Nil | 
| 68684 | 2617 | then have "a \<sim> \<one>" | 
| 73706 | 2618 | by (simp add: perm_wfactorsD) | 
| 68684 | 2619 | then have "as' = []" | 
| 2620 | using Nil.prems assoc_unit_l unit_wfactors_empty by blast | |
| 2621 | then show ?case | |
| 2622 | by auto | |
| 46129 | 2623 | next | 
| 63832 | 2624 | case (Cons ah as) | 
| 68684 | 2625 | then have ahdvda: "ah divides a" | 
| 2626 | using wfactors_dividesI by auto | |
| 63832 | 2627 | then obtain a' where a'carr: "a' \<in> carrier G" and a: "a = ah \<otimes> a'" | 
| 63847 | 2628 | by blast | 
| 68684 | 2629 | have carr_ah: "ah \<in> carrier G" "set as \<subseteq> carrier G" | 
| 2630 | using Cons.prems by fastforce+ | |
| 2631 | have "ah \<otimes> foldr (\<otimes>) as \<one> \<sim> a" | |
| 2632 | by (rule wfactorsE[OF \<open>wfactors G (ah # as) a\<close>]) auto | |
| 2633 | then have "foldr (\<otimes>) as \<one> \<sim> a'" | |
| 2634 | by (metis Cons.prems(4) a a'carr assoc_l_cancel insert_subset list.set(2) monoid.multlist_closed monoid_axioms) | |
| 2635 | then | |
| 46129 | 2636 | have a'fs: "wfactors G as a'" | 
| 68684 | 2637 | by (meson Cons.prems(1) set_subset_Cons subset_iff wfactorsE wfactorsI) | 
| 2638 | then have ahirr: "irreducible G ah" | |
| 2639 | by (meson Cons.prems(1) list.set_intros(1) wfactorsE) | |
| 2640 | with Cons have ahprime: "prime G ah" | |
| 2641 | by (simp add: irreducible_prime) | |
| 46129 | 2642 | note ahdvda | 
| 68684 | 2643 | also have "a divides (foldr (\<otimes>) as' \<one>)" | 
| 2644 | by (meson Cons.prems(2) associatedE wfactorsE) | |
| 67399 | 2645 | finally have "ah divides (foldr (\<otimes>) as' \<one>)" | 
| 68684 | 2646 | using Cons.prems(4) by auto | 
| 63832 | 2647 | with ahprime have "\<exists>i<length as'. ah divides as'!i" | 
| 68684 | 2648 | by (intro multlist_prime_pos) (use Cons.prems in auto) | 
| 63832 | 2649 | then obtain i where len: "i<length as'" and ahdvd: "ah divides as'!i" | 
| 63847 | 2650 | by blast | 
| 68684 | 2651 | then obtain x where "x \<in> carrier G" and asi: "as'!i = ah \<otimes> x" | 
| 63847 | 2652 | by blast | 
| 68684 | 2653 | have irrasi: "irreducible G (as'!i)" | 
| 2654 | using nth_mem[OF len] wfactorsE | |
| 2655 | by (metis Cons.prems(2)) | |
| 2656 | have asicarr[simp]: "as'!i \<in> carrier G" | |
| 2657 | using len \<open>set as' \<subseteq> carrier G\<close> nth_mem by blast | |
| 2658 | have asiah: "as'!i \<sim> ah" | |
| 2659 | by (metis \<open>ah \<in> carrier G\<close> \<open>x \<in> carrier G\<close> asi irrasi ahprime associatedI2 irreducible_prodE primeE) | |
| 46129 | 2660 | note setparts = set_take_subset[of i as'] set_drop_subset[of "Suc i" as'] | 
| 2661 | have "\<exists>aa_1. aa_1 \<in> carrier G \<and> wfactors G (take i as') aa_1" | |
| 68684 | 2662 | using Cons | 
| 2663 | by (metis setparts(1) subset_trans in_set_takeD wfactorsE wfactors_prod_exists) | |
| 2664 | then obtain aa_1 where aa1carr [simp]: "aa_1 \<in> carrier G" and aa1fs: "wfactors G (take i as') aa_1" | |
| 63832 | 2665 | by auto | 
| 68684 | 2666 | obtain aa_2 where aa2carr [simp]: "aa_2 \<in> carrier G" | 
| 63832 | 2667 | and aa2fs: "wfactors G (drop (Suc i) as') aa_2" | 
| 68684 | 2668 | by (metis Cons.prems(2) Cons.prems(5) subset_code(1) in_set_dropD wfactors_def wfactors_prod_exists) | 
| 2669 | ||
| 2670 | have set_drop: "set (drop (Suc i) as') \<subseteq> carrier G" | |
| 2671 | using Cons.prems(5) setparts(2) by blast | |
| 2672 | moreover have set_take: "set (take i as') \<subseteq> carrier G" | |
| 2673 | using Cons.prems(5) setparts by auto | |
| 2674 | moreover have v1: "wfactors G (take i as' @ drop (Suc i) as') (aa_1 \<otimes> aa_2)" | |
| 2675 | using aa1fs aa2fs \<open>set as' \<subseteq> carrier G\<close> by (force simp add: dest: in_set_takeD in_set_dropD) | |
| 2676 | ultimately have v1': "wfactors G (as'!i # take i as' @ drop (Suc i) as') (as'!i \<otimes> (aa_1 \<otimes> aa_2))" | |
| 2677 | using irrasi wfactors_mult_single | |
| 2678 | by (simp add: irrasi v1 wfactors_mult_single) | |
| 2679 | have "wfactors G (as'!i # drop (Suc i) as') (as'!i \<otimes> aa_2)" | |
| 2680 | by (simp add: aa2fs irrasi set_drop wfactors_mult_single) | |
| 2681 | with len aa1carr aa2carr aa1fs | |
| 63832 | 2682 | have v2: "wfactors G (take i as' @ as'!i # drop (Suc i) as') (aa_1 \<otimes> (as'!i \<otimes> aa_2))" | 
| 68684 | 2683 | using wfactors_mult by (simp add: set_take set_drop) | 
| 63832 | 2684 | 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 | 2685 | by (simp add: Cons_nth_drop_Suc) | 
| 68684 | 2686 | have eer: "essentially_equal G (take i as' @ as'!i # drop (Suc i) as') as'" | 
| 2687 | using Cons.prems(5) as' by auto | |
| 2688 | with v2 aa1carr aa2carr nth_mem[OF len] have "aa_1 \<otimes> (as'!i \<otimes> aa_2) \<sim> a" | |
| 2689 | using Cons.prems as' comm_monoid_cancel.ee_wfactorsD is_comm_monoid_cancel by fastforce | |
| 63832 | 2690 | 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 | 2691 | by (metis aa1carr aa2carr asicarr m_lcomm) | 
| 68684 | 2692 | from asiah have "ah \<otimes> (aa_1 \<otimes> aa_2) \<sim> as'!i \<otimes> (aa_1 \<otimes> aa_2)" | 
| 2693 | by (simp add: \<open>ah \<in> carrier G\<close> associated_sym mult_cong_l) | |
| 46129 | 2694 | also note t1 | 
| 68684 | 2695 | finally have "ah \<otimes> (aa_1 \<otimes> aa_2) \<sim> a" | 
| 2696 | using Cons.prems(3) carr_ah aa1carr aa2carr by blast | |
| 2697 | with aa1carr aa2carr a'carr nth_mem[OF len] have a': "aa_1 \<otimes> aa_2 \<sim> a'" | |
| 2698 | using a assoc_l_cancel carr_ah(1) by blast | |
| 46129 | 2699 | note v1 | 
| 2700 | also note a' | |
| 63832 | 2701 | finally have "wfactors G (take i as' @ drop (Suc i) as') a'" | 
| 68684 | 2702 | by (simp add: a'carr set_drop set_take) | 
| 2703 | from a'fs this have "essentially_equal G as (take i as' @ drop (Suc i) as')" | |
| 2704 | using Cons.hyps a'carr carr_ah(2) set_drop set_take by auto | |
| 73706 | 2705 | then obtain bs where \<open>mset as = mset bs\<close> \<open>bs [\<sim>] take i as' @ drop (Suc i) as'\<close> | 
| 2706 | by (auto simp add: essentially_equal_def) | |
| 2707 | with carr_ah have \<open>mset (ah # as) = mset (ah # bs)\<close> \<open>ah # bs [\<sim>] ah # take i as' @ drop (Suc i) as'\<close> | |
| 2708 | by simp_all | |
| 2709 | then have ee1: "essentially_equal G (ah # as) (ah # take i as' @ drop (Suc i) as')" | |
| 2710 | unfolding essentially_equal_def by blast | |
| 68684 | 2711 | have ee2: "essentially_equal G (ah # take i as' @ drop (Suc i) as') | 
| 46129 | 2712 | (as' ! i # take i as' @ drop (Suc i) as')" | 
| 2713 | proof (intro essentially_equalI) | |
| 2714 | show "ah # take i as' @ drop (Suc i) as' <~~> ah # take i as' @ drop (Suc i) as'" | |
| 27701 | 2715 | by simp | 
| 46129 | 2716 | next | 
| 2717 | show "ah # take i as' @ drop (Suc i) as' [\<sim>] as' ! i # take i as' @ drop (Suc i) as'" | |
| 68684 | 2718 | by (simp add: asiah associated_sym set_drop set_take) | 
| 46129 | 2719 | qed | 
| 2720 | ||
| 2721 | note ee1 | |
| 2722 | also note ee2 | |
| 2723 | 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 | 2724 | (take i as' @ as' ! i # drop (Suc i) as')" | 
| 68684 | 2725 | by (metis Cons.prems(5) as' essentially_equalI listassoc_refl perm_append_Cons) | 
| 63832 | 2726 | finally have "essentially_equal G (ah # as) (take i as' @ as' ! i # drop (Suc i) as')" | 
| 68684 | 2727 | using Cons.prems(4) set_drop set_take by auto | 
| 2728 | then show ?case | |
| 2729 | using as' by auto | |
| 27701 | 2730 | qed | 
| 2731 | ||
| 2732 | ||
| 61382 | 2733 | subsubsection \<open>Application to factorial monoids\<close> | 
| 2734 | ||
| 2735 | text \<open>Number of factors for wellfoundedness\<close> | |
| 27701 | 2736 | |
| 63832 | 2737 | definition factorcount :: "_ \<Rightarrow> 'a \<Rightarrow> nat" | 
| 2738 | where "factorcount G a = | |
| 2739 | (THE c. \<forall>as. set as \<subseteq> carrier G \<and> wfactors G as a \<longrightarrow> c = length as)" | |
| 27701 | 2740 | |
| 2741 | lemma (in monoid) ee_length: | |
| 2742 | assumes ee: "essentially_equal G as bs" | |
| 2743 | shows "length as = length bs" | |
| 63832 | 2744 | by (rule essentially_equalE[OF ee]) (metis list_all2_conv_all_nth perm_length) | 
| 27701 | 2745 | |
| 2746 | lemma (in factorial_monoid) factorcount_exists: | |
| 2747 | assumes carr[simp]: "a \<in> carrier G" | |
| 63832 | 2748 | shows "\<exists>c. \<forall>as. set as \<subseteq> carrier G \<and> wfactors G as a \<longrightarrow> c = length as" | 
| 27701 | 2749 | proof - | 
| 63832 | 2750 | have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a" | 
| 2751 | by (intro wfactors_exist) simp | |
| 2752 | then obtain as where ascarr[simp]: "set as \<subseteq> carrier G" and afs: "wfactors G as a" | |
| 2753 | by (auto simp del: carr) | |
| 2754 | have "\<forall>as'. set as' \<subseteq> carrier G \<and> wfactors G as' a \<longrightarrow> length as = length as'" | |
| 36278 | 2755 | by (metis afs ascarr assms ee_length wfactors_unique) | 
| 63832 | 2756 | then show "\<exists>c. \<forall>as'. set as' \<subseteq> carrier G \<and> wfactors G as' a \<longrightarrow> c = length as'" .. | 
| 27701 | 2757 | qed | 
| 2758 | ||
| 2759 | lemma (in factorial_monoid) factorcount_unique: | |
| 2760 | assumes afs: "wfactors G as a" | |
| 68488 
dfbd80c3d180
more modernisaton and de-applying
 paulson <lp15@cam.ac.uk> parents: 
68478diff
changeset | 2761 | and acarr[simp]: "a \<in> carrier G" and ascarr: "set as \<subseteq> carrier G" | 
| 27701 | 2762 | shows "factorcount G a = length as" | 
| 2763 | proof - | |
| 63832 | 2764 | have "\<exists>ac. \<forall>as. set as \<subseteq> carrier G \<and> wfactors G as a \<longrightarrow> ac = length as" | 
| 2765 | by (rule factorcount_exists) simp | |
| 2766 | then obtain ac where alen: "\<forall>as. set as \<subseteq> carrier G \<and> wfactors G as a \<longrightarrow> ac = length as" | |
| 2767 | by auto | |
| 68488 
dfbd80c3d180
more modernisaton and de-applying
 paulson <lp15@cam.ac.uk> parents: 
68478diff
changeset | 2768 | then have ac: "ac = factorcount G a" | 
| 
dfbd80c3d180
more modernisaton and de-applying
 paulson <lp15@cam.ac.uk> parents: 
68478diff
changeset | 2769 | unfolding factorcount_def using ascarr by (blast intro: theI2 afs) | 
| 63832 | 2770 | from ascarr afs have "ac = length as" | 
| 68488 
dfbd80c3d180
more modernisaton and de-applying
 paulson <lp15@cam.ac.uk> parents: 
68478diff
changeset | 2771 | by (simp add: alen) | 
| 63832 | 2772 | with ac show ?thesis | 
| 2773 | by simp | |
| 27701 | 2774 | qed | 
| 2775 | ||
| 2776 | lemma (in factorial_monoid) divides_fcount: | |
| 2777 | assumes dvd: "a divides b" | |
| 63832 | 2778 | and acarr: "a \<in> carrier G" | 
| 2779 | and bcarr:"b \<in> carrier G" | |
| 2780 | shows "factorcount G a \<le> factorcount G b" | |
| 2781 | proof (rule dividesE[OF dvd]) | |
| 27701 | 2782 | fix c | 
| 63832 | 2783 | from assms have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a" | 
| 63847 | 2784 | by blast | 
| 63832 | 2785 | then obtain as where ascarr: "set as \<subseteq> carrier G" and afs: "wfactors G as a" | 
| 63847 | 2786 | by blast | 
| 63832 | 2787 | with acarr have fca: "factorcount G a = length as" | 
| 2788 | by (intro factorcount_unique) | |
| 27701 | 2789 | |
| 2790 | assume ccarr: "c \<in> carrier G" | |
| 63832 | 2791 | then have "\<exists>cs. set cs \<subseteq> carrier G \<and> wfactors G cs c" | 
| 63847 | 2792 | by blast | 
| 63832 | 2793 | then obtain cs where cscarr: "set cs \<subseteq> carrier G" and cfs: "wfactors G cs c" | 
| 63847 | 2794 | by blast | 
| 27701 | 2795 | |
| 2796 | note [simp] = acarr bcarr ccarr ascarr cscarr | |
| 2797 | assume b: "b = a \<otimes> c" | |
| 63832 | 2798 | from afs cfs have "wfactors G (as@cs) (a \<otimes> c)" | 
| 2799 | by (intro wfactors_mult) simp_all | |
| 2800 | with b have "wfactors G (as@cs) b" | |
| 2801 | by simp | |
| 2802 | then have "factorcount G b = length (as@cs)" | |
| 2803 | by (intro factorcount_unique) simp_all | |
| 2804 | then have "factorcount G b = length as + length cs" | |
| 2805 | by simp | |
| 2806 | with fca show ?thesis | |
| 2807 | by simp | |
| 27701 | 2808 | qed | 
| 2809 | ||
| 2810 | lemma (in factorial_monoid) associated_fcount: | |
| 63832 | 2811 | assumes acarr: "a \<in> carrier G" | 
| 2812 | and bcarr: "b \<in> carrier G" | |
| 27701 | 2813 | and asc: "a \<sim> b" | 
| 2814 | shows "factorcount G a = factorcount G b" | |
| 68488 
dfbd80c3d180
more modernisaton and de-applying
 paulson <lp15@cam.ac.uk> parents: 
68478diff
changeset | 2815 | using assms | 
| 
dfbd80c3d180
more modernisaton and de-applying
 paulson <lp15@cam.ac.uk> parents: 
68478diff
changeset | 2816 | by (auto simp: associated_def factorial_monoid.divides_fcount factorial_monoid_axioms le_antisym) | 
| 27701 | 2817 | |
| 2818 | lemma (in factorial_monoid) properfactor_fcount: | |
| 2819 | assumes acarr: "a \<in> carrier G" and bcarr:"b \<in> carrier G" | |
| 2820 | and pf: "properfactor G a b" | |
| 2821 | shows "factorcount G a < factorcount G b" | |
| 63832 | 2822 | proof (rule properfactorE[OF pf], elim dividesE) | 
| 27701 | 2823 | fix c | 
| 63832 | 2824 | from assms have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a" | 
| 63847 | 2825 | by blast | 
| 63832 | 2826 | then obtain as where ascarr: "set as \<subseteq> carrier G" and afs: "wfactors G as a" | 
| 63847 | 2827 | by blast | 
| 63832 | 2828 | with acarr have fca: "factorcount G a = length as" | 
| 2829 | by (intro factorcount_unique) | |
| 27701 | 2830 | |
| 2831 | assume ccarr: "c \<in> carrier G" | |
| 63832 | 2832 | then have "\<exists>cs. set cs \<subseteq> carrier G \<and> wfactors G cs c" | 
| 63847 | 2833 | by blast | 
| 63832 | 2834 | then obtain cs where cscarr: "set cs \<subseteq> carrier G" and cfs: "wfactors G cs c" | 
| 63847 | 2835 | by blast | 
| 27701 | 2836 | |
| 2837 | assume b: "b = a \<otimes> c" | |
| 2838 | ||
| 63832 | 2839 | have "wfactors G (as@cs) (a \<otimes> c)" | 
| 2840 | by (rule wfactors_mult) fact+ | |
| 2841 | with b have "wfactors G (as@cs) b" | |
| 2842 | by simp | |
| 2843 | with ascarr cscarr bcarr have "factorcount G b = length (as@cs)" | |
| 2844 | by (simp add: factorcount_unique) | |
| 2845 | then have fcb: "factorcount G b = length as + length cs" | |
| 2846 | by simp | |
| 27701 | 2847 | |
| 2848 | assume nbdvda: "\<not> b divides a" | |
| 2849 | have "c \<notin> Units G" | |
| 63846 | 2850 | proof | 
| 27701 | 2851 | assume cunit:"c \<in> Units G" | 
| 63832 | 2852 | have "b \<otimes> inv c = a \<otimes> c \<otimes> inv c" | 
| 2853 | by (simp add: b) | |
| 2854 | also from ccarr acarr cunit have "\<dots> = a \<otimes> (c \<otimes> inv c)" | |
| 2855 | by (fast intro: m_assoc) | |
| 2856 | also from ccarr cunit have "\<dots> = a \<otimes> \<one>" by simp | |
| 2857 | also from acarr have "\<dots> = a" by simp | |
| 27701 | 2858 | finally have "a = b \<otimes> inv c" by simp | 
| 63832 | 2859 | with ccarr cunit have "b divides a" | 
| 2860 | by (fast intro: dividesI[of "inv c"]) | |
| 27701 | 2861 | with nbdvda show False by simp | 
| 2862 | qed | |
| 2863 | with cfs have "length cs > 0" | |
| 68474 | 2864 | by (metis Units_one_closed assoc_unit_r ccarr foldr.simps(1) id_apply length_greater_0_conv wfactors_def) | 
| 63832 | 2865 | with fca fcb show ?thesis | 
| 2866 | by simp | |
| 27701 | 2867 | qed | 
| 2868 | ||
| 29237 | 2869 | sublocale factorial_monoid \<subseteq> divisor_chain_condition_monoid | 
| 63832 | 2870 | apply unfold_locales | 
| 2871 | apply (rule wfUNIVI) | |
| 2872 | apply (rule measure_induct[of "factorcount G"]) | |
| 68684 | 2873 | using properfactor_fcount by auto | 
| 27701 | 2874 | |
| 29237 | 2875 | sublocale factorial_monoid \<subseteq> primeness_condition_monoid | 
| 63633 | 2876 | by standard (rule irreducible_prime) | 
| 27701 | 2877 | |
| 2878 | ||
| 63832 | 2879 | lemma (in factorial_monoid) primeness_condition: "primeness_condition_monoid G" .. | 
| 2880 | ||
| 2881 | lemma (in factorial_monoid) gcd_condition [simp]: "gcd_condition_monoid G" | |
| 61169 | 2882 | by standard (rule gcdof_exists) | 
| 27701 | 2883 | |
| 29237 | 2884 | sublocale factorial_monoid \<subseteq> gcd_condition_monoid | 
| 61169 | 2885 | by standard (rule gcdof_exists) | 
| 27701 | 2886 | |
| 63832 | 2887 | lemma (in factorial_monoid) division_weak_lattice [simp]: "weak_lattice (division_rel G)" | 
| 27701 | 2888 | proof - | 
| 63832 | 2889 | interpret weak_lower_semilattice "division_rel G" | 
| 2890 | by simp | |
| 27713 
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
 ballarin parents: 
27701diff
changeset | 2891 | show "weak_lattice (division_rel G)" | 
| 63832 | 2892 | proof (unfold_locales, simp_all) | 
| 27701 | 2893 | fix x y | 
| 2894 | assume carr: "x \<in> carrier G" "y \<in> carrier G" | |
| 63847 | 2895 | from lcmof_exists [OF this] obtain z where zcarr: "z \<in> carrier G" and isgcd: "z lcmof x y" | 
| 2896 | by blast | |
| 63832 | 2897 |     with carr have "least (division_rel G) z (Upper (division_rel G) {x, y})"
 | 
| 2898 | by (simp add: lcmof_leastUpper[symmetric]) | |
| 2899 |     then show "\<exists>z. least (division_rel G) z (Upper (division_rel G) {x, y})"
 | |
| 63847 | 2900 | by blast | 
| 27701 | 2901 | qed | 
| 2902 | qed | |
| 2903 | ||
| 2904 | ||
| 61382 | 2905 | subsection \<open>Factoriality Theorems\<close> | 
| 27701 | 2906 | |
| 2907 | theorem factorial_condition_one: (* Jacobson theorem 2.21 *) | |
| 63847 | 2908 | "divisor_chain_condition_monoid G \<and> primeness_condition_monoid G \<longleftrightarrow> factorial_monoid G" | 
| 2909 | proof (rule iffI, clarify) | |
| 27701 | 2910 | assume dcc: "divisor_chain_condition_monoid G" | 
| 63832 | 2911 | and pc: "primeness_condition_monoid G" | 
| 29237 | 2912 | interpret divisor_chain_condition_monoid "G" by (rule dcc) | 
| 2913 | interpret primeness_condition_monoid "G" by (rule pc) | |
| 27701 | 2914 | show "factorial_monoid G" | 
| 63832 | 2915 | by (fast intro: factorial_monoidI wfactors_exist wfactors_unique) | 
| 27701 | 2916 | next | 
| 63847 | 2917 | assume "factorial_monoid G" | 
| 2918 | then interpret factorial_monoid "G" . | |
| 27701 | 2919 | show "divisor_chain_condition_monoid G \<and> primeness_condition_monoid G" | 
| 63832 | 2920 | by rule unfold_locales | 
| 27701 | 2921 | qed | 
| 2922 | ||
| 2923 | theorem factorial_condition_two: (* Jacobson theorem 2.22 *) | |
| 63847 | 2924 | "divisor_chain_condition_monoid G \<and> gcd_condition_monoid G \<longleftrightarrow> factorial_monoid G" | 
| 2925 | proof (rule iffI, clarify) | |
| 57865 | 2926 | assume dcc: "divisor_chain_condition_monoid G" | 
| 63832 | 2927 | and gc: "gcd_condition_monoid G" | 
| 29237 | 2928 | interpret divisor_chain_condition_monoid "G" by (rule dcc) | 
| 2929 | interpret gcd_condition_monoid "G" by (rule gc) | |
| 27701 | 2930 | show "factorial_monoid G" | 
| 63832 | 2931 | by (simp add: factorial_condition_one[symmetric], rule, unfold_locales) | 
| 27701 | 2932 | next | 
| 63847 | 2933 | assume "factorial_monoid G" | 
| 2934 | then interpret factorial_monoid "G" . | |
| 27701 | 2935 | show "divisor_chain_condition_monoid G \<and> gcd_condition_monoid G" | 
| 63832 | 2936 | by rule unfold_locales | 
| 27701 | 2937 | qed | 
| 2938 | ||
| 2939 | end |