author | paulson <lp15@cam.ac.uk> |
Tue, 19 Jun 2018 23:11:00 +0100 | |
changeset 68470 | 7ddcce75c3ee |
parent 68399 | 0b71d08528f0 |
child 68474 | 346bdafaf5fa |
permissions | -rw-r--r-- |
41959 | 1 |
(* Title: HOL/Algebra/Divisibility.thy |
2 |
Author: Clemens Ballarin |
|
3 |
Author: Stephan Hohe |
|
27701 | 4 |
*) |
5 |
||
61382 | 6 |
section \<open>Divisibility in monoids and rings\<close> |
41959 | 7 |
|
27701 | 8 |
theory Divisibility |
66579 | 9 |
imports "HOL-Library.Permutation" Coset Group |
27701 | 10 |
begin |
11 |
||
61382 | 12 |
section \<open>Factorial Monoids\<close> |
13 |
||
14 |
subsection \<open>Monoids with Cancellation Law\<close> |
|
27701 | 15 |
|
16 |
locale monoid_cancel = monoid + |
|
63832 | 17 |
assumes l_cancel: "\<lbrakk>c \<otimes> a = c \<otimes> b; a \<in> carrier G; b \<in> carrier G; c \<in> carrier G\<rbrakk> \<Longrightarrow> a = b" |
18 |
and r_cancel: "\<lbrakk>a \<otimes> c = b \<otimes> c; a \<in> carrier G; b \<in> carrier G; c \<in> carrier G\<rbrakk> \<Longrightarrow> a = b" |
|
27701 | 19 |
|
20 |
lemma (in monoid) monoid_cancelI: |
|
63832 | 21 |
assumes l_cancel: "\<And>a b c. \<lbrakk>c \<otimes> a = c \<otimes> b; a \<in> carrier G; b \<in> carrier G; c \<in> carrier G\<rbrakk> \<Longrightarrow> a = b" |
22 |
and r_cancel: "\<And>a b c. \<lbrakk>a \<otimes> c = b \<otimes> c; a \<in> carrier G; b \<in> carrier G; c \<in> carrier G\<rbrakk> \<Longrightarrow> a = b" |
|
27701 | 23 |
shows "monoid_cancel G" |
61169 | 24 |
by standard fact+ |
27701 | 25 |
|
63832 | 26 |
lemma (in monoid_cancel) is_monoid_cancel: "monoid_cancel G" .. |
27701 | 27 |
|
29237 | 28 |
sublocale group \<subseteq> monoid_cancel |
61169 | 29 |
by standard simp_all |
27701 | 30 |
|
31 |
||
32 |
locale comm_monoid_cancel = monoid_cancel + comm_monoid |
|
33 |
||
34 |
lemma comm_monoid_cancelI: |
|
28599 | 35 |
fixes G (structure) |
36 |
assumes "comm_monoid G" |
|
63832 | 37 |
assumes cancel: "\<And>a b c. \<lbrakk>a \<otimes> c = b \<otimes> c; a \<in> carrier G; b \<in> carrier G; c \<in> carrier G\<rbrakk> \<Longrightarrow> a = b" |
27701 | 38 |
shows "comm_monoid_cancel G" |
28599 | 39 |
proof - |
29237 | 40 |
interpret comm_monoid G by fact |
28599 | 41 |
show "comm_monoid_cancel G" |
36278 | 42 |
by unfold_locales (metis assms(2) m_ac(2))+ |
28599 | 43 |
qed |
27701 | 44 |
|
63832 | 45 |
lemma (in comm_monoid_cancel) is_comm_monoid_cancel: "comm_monoid_cancel G" |
28823 | 46 |
by intro_locales |
27701 | 47 |
|
63832 | 48 |
sublocale comm_group \<subseteq> comm_monoid_cancel .. |
27701 | 49 |
|
50 |
||
61382 | 51 |
subsection \<open>Products of Units in Monoids\<close> |
27701 | 52 |
|
53 |
lemma (in monoid) prod_unit_l: |
|
63832 | 54 |
assumes abunit[simp]: "a \<otimes> b \<in> Units G" |
55 |
and aunit[simp]: "a \<in> Units G" |
|
27701 | 56 |
and carr[simp]: "a \<in> carrier G" "b \<in> carrier G" |
57 |
shows "b \<in> Units G" |
|
58 |
proof - |
|
59 |
have c: "inv (a \<otimes> b) \<otimes> a \<in> carrier G" by simp |
|
60 |
||
63832 | 61 |
have "(inv (a \<otimes> b) \<otimes> a) \<otimes> b = inv (a \<otimes> b) \<otimes> (a \<otimes> b)" |
62 |
by (simp add: m_assoc) |
|
57865 | 63 |
also have "\<dots> = \<one>" by simp |
27701 | 64 |
finally have li: "(inv (a \<otimes> b) \<otimes> a) \<otimes> b = \<one>" . |
65 |
||
66 |
have "\<one> = inv a \<otimes> a" by (simp add: Units_l_inv[symmetric]) |
|
67 |
also have "\<dots> = inv a \<otimes> \<one> \<otimes> a" by simp |
|
68 |
also have "\<dots> = inv a \<otimes> ((a \<otimes> b) \<otimes> inv (a \<otimes> b)) \<otimes> a" |
|
63832 | 69 |
by (simp add: Units_r_inv[OF abunit, symmetric] del: Units_r_inv) |
27701 | 70 |
also have "\<dots> = ((inv a \<otimes> a) \<otimes> b) \<otimes> inv (a \<otimes> b) \<otimes> a" |
71 |
by (simp add: m_assoc del: Units_l_inv) |
|
57865 | 72 |
also have "\<dots> = b \<otimes> inv (a \<otimes> b) \<otimes> a" by simp |
27701 | 73 |
also have "\<dots> = b \<otimes> (inv (a \<otimes> b) \<otimes> a)" by (simp add: m_assoc) |
74 |
finally have ri: "b \<otimes> (inv (a \<otimes> b) \<otimes> a) = \<one> " by simp |
|
75 |
||
63832 | 76 |
from c li ri show "b \<in> Units G" by (auto simp: Units_def) |
27701 | 77 |
qed |
78 |
||
79 |
lemma (in monoid) prod_unit_r: |
|
63832 | 80 |
assumes abunit[simp]: "a \<otimes> b \<in> Units G" |
81 |
and bunit[simp]: "b \<in> Units G" |
|
27701 | 82 |
and carr[simp]: "a \<in> carrier G" "b \<in> carrier G" |
83 |
shows "a \<in> Units G" |
|
84 |
proof - |
|
85 |
have c: "b \<otimes> inv (a \<otimes> b) \<in> carrier G" by simp |
|
86 |
||
87 |
have "a \<otimes> (b \<otimes> inv (a \<otimes> b)) = (a \<otimes> b) \<otimes> inv (a \<otimes> b)" |
|
88 |
by (simp add: m_assoc del: Units_r_inv) |
|
89 |
also have "\<dots> = \<one>" by simp |
|
90 |
finally have li: "a \<otimes> (b \<otimes> inv (a \<otimes> b)) = \<one>" . |
|
91 |
||
92 |
have "\<one> = b \<otimes> inv b" by (simp add: Units_r_inv[symmetric]) |
|
93 |
also have "\<dots> = b \<otimes> \<one> \<otimes> inv b" by simp |
|
63832 | 94 |
also have "\<dots> = b \<otimes> (inv (a \<otimes> b) \<otimes> (a \<otimes> b)) \<otimes> inv b" |
95 |
by (simp add: Units_l_inv[OF abunit, symmetric] del: Units_l_inv) |
|
27701 | 96 |
also have "\<dots> = (b \<otimes> inv (a \<otimes> b) \<otimes> a) \<otimes> (b \<otimes> inv b)" |
97 |
by (simp add: m_assoc del: Units_l_inv) |
|
98 |
also have "\<dots> = b \<otimes> inv (a \<otimes> b) \<otimes> a" by simp |
|
99 |
finally have ri: "(b \<otimes> inv (a \<otimes> b)) \<otimes> a = \<one> " by simp |
|
100 |
||
63832 | 101 |
from c li ri show "a \<in> Units G" by (auto simp: Units_def) |
27701 | 102 |
qed |
103 |
||
104 |
lemma (in comm_monoid) unit_factor: |
|
105 |
assumes abunit: "a \<otimes> b \<in> Units G" |
|
106 |
and [simp]: "a \<in> carrier G" "b \<in> carrier G" |
|
107 |
shows "a \<in> Units G" |
|
63832 | 108 |
using abunit[simplified Units_def] |
27701 | 109 |
proof clarsimp |
110 |
fix i |
|
111 |
assume [simp]: "i \<in> carrier G" |
|
112 |
||
113 |
have carr': "b \<otimes> i \<in> carrier G" by simp |
|
114 |
||
115 |
have "(b \<otimes> i) \<otimes> a = (i \<otimes> b) \<otimes> a" by (simp add: m_comm) |
|
116 |
also have "\<dots> = i \<otimes> (b \<otimes> a)" by (simp add: m_assoc) |
|
117 |
also have "\<dots> = i \<otimes> (a \<otimes> b)" by (simp add: m_comm) |
|
63832 | 118 |
also assume "i \<otimes> (a \<otimes> b) = \<one>" |
27701 | 119 |
finally have li': "(b \<otimes> i) \<otimes> a = \<one>" . |
120 |
||
121 |
have "a \<otimes> (b \<otimes> i) = a \<otimes> b \<otimes> i" by (simp add: m_assoc) |
|
63832 | 122 |
also assume "a \<otimes> b \<otimes> i = \<one>" |
27701 | 123 |
finally have ri': "a \<otimes> (b \<otimes> i) = \<one>" . |
124 |
||
125 |
from carr' li' ri' |
|
63832 | 126 |
show "a \<in> Units G" by (simp add: Units_def, fast) |
27701 | 127 |
qed |
128 |
||
35849 | 129 |
|
61382 | 130 |
subsection \<open>Divisibility and Association\<close> |
131 |
||
132 |
subsubsection \<open>Function definitions\<close> |
|
27701 | 133 |
|
63832 | 134 |
definition factor :: "[_, 'a, 'a] \<Rightarrow> bool" (infix "divides\<index>" 65) |
35848
5443079512ea
slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents:
35847
diff
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:
35847
diff
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:
35847
diff
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:
35847
diff
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:
68399
diff
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:
68399
diff
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:
68399
diff
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:
68399
diff
changeset
|
205 |
proof |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
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:
68399
diff
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:
68399
diff
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:
68399
diff
changeset
|
209 |
using carr(1) carr(3) by blast |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
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:
68399
diff
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:
68399
diff
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:
68399
diff
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:
68399
diff
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:
68399
diff
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:
68399
diff
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:
68399
diff
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:
68399
diff
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:
68399
diff
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:
68399
diff
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:
68399
diff
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:
68399
diff
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:
68399
diff
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:
68399
diff
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:
68399
diff
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:
27701
diff
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:
27701
diff
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:
68399
diff
changeset
|
393 |
apply (simp_all add: associated_sym divides_antisym) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
394 |
apply (metis associated_trans) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
395 |
apply (metis divides_trans) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
396 |
by (meson associated_def divides_trans) |
27701 | 397 |
|
63832 | 398 |
|
61382 | 399 |
subsubsection \<open>Multiplication and associativity\<close> |
27701 | 400 |
|
401 |
lemma (in monoid_cancel) mult_cong_r: |
|
68470
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
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:
68399
diff
changeset
|
404 |
by (meson assms associated_def divides_mult_lI) |
27701 | 405 |
|
406 |
lemma (in comm_monoid_cancel) mult_cong_l: |
|
68470
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
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:
68399
diff
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:
68399
diff
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:
68399
diff
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:
68399
diff
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:
68399
diff
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:
68399
diff
changeset
|
450 |
proof - |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
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:
68399
diff
changeset
|
452 |
proof - |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
453 |
have "a \<sim> \<one>" |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
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:
68399
diff
changeset
|
455 |
then show ?thesis |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
456 |
by (simp add: elem_def) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
457 |
qed |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
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:
68399
diff
changeset
|
459 |
by (simp add: equivalence.mem_imp_elem) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
460 |
ultimately show ?thesis |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
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:
68399
diff
changeset
|
465 |
apply (auto simp add: Units_def Lower_def) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
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 |
|
470 |
||
61382 | 471 |
subsubsection \<open>Proper factors\<close> |
27701 | 472 |
|
473 |
lemma properfactorI: |
|
474 |
fixes G (structure) |
|
475 |
assumes "a divides b" |
|
476 |
and "\<not>(b divides a)" |
|
477 |
shows "properfactor G a b" |
|
63832 | 478 |
using assms unfolding properfactor_def by simp |
27701 | 479 |
|
480 |
lemma properfactorI2: |
|
481 |
fixes G (structure) |
|
482 |
assumes advdb: "a divides b" |
|
483 |
and neq: "\<not>(a \<sim> b)" |
|
484 |
shows "properfactor G a b" |
|
63846 | 485 |
proof (rule properfactorI, rule advdb, rule notI) |
27701 | 486 |
assume "b divides a" |
487 |
with advdb have "a \<sim> b" by (rule associatedI) |
|
488 |
with neq show "False" by fast |
|
489 |
qed |
|
490 |
||
491 |
lemma (in comm_monoid_cancel) properfactorI3: |
|
492 |
assumes p: "p = a \<otimes> b" |
|
493 |
and nunit: "b \<notin> Units G" |
|
68470
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
494 |
and carr: "a \<in> carrier G" "b \<in> carrier G" |
27701 | 495 |
shows "properfactor G a p" |
63832 | 496 |
unfolding p |
497 |
using carr |
|
498 |
apply (intro properfactorI, fast) |
|
27701 | 499 |
proof (clarsimp, elim dividesE) |
500 |
fix c |
|
501 |
assume ccarr: "c \<in> carrier G" |
|
502 |
note [simp] = carr ccarr |
|
503 |
||
504 |
have "a \<otimes> \<one> = a" by simp |
|
505 |
also assume "a = a \<otimes> b \<otimes> c" |
|
506 |
also have "\<dots> = a \<otimes> (b \<otimes> c)" by (simp add: m_assoc) |
|
507 |
finally have "a \<otimes> \<one> = a \<otimes> (b \<otimes> c)" . |
|
508 |
||
63832 | 509 |
then have rinv: "\<one> = b \<otimes> c" by (intro l_cancel[of "a" "\<one>" "b \<otimes> c"], simp+) |
27701 | 510 |
also have "\<dots> = c \<otimes> b" by (simp add: m_comm) |
511 |
finally have linv: "\<one> = c \<otimes> b" . |
|
512 |
||
63832 | 513 |
from ccarr linv[symmetric] rinv[symmetric] have "b \<in> Units G" |
514 |
unfolding Units_def by fastforce |
|
515 |
with nunit show False .. |
|
27701 | 516 |
qed |
517 |
||
518 |
lemma properfactorE: |
|
519 |
fixes G (structure) |
|
520 |
assumes pf: "properfactor G a b" |
|
521 |
and r: "\<lbrakk>a divides b; \<not>(b divides a)\<rbrakk> \<Longrightarrow> P" |
|
522 |
shows "P" |
|
63832 | 523 |
using pf unfolding properfactor_def by (fast intro: r) |
27701 | 524 |
|
525 |
lemma properfactorE2: |
|
526 |
fixes G (structure) |
|
527 |
assumes pf: "properfactor G a b" |
|
528 |
and elim: "\<lbrakk>a divides b; \<not>(a \<sim> b)\<rbrakk> \<Longrightarrow> P" |
|
529 |
shows "P" |
|
63832 | 530 |
using pf unfolding properfactor_def by (fast elim: elim associatedE) |
27701 | 531 |
|
532 |
lemma (in monoid) properfactor_unitE: |
|
533 |
assumes uunit: "u \<in> Units G" |
|
534 |
and pf: "properfactor G a u" |
|
535 |
and acarr: "a \<in> carrier G" |
|
536 |
shows "P" |
|
63832 | 537 |
using pf unit_divides[OF uunit acarr] by (fast elim: properfactorE) |
27701 | 538 |
|
539 |
lemma (in monoid) properfactor_divides: |
|
540 |
assumes pf: "properfactor G a b" |
|
541 |
shows "a divides b" |
|
63832 | 542 |
using pf by (elim properfactorE) |
27701 | 543 |
|
544 |
lemma (in monoid) properfactor_trans1 [trans]: |
|
545 |
assumes dvds: "a divides b" "properfactor G b c" |
|
68470
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
546 |
and carr: "a \<in> carrier G" "c \<in> carrier G" |
27701 | 547 |
shows "properfactor G a c" |
63832 | 548 |
using dvds carr |
549 |
apply (elim properfactorE, intro properfactorI) |
|
550 |
apply (iprover intro: divides_trans)+ |
|
551 |
done |
|
27701 | 552 |
|
553 |
lemma (in monoid) properfactor_trans2 [trans]: |
|
554 |
assumes dvds: "properfactor G a b" "b divides c" |
|
68470
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
555 |
and carr: "a \<in> carrier G" "b \<in> carrier G" |
27701 | 556 |
shows "properfactor G a c" |
63832 | 557 |
using dvds carr |
558 |
apply (elim properfactorE, intro properfactorI) |
|
559 |
apply (iprover intro: divides_trans)+ |
|
560 |
done |
|
27701 | 561 |
|
27713
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents:
27701
diff
changeset
|
562 |
lemma properfactor_lless: |
27701 | 563 |
fixes G (structure) |
27713
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents:
27701
diff
changeset
|
564 |
shows "properfactor G = lless (division_rel G)" |
68470
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
565 |
by (force simp: lless_def properfactor_def associated_def) |
27701 | 566 |
|
567 |
lemma (in monoid) properfactor_cong_l [trans]: |
|
568 |
assumes x'x: "x' \<sim> x" |
|
569 |
and pf: "properfactor G x y" |
|
570 |
and carr: "x \<in> carrier G" "x' \<in> carrier G" "y \<in> carrier G" |
|
571 |
shows "properfactor G x' y" |
|
63832 | 572 |
using pf |
573 |
unfolding properfactor_lless |
|
27701 | 574 |
proof - |
29237 | 575 |
interpret weak_partial_order "division_rel G" .. |
63832 | 576 |
from x'x have "x' .=\<^bsub>division_rel G\<^esub> x" by simp |
27701 | 577 |
also assume "x \<sqsubset>\<^bsub>division_rel G\<^esub> y" |
63832 | 578 |
finally show "x' \<sqsubset>\<^bsub>division_rel G\<^esub> y" by (simp add: carr) |
27701 | 579 |
qed |
580 |
||
581 |
lemma (in monoid) properfactor_cong_r [trans]: |
|
582 |
assumes pf: "properfactor G x y" |
|
583 |
and yy': "y \<sim> y'" |
|
584 |
and carr: "x \<in> carrier G" "y \<in> carrier G" "y' \<in> carrier G" |
|
585 |
shows "properfactor G x y'" |
|
63832 | 586 |
using pf |
587 |
unfolding properfactor_lless |
|
27701 | 588 |
proof - |
29237 | 589 |
interpret weak_partial_order "division_rel G" .. |
27701 | 590 |
assume "x \<sqsubset>\<^bsub>division_rel G\<^esub> y" |
591 |
also from yy' |
|
63832 | 592 |
have "y .=\<^bsub>division_rel G\<^esub> y'" by simp |
593 |
finally show "x \<sqsubset>\<^bsub>division_rel G\<^esub> y'" by (simp add: carr) |
|
27701 | 594 |
qed |
595 |
||
596 |
lemma (in monoid_cancel) properfactor_mult_lI [intro]: |
|
597 |
assumes ab: "properfactor G a b" |
|
68470
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
598 |
and carr: "a \<in> carrier G" "c \<in> carrier G" |
27701 | 599 |
shows "properfactor G (c \<otimes> a) (c \<otimes> b)" |
63832 | 600 |
using ab carr by (fastforce elim: properfactorE intro: properfactorI) |
27701 | 601 |
|
602 |
lemma (in monoid_cancel) properfactor_mult_l [simp]: |
|
603 |
assumes carr: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" |
|
604 |
shows "properfactor G (c \<otimes> a) (c \<otimes> b) = properfactor G a b" |
|
63832 | 605 |
using carr by (fastforce elim: properfactorE intro: properfactorI) |
27701 | 606 |
|
607 |
lemma (in comm_monoid_cancel) properfactor_mult_rI [intro]: |
|
608 |
assumes ab: "properfactor G a b" |
|
68470
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
609 |
and carr: "a \<in> carrier G" "c \<in> carrier G" |
27701 | 610 |
shows "properfactor G (a \<otimes> c) (b \<otimes> c)" |
63832 | 611 |
using ab carr by (fastforce elim: properfactorE intro: properfactorI) |
27701 | 612 |
|
613 |
lemma (in comm_monoid_cancel) properfactor_mult_r [simp]: |
|
614 |
assumes carr: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" |
|
615 |
shows "properfactor G (a \<otimes> c) (b \<otimes> c) = properfactor G a b" |
|
63832 | 616 |
using carr by (fastforce elim: properfactorE intro: properfactorI) |
27701 | 617 |
|
618 |
lemma (in monoid) properfactor_prod_r: |
|
619 |
assumes ab: "properfactor G a b" |
|
620 |
and carr[simp]: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" |
|
621 |
shows "properfactor G a (b \<otimes> c)" |
|
63832 | 622 |
by (intro properfactor_trans2[OF ab] divides_prod_r) simp_all |
27701 | 623 |
|
624 |
lemma (in comm_monoid) properfactor_prod_l: |
|
625 |
assumes ab: "properfactor G a b" |
|
626 |
and carr[simp]: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" |
|
627 |
shows "properfactor G a (c \<otimes> b)" |
|
63832 | 628 |
by (intro properfactor_trans2[OF ab] divides_prod_l) simp_all |
27701 | 629 |
|
630 |
||
61382 | 631 |
subsection \<open>Irreducible Elements and Primes\<close> |
632 |
||
633 |
subsubsection \<open>Irreducible elements\<close> |
|
27701 | 634 |
|
635 |
lemma irreducibleI: |
|
636 |
fixes G (structure) |
|
637 |
assumes "a \<notin> Units G" |
|
638 |
and "\<And>b. \<lbrakk>b \<in> carrier G; properfactor G b a\<rbrakk> \<Longrightarrow> b \<in> Units G" |
|
639 |
shows "irreducible G a" |
|
63832 | 640 |
using assms unfolding irreducible_def by blast |
27701 | 641 |
|
642 |
lemma irreducibleE: |
|
643 |
fixes G (structure) |
|
644 |
assumes irr: "irreducible G a" |
|
63832 | 645 |
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 | 646 |
shows "P" |
63832 | 647 |
using assms unfolding irreducible_def by blast |
27701 | 648 |
|
649 |
lemma irreducibleD: |
|
650 |
fixes G (structure) |
|
651 |
assumes irr: "irreducible G a" |
|
63832 | 652 |
and pf: "properfactor G b a" |
653 |
and bcarr: "b \<in> carrier G" |
|
27701 | 654 |
shows "b \<in> Units G" |
63832 | 655 |
using assms by (fast elim: irreducibleE) |
27701 | 656 |
|
657 |
lemma (in monoid_cancel) irreducible_cong [trans]: |
|
658 |
assumes irred: "irreducible G a" |
|
68470
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
659 |
and aa': "a \<sim> a'" "a \<in> carrier G" "a' \<in> carrier G" |
27701 | 660 |
shows "irreducible G a'" |
63832 | 661 |
using assms |
662 |
apply (elim irreducibleE, intro irreducibleI) |
|
663 |
apply simp_all |
|
664 |
apply (metis assms(2) assms(3) assoc_unit_l) |
|
68470
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
665 |
apply (metis aa' associated_sym properfactor_cong_r) |
63832 | 666 |
done |
27701 | 667 |
|
668 |
lemma (in monoid) irreducible_prod_rI: |
|
669 |
assumes airr: "irreducible G a" |
|
670 |
and bunit: "b \<in> Units G" |
|
671 |
and carr[simp]: "a \<in> carrier G" "b \<in> carrier G" |
|
672 |
shows "irreducible G (a \<otimes> b)" |
|
63832 | 673 |
using airr carr bunit |
68470
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
674 |
apply (elim irreducibleE, intro irreducibleI) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
675 |
using prod_unit_r apply blast |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
676 |
using associatedI2' properfactor_cong_r by auto |
27701 | 677 |
|
678 |
lemma (in comm_monoid) irreducible_prod_lI: |
|
679 |
assumes birr: "irreducible G b" |
|
680 |
and aunit: "a \<in> Units G" |
|
681 |
and carr [simp]: "a \<in> carrier G" "b \<in> carrier G" |
|
682 |
shows "irreducible G (a \<otimes> b)" |
|
68470
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
683 |
by (metis aunit birr carr irreducible_prod_rI m_comm) |
27701 | 684 |
|
685 |
lemma (in comm_monoid_cancel) irreducible_prodE [elim]: |
|
686 |
assumes irr: "irreducible G (a \<otimes> b)" |
|
687 |
and carr[simp]: "a \<in> carrier G" "b \<in> carrier G" |
|
688 |
and e1: "\<lbrakk>irreducible G a; b \<in> Units G\<rbrakk> \<Longrightarrow> P" |
|
689 |
and e2: "\<lbrakk>a \<in> Units G; irreducible G b\<rbrakk> \<Longrightarrow> P" |
|
63832 | 690 |
shows P |
691 |
using irr |
|
27701 | 692 |
proof (elim irreducibleE) |
693 |
assume abnunit: "a \<otimes> b \<notin> Units G" |
|
694 |
and isunit[rule_format]: "\<forall>ba. ba \<in> carrier G \<and> properfactor G ba (a \<otimes> b) \<longrightarrow> ba \<in> Units G" |
|
63832 | 695 |
show P |
27701 | 696 |
proof (cases "a \<in> Units G") |
63832 | 697 |
case aunit: True |
27701 | 698 |
have "irreducible G b" |
63846 | 699 |
proof (rule irreducibleI, rule notI) |
27701 | 700 |
assume "b \<in> Units G" |
701 |
with aunit have "(a \<otimes> b) \<in> Units G" by fast |
|
702 |
with abnunit show "False" .. |
|
703 |
next |
|
704 |
fix c |
|
705 |
assume ccarr: "c \<in> carrier G" |
|
706 |
and "properfactor G c b" |
|
63832 | 707 |
then have "properfactor G c (a \<otimes> b)" by (simp add: properfactor_prod_l[of c b a]) |
708 |
with ccarr show "c \<in> Units G" by (fast intro: isunit) |
|
27701 | 709 |
qed |
63832 | 710 |
with aunit show "P" by (rule e2) |
27701 | 711 |
next |
63832 | 712 |
case anunit: False |
27701 | 713 |
with carr have "properfactor G b (b \<otimes> a)" by (fast intro: properfactorI3) |
63832 | 714 |
then have bf: "properfactor G b (a \<otimes> b)" by (subst m_comm[of a b], simp+) |
715 |
then have bunit: "b \<in> Units G" by (intro isunit, simp) |
|
27701 | 716 |
|
717 |
have "irreducible G a" |
|
63846 | 718 |
proof (rule irreducibleI, rule notI) |
27701 | 719 |
assume "a \<in> Units G" |
720 |
with bunit have "(a \<otimes> b) \<in> Units G" by fast |
|
721 |
with abnunit show "False" .. |
|
722 |
next |
|
723 |
fix c |
|
724 |
assume ccarr: "c \<in> carrier G" |
|
725 |
and "properfactor G c a" |
|
63832 | 726 |
then have "properfactor G c (a \<otimes> b)" |
727 |
by (simp add: properfactor_prod_r[of c a b]) |
|
728 |
with ccarr show "c \<in> Units G" by (fast intro: isunit) |
|
27701 | 729 |
qed |
730 |
from this bunit show "P" by (rule e1) |
|
731 |
qed |
|
732 |
qed |
|
733 |
||
734 |
||
61382 | 735 |
subsubsection \<open>Prime elements\<close> |
27701 | 736 |
|
737 |
lemma primeI: |
|
738 |
fixes G (structure) |
|
739 |
assumes "p \<notin> Units G" |
|
740 |
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" |
|
741 |
shows "prime G p" |
|
63832 | 742 |
using assms unfolding prime_def by blast |
27701 | 743 |
|
744 |
lemma primeE: |
|
745 |
fixes G (structure) |
|
746 |
assumes pprime: "prime G p" |
|
747 |
and e: "\<lbrakk>p \<notin> Units G; \<forall>a\<in>carrier G. \<forall>b\<in>carrier G. |
|
63832 | 748 |
p divides a \<otimes> b \<longrightarrow> p divides a \<or> p divides b\<rbrakk> \<Longrightarrow> P" |
27701 | 749 |
shows "P" |
63832 | 750 |
using pprime unfolding prime_def by (blast dest: e) |
27701 | 751 |
|
752 |
lemma (in comm_monoid_cancel) prime_divides: |
|
753 |
assumes carr: "a \<in> carrier G" "b \<in> carrier G" |
|
754 |
and pprime: "prime G p" |
|
755 |
and pdvd: "p divides a \<otimes> b" |
|
756 |
shows "p divides a \<or> p divides b" |
|
63832 | 757 |
using assms by (blast elim: primeE) |
27701 | 758 |
|
759 |
lemma (in monoid_cancel) prime_cong [trans]: |
|
760 |
assumes pprime: "prime G p" |
|
68470
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
761 |
and pp': "p \<sim> p'" "p \<in> carrier G" "p' \<in> carrier G" |
27701 | 762 |
shows "prime G p'" |
63832 | 763 |
using pprime |
764 |
apply (elim primeE, intro primeI) |
|
765 |
apply (metis assms(2) assms(3) assoc_unit_l) |
|
68470
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
766 |
apply (metis pp' associated_sym divides_cong_l) |
63832 | 767 |
done |
768 |
||
27701 | 769 |
|
61382 | 770 |
subsection \<open>Factorization and Factorial Monoids\<close> |
771 |
||
772 |
subsubsection \<open>Function definitions\<close> |
|
27701 | 773 |
|
63832 | 774 |
definition factors :: "[_, 'a list, 'a] \<Rightarrow> bool" |
67399 | 775 |
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 | 776 |
|
63832 | 777 |
definition wfactors ::"[_, 'a list, 'a] \<Rightarrow> bool" |
67399 | 778 |
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 | 779 |
|
63832 | 780 |
abbreviation list_assoc :: "('a,_) monoid_scheme \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> bool" (infix "[\<sim>]\<index>" 44) |
67399 | 781 |
where "list_assoc G \<equiv> list_all2 (\<sim>\<^bsub>G\<^esub>)" |
63832 | 782 |
|
783 |
definition essentially_equal :: "[_, 'a list, 'a list] \<Rightarrow> bool" |
|
35848
5443079512ea
slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents:
35847
diff
changeset
|
784 |
where "essentially_equal G fs1 fs2 \<longleftrightarrow> (\<exists>fs1'. fs1 <~~> fs1' \<and> fs1' [\<sim>]\<^bsub>G\<^esub> fs2)" |
27701 | 785 |
|
786 |
||
787 |
locale factorial_monoid = comm_monoid_cancel + |
|
63832 | 788 |
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" |
789 |
and factors_unique: |
|
790 |
"\<lbrakk>factors G fs a; factors G fs' a; a \<in> carrier G; a \<notin> Units G; |
|
791 |
set fs \<subseteq> carrier G; set fs' \<subseteq> carrier G\<rbrakk> \<Longrightarrow> essentially_equal G fs fs'" |
|
27701 | 792 |
|
793 |
||
61382 | 794 |
subsubsection \<open>Comparing lists of elements\<close> |
795 |
||
796 |
text \<open>Association on lists\<close> |
|
27701 | 797 |
|
798 |
lemma (in monoid) listassoc_refl [simp, intro]: |
|
799 |
assumes "set as \<subseteq> carrier G" |
|
800 |
shows "as [\<sim>] as" |
|
63832 | 801 |
using assms by (induct as) simp_all |
27701 | 802 |
|
803 |
lemma (in monoid) listassoc_sym [sym]: |
|
804 |
assumes "as [\<sim>] bs" |
|
63832 | 805 |
and "set as \<subseteq> carrier G" |
806 |
and "set bs \<subseteq> carrier G" |
|
27701 | 807 |
shows "bs [\<sim>] as" |
63832 | 808 |
using assms |
68470
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
809 |
proof (induction as arbitrary: bs) |
27701 | 810 |
case Cons |
63832 | 811 |
then show ?case |
68470
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
812 |
by (induction bs) (use associated_sym in auto) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
813 |
qed auto |
27701 | 814 |
|
815 |
lemma (in monoid) listassoc_trans [trans]: |
|
816 |
assumes "as [\<sim>] bs" and "bs [\<sim>] cs" |
|
817 |
and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G" and "set cs \<subseteq> carrier G" |
|
818 |
shows "as [\<sim>] cs" |
|
63832 | 819 |
using assms |
820 |
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:
68399
diff
changeset
|
821 |
by (metis (mono_tags, lifting) associated_trans nth_mem subsetCE) |
27701 | 822 |
|
823 |
lemma (in monoid_cancel) irrlist_listassoc_cong: |
|
824 |
assumes "\<forall>a\<in>set as. irreducible G a" |
|
825 |
and "as [\<sim>] bs" |
|
826 |
and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G" |
|
827 |
shows "\<forall>a\<in>set bs. irreducible G a" |
|
63832 | 828 |
using assms |
829 |
apply (clarsimp simp add: list_all2_conv_all_nth set_conv_nth) |
|
830 |
apply (blast intro: irreducible_cong) |
|
831 |
done |
|
27701 | 832 |
|
833 |
||
61382 | 834 |
text \<open>Permutations\<close> |
27701 | 835 |
|
836 |
lemma perm_map [intro]: |
|
837 |
assumes p: "a <~~> b" |
|
838 |
shows "map f a <~~> map f b" |
|
63832 | 839 |
using p by induct auto |
27701 | 840 |
|
841 |
lemma perm_map_switch: |
|
842 |
assumes m: "map f a = map f b" and p: "b <~~> c" |
|
843 |
shows "\<exists>d. a <~~> d \<and> map f d = map f c" |
|
63832 | 844 |
using p m by (induct arbitrary: a) (simp, force, force, blast) |
27701 | 845 |
|
846 |
lemma (in monoid) perm_assoc_switch: |
|
63832 | 847 |
assumes a:"as [\<sim>] bs" and p: "bs <~~> cs" |
848 |
shows "\<exists>bs'. as <~~> bs' \<and> bs' [\<sim>] cs" |
|
849 |
using p a |
|
68470
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
850 |
proof (induction bs cs arbitrary: as) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
851 |
case (swap y x l) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
852 |
then show ?case |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
853 |
by (metis (no_types, hide_lams) list_all2_Cons2 perm.swap) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
854 |
next |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
855 |
case (Cons xs ys z) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
856 |
then show ?case |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
857 |
by (metis list_all2_Cons2 perm.Cons) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
858 |
next |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
859 |
case (trans xs ys zs) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
860 |
then show ?case |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
861 |
by (meson perm.trans) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
862 |
qed auto |
27701 | 863 |
|
864 |
lemma (in monoid) perm_assoc_switch_r: |
|
63832 | 865 |
assumes p: "as <~~> bs" and a:"bs [\<sim>] cs" |
866 |
shows "\<exists>bs'. as [\<sim>] bs' \<and> bs' <~~> cs" |
|
867 |
using p a |
|
68470
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
868 |
proof (induction as bs arbitrary: cs) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
869 |
case Nil |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
870 |
then show ?case |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
871 |
by auto |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
872 |
next |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
873 |
case (swap y x l) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
874 |
then show ?case |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
875 |
by (metis (no_types, hide_lams) list_all2_Cons1 perm.swap) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
876 |
next |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
877 |
case (Cons xs ys z) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
878 |
then show ?case |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
879 |
by (metis list_all2_Cons1 perm.Cons) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
880 |
next |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
881 |
case (trans xs ys zs) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
882 |
then show ?case |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
883 |
by (blast intro: elim: ) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
884 |
qed |
27701 | 885 |
|
886 |
declare perm_sym [sym] |
|
887 |
||
888 |
lemma perm_setP: |
|
889 |
assumes perm: "as <~~> bs" |
|
890 |
and as: "P (set as)" |
|
891 |
shows "P (set bs)" |
|
892 |
proof - |
|
63832 | 893 |
from perm have "mset as = mset bs" |
894 |
by (simp add: mset_eq_perm) |
|
895 |
then have "set as = set bs" |
|
896 |
by (rule mset_eq_setD) |
|
897 |
with as show "P (set bs)" |
|
898 |
by simp |
|
27701 | 899 |
qed |
900 |
||
63832 | 901 |
lemmas (in monoid) perm_closed = perm_setP[of _ _ "\<lambda>as. as \<subseteq> carrier G"] |
902 |
||
903 |
lemmas (in monoid) irrlist_perm_cong = perm_setP[of _ _ "\<lambda>as. \<forall>a\<in>as. irreducible G a"] |
|
27701 | 904 |
|
905 |
||
61382 | 906 |
text \<open>Essentially equal factorizations\<close> |
27701 | 907 |
|
908 |
lemma (in monoid) essentially_equalI: |
|
909 |
assumes ex: "fs1 <~~> fs1'" "fs1' [\<sim>] fs2" |
|
910 |
shows "essentially_equal G fs1 fs2" |
|
63832 | 911 |
using ex unfolding essentially_equal_def by fast |
27701 | 912 |
|
913 |
lemma (in monoid) essentially_equalE: |
|
914 |
assumes ee: "essentially_equal G fs1 fs2" |
|
915 |
and e: "\<And>fs1'. \<lbrakk>fs1 <~~> fs1'; fs1' [\<sim>] fs2\<rbrakk> \<Longrightarrow> P" |
|
916 |
shows "P" |
|
63832 | 917 |
using ee unfolding essentially_equal_def by (fast intro: e) |
27701 | 918 |
|
919 |
lemma (in monoid) ee_refl [simp,intro]: |
|
920 |
assumes carr: "set as \<subseteq> carrier G" |
|
921 |
shows "essentially_equal G as as" |
|
63832 | 922 |
using carr by (fast intro: essentially_equalI) |
27701 | 923 |
|
924 |
lemma (in monoid) ee_sym [sym]: |
|
925 |
assumes ee: "essentially_equal G as bs" |
|
926 |
and carr: "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" |
|
927 |
shows "essentially_equal G bs as" |
|
63832 | 928 |
using ee |
27701 | 929 |
proof (elim essentially_equalE) |
930 |
fix fs |
|
931 |
assume "as <~~> fs" "fs [\<sim>] bs" |
|
63847 | 932 |
from perm_assoc_switch_r [OF this] obtain fs' where a: "as [\<sim>] fs'" and p: "fs' <~~> bs" |
933 |
by blast |
|
27701 | 934 |
from p have "bs <~~> fs'" by (rule perm_sym) |
63832 | 935 |
with a[symmetric] carr show ?thesis |
936 |
by (iprover intro: essentially_equalI perm_closed) |
|
27701 | 937 |
qed |
938 |
||
939 |
lemma (in monoid) ee_trans [trans]: |
|
940 |
assumes ab: "essentially_equal G as bs" and bc: "essentially_equal G bs cs" |
|
63832 | 941 |
and ascarr: "set as \<subseteq> carrier G" |
27701 | 942 |
and bscarr: "set bs \<subseteq> carrier G" |
943 |
and cscarr: "set cs \<subseteq> carrier G" |
|
944 |
shows "essentially_equal G as cs" |
|
63832 | 945 |
using ab bc |
27701 | 946 |
proof (elim essentially_equalE) |
947 |
fix abs bcs |
|
63847 | 948 |
assume "abs [\<sim>] bs" and pb: "bs <~~> bcs" |
949 |
from perm_assoc_switch [OF this] obtain bs' where p: "abs <~~> bs'" and a: "bs' [\<sim>] bcs" |
|
950 |
by blast |
|
27701 | 951 |
assume "as <~~> abs" |
63832 | 952 |
with p have pp: "as <~~> bs'" by fast |
27701 | 953 |
from pp ascarr have c1: "set bs' \<subseteq> carrier G" by (rule perm_closed) |
954 |
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:
68399
diff
changeset
|
955 |
assume "bcs [\<sim>] cs" |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
956 |
then have "bs' [\<sim>] cs" |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
957 |
using a c1 c2 cscarr listassoc_trans by blast |
63832 | 958 |
with pp show ?thesis |
959 |
by (rule essentially_equalI) |
|
27701 | 960 |
qed |
961 |
||
962 |
||
61382 | 963 |
subsubsection \<open>Properties of lists of elements\<close> |
964 |
||
965 |
text \<open>Multiplication of factors in a list\<close> |
|
27701 | 966 |
|
967 |
lemma (in monoid) multlist_closed [simp, intro]: |
|
968 |
assumes ascarr: "set fs \<subseteq> carrier G" |
|
67399 | 969 |
shows "foldr (\<otimes>) fs \<one> \<in> carrier G" |
63832 | 970 |
using ascarr by (induct fs) simp_all |
27701 | 971 |
|
68470
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
972 |
lemma (in comm_monoid) multlist_dividesI: |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
973 |
assumes "f \<in> set fs" and "set fs \<subseteq> carrier G" |
67399 | 974 |
shows "f divides (foldr (\<otimes>) fs \<one>)" |
63832 | 975 |
using assms |
68470
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
976 |
proof (induction fs) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
977 |
case (Cons a fs) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
978 |
then have f: "f \<in> carrier G" |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
979 |
by blast |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
980 |
show ?case |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
981 |
proof (cases "f = a") |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
982 |
case True |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
983 |
then show ?thesis |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
984 |
using Cons.prems by auto |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
985 |
next |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
986 |
case False |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
987 |
with Cons show ?thesis |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
988 |
by clarsimp (metis f divides_prod_l multlist_closed) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
989 |
qed |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
990 |
qed auto |
27701 | 991 |
|
992 |
lemma (in comm_monoid_cancel) multlist_listassoc_cong: |
|
993 |
assumes "fs [\<sim>] fs'" |
|
994 |
and "set fs \<subseteq> carrier G" and "set fs' \<subseteq> carrier G" |
|
67399 | 995 |
shows "foldr (\<otimes>) fs \<one> \<sim> foldr (\<otimes>) fs' \<one>" |
63832 | 996 |
using assms |
68470
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
997 |
proof (induct fs arbitrary: fs') |
27701 | 998 |
case (Cons a as fs') |
63832 | 999 |
then show ?case |
68470
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1000 |
proof (induction fs') |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1001 |
case (Cons b bs) |
67399 | 1002 |
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:
68399
diff
changeset
|
1003 |
by (simp add: mult_cong_l) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1004 |
then have "foldr (\<otimes>) as \<one> \<sim> foldr (\<otimes>) bs \<one>" |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1005 |
using Cons by auto |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1006 |
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:
68399
diff
changeset
|
1007 |
by (simp add: mult_cong_r) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1008 |
then show ?case |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1009 |
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:
68399
diff
changeset
|
1010 |
qed auto |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1011 |
qed auto |
27701 | 1012 |
|
1013 |
lemma (in comm_monoid) multlist_perm_cong: |
|
1014 |
assumes prm: "as <~~> bs" |
|
1015 |
and ascarr: "set as \<subseteq> carrier G" |
|
67399 | 1016 |
shows "foldr (\<otimes>) as \<one> = foldr (\<otimes>) bs \<one>" |
63832 | 1017 |
using prm ascarr |
1018 |
apply (induct, simp, clarsimp simp add: m_ac, clarsimp) |
|
27701 | 1019 |
proof clarsimp |
1020 |
fix xs ys zs |
|
1021 |
assume "xs <~~> ys" "set xs \<subseteq> carrier G" |
|
63832 | 1022 |
then have "set ys \<subseteq> carrier G" by (rule perm_closed) |
67399 | 1023 |
moreover assume "set ys \<subseteq> carrier G \<Longrightarrow> foldr (\<otimes>) ys \<one> = foldr (\<otimes>) zs \<one>" |
1024 |
ultimately show "foldr (\<otimes>) ys \<one> = foldr (\<otimes>) zs \<one>" by simp |
|
27701 | 1025 |
qed |
1026 |
||
1027 |
lemma (in comm_monoid_cancel) multlist_ee_cong: |
|
1028 |
assumes "essentially_equal G fs fs'" |
|
1029 |
and "set fs \<subseteq> carrier G" and "set fs' \<subseteq> carrier G" |
|
67399 | 1030 |
shows "foldr (\<otimes>) fs \<one> \<sim> foldr (\<otimes>) fs' \<one>" |
63832 | 1031 |
using assms |
1032 |
apply (elim essentially_equalE) |
|
1033 |
apply (simp add: multlist_perm_cong multlist_listassoc_cong perm_closed) |
|
1034 |
done |
|
27701 | 1035 |
|
1036 |
||
61382 | 1037 |
subsubsection \<open>Factorization in irreducible elements\<close> |
27701 | 1038 |
|
1039 |
lemma wfactorsI: |
|
28599 | 1040 |
fixes G (structure) |
27701 | 1041 |
assumes "\<forall>f\<in>set fs. irreducible G f" |
67399 | 1042 |
and "foldr (\<otimes>) fs \<one> \<sim> a" |
27701 | 1043 |
shows "wfactors G fs a" |
63832 | 1044 |
using assms unfolding wfactors_def by simp |
27701 | 1045 |
|
1046 |
lemma wfactorsE: |
|
28599 | 1047 |
fixes G (structure) |
27701 | 1048 |
assumes wf: "wfactors G fs a" |
67399 | 1049 |
and e: "\<lbrakk>\<forall>f\<in>set fs. irreducible G f; foldr (\<otimes>) fs \<one> \<sim> a\<rbrakk> \<Longrightarrow> P" |
27701 | 1050 |
shows "P" |
63832 | 1051 |
using wf unfolding wfactors_def by (fast dest: e) |
27701 | 1052 |
|
1053 |
lemma (in monoid) factorsI: |
|
1054 |
assumes "\<forall>f\<in>set fs. irreducible G f" |
|
67399 | 1055 |
and "foldr (\<otimes>) fs \<one> = a" |
27701 | 1056 |
shows "factors G fs a" |
63832 | 1057 |
using assms unfolding factors_def by simp |
27701 | 1058 |
|
1059 |
lemma factorsE: |
|
28599 | 1060 |
fixes G (structure) |
27701 | 1061 |
assumes f: "factors G fs a" |
67399 | 1062 |
and e: "\<lbrakk>\<forall>f\<in>set fs. irreducible G f; foldr (\<otimes>) fs \<one> = a\<rbrakk> \<Longrightarrow> P" |
27701 | 1063 |
shows "P" |
63832 | 1064 |
using f unfolding factors_def by (simp add: e) |
27701 | 1065 |
|
1066 |
lemma (in monoid) factors_wfactors: |
|
1067 |
assumes "factors G as a" and "set as \<subseteq> carrier G" |
|
1068 |
shows "wfactors G as a" |
|
63832 | 1069 |
using assms by (blast elim: factorsE intro: wfactorsI) |
27701 | 1070 |
|
1071 |
lemma (in monoid) wfactors_factors: |
|
1072 |
assumes "wfactors G as a" and "set as \<subseteq> carrier G" |
|
1073 |
shows "\<exists>a'. factors G as a' \<and> a' \<sim> a" |
|
63832 | 1074 |
using assms by (blast elim: wfactorsE intro: factorsI) |
27701 | 1075 |
|
1076 |
lemma (in monoid) factors_closed [dest]: |
|
1077 |
assumes "factors G fs a" and "set fs \<subseteq> carrier G" |
|
1078 |
shows "a \<in> carrier G" |
|
63832 | 1079 |
using assms by (elim factorsE, clarsimp) |
27701 | 1080 |
|
1081 |
lemma (in monoid) nunit_factors: |
|
1082 |
assumes anunit: "a \<notin> Units G" |
|
1083 |
and fs: "factors G as a" |
|
1084 |
shows "length as > 0" |
|
46129 | 1085 |
proof - |
1086 |
from anunit Units_one_closed have "a \<noteq> \<one>" by auto |
|
1087 |
with fs show ?thesis by (auto elim: factorsE) |
|
1088 |
qed |
|
27701 | 1089 |
|
1090 |
lemma (in monoid) unit_wfactors [simp]: |
|
1091 |
assumes aunit: "a \<in> Units G" |
|
1092 |
shows "wfactors G [] a" |
|
63832 | 1093 |
using aunit by (intro wfactorsI) (simp, simp add: Units_assoc) |
27701 | 1094 |
|
1095 |
lemma (in comm_monoid_cancel) unit_wfactors_empty: |
|
1096 |
assumes aunit: "a \<in> Units G" |
|
1097 |
and wf: "wfactors G fs a" |
|
1098 |
and carr[simp]: "set fs \<subseteq> carrier G" |
|
1099 |
shows "fs = []" |
|
63846 | 1100 |
proof (cases fs) |
1101 |
case Nil |
|
1102 |
then show ?thesis . |
|
1103 |
next |
|
1104 |
case fs: (Cons f fs') |
|
63832 | 1105 |
from carr have fcarr[simp]: "f \<in> carrier G" and carr'[simp]: "set fs' \<subseteq> carrier G" |
1106 |
by (simp_all add: fs) |
|
1107 |
||
1108 |
from fs wf have "irreducible G f" by (simp add: wfactors_def) |
|
1109 |
then have fnunit: "f \<notin> Units G" by (fast elim: irreducibleE) |
|
1110 |
||
67399 | 1111 |
from fs wf have a: "f \<otimes> foldr (\<otimes>) fs' \<one> \<sim> a" by (simp add: wfactors_def) |
27701 | 1112 |
|
1113 |
note aunit |
|
1114 |
also from fs wf |
|
67399 | 1115 |
have a: "f \<otimes> foldr (\<otimes>) fs' \<one> \<sim> a" by (simp add: wfactors_def) |
1116 |
have "a \<sim> f \<otimes> foldr (\<otimes>) fs' \<one>" |
|
63832 | 1117 |
by (simp add: Units_closed[OF aunit] a[symmetric]) |
67399 | 1118 |
finally have "f \<otimes> foldr (\<otimes>) fs' \<one> \<in> Units G" by simp |
63832 | 1119 |
then have "f \<in> Units G" by (intro unit_factor[of f], simp+) |
63846 | 1120 |
with fnunit show ?thesis by contradiction |
27701 | 1121 |
qed |
1122 |
||
1123 |
||
61382 | 1124 |
text \<open>Comparing wfactors\<close> |
27701 | 1125 |
|
1126 |
lemma (in comm_monoid_cancel) wfactors_listassoc_cong_l: |
|
1127 |
assumes fact: "wfactors G fs a" |
|
1128 |
and asc: "fs [\<sim>] fs'" |
|
1129 |
and carr: "a \<in> carrier G" "set fs \<subseteq> carrier G" "set fs' \<subseteq> carrier G" |
|
1130 |
shows "wfactors G fs' a" |
|
68470
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1131 |
proof - |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1132 |
{ 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:
68399
diff
changeset
|
1133 |
by (simp add: multlist_listassoc_cong carr) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1134 |
also assume "foldr (\<otimes>) fs \<one> \<sim> a" |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1135 |
finally have "foldr (\<otimes>) fs' \<one> \<sim> a" by (simp add: carr) } |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1136 |
then show ?thesis |
63832 | 1137 |
using fact |
68470
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1138 |
by (meson asc carr(2) carr(3) irrlist_listassoc_cong wfactors_def) |
27701 | 1139 |
qed |
1140 |
||
1141 |
lemma (in comm_monoid) wfactors_perm_cong_l: |
|
1142 |
assumes "wfactors G fs a" |
|
1143 |
and "fs <~~> fs'" |
|
1144 |
and "set fs \<subseteq> carrier G" |
|
1145 |
shows "wfactors G fs' a" |
|
68470
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1146 |
using assms irrlist_perm_cong multlist_perm_cong wfactors_def by fastforce |
27701 | 1147 |
|
1148 |
lemma (in comm_monoid_cancel) wfactors_ee_cong_l [trans]: |
|
1149 |
assumes ee: "essentially_equal G as bs" |
|
1150 |
and bfs: "wfactors G bs b" |
|
1151 |
and carr: "b \<in> carrier G" "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" |
|
1152 |
shows "wfactors G as b" |
|
63832 | 1153 |
using ee |
27701 | 1154 |
proof (elim essentially_equalE) |
1155 |
fix fs |
|
1156 |
assume prm: "as <~~> fs" |
|
63832 | 1157 |
with carr have fscarr: "set fs \<subseteq> carrier G" by (simp add: perm_closed) |
27701 | 1158 |
|
1159 |
note bfs |
|
1160 |
also assume [symmetric]: "fs [\<sim>] bs" |
|
1161 |
also (wfactors_listassoc_cong_l) |
|
63832 | 1162 |
note prm[symmetric] |
27701 | 1163 |
finally (wfactors_perm_cong_l) |
63832 | 1164 |
show "wfactors G as b" by (simp add: carr fscarr) |
27701 | 1165 |
qed |
1166 |
||
1167 |
lemma (in monoid) wfactors_cong_r [trans]: |
|
1168 |
assumes fac: "wfactors G fs a" and aa': "a \<sim> a'" |
|
1169 |
and carr[simp]: "a \<in> carrier G" "a' \<in> carrier G" "set fs \<subseteq> carrier G" |
|
1170 |
shows "wfactors G fs a'" |
|
63832 | 1171 |
using fac |
27701 | 1172 |
proof (elim wfactorsE, intro wfactorsI) |
67399 | 1173 |
assume "foldr (\<otimes>) fs \<one> \<sim> a" also note aa' |
1174 |
finally show "foldr (\<otimes>) fs \<one> \<sim> a'" by simp |
|
27701 | 1175 |
qed |
1176 |
||
1177 |
||
61382 | 1178 |
subsubsection \<open>Essentially equal factorizations\<close> |
27701 | 1179 |
|
1180 |
lemma (in comm_monoid_cancel) unitfactor_ee: |
|
1181 |
assumes uunit: "u \<in> Units G" |
|
1182 |
and carr: "set as \<subseteq> carrier G" |
|
63832 | 1183 |
shows "essentially_equal G (as[0 := (as!0 \<otimes> u)]) as" |
1184 |
(is "essentially_equal G ?as' as") |
|
68470
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1185 |
proof - |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1186 |
have "as[0 := as ! 0 \<otimes> u] [\<sim>] as" |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1187 |
proof (cases as) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1188 |
case (Cons a as') |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1189 |
then show ?thesis |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1190 |
using associatedI2 carr uunit by auto |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1191 |
qed auto |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1192 |
then show ?thesis |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1193 |
using essentially_equal_def by blast |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1194 |
qed |
27701 | 1195 |
|
1196 |
lemma (in comm_monoid_cancel) factors_cong_unit: |
|
68470
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1197 |
assumes u: "u \<in> Units G" |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1198 |
and a: "a \<notin> Units G" |
27701 | 1199 |
and afs: "factors G as a" |
1200 |
and ascarr: "set as \<subseteq> carrier G" |
|
63832 | 1201 |
shows "factors G (as[0 := (as!0 \<otimes> u)]) (a \<otimes> u)" |
1202 |
(is "factors G ?as' ?a'") |
|
68470
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1203 |
proof (cases as) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1204 |
case Nil |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1205 |
then show ?thesis |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1206 |
using afs a nunit_factors by auto |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1207 |
next |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1208 |
case (Cons b bs) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1209 |
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:
68399
diff
changeset
|
1210 |
using afs by (auto simp: factors_def) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1211 |
show ?thesis |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1212 |
proof (intro factorsI) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1213 |
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:
68399
diff
changeset
|
1214 |
using Cons u ascarr * by (auto simp add: m_ac Units_closed) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1215 |
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:
68399
diff
changeset
|
1216 |
using Cons u ascarr * by (force intro: irreducible_prod_rI) |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1217 |
qed |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1218 |
qed |
27701 | 1219 |
|
1220 |
lemma (in comm_monoid) perm_wfactorsD: |
|
1221 |
assumes prm: "as <~~> bs" |
|
63832 | 1222 |
and afs: "wfactors G as a" |
1223 |
and bfs: "wfactors G bs b" |
|
27701 | 1224 |
and [simp]: "a \<in> carrier G" "b \<in> carrier G" |
63832 | 1225 |
and ascarr [simp]: "set as \<subseteq> carrier G" |
27701 | 1226 |
shows "a \<sim> b" |
63832 | 1227 |
using afs bfs |
27701 | 1228 |
proof (elim wfactorsE) |
1229 |
from prm have [simp]: "set bs \<subseteq> carrier G" by (simp add: perm_closed) |
|
67399 | 1230 |
assume "foldr (\<otimes>) as \<one> \<sim> a" |
68470
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1231 |
then have "a \<sim> foldr (\<otimes>) as \<one>" |
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1232 |
by (simp add: associated_sym) |
27701 | 1233 |
also from prm |
67399 | 1234 |
have "foldr (\<otimes>) as \<one> = foldr (\<otimes>) bs \<one>" by (rule multlist_perm_cong, simp) |
1235 |
also assume "foldr (\<otimes>) bs \<one> \<sim> b" |
|
63832 | 1236 |
finally show "a \<sim> b" by simp |
27701 | 1237 |
qed |
1238 |
||
1239 |
lemma (in comm_monoid_cancel) listassoc_wfactorsD: |
|
1240 |
assumes assoc: "as [\<sim>] bs" |
|
63832 | 1241 |
and afs: "wfactors G as a" |
1242 |
and bfs: "wfactors G bs b" |
|
27701 | 1243 |
and [simp]: "a \<in> carrier G" "b \<in> carrier G" |
1244 |
and [simp]: "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" |
|
1245 |
shows "a \<sim> b" |
|
63832 | 1246 |
using afs bfs |
27701 | 1247 |
proof (elim wfactorsE) |
67399 | 1248 |
assume "foldr (\<otimes>) as \<one> \<sim> a" |
68470
7ddcce75c3ee
Partial de-apply of Divisibility
paulson <lp15@cam.ac.uk>
parents:
68399
diff
changeset
|
1249 |
then have "a \<sim> foldr (\<otimes>) as \<one>" by (simp add: associated_sym) |
27701 | 1250 |
also from assoc |
67399 | 1251 |
have "foldr (\<otimes>) as \<one> \<sim> foldr (\<otimes>) bs \<one>" by (rule multlist_listassoc_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) ee_wfactorsD: |
|
1257 |
assumes ee: "essentially_equal G as bs" |
|
1258 |
and afs: "wfactors G as a" and bfs: "wfactors G bs b" |
|
1259 |
and [simp]: "a \<in> carrier G" "b \<in> carrier G" |
|
1260 |
and ascarr[simp]: "set as \<subseteq> carrier G" and bscarr[simp]: "set bs \<subseteq> carrier G" |
|
1261 |
shows "a \<sim> b" |
|
63832 | 1262 |
using ee |
27701 | 1263 |
proof (elim essentially_equalE) |
1264 |
fix fs |
|
1265 |
assume prm: "as <~~> fs" |
|
63832 | 1266 |
then have as'carr[simp]: "set fs \<subseteq> carrier G" |
1267 |
by (simp add: perm_closed) |
|
1268 |
from afs prm have afs': "wfactors G fs a" |
|
1269 |
by (rule wfactors_perm_cong_l) simp |
|
27701 | 1270 |
assume "fs [\<sim>] bs" |
63832 | 1271 |
from this afs' bfs show "a \<sim> b" |
1272 |
by (rule listassoc_wfactorsD) simp_all |
|
27701 | 1273 |
qed |
1274 |
||
1275 |
lemma (in comm_monoid_cancel) ee_factorsD: |
|
1276 |
assumes ee: "essentially_equal G as bs" |
|
1277 |
and afs: "factors G as a" and bfs:"factors G bs b" |
|
1278 |
and "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" |
|
1279 |
shows "a \<sim> b" |
|
63832 | 1280 |
using assms by (blast intro: factors_wfactors dest: ee_wfactorsD) |
27701 | 1281 |
|
1282 |
lemma (in factorial_monoid) ee_factorsI: |
|
1283 |
assumes ab: "a \<sim> b" |
|
1284 |
and afs: "factors G as a" and anunit: "a \<notin> Units G" |
|
1285 |
and bfs: "factors G bs b" and bnunit: "b \<notin> Units G" |
|
1286 |
and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G" |
|
1287 |
shows "essentially_equal G as bs" |
|
1288 |
proof - |
|
1289 |
note carr[simp] = factors_closed[OF afs ascarr] ascarr[THEN subsetD] |
|
63832 | 1290 |
factors_closed[OF bfs bscarr] bscarr[THEN subsetD] |
1291 |
||
63847 | 1292 |
from ab carr obtain u where uunit: "u \<in> Units G" and a: "a = b \<otimes> u" |
1293 |
by (elim associatedE2) |
|
63832 | 1294 |
|
1295 |
from uunit bscarr have ee: "essentially_equal G (bs[0 := (bs!0 \<otimes> u)]) bs" |
|
1296 |
(is "essentially_equal G ?bs' bs") |
|
1297 |
by (rule unitfactor_ee) |
|
1298 |
||
1299 |
from bscarr uunit have bs'carr: "set ?bs' \<subseteq> carrier G" |
|
1300 |
by (cases bs) (simp_all add: Units_closed) |
|
1301 |
||
1302 |
from uunit bnunit bfs bscarr have fac: "factors G ?bs' (b \<otimes> u)" |
|
1303 |
by (rule factors_cong_unit) |
|
27701 | 1304 |
|
1305 |
from afs fac[simplified a[symmetric]] ascarr bs'carr anunit |
|
63832 | 1306 |
have "essentially_equal G as ?bs'" |
1307 |
by (blast intro: factors_unique) |
|
27701 | 1308 |
also note ee |
63832 | 1309 |
finally show "essentially_equal G as bs" |
1310 |
by (simp add: ascarr bscarr bs'carr) |
|
27701 | 1311 |
qed |
1312 |
||
1313 |
lemma (in factorial_monoid) ee_wfactorsI: |
|
1314 |
assumes asc: "a \<sim> b" |
|
1315 |
and asf: "wfactors G as a" and bsf: "wfactors G bs b" |
|
1316 |
and acarr[simp]: "a \<in> carrier G" and bcarr[simp]: "b \<in> carrier G" |
|
1317 |
and ascarr[simp]: "set as \<subseteq> carrier G" and bscarr[simp]: "set bs \<subseteq> carrier G" |
|
1318 |
shows "essentially_equal G as bs" |
|
63832 | 1319 |
using assms |
27701 | 1320 |
proof (cases "a \<in> Units G") |
63832 | 1321 |
case aunit: True |
27701 | 1322 |
also note asc |
1323 |
finally have bunit: "b \<in> Units G" by simp |
|
1324 |
||
63832 | 1325 |
from aunit asf ascarr have e: "as = []" |
1326 |
by (rule unit_wfactors_empty) |
|
1327 |
from bunit bsf bscarr have e': "bs = []" |
|
1328 |
by (rule unit_wfactors_empty) |
|
27701 | 1329 |
|
1330 |
have "essentially_equal G [] []" |
|
63832 | 1331 |
by (fast intro: essentially_equalI) |
1332 |
then show ?thesis |
|
1333 |
by (simp add: e e') |
|
27701 | 1334 |
next |
63832 | 1335 |
case anunit: False |
27701 | 1336 |
have bnunit: "b \<notin> Units G" |
1337 |
proof clarify |
|
1338 |
assume "b \<in> Units G" |
|
1339 |
also note asc[symmetric] |
|
1340 |
finally have "a \<in> Units G" by simp |
|
63832 | 1341 |
with anunit show False .. |
27701 | 1342 |
qed |
1343 |
||
63847 | 1344 |
from wfactors_factors[OF asf ascarr] obtain a' where fa': "factors G as a'" and a': "a' \<sim> a" |
1345 |
by blast |
|
63832 | 1346 |
from fa' ascarr have a'carr[simp]: "a' \<in> carrier G" |
1347 |
by fast |
|
27701 | 1348 |
|
1349 |
have a'nunit: "a' \<notin> Units G" |
|
63832 | 1350 |
proof clarify |
27701 | 1351 |
assume "a' \<in> Units G" |
1352 |
also note a' |
|
1353 |
finally have "a \<in> Units G" by simp |
|
1354 |
with anunit |
|
63832 | 1355 |
show "False" .. |
27701 | 1356 |
qed |
1357 |
||
63847 | 1358 |
from wfactors_factors[OF bsf bscarr] obtain b' where fb': "factors G bs b'" and b': "b' \<sim> b" |
1359 |
by blast |
|
63832 | 1360 |
from fb' bscarr have b'carr[simp]: "b' \<in> carrier G" |
1361 |
by fast |
|
27701 | 1362 |
|
1363 |
have b'nunit: "b' \<notin> Units G" |
|
63832 | 1364 |
proof clarify |
27701 | 1365 |
assume "b' \<in> Units G" |
1366 |
also note b' |
|
1367 |
finally have "b \<in> Units G" by simp |
|
63832 | 1368 |
with bnunit show False .. |
27701 | 1369 |
qed |
1370 |
||
1371 |
note a' |
|
1372 |
also note asc |
|
1373 |
also note b'[symmetric] |
|
63832 | 1374 |
finally have "a' \<sim> b'" by simp |
1375 |
from this fa' a'nunit fb' b'nunit ascarr bscarr show "essentially_equal G as bs" |
|
1376 |
by (rule ee_factorsI) |
|
27701 | 1377 |
qed |
1378 |
||
1379 |
lemma (in factorial_monoid) ee_wfactors: |
|
1380 |
assumes asf: "wfactors G as a" |
|
1381 |
and bsf: "wfactors G bs b" |
|
1382 |
and acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" |
|
1383 |
and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G" |
|
1384 |
shows asc: "a \<sim> b = essentially_equal G as bs" |
|
63832 | 1385 |
using assms by (fast intro: ee_wfactorsI ee_wfactorsD) |
27701 | 1386 |
|
1387 |
lemma (in factorial_monoid) wfactors_exist [intro, simp]: |
|
1388 |
assumes acarr[simp]: "a \<in> carrier G" |
|
1389 |
shows "\<exists>fs. set fs \<subseteq> carrier G \<and> wfactors G fs a" |
|
1390 |
proof (cases "a \<in> Units G") |
|
63832 | 1391 |
case True |
1392 |
then have "wfactors G [] a" by (rule unit_wfactors) |
|
1393 |
then show ?thesis by (intro exI) force |
|
27701 | 1394 |
next |
63832 | 1395 |
case False |
63847 | 1396 |
with factors_exist [OF acarr] obtain fs where fscarr: "set fs \<subseteq> carrier G" and f: "factors G fs a" |
1397 |
by blast |
|
27701 | 1398 |
from f have "wfactors G fs a" by (rule factors_wfactors) fact |
63832 | 1399 |
with fscarr show ?thesis by fast |
27701 | 1400 |
qed |
1401 |
||
1402 |
lemma (in monoid) wfactors_prod_exists [intro, simp]: |
|
1403 |
assumes "\<forall>a \<in> set as. irreducible G a" and "set as \<subseteq> carrier G" |
|
1404 |
shows "\<exists>a. a \<in> carrier G \<and> wfactors G as a" |
|
63832 | 1405 |
unfolding wfactors_def using assms by blast |
27701 | 1406 |
|
1407 |
lemma (in factorial_monoid) wfactors_unique: |
|
63832 | 1408 |
assumes "wfactors G fs a" |
1409 |
and "wfactors G fs' a" |
|
27701 | 1410 |
and "a \<in> carrier G" |
63832 | 1411 |
and "set fs \<subseteq> carrier G" |
1412 |
and "set fs' \<subseteq> carrier G" |
|
27701 | 1413 |
shows "essentially_equal G fs fs'" |
63832 | 1414 |
using assms by (fast intro: ee_wfactorsI[of a a]) |
27701 | 1415 |
|
1416 |
lemma (in monoid) factors_mult_single: |
|
1417 |
assumes "irreducible G a" and "factors G fb b" and "a \<in> carrier G" |
|
1418 |
shows "factors G (a # fb) (a \<otimes> b)" |
|
63832 | 1419 |
using assms unfolding factors_def by simp |
27701 | 1420 |
|
1421 |
lemma (in monoid_cancel) wfactors_mult_single: |
|
1422 |
assumes f: "irreducible G a" "wfactors G fb b" |
|
63832 | 1423 |
"a \<in> carrier G" "b \<in> carrier G" "set fb \<subseteq> carrier G" |
27701 | 1424 |
shows "wfactors G (a # fb) (a \<otimes> b)" |
63832 | 1425 |
using assms unfolding wfactors_def by (simp add: mult_cong_r) |
27701 | 1426 |
|
1427 |
lemma (in monoid) factors_mult: |
|
1428 |
assumes factors: "factors G fa a" "factors G fb b" |
|
63832 | 1429 |
and ascarr: "set fa \<subseteq> carrier G" |
1430 |
and bscarr: "set fb \<subseteq> carrier G" |
|
27701 | 1431 |
shows "factors G (fa @ fb) (a \<otimes> b)" |
63832 | 1432 |
using assms |
1433 |
unfolding factors_def |
|
1434 |
apply safe |
|
1435 |
apply force |
|
1436 |
apply hypsubst_thin |
|
1437 |
apply (induct fa) |
|
1438 |
apply simp |
|
1439 |
apply (simp add: m_assoc) |
|
1440 |
done |
|
27701 | 1441 |
|
1442 |
lemma (in comm_monoid_cancel) wfactors_mult [intro]: |
|
1443 |
assumes asf: "wfactors G as a" and bsf:"wfactors G bs b" |
|
1444 |
and acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" |
|
1445 |
and ascarr: "set as \<subseteq> carrier G" and bscarr:"set bs \<subseteq> carrier G" |
|
1446 |
shows "wfactors G (as @ bs) (a \<otimes> b)" |
|
63832 | 1447 |
using wfactors_factors[OF asf ascarr] and wfactors_factors[OF bsf bscarr] |
1448 |
proof clarsimp |
|
27701 | 1449 |
fix a' b' |
1450 |
assume asf': "factors G as a'" and a'a: "a' \<sim> a" |
|
63832 | 1451 |
and bsf': "factors G bs b'" and b'b: "b' \<sim> b" |
27701 | 1452 |
from asf' have a'carr: "a' \<in> carrier G" by (rule factors_closed) fact |
1453 |
from bsf' have b'carr: "b' \<in> carrier G" by (rule factors_closed) fact |
|
1454 |
||
1455 |
note carr = acarr bcarr a'carr b'carr ascarr bscarr |
|
1456 |
||
63832 | 1457 |
from asf' bsf' have "factors G (as @ bs) (a' \<otimes> b')" |
1458 |
by (rule factors_mult) fact+ |
|
1459 |
||
1460 |
with carr have abf': "wfactors G (as @ bs) (a' \<otimes> b')" |
|
1461 |
by (intro factors_wfactors) simp_all |
|
1462 |
also from b'b carr have trb: "a' \<otimes> b' \<sim> a' \<otimes> b" |
|
1463 |
by (intro mult_cong_r) |
|
1464 |
also from a'a carr have tra: "a' \<otimes> b \<sim> a \<otimes> b" |
|
1465 |
by (intro mult_cong_l) |
|
1466 |
finally show "wfactors G (as @ bs) (a \<otimes> b)" |
|
1467 |
by (simp add: carr) |
|
27701 | 1468 |
qed |
1469 |
||
1470 |
lemma (in comm_monoid) factors_dividesI: |
|
63832 | 1471 |
assumes "factors G fs a" |
1472 |
and "f \<in> set fs" |
|
27701 | 1473 |
and "set fs \<subseteq> carrier G" |
1474 |
shows "f divides a" |
|
63832 | 1475 |
using assms by (fast elim: factorsE intro: multlist_dividesI) |
27701 | 1476 |
|
1477 |
lemma (in comm_monoid) wfactors_dividesI: |
|
1478 |
assumes p: "wfactors G fs a" |
|
1479 |
and fscarr: "set fs \<subseteq> carrier G" and acarr: "a \<in> carrier G" |
|
1480 |
and f: "f \<in> set fs" |
|
1481 |
shows "f divides a" |
|
63832 | 1482 |
using wfactors_factors[OF p fscarr] |
1483 |
proof clarsimp |
|
27701 | 1484 |
fix a' |
63832 | 1485 |
assume fsa': "factors G fs a'" and a'a: "a' \<sim> a" |
1486 |
with fscarr have a'carr: "a' \<in> carrier G" |
|
1487 |
by (simp add: factors_closed) |
|
1488 |
||
1489 |
from fsa' fscarr f have "f divides a'" |
|
1490 |
by (fast intro: factors_dividesI) |
|
27701 | 1491 |
also note a'a |
63832 | 1492 |
finally show "f divides a" |
1493 |
by (simp add: f fscarr[THEN subsetD] acarr a'carr) |
|
27701 | 1494 |
qed |
1495 |
||
1496 |
||
61382 | 1497 |
subsubsection \<open>Factorial monoids and wfactors\<close> |
27701 | 1498 |
|
1499 |
lemma (in comm_monoid_cancel) factorial_monoidI: |
|
63832 | 1500 |
assumes wfactors_exists: "\<And>a. a \<in> carrier G \<Longrightarrow> \<exists>fs. set fs \<subseteq> carrier G \<and> wfactors G fs a" |
1501 |
and wfactors_unique: |
|
1502 |
"\<And>a fs fs'. \<lbrakk>a \<in> carrier G; set fs \<subseteq> carrier G; set fs' \<subseteq> carrier G; |
|
1503 |
wfactors G fs a; wfactors G fs' a\<rbrakk> \<Longrightarrow> essentially_equal G fs fs'" |
|
27701 | 1504 |
shows "factorial_monoid G" |
28823 | 1505 |
proof |
27701 | 1506 |
fix a |
1507 |
assume acarr: "a \<in> carrier G" and anunit: "a \<notin> Units G" |
|
1508 |
||
1509 |
from wfactors_exists[OF acarr] |
|
63832 | 1510 |
obtain as where ascarr: "set as \<subseteq> carrier G" and afs: "wfactors G as a" |
63847 | 1511 |
by blast |
1512 |
from wfactors_factors [OF afs ascarr] obtain a' where afs': "factors G as a'" and a'a: "a' \<sim> a" |
|
1513 |
by blast |
|
63832 | 1514 |
from afs' ascarr have a'carr: "a' \<in> carrier G" |
1515 |
by fast |
|
27701 | 1516 |
have a'nunit: "a' \<notin> Units G" |
1517 |
proof clarify |
|
1518 |
assume "a' \<in> Units G" |
|
1519 |
also note a'a |
|
1520 |
finally have "a \<in> Units G" by (simp add: acarr) |
|
63832 | 1521 |
with anunit show False .. |
27701 | 1522 |
qed |
1523 |
||
63847 | 1524 |
from a'carr acarr a'a obtain u where uunit: "u \<in> Units G" and a': "a' = a \<otimes> u" |
63832 | 1525 |
by (blast elim: associatedE2) |
27701 | 1526 |
|
1527 |
note [simp] = acarr Units_closed[OF uunit] Units_inv_closed[OF uunit] |
|
1528 |
||
1529 |
have "a = a \<otimes> \<one>" by simp |
|
57865 | 1530 |
also have "\<dots> = a \<otimes> (u \<otimes> inv u)" by (simp add: uunit) |
27701 | 1531 |
also have "\<dots> = a' \<otimes> inv u" by (simp add: m_assoc[symmetric] a'[symmetric]) |
63832 | 1532 |
finally have a: "a = a' \<otimes> inv u" . |
1533 |
||
1534 |
from ascarr uunit have cr: "set (as[0:=(as!0 \<otimes> inv u)]) \<subseteq> carrier G" |
|
1535 |
by (cases as) auto |
|
1536 |
||
1537 |
from afs' uunit a'nunit acarr ascarr have "factors G (as[0:=(as!0 \<otimes> inv u)]) a" |
|
1538 |
by (simp add: a factors_cong_unit) |
|
1539 |
with cr show "\<exists>fs. set fs \<subseteq> carrier G \<and> factors G fs a" |
|
1540 |
by fast |
|
27701 | 1541 |
qed (blast intro: factors_wfactors wfactors_unique) |
1542 |
||
1543 |
||
61382 | 1544 |
subsection \<open>Factorizations as Multisets\<close> |
1545 |
||
1546 |
text \<open>Gives useful operations like intersection\<close> |
|
27701 | 1547 |
|
1548 |
(* FIXME: use class_of x instead of closure_of {x} *) |
|
1549 |
||
63832 | 1550 |
abbreviation "assocs G x \<equiv> eq_closure_of (division_rel G) {x}" |
1551 |
||
1552 |
definition "fmset G as = mset (map (\<lambda>a. assocs G a) as)" |
|
27701 | 1553 |
|
1554 |
||
61382 | 1555 |
text \<open>Helper lemmas\<close> |
27701 | 1556 |
|
1557 |
lemma (in monoid) assocs_repr_independence: |
|
1558 |
assumes "y \<in> assocs G x" |
|
1559 |
and "x \<in> carrier G" |
|
1560 |
shows "assocs G x = assocs G y" |
|
63832 | 1561 |
using assms |
1562 |
apply safe |
|
1563 |
apply (elim closure_ofE2, intro closure_ofI2[of _ _ y]) |
|
1564 |
apply (clarsimp, iprover intro: associated_trans associated_sym, simp+) |
|
1565 |
apply (elim closure_ofE2, intro closure_ofI2[of _ _ x]) |
|
1566 |
apply (clarsimp, iprover intro: associated_trans, simp+) |
|
1567 |
done |
|
27701 | 1568 |
|
1569 |
lemma (in monoid) assocs_self: |
|
1570 |
assumes "x \<in> carrier G" |
|
1571 |
shows "x \<in> assocs G x" |
|
63832 | 1572 |
using assms by (fastforce intro: closure_ofI2) |
27701 | 1573 |
|
1574 |
lemma (in monoid) assocs_repr_independenceD: |
|
1575 |
assumes repr: "assocs G x = assocs G y" |
|
1576 |
and ycarr: "y \<in> carrier G" |
|
1577 |
shows "y \<in> assocs G x" |
|
63832 | 1578 |
unfolding repr using ycarr by (intro assocs_self) |
27701 | 1579 |
|
1580 |
lemma (in comm_monoid) assocs_assoc: |
|
1581 |
assumes "a \<in> assocs G b" |
|
1582 |
and "b \<in> carrier G" |
|
1583 |
shows "a \<sim> b" |
|
63832 | 1584 |
using assms by (elim closure_ofE2) simp |
1585 |
||
1586 |
lemmas (in comm_monoid) assocs_eqD = assocs_repr_independenceD[THEN assocs_assoc] |
|
27701 | 1587 |
|
1588 |
||
61382 | 1589 |
subsubsection \<open>Comparing multisets\<close> |
27701 | 1590 |
|
1591 |
lemma (in monoid) fmset_perm_cong: |
|
1592 |
assumes prm: "as <~~> bs" |
|
1593 |
shows "fmset G as = fmset G bs" |
|
63832 | 1594 |
using perm_map[OF prm] unfolding mset_eq_perm fmset_def by blast |
27701 | 1595 |
|
1596 |
lemma (in comm_monoid_cancel) eqc_listassoc_cong: |
|
1597 |
assumes "as [\<sim>] bs" |
|
1598 |
and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G" |
|
1599 |
shows "map (assocs G) as = map (assocs G) bs" |
|
63832 | 1600 |
using assms |
1601 |
apply (induct as arbitrary: bs, simp) |
|
1602 |
apply (clarsimp simp add: Cons_eq_map_conv list_all2_Cons1, safe) |
|
1603 |
apply (clarsimp elim!: closure_ofE2) defer 1 |
|
1604 |
apply (clarsimp elim!: closure_ofE2) defer 1 |
|
27701 | 1605 |
proof - |
1606 |
fix a x z |
|
1607 |
assume carr[simp]: "a \<in> carrier G" "x \<in> carrier G" "z \<in> carrier G" |
|
1608 |
assume "x \<sim> a" |
|
1609 |
also assume "a \<sim> z" |
|
1610 |
finally have "x \<sim> z" by simp |
|
63832 | 1611 |
with carr show "x \<in> assocs G z" |
1612 |
by (intro closure_ofI2) simp_all |
|
27701 | 1613 |
next |
1614 |
fix a x z |
|
1615 |
assume carr[simp]: "a \<in> carrier G" "x \<in> carrier G" "z \<in> carrier G" |
|
1616 |
assume "x \<sim> z" |
|
1617 |
also assume [symmetric]: "a \<sim> z" |
|
1618 |
finally have "x \<sim> a" by simp |
|
63832 | 1619 |
with carr show "x \<in> assocs G a" |
1620 |
by (intro closure_ofI2) simp_all |
|
27701 | 1621 |
qed |
1622 |
||
1623 |
lemma (in comm_monoid_cancel) fmset_listassoc_cong: |
|
63832 | 1624 |
assumes "as [\<sim>] bs" |
27701 | 1625 |
and "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G" |
1626 |
shows "fmset G as = fmset G bs" |
|
63832 | 1627 |
using assms unfolding fmset_def by (simp add: eqc_listassoc_cong) |
27701 | 1628 |
|
1629 |
lemma (in comm_monoid_cancel) ee_fmset: |
|
63832 | 1630 |
assumes ee: "essentially_equal G as bs" |
27701 | 1631 |
and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G" |
1632 |
shows "fmset G as = fmset G bs" |
|
63832 | 1633 |
using ee |
27701 | 1634 |
proof (elim essentially_equalE) |
1635 |
fix as' |
|
1636 |
assume prm: "as <~~> as'" |
|
63832 | 1637 |
from prm ascarr have as'carr: "set as' \<subseteq> carrier G" |
1638 |
by (rule perm_closed) |
|
1639 |
||
1640 |
from prm have "fmset G as = fmset G as'" |
|
1641 |
by (rule fmset_perm_cong) |
|
27701 | 1642 |
also assume "as' [\<sim>] bs" |
63832 | 1643 |
with as'carr bscarr have "fmset G as' = fmset G bs" |
1644 |
by (simp add: fmset_listassoc_cong) |
|
1645 |
finally show "fmset G as = fmset G bs" . |
|
27701 | 1646 |
qed |
1647 |
||
1648 |
lemma (in monoid_cancel) fmset_ee__hlp_induct: |
|
1649 |
assumes prm: "cas <~~> cbs" |
|
1650 |
and cdef: "cas = map (assocs G) as" "cbs = map (assocs G) bs" |
|
63832 | 1651 |
shows "\<forall>as bs. (cas <~~> cbs \<and> cas = map (assocs G) as \<and> |
1652 |
cbs = map (assocs G) bs) \<longrightarrow> (\<exists>as'. as <~~> as' \<and> map (assocs G) as' = cbs)" |
|
1653 |
apply (rule perm.induct[of cas cbs], rule prm) |
|
1654 |
apply safe |
|
1655 |
apply (simp_all del: mset_map) |
|
1656 |
apply (simp add: map_eq_Cons_conv) |
|
1657 |
apply blast |
|
1658 |
apply force |
|
27701 | 1659 |
proof - |
1660 |
fix ys as bs |
|
1661 |
assume p1: "map (assocs G) as <~~> ys" |
|
1662 |
and r1[rule_format]: |
|
63832 | 1663 |
"\<forall>asa bs. map (assocs G) as = map (assocs G) asa \<and> ys = map (assocs G) bs |
1664 |
\<longrightarrow> (\<exists>as'. asa <~~> as' \<and> map (assocs G) as' = map (assocs G) bs)" |
|
27701 | 1665 |
and p2: "ys <~~> map (assocs G) bs" |
63832 | 1666 |
and r2[rule_format]: "\<forall>as bsa. ys = map (assocs G) as \<and> map (assocs G) bs = map (assocs G) bsa |
1667 |
\<longrightarrow> (\<exists>as'. as <~~> as' \<and> map (assocs G) as' = map (assocs G) bsa)" |
|
27701 | 1668 |
and p3: "map (assocs G) as <~~> map (assocs G) bs" |
1669 |
||
63832 | 1670 |
from p1 have "mset (map (assocs G) as) = mset ys" |
1671 |
by (simp add: mset_eq_perm del: mset_map) |
|
1672 |
then have setys: "set (map (assocs G) as) = set ys" |
|
1673 |
by (rule mset_eq_setD) |
|
1674 |
||
1675 |
have "set (map (assocs G) as) = {assocs G x | x. x \<in> set as}" by auto |
|
27701 | 1676 |
with setys have "set ys \<subseteq> { assocs G x | x. x \<in> set as}" by simp |
63832 | 1677 |
then have "\<exists>yy. ys = map (assocs G) yy" |
63847 | 1678 |
proof (induct ys) |
1679 |
case Nil |
|
1680 |
then show ?case by simp |
|
1681 |
next |
|
1682 |
case Cons |
|
1683 |
then show ?case |
|
1684 |
proof clarsimp |
|
1685 |
fix yy x |
|
1686 |
show "\<exists>yya. assocs G x # map (assocs G) yy = map (assocs G) yya" |
|
1687 |
by (rule exI[of _ "x#yy"]) simp |
|
1688 |
qed |
|
27701 | 1689 |
qed |
63847 | 1690 |
then obtain yy where ys: "ys = map (assocs G) yy" .. |
63832 | 1691 |
|
1692 |
from p1 ys have "\<exists>as'. as <~~> as' \<and> map (assocs G) as' = map (assocs G) yy" |
|
1693 |
by (intro r1) simp |
|
1694 |
then obtain as' where asas': "as <~~> as'" and as'yy: "map (assocs G) as' = map (assocs G) yy" |
|
1695 |
by auto |
|
1696 |
||
1697 |
from p2 ys have "\<exists>as'. yy <~~> as' \<and> map (assocs G) as' = map (assocs G) bs" |
|
1698 |
by (intro r2) simp |
|
1699 |
then obtain as'' where yyas'': "yy <~~> as''" and as''bs: "map (assocs G) as'' = map (assocs G) bs" |
|
1700 |
by auto |
|
1701 |
||
63847 | 1702 |
from perm_map_switch [OF as'yy yyas''] |
1703 |
obtain cs where as'cs: "as' <~~> cs" and csas'': "map (assocs G) cs = map (assocs G) as''" |
|
1704 |
by blast |
|
1705 |
||
1706 |
from asas' and as'cs have ascs: "as <~~> cs" |
|
1707 |
by fast |
|
1708 |
from csas'' and as''bs have "map (assocs G) cs = map (assocs G) bs" |
|
1709 |
by simp |
|
1710 |
with ascs show "\<exists>as'. as <~~> as' \<and> map (assocs G) as' = map (assocs G) bs" |
|
1711 |
by fast |
|
27701 | 1712 |
qed |
1713 |
||
1714 |
lemma (in comm_monoid_cancel) fmset_ee: |
|
1715 |
assumes mset: "fmset G as = fmset G bs" |
|
1716 |
and ascarr: "set as \<subseteq> carrier G" and bscarr: "set bs \<subseteq> carrier G" |
|
1717 |
shows "essentially_equal G as bs" |
|
1718 |
proof - |
|
63832 | 1719 |
from mset have mpp: "map (assocs G) as <~~> map (assocs G) bs" |
1720 |
by (simp add: fmset_def mset_eq_perm del: mset_map) |
|
27701 | 1721 |
|
63847 | 1722 |
define cas where "cas = map (assocs G) as" |
1723 |
define cbs where "cbs = map (assocs G) bs" |
|
1724 |
||
1725 |
from cas_def cbs_def mpp have [rule_format]: |
|
63832 | 1726 |
"\<forall>as bs. (cas <~~> cbs \<and> cas = map (assocs G) as \<and> cbs = map (assocs G) bs) |
1727 |
\<longrightarrow> (\<exists>as'. as <~~> as' \<and> map (assocs G) as' = cbs)" |
|
1728 |
by (intro fmset_ee__hlp_induct, simp+) |
|
63847 | 1729 |
with mpp cas_def cbs_def have "\<exists>as'. as <~~> as' \<and> map (assocs G) as' = map (assocs G) bs" |
63832 | 1730 |
by simp |
1731 |
||
1732 |
then obtain as' where tp: "as <~~> as'" and tm: "map (assocs G) as' = map (assocs G) bs" |
|
1733 |
by auto |
|
1734 |
from tm have lene: "length as' = length bs" |
|
1735 |
by (rule map_eq_imp_length_eq) |
|
1736 |
from tp have "set as = set as'" |
|
1737 |
by (simp add: mset_eq_perm mset_eq_setD) |
|
1738 |
with ascarr have as'carr: "set as' \<subseteq> carrier G" |
|
1739 |
by simp |
|
27701 | 1740 |
|
63847 | 1741 |
from tm as'carr[THEN subsetD] bscarr[THEN subsetD] have "as' [\<sim>] bs" |
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
44655
diff
changeset
|
1742 |
by (induct as' arbitrary: bs) (simp, fastforce dest: assocs_eqD[THEN associated_sym]) |
63832 | 1743 |
with tp show "essentially_equal G as bs" |
1744 |
by (fast intro: essentially_equalI) |
|
27701 | 1745 |
qed |
1746 |
||
1747 |
lemma (in comm_monoid_cancel) ee_is_fmset: |
|
1748 |
assumes "set as \<subseteq> carrier G" and "set bs \<subseteq> carrier G" |
|
1749 |
shows "essentially_equal G as bs = (fmset G as = fmset G bs)" |
|
63832 | 1750 |
using assms by (fast intro: ee_fmset fmset_ee) |
27701 | 1751 |
|
1752 |
||
61382 | 1753 |
subsubsection \<open>Interpreting multisets as factorizations\<close> |
27701 | 1754 |
|
1755 |
lemma (in monoid) mset_fmsetEx: |
|
60495 | 1756 |
assumes elems: "\<And>X. X \<in> set_mset Cs \<Longrightarrow> \<exists>x. P x \<and> X = assocs G x" |
27701 | 1757 |
shows "\<exists>cs. (\<forall>c \<in> set cs. P c) \<and> fmset G cs = Cs" |
1758 |
proof - |
|
63847 | 1759 |
from surjE[OF surj_mset] obtain Cs' where Cs: "Cs = mset Cs'" |
1760 |
by blast |
|
60515 | 1761 |
have "\<exists>cs. (\<forall>c \<in> set cs. P c) \<and> mset (map (assocs G) cs) = Cs" |
63832 | 1762 |
using elems |
1763 |
unfolding Cs |
|
27701 | 1764 |
apply (induct Cs', simp) |
63524
4ec755485732
adding mset_map to the simp rules
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
63167
diff
changeset
|
1765 |
proof (clarsimp simp del: mset_map) |
63832 | 1766 |
fix a Cs' cs |
27701 | 1767 |
assume ih: "\<And>X. X = a \<or> X \<in> set Cs' \<Longrightarrow> \<exists>x. P x \<and> X = assocs G x" |
1768 |
and csP: "\<forall>x\<in>set cs. P x" |
|
60515 | 1769 |
and mset: "mset (map (assocs G) cs) = mset Cs'" |
63847 | 1770 |
from ih obtain c where cP: "P c" and a: "a = assocs G c" |
1771 |
by auto |
|
1772 |
from cP csP have tP: "\<forall>x\<in>set (c#cs). P x" |
|
1773 |
by simp |
|
1774 |
from mset a have "mset (map (assocs G) (c#cs)) = add_mset a (mset Cs')" |
|
1775 |
by simp |
|
1776 |
with tP show "\<exists>cs. (\<forall>x\<in>set cs. P x) \<and> mset (map (assocs G) cs) = add_mset a (mset Cs')" |
|
1777 |
by fast |
|
60143 | 1778 |
qed |
63832 | 1779 |
then show ?thesis by (simp add: fmset_def) |
27701 | 1780 |
qed |
1781 |
||
1782 |
lemma (in monoid) mset_wfactorsEx: |
|
63832 | 1783 |
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 | 1784 |
shows "\<exists>c cs. c \<in> carrier G \<and> set cs \<subseteq> carrier G \<and> wfactors G cs c \<and> fmset G cs = Cs" |
1785 |
proof - |
|
1786 |
have "\<exists>cs. (\<forall>c\<in>set cs. c \<in> carrier G \<and> irreducible G c) \<and> fmset G cs = Cs" |
|
63832 | 1787 |
by (intro mset_fmsetEx, rule elems) |
1788 |
then obtain cs where p[rule_format]: "\<forall>c\<in>set cs. c \<in> carrier G \<and> irreducible G c" |
|
1789 |
and Cs[symmetric]: "fmset G cs = Cs" by auto |
|
1790 |
from p have cscarr: "set cs \<subseteq> carrier G" by fast |
|
1791 |
from p have "\<exists>c. c \<in> carrier G \<and> wfactors G cs c" |
|
1792 |
by (intro wfactors_prod_exists) auto |
|
1793 |
then obtain c where ccarr: "c \<in> carrier G" and cfs: "wfactors G cs c" by auto |
|
1794 |
with cscarr Cs show ?thesis by fast |
|
27701 | 1795 |
qed |
1796 |
||
1797 |
||
61382 | 1798 |
subsubsection \<open>Multiplication on multisets\<close> |
27701 | 1799 |
|
1800 |
lemma (in factorial_monoid) mult_wfactors_fmset: |
|
63832 | 1801 |
assumes afs: "wfactors G as a" |
1802 |
and bfs: "wfactors G bs b" |
|
1803 |
and cfs: "wfactors G cs (a \<otimes> b)" |
|
27701 | 1804 |
and carr: "a \<in> carrier G" "b \<in> carrier G" |
1805 |
"set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" "set cs \<subseteq> carrier G" |
|
1806 |
shows "fmset G cs = fmset G as + fmset G bs" |
|
1807 |
proof - |
|
63832 | 1808 |
from assms have "wfactors G (as @ bs) (a \<otimes> b)" |
1809 |
by (intro wfactors_mult) |
|
1810 |
with carr cfs have "essentially_equal G cs (as@bs)" |
|
1811 |
by (intro ee_wfactorsI[of "a\<otimes>b" "a\<otimes>b"]) simp_all |
|
1812 |
with carr have "fmset G cs = fmset G (as@bs)" |
|
1813 |
by (intro ee_fmset) simp_all |
|
1814 |
also have "fmset G (as@bs) = fmset G as + fmset G bs" |
|
1815 |
by (simp add: fmset_def) |
|
27701 | 1816 |
finally show "fmset G cs = fmset G as + fmset G bs" . |
1817 |
qed |
|
1818 |
||
1819 |
lemma (in factorial_monoid) mult_factors_fmset: |
|
63832 | 1820 |
assumes afs: "factors G as a" |
1821 |
and bfs: "factors G bs b" |
|
1822 |
and cfs: "factors G cs (a \<otimes> b)" |
|
27701 | 1823 |
and "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" "set cs \<subseteq> carrier G" |
1824 |
shows "fmset G cs = fmset G as + fmset G bs" |
|
63832 | 1825 |
using assms by (blast intro: factors_wfactors mult_wfactors_fmset) |
27701 | 1826 |
|
1827 |
lemma (in comm_monoid_cancel) fmset_wfactors_mult: |
|
1828 |
assumes mset: "fmset G cs = fmset G as + fmset G bs" |
|
1829 |
and carr: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" |
|
63832 | 1830 |
"set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" "set cs \<subseteq> carrier G" |
27701 | 1831 |
and fs: "wfactors G as a" "wfactors G bs b" "wfactors G cs c" |
1832 |
shows "c \<sim> a \<otimes> b" |
|
1833 |
proof - |
|
63832 | 1834 |
from carr fs have m: "wfactors G (as @ bs) (a \<otimes> b)" |
1835 |
by (intro wfactors_mult) |
|
1836 |
||
1837 |
from mset have "fmset G cs = fmset G (as@bs)" |
|
1838 |
by (simp add: fmset_def) |
|
1839 |
then have "essentially_equal G cs (as@bs)" |
|
1840 |
by (rule fmset_ee) (simp_all add: carr) |
|
1841 |
then show "c \<sim> a \<otimes> b" |
|
1842 |
by (rule ee_wfactorsD[of "cs" "as@bs"]) (simp_all add: assms m) |
|
27701 | 1843 |
qed |
1844 |
||
1845 |
||
61382 | 1846 |
subsubsection \<open>Divisibility on multisets\<close> |
27701 | 1847 |
|
1848 |
lemma (in factorial_monoid) divides_fmsubset: |
|
1849 |
assumes ab: "a divides b" |
|
63832 | 1850 |
and afs: "wfactors G as a" |
1851 |
and bfs: "wfactors G bs b" |
|
27701 | 1852 |
and carr: "a \<in> carrier G" "b \<in> carrier G" "set as \<subseteq> carrier G" "set bs \<subseteq> carrier G" |
64587 | 1853 |
shows "fmset G as \<subseteq># fmset G bs" |
63832 | 1854 |
using ab |
27701 | 1855 |
proof (elim dividesE) |
1856 |
fix c |
|
1857 |
assume ccarr: "c \<in> carrier G" |
|
63847 | 1858 |
from wfactors_exist [OF this] |
1859 |
obtain cs where cscarr: "set cs \<subseteq> carrier G" and cfs: "wfactors G cs c" |
|
1860 |
by blast |
|
27701 | 1861 |
note carr = carr ccarr cscarr |
1862 |
||
1863 |
assume "b = a \<otimes> c" |
|
63832 | 1864 |
with afs bfs cfs carr have "fmset G bs = fmset G as + fmset G cs" |
1865 |
by (intro mult_wfactors_fmset[OF afs cfs]) simp_all |
|
1866 |
then show ?thesis by simp |
|
27701 | 1867 |
qed |
1868 |
||
1869 |
lemma (in comm_monoid_cancel) fmsubset_divides: |
|
64587 | 1870 |
assumes msubset: "fmset G as \<subseteq># fmset G bs" |
63832 | 1871 |
and afs: "wfactors G as a" |
1872 |
and bfs: "wfactors G bs b" |
|
1873 |
and acarr: "a \<in> carrier G" |
|
1874 |
and bcarr: "b \<in> carrier G" |
|
1875 |
and ascarr: "set as \<subseteq> carrier G" |
|
1876 |
and bscarr: "set bs \<subseteq> carrier G" |
|
27701 | 1877 |
shows "a divides b" |
1878 |
proof - |
|
1879 |
from afs have airr: "\<forall>a \<in> set as. irreducible G a" by (fast elim: wfactorsE) |
|
1880 |
from bfs have birr: "\<forall>b \<in> set bs. irreducible G b" by (fast elim: wfactorsE) |
|
1881 |
||
1882 |
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" |
|
1883 |
proof (intro mset_wfactorsEx, simp) |
|
1884 |
fix X |
|
62430
9527ff088c15
more succint formulation of membership for multisets, similar to lists;
haftmann
parents:
61382
diff
changeset
|
1885 |
assume "X \<in># fmset G bs - fmset G as" |
63832 | 1886 |
then have "X \<in># fmset G bs" by (rule in_diffD) |
1887 |
then have "X \<in> set (map (assocs G) bs)" by (simp add: fmset_def) |
|
1888 |
then have "\<exists>x. x \<in> set bs \<and> X = assocs G x" by (induct bs) auto |
|
1889 |
then obtain x where xbs: "x \<in> set bs" and X: "X = assocs G x" by auto |
|
27701 | 1890 |
with bscarr have xcarr: "x \<in> carrier G" by fast |
1891 |
from xbs birr have xirr: "irreducible G x" by simp |
|
1892 |
||
63832 | 1893 |
from xcarr and xirr and X show "\<exists>x. x \<in> carrier G \<and> irreducible G x \<and> X = assocs G x" |
1894 |
by fast |
|
27701 | 1895 |
qed |
63832 | 1896 |
then obtain c cs |
1897 |
where ccarr: "c \<in> carrier G" |
|
1898 |
and cscarr: "set cs \<subseteq> carrier G" |
|
27701 | 1899 |
and csf: "wfactors G cs c" |
1900 |
and csmset: "fmset G cs = fmset G bs - fmset G as" by auto |
|
1901 |
||
1902 |
from csmset msubset |
|
63832 | 1903 |
have "fmset G bs = fmset G as + fmset G cs" |
1904 |
by (simp add: multiset_eq_iff subseteq_mset_def) |
|
1905 |
then have basc: "b \<sim> a \<otimes> c" |
|
1906 |
by (rule fmset_wfactors_mult) fact+ |
|
1907 |
then show ?thesis |
|
27701 | 1908 |
proof (elim associatedE2) |
1909 |
fix u |
|
1910 |
assume "u \<in> Units G" "b = a \<otimes> c \<otimes> u" |
|
63832 | 1911 |
with acarr ccarr show "a divides b" |
1912 |
by (fast intro: dividesI[of "c \<otimes> u"] m_assoc) |
|
1913 |
qed (simp_all add: acarr bcarr ccarr) |
|
27701 | 1914 |
qed |
1915 |
||
1916 |
lemma (in factorial_monoid) divides_as_fmsubset: |
|
63832 | 1917 |
assumes "wfactors G as a" |
1918 |
and "wfactors G bs b" |
|
1919 |
and "a \<in> carrier G" |
|
1920 |
and "b \<in> carrier G" |
|
1921 |
and "set as \<subseteq> carrier G" |
|
1922 |
and "set bs \<subseteq> carrier G" |
|
64587 | 1923 |
shows "a divides b = (fmset G as \<subseteq># fmset G bs)" |
63832 | 1924 |
using assms |
1925 |
by (blast intro: divides_fmsubset fmsubset_divides) |
|
27701 | 1926 |
|
1927 |
||
61382 | 1928 |
text \<open>Proper factors on multisets\<close> |
27701 | 1929 |
|
1930 |
lemma (in factorial_monoid) fmset_properfactor: |
|
64587 | 1931 |
assumes asubb: "fmset G as \<subseteq># fmset G bs" |
27701 | 1932 |
and anb: "fmset G as \<noteq> fmset G bs" |
63832 | 1933 |
and "wfactors G as a" |
1934 |
and "wfactors G bs b" |
|
1935 |
and "a \<in> carrier G" |
|
1936 |
and "b \<in> carrier G" |
|
1937 |
and "set as \<subseteq> carrier G" |
|
1938 |
and "set bs \<subseteq> carrier G" |
|
27701 | 1939 |
shows "properfactor G a b" |
63832 | 1940 |
apply (rule properfactorI) |
1941 |
apply (rule fmsubset_divides[of as bs], fact+) |
|
27701 | 1942 |
proof |
1943 |
assume "b divides a" |
|
64587 | 1944 |
then have "fmset G bs \<subseteq># fmset G as" |
63832 | 1945 |
by (rule divides_fmsubset) fact+ |
1946 |
with asubb have "fmset G as = fmset G bs" |
|
1947 |
by (rule subset_mset.antisym) |
|
1948 |
with anb show False .. |
|
27701 | 1949 |
qed |
1950 |
||
1951 |
lemma (in factorial_monoid) properfactor_fmset: |
|
1952 |
assumes pf: "properfactor G a b" |
|
63832 | 1953 |
and "wfactors G as a" |
1954 |
and "wfactors G bs b" |
|
1955 |
and "a \<in> carrier G" |
|
1956 |
and "b \<in> carrier G" |
|
1957 |
and "set as \<subseteq> carrier G" |
|
1958 |
and "set bs \<subseteq> carrier G" |
|
64587 | 1959 |
shows "fmset G as \<subseteq># fmset G bs \<and> fmset G as \<noteq> fmset G bs" |
63832 | 1960 |
using pf |
1961 |
apply (elim properfactorE) |
|
1962 |
apply rule |
|
1963 |
apply (intro divides_fmsubset, assumption) |
|
1964 |
apply (rule assms)+ |
|
1965 |
using assms(2,3,4,6,7) divides_as_fmsubset |
|
1966 |
apply auto |
|
1967 |
done |
|
27701 | 1968 |
|
61382 | 1969 |
subsection \<open>Irreducible Elements are Prime\<close> |
27701 | 1970 |
|
63633 | 1971 |
lemma (in factorial_monoid) irreducible_prime: |
27701 | 1972 |
assumes pirr: "irreducible G p" |
1973 |
and pcarr: "p \<in> carrier G" |
|
1974 |
shows "prime G p" |
|
63832 | 1975 |
using pirr |
27701 | 1976 |
proof (elim irreducibleE, intro primeI) |
1977 |
fix a b |
|
1978 |
assume acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" |
|
1979 |
and pdvdab: "p divides (a \<otimes> b)" |
|
1980 |
and pnunit: "p \<notin> Units G" |
|
1981 |
assume irreduc[rule_format]: |
|
63832 | 1982 |
"\<forall>b. b \<in> carrier G \<and> properfactor G b p \<longrightarrow> b \<in> Units G" |
63847 | 1983 |
from pdvdab obtain c where ccarr: "c \<in> carrier G" and abpc: "a \<otimes> b = p \<otimes> c" |
1984 |
by (rule dividesE) |
|
1985 |
||
1986 |
from wfactors_exist [OF acarr] |
|
1987 |
obtain as where ascarr: "set as \<subseteq> carrier G" and afs: "wfactors G as a" |
|
1988 |
by blast |
|
1989 |
||
1990 |
from wfactors_exist [OF bcarr] |
|
1991 |
obtain bs where bscarr: "set bs \<subseteq> carrier G" and bfs: "wfactors G bs b" |
|
63832 | 1992 |
by auto |
1993 |
||
63847 | 1994 |
from wfactors_exist [OF ccarr] |
1995 |
obtain cs where cscarr: "set cs \<subseteq> carrier G" and cfs: "wfactors G cs c" |
|
63832 | 1996 |
by auto |
27701 | 1997 |
|
1998 |
note carr[simp] = pcarr acarr bcarr ccarr ascarr bscarr cscarr |
|
1999 |
||
63832 | 2000 |
from afs and bfs have abfs: "wfactors G (as @ bs) (a \<otimes> b)" |
2001 |
by (rule wfactors_mult) fact+ |
|
2002 |
||
2003 |
from pirr cfs have pcfs: "wfactors G (p # cs) (p \<otimes> c)" |
|
2004 |
by (rule wfactors_mult_single) fact+ |
|
2005 |
with abpc have abfs': "wfactors G (p # cs) (a \<otimes> b)" |
|
2006 |
by simp |
|
2007 |
||
2008 |
from abfs' abfs have "essentially_equal G (p # cs) (as @ bs)" |
|
2009 |
by (rule wfactors_unique) simp+ |
|
2010 |
||
63847 | 2011 |
then obtain ds where "p # cs <~~> ds" and dsassoc: "ds [\<sim>] (as @ bs)" |
63832 | 2012 |
by (fast elim: essentially_equalE) |
27701 | 2013 |
then have "p \<in> set ds" |
63832 | 2014 |
by (simp add: perm_set_eq[symmetric]) |
63847 | 2015 |
with dsassoc obtain p' where "p' \<in> set (as@bs)" and pp': "p \<sim> p'" |
63832 | 2016 |
unfolding list_all2_conv_all_nth set_conv_nth by force |
2017 |
then consider "p' \<in> set as" | "p' \<in> set bs" by auto |
|
2018 |
then show "p divides a \<or> p divides b" |
|
2019 |
proof cases |
|
2020 |
case 1 |
|
27701 | 2021 |
with ascarr have [simp]: "p' \<in> carrier G" by fast |
2022 |
||
2023 |
note pp' |
|
2024 |
also from afs |
|
63832 | 2025 |
have "p' divides a" by (rule wfactors_dividesI) fact+ |
2026 |
finally have "p divides a" by simp |
|
2027 |
then show ?thesis .. |
|
2028 |
next |
|
2029 |
case 2 |
|
27701 | 2030 |
with bscarr have [simp]: "p' \<in> carrier G" by fast |
2031 |
||
2032 |
note pp' |
|
2033 |
also from bfs |
|
63832 | 2034 |
have "p' divides b" by (rule wfactors_dividesI) fact+ |
2035 |
finally have "p divides b" by simp |
|
2036 |
then show ?thesis .. |
|
2037 |
qed |
|
27701 | 2038 |
qed |
2039 |
||
2040 |
||
67443
3abf6a722518
standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents:
67399
diff
changeset
|
2041 |
\<comment> \<open>A version using @{const factors}, more complicated\<close> |
63633 | 2042 |
lemma (in factorial_monoid) factors_irreducible_prime: |
27701 | 2043 |
assumes pirr: "irreducible G p" |
2044 |
and pcarr: "p \<in> carrier G" |
|
2045 |
shows "prime G p" |
|
63832 | 2046 |
using pirr |
2047 |
apply (elim irreducibleE, intro primeI) |
|
2048 |
apply assumption |
|
27701 | 2049 |
proof - |
2050 |
fix a b |
|
63832 | 2051 |
assume acarr: "a \<in> carrier G" |
27701 | 2052 |
and bcarr: "b \<in> carrier G" |
2053 |
and pdvdab: "p divides (a \<otimes> b)" |
|
63832 | 2054 |
assume irreduc[rule_format]: "\<forall>b. b \<in> carrier G \<and> properfactor G b p \<longrightarrow> b \<in> Units G" |
63847 | 2055 |
from pdvdab obtain c where ccarr: "c \<in> carrier G" and abpc: "a \<otimes> b = p \<otimes> c" |
2056 |
by (rule dividesE) |
|
27701 | 2057 |
note [simp] = pcarr acarr bcarr ccarr |
2058 |
||
2059 |
show "p divides a \<or> p divides b" |
|
2060 |
proof (cases "a \<in> Units G") |
|
63832 | 2061 |
case aunit: True |
27701 | 2062 |
|
2063 |
note pdvdab |
|
2064 |
also have "a \<otimes> b = b \<otimes> a" by (simp add: m_comm) |
|
63832 | 2065 |
also from aunit have bab: "b \<otimes> a \<sim> b" |
2066 |
by (intro associatedI2[of "a"], simp+) |
|
2067 |
finally have "p divides b" by simp |
|
2068 |
then show ?thesis .. |
|
27701 | 2069 |
next |
63832 | 2070 |
case anunit: False |
2071 |
show ?thesis |
|
27701 | 2072 |
proof (cases "b \<in> Units G") |
63832 | 2073 |
case bunit: True |
27701 | 2074 |
note pdvdab |
2075 |
also from bunit |
|
63832 | 2076 |
have baa: "a \<otimes> b \<sim> a" |
2077 |
by (intro associatedI2[of "b"], simp+) |
|
2078 |
finally have "p divides a" by simp |
|
2079 |
then show ?thesis .. |
|
27701 | 2080 |
next |
63832 | 2081 |
case bnunit: False |
27701 | 2082 |
have cnunit: "c \<notin> Units G" |
63846 | 2083 |
proof |
27701 | 2084 |
assume cunit: "c \<in> Units G" |
63832 | 2085 |
from bnunit have "properfactor G a (a \<otimes> b)" |
2086 |
by (intro properfactorI3[of _ _ b], simp+) |
|
27701 | 2087 |
also note abpc |
63832 | 2088 |
also from cunit have "p \<otimes> c \<sim> p" |
2089 |
by (intro associatedI2[of c], simp+) |
|
2090 |
finally have "properfactor G a p" by simp |
|
2091 |
with acarr have "a \<in> Units G" by (fast intro: irreduc) |
|
2092 |
with anunit show False .. |
|
27701 | 2093 |
qed |
2094 |
||
2095 |
have abnunit: "a \<otimes> b \<notin> Units G" |
|
2096 |
proof clarsimp |
|
63832 | 2097 |
assume "a \<otimes> b \<in> Units G" |
2098 |
then have "a \<in> Units G" by (rule unit_factor) fact+ |
|
2099 |
with anunit show False .. |
|
27701 | 2100 |
qed |
2101 |
||
63847 | 2102 |
from factors_exist [OF acarr anunit] |
2103 |
obtain as where ascarr: "set as \<subseteq> carrier G" and afac: "factors G as a" |
|
2104 |
by blast |
|
2105 |
||
2106 |
from factors_exist [OF bcarr bnunit] |
|
2107 |
obtain bs where bscarr: "set bs \<subseteq> carrier G" and bfac: "factors G bs b" |
|
2108 |
by blast |
|
2109 |
||
2110 |
from factors_exist [OF ccarr cnunit] |
|
2111 |
obtain cs where cscarr: "set cs \<subseteq> carrier G" and cfac: "factors G cs c" |
|
63832 | 2112 |
by auto |
27701 | 2113 |
|
2114 |
note [simp] = ascarr bscarr cscarr |
|
2115 |
||
63832 | 2116 |
from afac and bfac have abfac: "factors G (as @ bs) (a \<otimes> b)" |
2117 |
by (rule factors_mult) fact+ |
|
2118 |
||
2119 |
from pirr cfac have pcfac: "factors G (p # cs) (p \<otimes> c)" |
|
2120 |
by (rule factors_mult_single) fact+ |
|
2121 |
with abpc have abfac': "factors G (p # cs) (a \<otimes> b)" |
|
2122 |
by simp |
|
2123 |
||
2124 |
from abfac' abfac have "essentially_equal G (p # cs) (as @ bs)" |
|
2125 |
by (rule factors_unique) (fact | simp)+ |
|
63847 | 2126 |
then obtain ds where "p # cs <~~> ds" and dsassoc: "ds [\<sim>] (as @ bs)" |
63832 | 2127 |
by (fast elim: essentially_equalE) |
27701 | 2128 |
then have "p \<in> set ds" |
63832 | 2129 |
by (simp add: perm_set_eq[symmetric]) |
63847 | 2130 |
with dsassoc obtain p' where "p' \<in> set (as@bs)" and pp': "p \<sim> p'" |
63832 | 2131 |
unfolding list_all2_conv_all_nth set_conv_nth by force |
2132 |
then consider "p' \<in> set as" | "p' \<in> set bs" by auto |
|
2133 |
then show "p divides a \<or> p divides b" |
|
2134 |
proof cases |
|
2135 |
case 1 |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32456
diff
changeset
|
2136 |
with ascarr have [simp]: "p' \<in> carrier G" by fast |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32456
diff
changeset
|
2137 |
|
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32456
diff
changeset
|
2138 |
note pp' |
63832 | 2139 |
also from afac 1 have "p' divides a" by (rule factors_dividesI) fact+ |
2140 |
finally have "p divides a" by simp |
|
2141 |
then show ?thesis .. |
|
2142 |
next |
|
2143 |
case 2 |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32456
diff
changeset
|
2144 |
with bscarr have [simp]: "p' \<in> carrier G" by fast |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32456
diff
changeset
|
2145 |
|
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32456
diff
changeset
|
2146 |
note pp' |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32456
diff
changeset
|
2147 |
also from bfac |
63832 | 2148 |
have "p' divides b" by (rule factors_dividesI) fact+ |
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32456
diff
changeset
|
2149 |
finally have "p divides b" by simp |
63832 | 2150 |
then show ?thesis .. |
2151 |
qed |
|
27701 | 2152 |
qed |
2153 |
qed |
|
2154 |
qed |
|
2155 |
||
2156 |
||
61382 | 2157 |
subsection \<open>Greatest Common Divisors and Lowest Common Multiples\<close> |
2158 |
||
2159 |
subsubsection \<open>Definitions\<close> |
|
27701 | 2160 |
|
63832 | 2161 |
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:
35847
diff
changeset
|
2162 |
where "x gcdof\<^bsub>G\<^esub> a b \<longleftrightarrow> x divides\<^bsub>G\<^esub> a \<and> x divides\<^bsub>G\<^esub> b \<and> |
35847 | 2163 |
(\<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))" |
2164 |
||
63832 | 2165 |
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:
35847
diff
changeset
|
2166 |
where "x lcmof\<^bsub>G\<^esub> a b \<longleftrightarrow> a divides\<^bsub>G\<^esub> x \<and> b divides\<^bsub>G\<^esub> x \<and> |
35847 | 2167 |
(\<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))" |
2168 |
||
63832 | 2169 |
definition somegcd :: "('a,_) monoid_scheme \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'a" |
35848
5443079512ea
slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents:
35847
diff
changeset
|
2170 |
where "somegcd G a b = (SOME x. x \<in> carrier G \<and> x gcdof\<^bsub>G\<^esub> a b)" |
35847 | 2171 |
|
63832 | 2172 |
definition somelcm :: "('a,_) monoid_scheme \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'a" |
35848
5443079512ea
slightly more uniform definitions -- eliminated old-style meta-equality;
wenzelm
parents:
35847
diff
changeset
|
2173 |
where "somelcm G a b = (SOME x. x \<in> carrier G \<and> x lcmof\<^bsub>G\<^esub> a b)" |
35847 | 2174 |
|
63832 | 2175 |
definition "SomeGcd G A = inf (division_rel G) A" |
27701 | 2176 |
|
2177 |
||
2178 |
locale gcd_condition_monoid = comm_monoid_cancel + |
|
63832 | 2179 |
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 | 2180 |
|
2181 |
locale primeness_condition_monoid = comm_monoid_cancel + |
|
63832 | 2182 |
assumes irreducible_prime: "\<lbrakk>a \<in> carrier G; irreducible G a\<rbrakk> \<Longrightarrow> prime G a" |
27701 | 2183 |
|
2184 |
locale divisor_chain_condition_monoid = comm_monoid_cancel + |
|
63832 | 2185 |
assumes division_wellfounded: "wf {(x, y). x \<in> carrier G \<and> y \<in> carrier G \<and> properfactor G x y}" |
27701 | 2186 |
|
2187 |
||
61382 | 2188 |
subsubsection \<open>Connections to \texttt{Lattice.thy}\<close> |
27701 | 2189 |
|
27713
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents:
27701
diff
changeset
|
2190 |
lemma gcdof_greatestLower: |
27701 | 2191 |
fixes G (structure) |
2192 |
assumes carr[simp]: "a \<in> carrier G" "b \<in> carrier G" |
|
63832 | 2193 |
shows "(x \<in> carrier G \<and> x gcdof a b) = greatest (division_rel G) x (Lower (division_rel G) {a, b})" |
2194 |
by (auto simp: isgcd_def greatest_def Lower_def elem_def) |
|
27701 | 2195 |
|
27713
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents:
27701
diff
changeset
|
2196 |
lemma lcmof_leastUpper: |
27701 | 2197 |
fixes G (structure) |
2198 |
assumes carr[simp]: "a \<in> carrier G" "b \<in> carrier G" |
|
63832 | 2199 |
shows "(x \<in> carrier G \<and> x lcmof a b) = least (division_rel G) x (Upper (division_rel G) {a, b})" |
2200 |
by (auto simp: islcm_def least_def Upper_def elem_def) |
|
27701 | 2201 |
|
27713
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents:
27701
diff
changeset
|
2202 |
lemma somegcd_meet: |
27701 | 2203 |
fixes G (structure) |
2204 |
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:
27701
diff
changeset
|
2205 |
shows "somegcd G a b = meet (division_rel G) a b" |
63832 | 2206 |
by (simp add: somegcd_def meet_def inf_def gcdof_greatestLower[OF carr]) |
27701 | 2207 |
|
2208 |
lemma (in monoid) isgcd_divides_l: |
|
2209 |
assumes "a divides b" |
|
2210 |
and "a \<in> carrier G" "b \<in> carrier G" |
|
2211 |
shows "a gcdof a b" |
|
63832 | 2212 |
using assms unfolding isgcd_def by fast |
27701 | 2213 |
|
2214 |
lemma (in monoid) isgcd_divides_r: |
|
2215 |
assumes "b divides a" |
|
2216 |
and "a \<in> carrier G" "b \<in> carrier G" |
|
2217 |
shows "b gcdof a b" |
|
63832 | 2218 |
using assms unfolding isgcd_def by fast |
27701 | 2219 |
|
2220 |
||
61382 | 2221 |
subsubsection \<open>Existence of gcd and lcm\<close> |
27701 | 2222 |
|
2223 |
lemma (in factorial_monoid) gcdof_exists: |
|
63832 | 2224 |
assumes acarr: "a \<in> carrier G" |
2225 |
and bcarr: "b \<in> carrier G" |
|
27701 | 2226 |
shows "\<exists>c. c \<in> carrier G \<and> c gcdof a b" |
2227 |
proof - |
|
63847 | 2228 |
from wfactors_exist [OF acarr] |
2229 |
obtain as where ascarr: "set as \<subseteq> carrier G" and afs: "wfactors G as a" |
|
2230 |
by blast |
|
63832 | 2231 |
from afs have airr: "\<forall>a \<in> set as. irreducible G a" |
2232 |
by (fast elim: wfactorsE) |
|
2233 |
||
63847 | 2234 |
from wfactors_exist [OF bcarr] |
2235 |
obtain bs where bscarr: "set bs \<subseteq> carrier G" and bfs: "wfactors G bs b" |
|
2236 |
by blast |
|
63832 | 2237 |
from bfs have birr: "\<forall>b \<in> set bs. irreducible G b" |
2238 |
by (fast elim: wfactorsE) |
|
2239 |
||
2240 |
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:
63847
diff
changeset
|
2241 |
fmset G cs = fmset G as \<inter># fmset G bs" |
27701 | 2242 |
proof (intro mset_wfactorsEx) |
2243 |
fix X |
|
63919
9aed2da07200
# after multiset intersection and union symbol
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
63847
diff
changeset
|
2244 |
assume "X \<in># fmset G as \<inter># fmset G bs" |
63832 | 2245 |
then have "X \<in># fmset G as" by simp |
2246 |
then have "X \<in> set (map (assocs G) as)" |
|
2247 |
by (simp add: fmset_def) |
|
2248 |
then have "\<exists>x. X = assocs G x \<and> x \<in> set as" |
|
2249 |
by (induct as) auto |
|
2250 |
then obtain x where X: "X = assocs G x" and xas: "x \<in> set as" |
|
63847 | 2251 |
by blast |
63832 | 2252 |
with ascarr have xcarr: "x \<in> carrier G" |
63847 | 2253 |
by blast |
63832 | 2254 |
from xas airr have xirr: "irreducible G x" |
2255 |
by simp |
|
2256 |
from xcarr and xirr and X show "\<exists>x. (x \<in> carrier G \<and> irreducible G x) \<and> X = assocs G x" |
|
63847 | 2257 |
by blast |
27701 | 2258 |
qed |
63832 | 2259 |
then obtain c cs |
2260 |
where ccarr: "c \<in> carrier G" |
|
2261 |
and cscarr: "set cs \<subseteq> carrier G" |
|
27701 | 2262 |
and csirr: "wfactors G cs c" |
63919
9aed2da07200
# after multiset intersection and union symbol
fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
63847
diff
changeset
|
2263 |
and csmset: "fmset G cs = fmset G as \<inter># fmset G bs" |
63832 | 2264 |
by auto |
27701 | 2265 |
|
2266 |
have "c gcdof a b" |
|
2267 |
proof (simp add: isgcd_def, safe) |
|
2268 |
from csmset |
|
64587 | 2269 |
have "fmset G cs \<subseteq># fmset G as" |
63832 | 2270 |
by (simp add: multiset_inter_def subset_mset_def) |
2271 |
then show "c divides a" by (rule fmsubset_divides) fact+ |
|
27701 | 2272 |
next |
64587 | 2273 |
from csmset have "fmset G cs \<subseteq># fmset G bs" |
63832 | 2274 |
by (simp add: multiset_inter_def subseteq_mset_def, force) |
2275 |
then show "c divides b" |
|
2276 |
by (rule fmsubset_divides) fact+ |
|
27701 | 2277 |
next |
2278 |
fix y |
|
63847 | 2279 |
assume "y \<in> carrier G" |
2280 |
from wfactors_exist [OF this] |
|
2281 |
obtain ys where yscarr: "set ys \<subseteq> carrier G" and yfs: "wfactors G ys y" |
|
2282 |
by blast |
|
27701 | 2283 |
|
2284 |
assume "y divides a" |
|
64587 | 2285 |
then have ya: "fmset G ys \<subseteq># fmset G as" |
63832 | 2286 |
by (rule divides_fmsubset) fact+ |
27701 | 2287 |
|
2288 |
assume "y divides b" |
|
64587 | 2289 |
then have yb: "fmset G ys \<subseteq># fmset G bs" |
63832 | 2290 |
by (rule divides_fmsubset) fact+ |
2291 |
||
64587 | 2292 |
from ya yb csmset have "fmset G ys \<subseteq># fmset G cs" |
63832 | 2293 |
by (simp add: subset_mset_def) |
2294 |
then show "y divides c" |
|
2295 |
by (rule fmsubset_divides) fact+ |
|
27701 | 2296 |
qed |
63832 | 2297 |
with ccarr show "\<exists>c. c \<in> carrier G \<and> c gcdof a b" |
2298 |
by fast |
|
27701 | 2299 |
qed |
2300 |
||
2301 |
lemma (in factorial_monoid) lcmof_exists: |
|
63832 | 2302 |
assumes acarr: "a \<in> carrier G" |
2303 |
and bcarr: "b \<in> carrier G" |
|
27701 | 2304 |
shows "\<exists>c. c \<in> carrier G \<and> c lcmof a b" |
2305 |
proof - |
|
63847 | 2306 |
from wfactors_exist [OF acarr] |
2307 |
obtain as where ascarr: "set as \<subseteq> carrier G" and afs: "wfactors G as a" |
|
2308 |
by blast |
|
63832 | 2309 |
from afs have airr: "\<forall>a \<in> set as. irreducible G a" |
2310 |
by (fast elim: wfactorsE) |
|
2311 |
||
63847 | 2312 |
from wfactors_exist [OF bcarr] |
2313 |
obtain bs where bscarr: "set bs \<subseteq> carrier G" and bfs: "wfactors G bs b" |
|
2314 |
by blast |
|
63832 | 2315 |
from bfs have birr: "\<forall>b \<in> set bs. irreducible G b" |
2316 |
by (fast elim: wfactorsE) |
|
2317 |
||
2318 |
have "\<exists>c cs. c \<in> carrier G \<and> set cs \<subseteq> carrier G \<and> wfactors G cs c \<and> |
|
2319 |
fmset G cs = (fmset G as - fmset G bs) + fmset G bs" |
|
27701 | 2320 |
proof (intro mset_wfactorsEx) |
2321 |
fix X |
|
62430
9527ff088c15
more succint formulation of membership for multisets, similar to lists;
haftmann
parents:
61382
diff
changeset
|
2322 |
assume "X \<in># (fmset G as - fmset G bs) + fmset G bs" |
63832 | 2323 |
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:
61382
diff
changeset
|
2324 |
by (auto dest: in_diffD) |
63832 | 2325 |
then consider "X \<in> set_mset (fmset G as)" | "X \<in> set_mset (fmset G bs)" |
2326 |
by fast |
|
2327 |
then show "\<exists>x. (x \<in> carrier G \<and> irreducible G x) \<and> X = assocs G x" |
|
2328 |
proof cases |
|
2329 |
case 1 |
|
2330 |
then have "X \<in> set (map (assocs G) as)" by (simp add: fmset_def) |
|
2331 |
then have "\<exists>x. x \<in> set as \<and> X = assocs G x" by (induct as) auto |
|
2332 |
then obtain x where xas: "x \<in> set as" and X: "X = assocs G x" by auto |
|
27701 | 2333 |
with ascarr have xcarr: "x \<in> carrier G" by fast |
2334 |
from xas airr have xirr: "irreducible G x" by simp |
|
63832 | 2335 |
from xcarr and xirr and X show ?thesis by fast |
2336 |
next |
|
2337 |
case 2 |
|
2338 |
then have "X \<in> set (map (assocs G) bs)" by (simp add: fmset_def) |
|
2339 |
then have "\<exists>x. x \<in> set bs \<and> X = assocs G x" by (induct as) auto |
|
2340 |
then obtain x where xbs: "x \<in> set bs" and X: "X = assocs G x" by auto |
|
27701 | 2341 |
with bscarr have xcarr: "x \<in> carrier G" by fast |
2342 |
from xbs birr have xirr: "irreducible G x" by simp |
|
63832 | 2343 |
from xcarr and xirr and X show ?thesis by fast |
2344 |
qed |
|
27701 | 2345 |
qed |
63832 | 2346 |
then obtain c cs |
2347 |
where ccarr: "c \<in> carrier G" |
|
2348 |
and cscarr: "set cs \<subseteq> carrier G" |
|
27701 | 2349 |
and csirr: "wfactors G cs c" |
63832 | 2350 |
and csmset: "fmset G cs = fmset G as - fmset G bs + fmset G bs" |
2351 |
by auto |
|
27701 | 2352 |
|
2353 |
have "c lcmof a b" |
|
2354 |
proof (simp add: islcm_def, safe) |
|
64587 | 2355 |
from csmset have "fmset G as \<subseteq># fmset G cs" |
63832 | 2356 |
by (simp add: subseteq_mset_def, force) |
2357 |
then show "a divides c" |
|
2358 |
by (rule fmsubset_divides) fact+ |
|
27701 | 2359 |
next |
64587 | 2360 |
from csmset have "fmset G bs \<subseteq># fmset G cs" |
63832 | 2361 |
by (simp add: subset_mset_def) |
2362 |
then show "b divides c" |
|
2363 |
by (rule fmsubset_divides) fact+ |
|
27701 | 2364 |
next |
2365 |
fix y |
|
63847 | 2366 |
assume "y \<in> carrier G" |
2367 |
from wfactors_exist [OF this] |
|
2368 |
obtain ys where yscarr: "set ys \<subseteq> carrier G" and yfs: "wfactors G ys y" |
|
2369 |
by blast |
|
27701 | 2370 |
|
2371 |
assume "a divides y" |
|
64587 | 2372 |
then have ya: "fmset G as \<subseteq># fmset G ys" |
63832 | 2373 |
by (rule divides_fmsubset) fact+ |
27701 | 2374 |
|
2375 |
assume "b divides y" |
|
64587 | 2376 |
then have yb: "fmset G bs \<subseteq># fmset G ys" |
63832 | 2377 |
by (rule divides_fmsubset) fact+ |
2378 |
||
64587 | 2379 |
from ya yb csmset have "fmset G cs \<subseteq># fmset G ys" |
60397
f8a513fedb31
Renaming multiset operators < ~> <#,...
Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de>
parents:
60143
diff
changeset
|
2380 |
apply (simp add: subseteq_mset_def, clarify) |
27701 | 2381 |
apply (case_tac "count (fmset G as) a < count (fmset G bs) a") |
2382 |
apply simp |
|
2383 |
apply simp |
|
63832 | 2384 |
done |
2385 |
then show "c divides y" |
|
2386 |
by (rule fmsubset_divides) fact+ |
|
27701 | 2387 |
qed |
63832 | 2388 |
with ccarr show "\<exists>c. c \<in> carrier G \<and> c lcmof a b" |
2389 |
by fast |
|
27701 | 2390 |
qed |
2391 |
||
2392 |
||
61382 | 2393 |
subsection \<open>Conditions for Factoriality\<close> |
2394 |
||
2395 |
subsubsection \<open>Gcd condition\<close> |
|
27701 | 2396 |
|
27713
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents:
27701
diff
changeset
|
2397 |
lemma (in gcd_condition_monoid) division_weak_lower_semilattice [simp]: |
63832 | 2398 |
"weak_lower_semilattice (division_rel G)" |
27701 | 2399 |
proof - |
29237 | 2400 |
interpret weak_partial_order "division_rel G" .. |
27701 | 2401 |
show ?thesis |
63832 | 2402 |
apply (unfold_locales, simp_all) |
27701 | 2403 |
proof - |
2404 |
fix x y |
|
2405 |
assume carr: "x \<in> carrier G" "y \<in> carrier G" |
|
63847 | 2406 |
from gcdof_exists [OF this] obtain z where zcarr: "z \<in> carrier G" and isgcd: "z gcdof x y" |
2407 |
by blast |
|
63832 | 2408 |
with carr have "greatest (division_rel G) z (Lower (division_rel G) {x, y})" |
2409 |
by (subst gcdof_greatestLower[symmetric], simp+) |
|
2410 |
then show "\<exists>z. greatest (division_rel G) z (Lower (division_rel G) {x, y})" |
|
2411 |
by fast |
|
27701 | 2412 |
qed |
2413 |
qed |
|
2414 |
||
2415 |
lemma (in gcd_condition_monoid) gcdof_cong_l: |
|
2416 |
assumes a'a: "a' \<sim> a" |
|
2417 |
and agcd: "a gcdof b c" |
|
2418 |
and a'carr: "a' \<in> carrier G" and carr': "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" |
|
2419 |
shows "a' gcdof b c" |
|
2420 |
proof - |
|
2421 |
note carr = a'carr carr' |
|
29237 | 2422 |
interpret weak_lower_semilattice "division_rel G" by simp |
27701 | 2423 |
have "a' \<in> carrier G \<and> a' gcdof b c" |
27713
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents:
27701
diff
changeset
|
2424 |
apply (simp add: gcdof_greatestLower carr') |
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents:
27701
diff
changeset
|
2425 |
apply (subst greatest_Lower_cong_l[of _ a]) |
68004 | 2426 |
apply (simp_all add: a'a carr gcdof_greatestLower[symmetric] agcd) |
63832 | 2427 |
done |
2428 |
then show ?thesis .. |
|
27701 | 2429 |
qed |
2430 |
||
2431 |
lemma (in gcd_condition_monoid) gcd_closed [simp]: |
|
2432 |
assumes carr: "a \<in> carrier G" "b \<in> carrier G" |
|
2433 |
shows "somegcd G a b \<in> carrier G" |
|
2434 |
proof - |
|
29237 | 2435 |
interpret weak_lower_semilattice "division_rel G" by simp |
27701 | 2436 |
show ?thesis |
27713
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents:
27701
diff
changeset
|
2437 |
apply (simp add: somegcd_meet[OF carr]) |
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents:
27701
diff
changeset
|
2438 |
apply (rule meet_closed[simplified], fact+) |
63832 | 2439 |
done |
27701 | 2440 |
qed |
2441 |
||
2442 |
lemma (in gcd_condition_monoid) gcd_isgcd: |
|
2443 |
assumes carr: "a \<in> carrier G" "b \<in> carrier G" |
|
2444 |
shows "(somegcd G a b) gcdof a b" |
|
2445 |
proof - |
|
63832 | 2446 |
interpret weak_lower_semilattice "division_rel G" |
2447 |
by simp |
|
2448 |
from carr have "somegcd G a b \<in> carrier G \<and> (somegcd G a b) gcdof a b" |
|
27713
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents:
27701
diff
changeset
|
2449 |
apply (subst gcdof_greatestLower, simp, simp) |
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents:
27701
diff
changeset
|
2450 |
apply (simp add: somegcd_meet[OF carr] meet_def) |
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents:
27701
diff
changeset
|
2451 |
apply (rule inf_of_two_greatest[simplified], assumption+) |
63832 | 2452 |
done |
2453 |
then show "(somegcd G a b) gcdof a b" |
|
2454 |
by simp |
|
27701 | 2455 |
qed |
2456 |
||
2457 |
lemma (in gcd_condition_monoid) gcd_exists: |
|
2458 |
assumes carr: "a \<in> carrier G" "b \<in> carrier G" |
|
2459 |
shows "\<exists>x\<in>carrier G. x = somegcd G a b" |
|
2460 |
proof - |
|
63832 | 2461 |
interpret weak_lower_semilattice "division_rel G" |
2462 |
by simp |
|
27701 | 2463 |
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:
53374
diff
changeset
|
2464 |
by (metis carr(1) carr(2) gcd_closed) |
27701 | 2465 |
qed |
2466 |
||
2467 |
lemma (in gcd_condition_monoid) gcd_divides_l: |
|
2468 |
assumes carr: "a \<in> carrier G" "b \<in> carrier G" |
|
2469 |
shows "(somegcd G a b) divides a" |
|
2470 |
proof - |
|
63832 | 2471 |
interpret weak_lower_semilattice "division_rel G" |
2472 |
by simp |
|
27701 | 2473 |
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:
53374
diff
changeset
|
2474 |
by (metis carr(1) carr(2) gcd_isgcd isgcd_def) |
27701 | 2475 |
qed |
2476 |
||
2477 |
lemma (in gcd_condition_monoid) gcd_divides_r: |
|
2478 |
assumes carr: "a \<in> carrier G" "b \<in> carrier G" |
|
2479 |
shows "(somegcd G a b) divides b" |
|
2480 |
proof - |
|
63832 | 2481 |
interpret weak_lower_semilattice "division_rel G" |
2482 |
by simp |
|
27701 | 2483 |
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:
53374
diff
changeset
|
2484 |
by (metis carr gcd_isgcd isgcd_def) |
27701 | 2485 |
qed |
2486 |
||
2487 |
lemma (in gcd_condition_monoid) gcd_divides: |
|
2488 |
assumes sub: "z divides x" "z divides y" |
|
2489 |
and L: "x \<in> carrier G" "y \<in> carrier G" "z \<in> carrier G" |
|
2490 |
shows "z divides (somegcd G x y)" |
|
2491 |
proof - |
|
63832 | 2492 |
interpret weak_lower_semilattice "division_rel G" |
2493 |
by simp |
|
27701 | 2494 |
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:
53374
diff
changeset
|
2495 |
by (metis gcd_isgcd isgcd_def assms) |
27701 | 2496 |
qed |
2497 |
||
2498 |
lemma (in gcd_condition_monoid) gcd_cong_l: |
|
2499 |
assumes xx': "x \<sim> x'" |
|
2500 |
and carr: "x \<in> carrier G" "x' \<in> carrier G" "y \<in> carrier G" |
|
2501 |
shows "somegcd G x y \<sim> somegcd G x' y" |
|
2502 |
proof - |
|
63832 | 2503 |
interpret weak_lower_semilattice "division_rel G" |
2504 |
by simp |
|
27701 | 2505 |
show ?thesis |
27713
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents:
27701
diff
changeset
|
2506 |
apply (simp add: somegcd_meet carr) |
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents:
27701
diff
changeset
|
2507 |
apply (rule meet_cong_l[simplified], fact+) |
63832 | 2508 |
done |
27701 | 2509 |
qed |
2510 |
||
2511 |
lemma (in gcd_condition_monoid) gcd_cong_r: |
|
2512 |
assumes carr: "x \<in> carrier G" "y \<in> carrier G" "y' \<in> carrier G" |
|
2513 |
and yy': "y \<sim> y'" |
|
2514 |
shows "somegcd G x y \<sim> somegcd G x y'" |
|
2515 |
proof - |
|
29237 | 2516 |
interpret weak_lower_semilattice "division_rel G" by simp |
27701 | 2517 |
show ?thesis |
27713
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents:
27701
diff
changeset
|
2518 |
apply (simp add: somegcd_meet carr) |
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents:
27701
diff
changeset
|
2519 |
apply (rule meet_cong_r[simplified], fact+) |
63832 | 2520 |
done |
27701 | 2521 |
qed |
2522 |
||
2523 |
(* |
|
2524 |
lemma (in gcd_condition_monoid) asc_cong_gcd_l [intro]: |
|
2525 |
assumes carr: "b \<in> carrier G" |
|
2526 |
shows "asc_cong (\<lambda>a. somegcd G a b)" |
|
2527 |
using carr |
|
2528 |
unfolding CONG_def |
|
2529 |
by clarsimp (blast intro: gcd_cong_l) |
|
2530 |
||
2531 |
lemma (in gcd_condition_monoid) asc_cong_gcd_r [intro]: |
|
2532 |
assumes carr: "a \<in> carrier G" |
|
2533 |
shows "asc_cong (\<lambda>b. somegcd G a b)" |
|
2534 |
using carr |
|
2535 |
unfolding CONG_def |
|
2536 |
by clarsimp (blast intro: gcd_cong_r) |
|
2537 |
||
63832 | 2538 |
lemmas (in gcd_condition_monoid) asc_cong_gcd_split [simp] = |
27701 | 2539 |
assoc_split[OF _ asc_cong_gcd_l] assoc_split[OF _ asc_cong_gcd_r] |
2540 |
*) |
|
2541 |
||
2542 |
lemma (in gcd_condition_monoid) gcdI: |
|
2543 |
assumes dvd: "a divides b" "a divides c" |
|
2544 |
and others: "\<forall>y\<in>carrier G. y divides b \<and> y divides c \<longrightarrow> y divides a" |
|
2545 |
and acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" and ccarr: "c \<in> carrier G" |
|
2546 |
shows "a \<sim> somegcd G b c" |
|
63832 | 2547 |
apply (simp add: somegcd_def) |
2548 |
apply (rule someI2_ex) |
|
2549 |
apply (rule exI[of _ a], simp add: isgcd_def) |
|
2550 |
apply (simp add: assms) |
|
2551 |
apply (simp add: isgcd_def assms, clarify) |
|
2552 |
apply (insert assms, blast intro: associatedI) |
|
2553 |
done |
|
27701 | 2554 |
|
2555 |
lemma (in gcd_condition_monoid) gcdI2: |
|
63832 | 2556 |
assumes "a gcdof b c" and "a \<in> carrier G" and "b \<in> carrier G" and "c \<in> carrier G" |
27701 | 2557 |
shows "a \<sim> somegcd G b c" |
63832 | 2558 |
using assms unfolding isgcd_def by (blast intro: gcdI) |
27701 | 2559 |
|
2560 |
lemma (in gcd_condition_monoid) SomeGcd_ex: |
|
2561 |
assumes "finite A" "A \<subseteq> carrier G" "A \<noteq> {}" |
|
2562 |
shows "\<exists>x\<in> carrier G. x = SomeGcd G A" |
|
2563 |
proof - |
|
63832 | 2564 |
interpret weak_lower_semilattice "division_rel G" |
2565 |
by simp |
|
27701 | 2566 |
show ?thesis |
2567 |
apply (simp add: SomeGcd_def) |
|
27713
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents:
27701
diff
changeset
|
2568 |
apply (rule finite_inf_closed[simplified], fact+) |
63832 | 2569 |
done |
27701 | 2570 |
qed |
2571 |
||
2572 |
lemma (in gcd_condition_monoid) gcd_assoc: |
|
2573 |
assumes carr: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" |
|
2574 |
shows "somegcd G (somegcd G a b) c \<sim> somegcd G a (somegcd G b c)" |
|
2575 |
proof - |
|
63832 | 2576 |
interpret weak_lower_semilattice "division_rel G" |
2577 |
by simp |
|
27701 | 2578 |
show ?thesis |
27713
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents:
27701
diff
changeset
|
2579 |
apply (subst (2 3) somegcd_meet, (simp add: carr)+) |
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents:
27701
diff
changeset
|
2580 |
apply (simp add: somegcd_meet carr) |
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents:
27701
diff
changeset
|
2581 |
apply (rule weak_meet_assoc[simplified], fact+) |
63832 | 2582 |
done |
27701 | 2583 |
qed |
2584 |
||
2585 |
lemma (in gcd_condition_monoid) gcd_mult: |
|
2586 |
assumes acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" and ccarr: "c \<in> carrier G" |
|
2587 |
shows "c \<otimes> somegcd G a b \<sim> somegcd G (c \<otimes> a) (c \<otimes> b)" |
|
2588 |
proof - (* following Jacobson, Basic Algebra, p.140 *) |
|
2589 |
let ?d = "somegcd G a b" |
|
2590 |
let ?e = "somegcd G (c \<otimes> a) (c \<otimes> b)" |
|
2591 |
note carr[simp] = acarr bcarr ccarr |
|
2592 |
have dcarr: "?d \<in> carrier G" by simp |
|
2593 |
have ecarr: "?e \<in> carrier G" by simp |
|
2594 |
note carr = carr dcarr ecarr |
|
2595 |
||
2596 |
have "?d divides a" by (simp add: gcd_divides_l) |
|
63832 | 2597 |
then have cd'ca: "c \<otimes> ?d divides (c \<otimes> a)" by (simp add: divides_mult_lI) |
27701 | 2598 |
|
2599 |
have "?d divides b" by (simp add: gcd_divides_r) |
|
63832 | 2600 |
then have cd'cb: "c \<otimes> ?d divides (c \<otimes> b)" by (simp add: divides_mult_lI) |
2601 |
||
2602 |
from cd'ca cd'cb have cd'e: "c \<otimes> ?d divides ?e" |
|
2603 |
by (rule gcd_divides) simp_all |
|
2604 |
then obtain u where ucarr[simp]: "u \<in> carrier G" and e_cdu: "?e = c \<otimes> ?d \<otimes> u" |
|
63847 | 2605 |
by blast |
27701 | 2606 |
|
2607 |
note carr = carr ucarr |
|
2608 |
||
63832 | 2609 |
have "?e divides c \<otimes> a" by (rule gcd_divides_l) simp_all |
2610 |
then obtain x where xcarr: "x \<in> carrier G" and ca_ex: "c \<otimes> a = ?e \<otimes> x" |
|
63847 | 2611 |
by blast |
63832 | 2612 |
with e_cdu have ca_cdux: "c \<otimes> a = c \<otimes> ?d \<otimes> u \<otimes> x" |
2613 |
by simp |
|
2614 |
||
2615 |
from ca_cdux xcarr have "c \<otimes> a = c \<otimes> (?d \<otimes> u \<otimes> x)" |
|
2616 |
by (simp add: m_assoc) |
|
2617 |
then have "a = ?d \<otimes> u \<otimes> x" |
|
2618 |
by (rule l_cancel[of c a]) (simp add: xcarr)+ |
|
2619 |
then have du'a: "?d \<otimes> u divides a" |
|
2620 |
by (rule dividesI[OF xcarr]) |
|
2621 |
||
2622 |
have "?e divides c \<otimes> b" by (intro gcd_divides_r) simp_all |
|
2623 |
then obtain x where xcarr: "x \<in> carrier G" and cb_ex: "c \<otimes> b = ?e \<otimes> x" |
|
63847 | 2624 |
by blast |
63832 | 2625 |
with e_cdu have cb_cdux: "c \<otimes> b = c \<otimes> ?d \<otimes> u \<otimes> x" |
2626 |
by simp |
|
2627 |
||
2628 |
from cb_cdux xcarr have "c \<otimes> b = c \<otimes> (?d \<otimes> u \<otimes> x)" |
|
2629 |
by (simp add: m_assoc) |
|
2630 |
with xcarr have "b = ?d \<otimes> u \<otimes> x" |
|
2631 |
by (intro l_cancel[of c b]) simp_all |
|
2632 |
then have du'b: "?d \<otimes> u divides b" |
|
2633 |
by (intro dividesI[OF xcarr]) |
|
2634 |
||
2635 |
from du'a du'b carr have du'd: "?d \<otimes> u divides ?d" |
|
2636 |
by (intro gcd_divides) simp_all |
|
2637 |
then have uunit: "u \<in> Units G" |
|
27701 | 2638 |
proof (elim dividesE) |
2639 |
fix v |
|
2640 |
assume vcarr[simp]: "v \<in> carrier G" |
|
2641 |
assume d: "?d = ?d \<otimes> u \<otimes> v" |
|
2642 |
have "?d \<otimes> \<one> = ?d \<otimes> u \<otimes> v" by simp fact |
|
2643 |
also have "?d \<otimes> u \<otimes> v = ?d \<otimes> (u \<otimes> v)" by (simp add: m_assoc) |
|
2644 |
finally have "?d \<otimes> \<one> = ?d \<otimes> (u \<otimes> v)" . |
|
63832 | 2645 |
then have i2: "\<one> = u \<otimes> v" by (rule l_cancel) simp_all |
2646 |
then have i1: "\<one> = v \<otimes> u" by (simp add: m_comm) |
|
2647 |
from vcarr i1[symmetric] i2[symmetric] show "u \<in> Units G" |
|
2648 |
by (auto simp: Units_def) |
|
27701 | 2649 |
qed |
2650 |
||
63832 | 2651 |
from e_cdu uunit have "somegcd G (c \<otimes> a) (c \<otimes> b) \<sim> c \<otimes> somegcd G a b" |
2652 |
by (intro associatedI2[of u]) simp_all |
|
2653 |
from this[symmetric] show "c \<otimes> somegcd G a b \<sim> somegcd G (c \<otimes> a) (c \<otimes> b)" |
|
2654 |
by simp |
|
27701 | 2655 |
qed |
2656 |
||
2657 |
lemma (in monoid) assoc_subst: |
|
2658 |
assumes ab: "a \<sim> b" |
|
63832 | 2659 |
and cP: "\<forall>a b. a \<in> carrier G \<and> b \<in> carrier G \<and> a \<sim> b |
2660 |
\<longrightarrow> f a \<in> carrier G \<and> f b \<in> carrier G \<and> f a \<sim> f b" |
|
27701 | 2661 |
and carr: "a \<in> carrier G" "b \<in> carrier G" |
2662 |
shows "f a \<sim> f b" |
|
2663 |
using assms by auto |
|
2664 |
||
2665 |
lemma (in gcd_condition_monoid) relprime_mult: |
|
63832 | 2666 |
assumes abrelprime: "somegcd G a b \<sim> \<one>" |
2667 |
and acrelprime: "somegcd G a c \<sim> \<one>" |
|
27701 | 2668 |
and carr[simp]: "a \<in> carrier G" "b \<in> carrier G" "c \<in> carrier G" |
2669 |
shows "somegcd G a (b \<otimes> c) \<sim> \<one>" |
|
2670 |
proof - |
|
2671 |
have "c = c \<otimes> \<one>" by simp |
|
2672 |
also from abrelprime[symmetric] |
|
63832 | 2673 |
have "\<dots> \<sim> c \<otimes> somegcd G a b" |
2674 |
by (rule assoc_subst) (simp add: mult_cong_r)+ |
|
2675 |
also have "\<dots> \<sim> somegcd G (c \<otimes> a) (c \<otimes> b)" |
|
2676 |
by (rule gcd_mult) fact+ |
|
2677 |
finally have c: "c \<sim> somegcd G (c \<otimes> a) (c \<otimes> b)" |
|
2678 |
by simp |
|
2679 |
||
2680 |
from carr have a: "a \<sim> somegcd G a (c \<otimes> a)" |
|
2681 |
by (fast intro: gcdI divides_prod_l) |
|
2682 |
||
2683 |
have "somegcd G a (b \<otimes> c) \<sim> somegcd G a (c \<otimes> b)" |
|
2684 |
by (simp add: m_comm) |
|
2685 |
also from a have "\<dots> \<sim> somegcd G (somegcd G a (c \<otimes> a)) (c \<otimes> b)" |
|
2686 |
by (rule assoc_subst) (simp add: gcd_cong_l)+ |
|
2687 |
also from gcd_assoc have "\<dots> \<sim> somegcd G a (somegcd G (c \<otimes> a) (c \<otimes> b))" |
|
2688 |
by (rule assoc_subst) simp+ |
|
2689 |
also from c[symmetric] have "\<dots> \<sim> somegcd G a c" |
|
2690 |
by (rule assoc_subst) (simp add: gcd_cong_r)+ |
|
27701 | 2691 |
also note acrelprime |
63832 | 2692 |
finally show "somegcd G a (b \<otimes> c) \<sim> \<one>" |
2693 |
by simp |
|
27701 | 2694 |
qed |
2695 |
||
63832 | 2696 |
lemma (in gcd_condition_monoid) primeness_condition: "primeness_condition_monoid G" |
2697 |
apply unfold_locales |
|
2698 |
apply (rule primeI) |
|
2699 |
apply (elim irreducibleE, assumption) |
|
27701 | 2700 |
proof - |
2701 |
fix p a b |
|
2702 |
assume pcarr: "p \<in> carrier G" and acarr: "a \<in> carrier G" and bcarr: "b \<in> carrier G" |
|
2703 |
and pirr: "irreducible G p" |
|
2704 |
and pdvdab: "p divides a \<otimes> b" |
|
63832 | 2705 |
from pirr have pnunit: "p \<notin> Units G" |
2706 |
and r[rule_format]: "\<forall>b. b \<in> carrier G \<and> properfactor G b p \<longrightarrow> b \<in> Units G" |
|
2707 |
by (fast elim: irreducibleE)+ |
|
27701 | 2708 |
|
2709 |
show "p divides a \<or> p divides b" |
|
2710 |
proof (rule ccontr, clarsimp) |
|
2711 |
assume npdvda: "\<not> p divides a" |
|
63832 | 2712 |
with pcarr acarr have "\<one> \<sim> somegcd G p a" |
2713 |
apply (intro gcdI, simp, simp, simp) |
|
2714 |
apply (fast intro: unit_divides) |
|
2715 |
apply (fast intro: unit_divides) |
|
2716 |
apply (clarsimp simp add: Unit_eq_dividesone[symmetric]) |
|
2717 |
apply (rule r, rule, assumption) |
|
2718 |
apply (rule properfactorI, assumption) |
|
63846 | 2719 |
proof |
27701 | 2720 |
fix y |
2721 |
assume ycarr: "y \<in> carrier G" |
|
2722 |
assume "p divides y" |
|
2723 |
also assume "y divides a" |
|
63832 | 2724 |
finally have "p divides a" |
2725 |
by (simp add: pcarr ycarr acarr) |
|
2726 |
with npdvda show False .. |
|
2727 |
qed simp_all |
|
2728 |
with pcarr acarr have pa: "somegcd G p a \<sim> \<one>" |
|
2729 |
by (fast intro: associated_sym[of "\<one>"] gcd_closed) |
|
27701 | 2730 |
|
2731 |
assume npdvdb: "\<not> p divides b" |
|
63832 | 2732 |
with pcarr bcarr have "\<one> \<sim> somegcd G p b" |
2733 |
apply (intro gcdI, simp, simp, simp) |
|
2734 |
apply (fast intro: unit_divides) |
|
2735 |
apply (fast intro: unit_divides) |
|
2736 |
apply (clarsimp simp add: Unit_eq_dividesone[symmetric]) |
|
2737 |
apply (rule r, rule, assumption) |
|
2738 |
apply (rule properfactorI, assumption) |
|
63846 | 2739 |
proof |
27701 | 2740 |
fix y |
2741 |
assume ycarr: "y \<in> carrier G" |
|
2742 |
assume "p divides y" |
|
2743 |
also assume "y divides b" |
|
2744 |
finally have "p divides b" by (simp add: pcarr ycarr bcarr) |
|
2745 |
with npdvdb |
|
63832 | 2746 |
show "False" .. |
2747 |
qed simp_all |
|
2748 |
with pcarr bcarr have pb: "somegcd G p b \<sim> \<one>" |
|
2749 |
by (fast intro: associated_sym[of "\<one>"] gcd_closed) |
|
2750 |
||
2751 |
from pcarr acarr bcarr pdvdab have "p gcdof p (a \<otimes> b)" |
|
2752 |
by (fast intro: isgcd_divides_l) |
|
2753 |
with pcarr acarr bcarr have "p \<sim> somegcd G p (a \<otimes> b)" |
|
2754 |
by (fast intro: gcdI2) |
|
2755 |
also from pa pb pcarr acarr bcarr have "somegcd G p (a \<otimes> b) \<sim> \<one>" |
|
2756 |
by (rule relprime_mult) |
|
2757 |
finally have "p \<sim> \<one>" |
|
2758 |
by (simp add: pcarr acarr bcarr) |
|
2759 |
with pcarr have "p \<in> Units G" |
|
2760 |
by (fast intro: assoc_unit_l) |
|
2761 |
with pnunit show False .. |
|
27701 | 2762 |
qed |
2763 |
qed |
|
2764 |
||
29237 | 2765 |
sublocale gcd_condition_monoid \<subseteq> primeness_condition_monoid |
27701 | 2766 |
by (rule primeness_condition) |
2767 |
||
2768 |
||
61382 | 2769 |
subsubsection \<open>Divisor chain condition\<close> |
27701 | 2770 |
|
2771 |
lemma (in divisor_chain_condition_monoid) wfactors_exist: |
|
2772 |
assumes acarr: "a \<in> carrier G" |
|
2773 |
shows "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a" |
|
2774 |
proof - |
|
2775 |
have r[rule_format]: "a \<in> carrier G \<longrightarrow> (\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a)" |
|
63832 | 2776 |
proof (rule wf_induct[OF division_wellfounded]) |
27701 | 2777 |
fix x |
2778 |
assume ih: "\<forall>y. (y, x) \<in> {(x, y). x \<in> carrier G \<and> y \<in> carrier G \<and> properfactor G x y} |
|
2779 |
\<longrightarrow> y \<in> carrier G \<longrightarrow> (\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as y)" |
|
2780 |
||
2781 |
show "x \<in> carrier G \<longrightarrow> (\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as x)" |
|
63832 | 2782 |
apply clarify |
2783 |
apply (cases "x \<in> Units G") |
|
2784 |
apply (rule exI[of _ "[]"], simp) |
|
2785 |
apply (cases "irreducible G x") |
|
2786 |
apply (rule exI[of _ "[x]"], simp add: wfactors_def) |
|
27701 | 2787 |
proof - |
2788 |
assume xcarr: "x \<in> carrier G" |
|
2789 |
and xnunit: "x \<notin> Units G" |
|
2790 |
and xnirr: "\<not> irreducible G x" |
|
63832 | 2791 |
then have "\<exists>y. y \<in> carrier G \<and> properfactor G y x \<and> y \<notin> Units G" |
2792 |
apply - |
|
2793 |
apply (rule ccontr) |
|
2794 |
apply simp |
|
27701 | 2795 |
apply (subgoal_tac "irreducible G x", simp) |
2796 |
apply (rule irreducibleI, simp, simp) |
|
63832 | 2797 |
done |
2798 |
then obtain y where ycarr: "y \<in> carrier G" and ynunit: "y \<notin> Units G" |
|
2799 |
and pfyx: "properfactor G y x" |
|
63847 | 2800 |
by blast |
63832 | 2801 |
|
2802 |
have ih': "\<And>y. \<lbrakk>y \<in> carrier G; properfactor G y x\<rbrakk> |
|
2803 |
\<Longrightarrow> \<exists>as. set as \<subseteq> carrier G \<and> wfactors G as y" |
|
2804 |
by (rule ih[rule_format, simplified]) (simp add: xcarr)+ |
|
2805 |
||
63847 | 2806 |
from ih' [OF ycarr pfyx] |
2807 |
obtain ys where yscarr: "set ys \<subseteq> carrier G" and yfs: "wfactors G ys y" |
|
2808 |
by blast |
|
63832 | 2809 |
|
2810 |
from pfyx have "y divides x" and nyx: "\<not> y \<sim> x" |
|
2811 |
by (fast elim: properfactorE2)+ |
|
2812 |
then obtain z where zcarr: "z \<in> carrier G" and x: "x = y \<otimes> z" |
|
63847 | 2813 |
by blast |
63832 | 2814 |
|
2815 |
from zcarr ycarr have "properfactor G z x" |
|
27701 | 2816 |
apply (subst x) |
2817 |
apply (intro properfactorI3[of _ _ y]) |
|
63832 | 2818 |
apply (simp add: m_comm) |
2819 |
apply (simp add: ynunit)+ |
|
2820 |
done |
|
63847 | 2821 |
from ih' [OF zcarr this] |
2822 |
obtain zs where zscarr: "set zs \<subseteq> carrier G" and zfs: "wfactors G zs z" |
|
2823 |
by blast |
|
63832 | 2824 |
from yscarr zscarr have xscarr: "set (ys@zs) \<subseteq> carrier G" |
2825 |
by simp |
|
2826 |
from yfs zfs ycarr zcarr yscarr zscarr have "wfactors G (ys@zs) (y\<otimes>z)" |
|
2827 |
by (rule wfactors_mult) |
|
2828 |
then have "wfactors G (ys@zs) x" |
|
2829 |
by (simp add: x) |
|
2830 |
with xscarr show "\<exists>xs. set xs \<subseteq> carrier G \<and> wfactors G xs x" |
|
2831 |
by fast |
|
27701 | 2832 |
qed |
2833 |
qed |
|
63832 | 2834 |
from acarr show ?thesis by (rule r) |
27701 | 2835 |
qed |
2836 |
||
2837 |
||
61382 | 2838 |
subsubsection \<open>Primeness condition\<close> |
27701 | 2839 |
|
2840 |
lemma (in comm_monoid_cancel) multlist_prime_pos: |
|
2841 |
assumes carr: "a \<in> carrier G" "set as \<subseteq> carrier G" |
|
2842 |
and aprime: "prime G a" |
|
67399 | 2843 |
and "a divides (foldr (\<otimes>) as \<one>)" |
27701 | 2844 |
shows "\<exists>i<length as. a divides (as!i)" |
2845 |
proof - |
|
67399 | 2846 |
have r[rule_format]: "set as \<subseteq> carrier G \<and> a divides (foldr (\<otimes>) as \<one>) |
63832 | 2847 |
\<longrightarrow> (\<exists>i. i < length as \<and> a divides (as!i))" |
27701 | 2848 |
apply (induct as) |
2849 |
apply clarsimp defer 1 |
|
2850 |
apply clarsimp defer 1 |
|
2851 |
proof - |
|
2852 |
assume "a divides \<one>" |
|
63832 | 2853 |
with carr have "a \<in> Units G" |
2854 |
by (fast intro: divides_unit[of a \<one>]) |
|
2855 |
with aprime show False |
|
2856 |
by (elim primeE, simp) |
|
27701 | 2857 |
next |
2858 |
fix aa as |
|
67399 | 2859 |
assume ih[rule_format]: "a divides foldr (\<otimes>) as \<one> \<longrightarrow> (\<exists>i<length as. a divides as ! i)" |
27701 | 2860 |
and carr': "aa \<in> carrier G" "set as \<subseteq> carrier G" |
67399 | 2861 |
and "a divides aa \<otimes> foldr (\<otimes>) as \<one>" |
2862 |
with carr aprime have "a divides aa \<or> a divides foldr (\<otimes>) as \<one>" |
|
63832 | 2863 |
by (intro prime_divides) simp+ |
2864 |
then show "\<exists>i<Suc (length as). a divides (aa # as) ! i" |
|
2865 |
proof |
|
27701 | 2866 |
assume "a divides aa" |
63832 | 2867 |
then have p1: "a divides (aa#as)!0" by simp |
27701 | 2868 |
have "0 < Suc (length as)" by simp |
63832 | 2869 |
with p1 show ?thesis by fast |
2870 |
next |
|
67399 | 2871 |
assume "a divides foldr (\<otimes>) as \<one>" |
63847 | 2872 |
from ih [OF this] obtain i where "a divides as ! i" and len: "i < length as" by auto |
63832 | 2873 |
then have p1: "a divides (aa#as) ! (Suc i)" by simp |
27701 | 2874 |
from len have "Suc i < Suc (length as)" by simp |
63832 | 2875 |
with p1 show ?thesis by force |
2876 |
qed |
|
27701 | 2877 |
qed |
63832 | 2878 |
from assms show ?thesis |
2879 |
by (intro r) auto |
|
27701 | 2880 |
qed |
2881 |
||
2882 |
lemma (in primeness_condition_monoid) wfactors_unique__hlp_induct: |
|
63832 | 2883 |
"\<forall>a as'. a \<in> carrier G \<and> set as \<subseteq> carrier G \<and> set as' \<subseteq> carrier G \<and> |
27701 | 2884 |
wfactors G as a \<and> wfactors G as' a \<longrightarrow> essentially_equal G as as'" |
46129 | 2885 |
proof (induct as) |
63832 | 2886 |
case Nil |
2887 |
show ?case |
|
2888 |
proof auto |
|
46129 | 2889 |
fix a as' |
2890 |
assume a: "a \<in> carrier G" |
|
2891 |
assume "wfactors G [] a" |
|
2892 |
then obtain "\<one> \<sim> a" by (auto elim: wfactorsE) |
|
2893 |
with a have "a \<in> Units G" by (auto intro: assoc_unit_r) |
|
2894 |
moreover assume "wfactors G as' a" |
|
2895 |
moreover assume "set as' \<subseteq> carrier G" |
|
2896 |
ultimately have "as' = []" by (rule unit_wfactors_empty) |
|
2897 |
then show "essentially_equal G [] as'" by simp |
|
2898 |
qed |
|
2899 |
next |
|
63832 | 2900 |
case (Cons ah as) |
2901 |
then show ?case |
|
2902 |
proof clarsimp |
|
46129 | 2903 |
fix a as' |
63832 | 2904 |
assume ih [rule_format]: |
46129 | 2905 |
"\<forall>a as'. a \<in> carrier G \<and> set as' \<subseteq> carrier G \<and> wfactors G as a \<and> |
2906 |
wfactors G as' a \<longrightarrow> essentially_equal G as as'" |
|
2907 |
and acarr: "a \<in> carrier G" and ahcarr: "ah \<in> carrier G" |
|
2908 |
and ascarr: "set as \<subseteq> carrier G" and as'carr: "set as' \<subseteq> carrier G" |
|
2909 |
and afs: "wfactors G (ah # as) a" |
|
2910 |
and afs': "wfactors G as' a" |
|
63832 | 2911 |
then have ahdvda: "ah divides a" |
63847 | 2912 |
by (intro wfactors_dividesI[of "ah#as" "a"]) simp_all |
63832 | 2913 |
then obtain a' where a'carr: "a' \<in> carrier G" and a: "a = ah \<otimes> a'" |
63847 | 2914 |
by blast |
46129 | 2915 |
have a'fs: "wfactors G as a'" |
2916 |
apply (rule wfactorsE[OF afs], rule wfactorsI, simp) |
|
63847 | 2917 |
apply (simp add: a) |
2918 |
apply (insert ascarr a'carr) |
|
46129 | 2919 |
apply (intro assoc_l_cancel[of ah _ a'] multlist_closed ahcarr, assumption+) |
2920 |
done |
|
63832 | 2921 |
from afs have ahirr: "irreducible G ah" |
2922 |
by (elim wfactorsE) simp |
|
2923 |
with ascarr have ahprime: "prime G ah" |
|
2924 |
by (intro irreducible_prime ahcarr) |
|
46129 | 2925 |
|
2926 |
note carr [simp] = acarr ahcarr ascarr as'carr a'carr |
|
2927 |
||
2928 |
note ahdvda |
|
67399 | 2929 |
also from afs' have "a divides (foldr (\<otimes>) as' \<one>)" |
46129 | 2930 |
by (elim wfactorsE associatedE, simp) |
67399 | 2931 |
finally have "ah divides (foldr (\<otimes>) as' \<one>)" |
63832 | 2932 |
by simp |
2933 |
with ahprime have "\<exists>i<length as'. ah divides as'!i" |
|
63847 | 2934 |
by (intro multlist_prime_pos) simp_all |
63832 | 2935 |
then obtain i where len: "i<length as'" and ahdvd: "ah divides as'!i" |
63847 | 2936 |
by blast |
46129 | 2937 |
from afs' carr have irrasi: "irreducible G (as'!i)" |
27701 | 2938 |
by (fast intro: nth_mem[OF len] elim: wfactorsE) |
63832 | 2939 |
from len carr have asicarr[simp]: "as'!i \<in> carrier G" |
2940 |
unfolding set_conv_nth by force |
|
46129 | 2941 |
note carr = carr asicarr |
2942 |
||
63847 | 2943 |
from ahdvd obtain x where "x \<in> carrier G" and asi: "as'!i = ah \<otimes> x" |
2944 |
by blast |
|
63832 | 2945 |
with carr irrasi[simplified asi] have asiah: "as'!i \<sim> ah" |
2946 |
apply - |
|
46129 | 2947 |
apply (elim irreducible_prodE[of "ah" "x"], assumption+) |
2948 |
apply (rule associatedI2[of x], assumption+) |
|
2949 |
apply (rule irreducibleE[OF ahirr], simp) |
|
2950 |
done |
|
2951 |
||
2952 |
note setparts = set_take_subset[of i as'] set_drop_subset[of "Suc i" as'] |
|
2953 |
note partscarr [simp] = setparts[THEN subset_trans[OF _ as'carr]] |
|
2954 |
note carr = carr partscarr |
|
2955 |
||
2956 |
have "\<exists>aa_1. aa_1 \<in> carrier G \<and> wfactors G (take i as') aa_1" |
|
2957 |
apply (intro wfactors_prod_exists) |
|
63832 | 2958 |
using setparts afs' |
2959 |
apply (fast elim: wfactorsE) |
|
2960 |
apply simp |
|
2961 |
done |
|
2962 |
then obtain aa_1 where aa1carr: "aa_1 \<in> carrier G" and aa1fs: "wfactors G (take i as') aa_1" |
|
2963 |
by auto |
|
46129 | 2964 |
|
2965 |
have "\<exists>aa_2. aa_2 \<in> carrier G \<and> wfactors G (drop (Suc i) as') aa_2" |
|
2966 |
apply (intro wfactors_prod_exists) |
|
63832 | 2967 |
using setparts afs' |
2968 |
apply (fast elim: wfactorsE) |
|
2969 |
apply simp |
|
2970 |
done |
|
2971 |
then obtain aa_2 where aa2carr: "aa_2 \<in> carrier G" |
|
2972 |
and aa2fs: "wfactors G (drop (Suc i) as') aa_2" |
|
2973 |
by auto |
|
46129 | 2974 |
|
2975 |
note carr = carr aa1carr[simp] aa2carr[simp] |
|
2976 |
||
2977 |
from aa1fs aa2fs |
|
63832 | 2978 |
have v1: "wfactors G (take i as' @ drop (Suc i) as') (aa_1 \<otimes> aa_2)" |
27701 | 2979 |
by (intro wfactors_mult, simp+) |
63832 | 2980 |
then have v1': "wfactors G (as'!i # take i as' @ drop (Suc i) as') (as'!i \<otimes> (aa_1 \<otimes> aa_2))" |
27701 | 2981 |
apply (intro wfactors_mult_single) |
2982 |
using setparts afs' |
|
63832 | 2983 |
apply (fast intro: nth_mem[OF len] elim: wfactorsE) |
2984 |
apply simp_all |
|
2985 |
done |
|
2986 |
||
2987 |
from aa2carr carr aa1fs aa2fs have "wfactors G (as'!i # drop (Suc i) as') (as'!i \<otimes> aa_2)" |
|
2988 |
by (metis irrasi wfactors_mult_single) |
|
46129 | 2989 |
with len carr aa1carr aa2carr aa1fs |
63832 | 2990 |
have v2: "wfactors G (take i as' @ as'!i # drop (Suc i) as') (aa_1 \<otimes> (as'!i \<otimes> aa_2))" |
46129 | 2991 |
apply (intro wfactors_mult) |
2992 |
apply fast |
|
2993 |
apply (simp, (fast intro: nth_mem[OF len])?)+ |
|
63832 | 2994 |
done |
2995 |
||
2996 |
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:
57865
diff
changeset
|
2997 |
by (simp add: Cons_nth_drop_Suc) |
63832 | 2998 |
with carr have eer: "essentially_equal G (take i as' @ as'!i # drop (Suc i) as') as'" |
27701 | 2999 |
by simp |
63832 | 3000 |
with v2 afs' carr aa1carr aa2carr nth_mem[OF len] have "aa_1 \<otimes> (as'!i \<otimes> aa_2) \<sim> a" |
3001 |
by (metis as' ee_wfactorsD m_closed) |
|
3002 |
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:
53374
diff
changeset
|
3003 |
by (metis aa1carr aa2carr asicarr m_lcomm) |
63832 | 3004 |
from carr asiah have "ah \<otimes> (aa_1 \<otimes> aa_2) \<sim> as'!i \<otimes> (aa_1 \<otimes> aa_2)" |
55242
413ec965f95d
Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents:
53374
diff
changeset
|
3005 |
by (metis associated_sym m_closed mult_cong_l) |
46129 | 3006 |
also note t1 |
63832 | 3007 |
finally have "ah \<otimes> (aa_1 \<otimes> aa_2) \<sim> a" by simp |
3008 |
||
3009 |
with carr aa1carr aa2carr a'carr nth_mem[OF len] have a': "aa_1 \<otimes> aa_2 \<sim> a'" |
|
27701 | 3010 |
by (simp add: a, fast intro: assoc_l_cancel[of ah _ a']) |
3011 |
||
46129 | 3012 |
note v1 |
3013 |
also note a' |
|
63832 | 3014 |
finally have "wfactors G (take i as' @ drop (Suc i) as') a'" |
3015 |
by simp |
|
3016 |
||
3017 |
from a'fs this carr have "essentially_equal G as (take i as' @ drop (Suc i) as')" |
|
27701 | 3018 |
by (intro ih[of a']) simp |
63832 | 3019 |
then have ee1: "essentially_equal G (ah # as) (ah # take i as' @ drop (Suc i) as')" |
3020 |
by (elim essentially_equalE) (fastforce intro: essentially_equalI) |
|
3021 |
||
3022 |
from carr have ee2: "essentially_equal G (ah # take i as' @ drop (Suc i) as') |
|
46129 | 3023 |
(as' ! i # take i as' @ drop (Suc i) as')" |
3024 |
proof (intro essentially_equalI) |
|
3025 |
show "ah # take i as' @ drop (Suc i) as' <~~> ah # take i as' @ drop (Suc i) as'" |
|
27701 | 3026 |
by simp |
46129 | 3027 |
next |
3028 |
show "ah # take i as' @ drop (Suc i) as' [\<sim>] as' ! i # take i as' @ drop (Suc i) as'" |
|
63832 | 3029 |
by (simp add: list_all2_append) (simp add: asiah[symmetric]) |
46129 | 3030 |
qed |
3031 |
||
3032 |
note ee1 |
|
3033 |
also note ee2 |
|
3034 |
also have "essentially_equal G (as' ! i # take i as' @ drop (Suc i) as') |
|
3035 |
(take i as' @ as' ! i # drop (Suc i) as')" |
|
3036 |
apply (intro essentially_equalI) |
|
63832 | 3037 |
apply (subgoal_tac "as' ! i # take i as' @ drop (Suc i) as' <~~> |
3038 |
take i as' @ as' ! i # drop (Suc i) as'") |
|
57865 | 3039 |
apply simp |
46129 | 3040 |
apply (rule perm_append_Cons) |
3041 |
apply simp |
|
57865 | 3042 |
done |
63832 | 3043 |
finally have "essentially_equal G (ah # as) (take i as' @ as' ! i # drop (Suc i) as')" |
3044 |
by simp |
|
3045 |
then show "essentially_equal G (ah # as) as'" |
|
3046 |
by (subst as') |
|
27701 | 3047 |
qed |
3048 |
qed |
|
3049 |
||
3050 |
lemma (in primeness_condition_monoid) wfactors_unique: |
|
3051 |
assumes "wfactors G as a" "wfactors G as' a" |
|
3052 |
and "a \<in> carrier G" "set as \<subseteq> carrier G" "set as' \<subseteq> carrier G" |
|
3053 |
shows "essentially_equal G as as'" |
|
63832 | 3054 |
by (rule wfactors_unique__hlp_induct[rule_format, of a]) (simp add: assms) |
27701 | 3055 |
|
3056 |
||
61382 | 3057 |
subsubsection \<open>Application to factorial monoids\<close> |
3058 |
||
3059 |
text \<open>Number of factors for wellfoundedness\<close> |
|
27701 | 3060 |
|
63832 | 3061 |
definition factorcount :: "_ \<Rightarrow> 'a \<Rightarrow> nat" |
3062 |
where "factorcount G a = |
|
3063 |
(THE c. \<forall>as. set as \<subseteq> carrier G \<and> wfactors G as a \<longrightarrow> c = length as)" |
|
27701 | 3064 |
|
3065 |
lemma (in monoid) ee_length: |
|
3066 |
assumes ee: "essentially_equal G as bs" |
|
3067 |
shows "length as = length bs" |
|
63832 | 3068 |
by (rule essentially_equalE[OF ee]) (metis list_all2_conv_all_nth perm_length) |
27701 | 3069 |
|
3070 |
lemma (in factorial_monoid) factorcount_exists: |
|
3071 |
assumes carr[simp]: "a \<in> carrier G" |
|
63832 | 3072 |
shows "\<exists>c. \<forall>as. set as \<subseteq> carrier G \<and> wfactors G as a \<longrightarrow> c = length as" |
27701 | 3073 |
proof - |
63832 | 3074 |
have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a" |
3075 |
by (intro wfactors_exist) simp |
|
3076 |
then obtain as where ascarr[simp]: "set as \<subseteq> carrier G" and afs: "wfactors G as a" |
|
3077 |
by (auto simp del: carr) |
|
3078 |
have "\<forall>as'. set as' \<subseteq> carrier G \<and> wfactors G as' a \<longrightarrow> length as = length as'" |
|
36278 | 3079 |
by (metis afs ascarr assms ee_length wfactors_unique) |
63832 | 3080 |
then show "\<exists>c. \<forall>as'. set as' \<subseteq> carrier G \<and> wfactors G as' a \<longrightarrow> c = length as'" .. |
27701 | 3081 |
qed |
3082 |
||
3083 |
lemma (in factorial_monoid) factorcount_unique: |
|
3084 |
assumes afs: "wfactors G as a" |
|
3085 |
and acarr[simp]: "a \<in> carrier G" and ascarr[simp]: "set as \<subseteq> carrier G" |
|
3086 |
shows "factorcount G a = length as" |
|
3087 |
proof - |
|
63832 | 3088 |
have "\<exists>ac. \<forall>as. set as \<subseteq> carrier G \<and> wfactors G as a \<longrightarrow> ac = length as" |
3089 |
by (rule factorcount_exists) simp |
|
3090 |
then obtain ac where alen: "\<forall>as. set as \<subseteq> carrier G \<and> wfactors G as a \<longrightarrow> ac = length as" |
|
3091 |
by auto |
|
27701 | 3092 |
have ac: "ac = factorcount G a" |
3093 |
apply (simp add: factorcount_def) |
|
3094 |
apply (rule theI2) |
|
3095 |
apply (rule alen) |
|
55242
413ec965f95d
Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents:
53374
diff
changeset
|
3096 |
apply (metis afs alen ascarr)+ |
63832 | 3097 |
done |
3098 |
from ascarr afs have "ac = length as" |
|
3099 |
by (iprover intro: alen[rule_format]) |
|
3100 |
with ac show ?thesis |
|
3101 |
by simp |
|
27701 | 3102 |
qed |
3103 |
||
3104 |
lemma (in factorial_monoid) divides_fcount: |
|
3105 |
assumes dvd: "a divides b" |
|
63832 | 3106 |
and acarr: "a \<in> carrier G" |
3107 |
and bcarr:"b \<in> carrier G" |
|
3108 |
shows "factorcount G a \<le> factorcount G b" |
|
3109 |
proof (rule dividesE[OF dvd]) |
|
27701 | 3110 |
fix c |
63832 | 3111 |
from assms have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a" |
63847 | 3112 |
by blast |
63832 | 3113 |
then obtain as where ascarr: "set as \<subseteq> carrier G" and afs: "wfactors G as a" |
63847 | 3114 |
by blast |
63832 | 3115 |
with acarr have fca: "factorcount G a = length as" |
3116 |
by (intro factorcount_unique) |
|
27701 | 3117 |
|
3118 |
assume ccarr: "c \<in> carrier G" |
|
63832 | 3119 |
then have "\<exists>cs. set cs \<subseteq> carrier G \<and> wfactors G cs c" |
63847 | 3120 |
by blast |
63832 | 3121 |
then obtain cs where cscarr: "set cs \<subseteq> carrier G" and cfs: "wfactors G cs c" |
63847 | 3122 |
by blast |
27701 | 3123 |
|
3124 |
note [simp] = acarr bcarr ccarr ascarr cscarr |
|
3125 |
||
3126 |
assume b: "b = a \<otimes> c" |
|
63832 | 3127 |
from afs cfs have "wfactors G (as@cs) (a \<otimes> c)" |
3128 |
by (intro wfactors_mult) simp_all |
|
3129 |
with b have "wfactors G (as@cs) b" |
|
3130 |
by simp |
|
3131 |
then have "factorcount G b = length (as@cs)" |
|
3132 |
by (intro factorcount_unique) simp_all |
|
3133 |
then have "factorcount G b = length as + length cs" |
|
3134 |
by simp |
|
3135 |
with fca show ?thesis |
|
3136 |
by simp |
|
27701 | 3137 |
qed |
3138 |
||
3139 |
lemma (in factorial_monoid) associated_fcount: |
|
63832 | 3140 |
assumes acarr: "a \<in> carrier G" |
3141 |
and bcarr: "b \<in> carrier G" |
|
27701 | 3142 |
and asc: "a \<sim> b" |
3143 |
shows "factorcount G a = factorcount G b" |
|
63832 | 3144 |
apply (rule associatedE[OF asc]) |
3145 |
apply (drule divides_fcount[OF _ acarr bcarr]) |
|
3146 |
apply (drule divides_fcount[OF _ bcarr acarr]) |
|
3147 |
apply simp |
|
3148 |
done |
|
27701 | 3149 |
|
3150 |
lemma (in factorial_monoid) properfactor_fcount: |
|
3151 |
assumes acarr: "a \<in> carrier G" and bcarr:"b \<in> carrier G" |
|
3152 |
and pf: "properfactor G a b" |
|
3153 |
shows "factorcount G a < factorcount G b" |
|
63832 | 3154 |
proof (rule properfactorE[OF pf], elim dividesE) |
27701 | 3155 |
fix c |
63832 | 3156 |
from assms have "\<exists>as. set as \<subseteq> carrier G \<and> wfactors G as a" |
63847 | 3157 |
by blast |
63832 | 3158 |
then obtain as where ascarr: "set as \<subseteq> carrier G" and afs: "wfactors G as a" |
63847 | 3159 |
by blast |
63832 | 3160 |
with acarr have fca: "factorcount G a = length as" |
3161 |
by (intro factorcount_unique) |
|
27701 | 3162 |
|
3163 |
assume ccarr: "c \<in> carrier G" |
|
63832 | 3164 |
then have "\<exists>cs. set cs \<subseteq> carrier G \<and> wfactors G cs c" |
63847 | 3165 |
by blast |
63832 | 3166 |
then obtain cs where cscarr: "set cs \<subseteq> carrier G" and cfs: "wfactors G cs c" |
63847 | 3167 |
by blast |
27701 | 3168 |
|
3169 |
assume b: "b = a \<otimes> c" |
|
3170 |
||
63832 | 3171 |
have "wfactors G (as@cs) (a \<otimes> c)" |
3172 |
by (rule wfactors_mult) fact+ |
|
3173 |
with b have "wfactors G (as@cs) b" |
|
3174 |
by simp |
|
3175 |
with ascarr cscarr bcarr have "factorcount G b = length (as@cs)" |
|
3176 |
by (simp add: factorcount_unique) |
|
3177 |
then have fcb: "factorcount G b = length as + length cs" |
|
3178 |
by simp |
|
27701 | 3179 |
|
3180 |
assume nbdvda: "\<not> b divides a" |
|
3181 |
have "c \<notin> Units G" |
|
63846 | 3182 |
proof |
27701 | 3183 |
assume cunit:"c \<in> Units G" |
63832 | 3184 |
have "b \<otimes> inv c = a \<otimes> c \<otimes> inv c" |
3185 |
by (simp add: b) |
|
3186 |
also from ccarr acarr cunit have "\<dots> = a \<otimes> (c \<otimes> inv c)" |
|
3187 |
by (fast intro: m_assoc) |
|
3188 |
also from ccarr cunit have "\<dots> = a \<otimes> \<one>" by simp |
|
3189 |
also from acarr have "\<dots> = a" by simp |
|
27701 | 3190 |
finally have "a = b \<otimes> inv c" by simp |
63832 | 3191 |
with ccarr cunit have "b divides a" |
3192 |
by (fast intro: dividesI[of "inv c"]) |
|
27701 | 3193 |
with nbdvda show False by simp |
3194 |
qed |
|
3195 |
with cfs have "length cs > 0" |
|
36278 | 3196 |
apply - |
3197 |
apply (rule ccontr, simp) |
|
3198 |
apply (metis Units_one_closed ccarr cscarr l_one one_closed properfactorI3 properfactor_fmset unit_wfactors) |
|
3199 |
done |
|
63832 | 3200 |
with fca fcb show ?thesis |
3201 |
by simp |
|
27701 | 3202 |
qed |
3203 |
||
29237 | 3204 |
sublocale factorial_monoid \<subseteq> divisor_chain_condition_monoid |
63832 | 3205 |
apply unfold_locales |
3206 |
apply (rule wfUNIVI) |
|
3207 |
apply (rule measure_induct[of "factorcount G"]) |
|
3208 |
apply simp |
|
3209 |
apply (metis properfactor_fcount) |
|
3210 |
done |
|
27701 | 3211 |
|
29237 | 3212 |
sublocale factorial_monoid \<subseteq> primeness_condition_monoid |
63633 | 3213 |
by standard (rule irreducible_prime) |
27701 | 3214 |
|
3215 |
||
63832 | 3216 |
lemma (in factorial_monoid) primeness_condition: "primeness_condition_monoid G" .. |
3217 |
||
3218 |
lemma (in factorial_monoid) gcd_condition [simp]: "gcd_condition_monoid G" |
|
61169 | 3219 |
by standard (rule gcdof_exists) |
27701 | 3220 |
|
29237 | 3221 |
sublocale factorial_monoid \<subseteq> gcd_condition_monoid |
61169 | 3222 |
by standard (rule gcdof_exists) |
27701 | 3223 |
|
63832 | 3224 |
lemma (in factorial_monoid) division_weak_lattice [simp]: "weak_lattice (division_rel G)" |
27701 | 3225 |
proof - |
63832 | 3226 |
interpret weak_lower_semilattice "division_rel G" |
3227 |
by simp |
|
27713
95b36bfe7fc4
New locales for orders and lattices where the equivalence relation is not restricted to equality.
ballarin
parents:
27701
diff
changeset
|
3228 |
show "weak_lattice (division_rel G)" |
63832 | 3229 |
proof (unfold_locales, simp_all) |
27701 | 3230 |
fix x y |
3231 |
assume carr: "x \<in> carrier G" "y \<in> carrier G" |
|
63847 | 3232 |
from lcmof_exists [OF this] obtain z where zcarr: "z \<in> carrier G" and isgcd: "z lcmof x y" |
3233 |
by blast |
|
63832 | 3234 |
with carr have "least (division_rel G) z (Upper (division_rel G) {x, y})" |
3235 |
by (simp add: lcmof_leastUpper[symmetric]) |
|
3236 |
then show "\<exists>z. least (division_rel G) z (Upper (division_rel G) {x, y})" |
|
63847 | 3237 |
by blast |
27701 | 3238 |
qed |
3239 |
qed |
|
3240 |
||
3241 |
||
61382 | 3242 |
subsection \<open>Factoriality Theorems\<close> |
27701 | 3243 |
|
3244 |
theorem factorial_condition_one: (* Jacobson theorem 2.21 *) |
|
63847 | 3245 |
"divisor_chain_condition_monoid G \<and> primeness_condition_monoid G \<longleftrightarrow> factorial_monoid G" |
3246 |
proof (rule iffI, clarify) |
|
27701 | 3247 |
assume dcc: "divisor_chain_condition_monoid G" |
63832 | 3248 |
and pc: "primeness_condition_monoid G" |
29237 | 3249 |
interpret divisor_chain_condition_monoid "G" by (rule dcc) |
3250 |
interpret primeness_condition_monoid "G" by (rule pc) |
|
27701 | 3251 |
show "factorial_monoid G" |
63832 | 3252 |
by (fast intro: factorial_monoidI wfactors_exist wfactors_unique) |
27701 | 3253 |
next |
63847 | 3254 |
assume "factorial_monoid G" |
3255 |
then interpret factorial_monoid "G" . |
|
27701 | 3256 |
show "divisor_chain_condition_monoid G \<and> primeness_condition_monoid G" |
63832 | 3257 |
by rule unfold_locales |
27701 | 3258 |
qed |
3259 |
||
3260 |
theorem factorial_condition_two: (* Jacobson theorem 2.22 *) |
|
63847 | 3261 |
"divisor_chain_condition_monoid G \<and> gcd_condition_monoid G \<longleftrightarrow> factorial_monoid G" |
3262 |
proof (rule iffI, clarify) |
|
57865 | 3263 |
assume dcc: "divisor_chain_condition_monoid G" |
63832 | 3264 |
and gc: "gcd_condition_monoid G" |
29237 | 3265 |
interpret divisor_chain_condition_monoid "G" by (rule dcc) |
3266 |
interpret gcd_condition_monoid "G" by (rule gc) |
|
27701 | 3267 |
show "factorial_monoid G" |
63832 | 3268 |
by (simp add: factorial_condition_one[symmetric], rule, unfold_locales) |
27701 | 3269 |
next |
63847 | 3270 |
assume "factorial_monoid G" |
3271 |
then interpret factorial_monoid "G" . |
|
27701 | 3272 |
show "divisor_chain_condition_monoid G \<and> gcd_condition_monoid G" |
63832 | 3273 |
by rule unfold_locales |
27701 | 3274 |
qed |
3275 |
||
3276 |
end |