author | wenzelm |
Wed, 04 Nov 2015 23:27:00 +0100 | |
changeset 61578 | 6623c81cb15a |
parent 60981 | e1159bd15982 |
child 61714 | 7c1ad030f0c9 |
permissions | -rw-r--r-- |
41959 | 1 |
(* Title: HOL/Number_Theory/UniqueFactorization.thy |
31719 | 2 |
Author: Jeremy Avigad |
3 |
||
41541 | 4 |
Note: there were previous Isabelle formalizations of unique |
5 |
factorization due to Thomas Marthedal Rasmussen, and, building on |
|
60527 | 6 |
that, by Jeremy Avigad and David Gray. |
31719 | 7 |
*) |
8 |
||
60527 | 9 |
section \<open>Unique factorization for the natural numbers and the integers\<close> |
31719 | 10 |
|
11 |
theory UniqueFactorization |
|
41413
64cd30d6b0b8
explicit file specifications -- avoid secondary load path;
wenzelm
parents:
40461
diff
changeset
|
12 |
imports Cong "~~/src/HOL/Library/Multiset" |
31719 | 13 |
begin |
14 |
||
15 |
(* As a simp or intro rule, |
|
16 |
||
17 |
prime p \<Longrightarrow> p > 0 |
|
18 |
||
60527 | 19 |
wreaks havoc here. When the premise includes \<forall>x \<in># M. prime x, it |
31719 | 20 |
leads to the backchaining |
21 |
||
60527 | 22 |
x > 0 |
23 |
prime x |
|
24 |
x \<in># M which is, unfortunately, |
|
31719 | 25 |
count M x > 0 |
26 |
*) |
|
27 |
||
28 |
(* Here is a version of set product for multisets. Is it worth moving |
|
60527 | 29 |
to multiset.thy? If so, one should similarly define msetsum for abelian |
30 |
semirings, using of_nat. Also, is it worth developing bounded quantifiers |
|
31 |
"\<forall>i \<in># M. P i"? |
|
31719 | 32 |
*) |
33 |
||
34 |
||
60527 | 35 |
subsection \<open>Unique factorization: multiset version\<close> |
31719 | 36 |
|
60527 | 37 |
lemma multiset_prime_factorization_exists: |
38 |
"n > 0 \<Longrightarrow> (\<exists>M. (\<forall>p::nat \<in> set_mset M. prime p) \<and> n = (\<Prod>i \<in># M. i))" |
|
39 |
proof (induct n rule: nat_less_induct) |
|
31719 | 40 |
fix n :: nat |
60527 | 41 |
assume ih: "\<forall>m < n. 0 < m \<longrightarrow> (\<exists>M. (\<forall>p\<in>set_mset M. prime p) \<and> m = (\<Prod>i \<in># M. i))" |
42 |
assume "n > 0" |
|
43 |
then consider "n = 1" | "n > 1" "prime n" | "n > 1" "\<not> prime n" |
|
31719 | 44 |
by arith |
60567 | 45 |
then show "\<exists>M. (\<forall>p \<in> set_mset M. prime p) \<and> n = (\<Prod>i\<in>#M. i)" |
60527 | 46 |
proof cases |
47 |
case 1 |
|
48 |
then have "(\<forall>p\<in>set_mset {#}. prime p) \<and> n = (\<Prod>i \<in># {#}. i)" |
|
49824 | 49 |
by auto |
60527 | 50 |
then show ?thesis .. |
51 |
next |
|
52 |
case 2 |
|
53 |
then have "(\<forall>p\<in>set_mset {#n#}. prime p) \<and> n = (\<Prod>i \<in># {#n#}. i)" |
|
54 |
by auto |
|
55 |
then show ?thesis .. |
|
56 |
next |
|
57 |
case 3 |
|
44872 | 58 |
with not_prime_eq_prod_nat |
60527 | 59 |
obtain m k where n: "n = m * k" "1 < m" "m < n" "1 < k" "k < n" |
44872 | 60 |
by blast |
60527 | 61 |
with ih obtain Q R where "(\<forall>p \<in> set_mset Q. prime p) \<and> m = (\<Prod>i\<in>#Q. i)" |
62 |
and "(\<forall>p\<in>set_mset R. prime p) \<and> k = (\<Prod>i\<in>#R. i)" |
|
31719 | 63 |
by blast |
60527 | 64 |
then have "(\<forall>p\<in>set_mset (Q + R). prime p) \<and> n = (\<Prod>i \<in># Q + R. i)" |
41541 | 65 |
by (auto simp add: n msetprod_Un) |
60527 | 66 |
then show ?thesis .. |
67 |
qed |
|
31719 | 68 |
qed |
69 |
||
70 |
lemma multiset_prime_factorization_unique_aux: |
|
71 |
fixes a :: nat |
|
60527 | 72 |
assumes "\<forall>p\<in>set_mset M. prime p" |
73 |
and "\<forall>p\<in>set_mset N. prime p" |
|
74 |
and "(\<Prod>i \<in># M. i) dvd (\<Prod>i \<in># N. i)" |
|
75 |
shows "count M a \<le> count N a" |
|
76 |
proof (cases "a \<in> set_mset M") |
|
77 |
case True |
|
78 |
with assms have a: "prime a" |
|
79 |
by auto |
|
80 |
with True have "a ^ count M a dvd (\<Prod>i \<in># M. i)" |
|
59010 | 81 |
by (auto simp add: msetprod_multiplicity) |
60527 | 82 |
also have "\<dots> dvd (\<Prod>i \<in># N. i)" |
83 |
by (rule assms) |
|
84 |
also have "\<dots> = (\<Prod>i \<in> set_mset N. i ^ count N i)" |
|
49824 | 85 |
by (simp add: msetprod_multiplicity) |
60527 | 86 |
also have "\<dots> = a ^ count N a * (\<Prod>i \<in> (set_mset N - {a}). i ^ count N i)" |
87 |
proof (cases "a \<in> set_mset N") |
|
88 |
case True |
|
89 |
then have b: "set_mset N = {a} \<union> (set_mset N - {a})" |
|
44872 | 90 |
by auto |
91 |
then show ?thesis |
|
57418 | 92 |
by (subst (1) b, subst setprod.union_disjoint, auto) |
44872 | 93 |
next |
60527 | 94 |
case False |
95 |
then show ?thesis |
|
96 |
by auto |
|
44872 | 97 |
qed |
60527 | 98 |
finally have "a ^ count M a dvd a ^ count N a * (\<Prod>i \<in> (set_mset N - {a}). i ^ count N i)" . |
44872 | 99 |
moreover |
60527 | 100 |
have "coprime (a ^ count M a) (\<Prod>i \<in> (set_mset N - {a}). i ^ count N i)" |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
101 |
apply (subst gcd_commute_nat) |
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
102 |
apply (rule setprod_coprime_nat) |
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
103 |
apply (rule primes_imp_powers_coprime_nat) |
60527 | 104 |
using assms True |
41541 | 105 |
apply auto |
31719 | 106 |
done |
60527 | 107 |
ultimately have "a ^ count M a dvd a ^ count N a" |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
108 |
by (elim coprime_dvd_mult_nat) |
60527 | 109 |
with a show ?thesis |
44872 | 110 |
apply (intro power_dvd_imp_le) |
111 |
apply auto |
|
112 |
done |
|
31719 | 113 |
next |
60527 | 114 |
case False |
115 |
then show ?thesis |
|
116 |
by auto |
|
31719 | 117 |
qed |
118 |
||
119 |
lemma multiset_prime_factorization_unique: |
|
60527 | 120 |
assumes "\<forall>p::nat \<in> set_mset M. prime p" |
121 |
and "\<forall>p \<in> set_mset N. prime p" |
|
122 |
and "(\<Prod>i \<in># M. i) = (\<Prod>i \<in># N. i)" |
|
123 |
shows "M = N" |
|
31719 | 124 |
proof - |
60527 | 125 |
have "count M a = count N a" for a |
126 |
proof - |
|
127 |
from assms have "count M a \<le> count N a" |
|
128 |
by (intro multiset_prime_factorization_unique_aux, auto) |
|
129 |
moreover from assms have "count N a \<le> count M a" |
|
130 |
by (intro multiset_prime_factorization_unique_aux, auto) |
|
131 |
ultimately show ?thesis |
|
31719 | 132 |
by auto |
60527 | 133 |
qed |
134 |
then show ?thesis |
|
135 |
by (simp add: multiset_eq_iff) |
|
31719 | 136 |
qed |
137 |
||
60527 | 138 |
definition multiset_prime_factorization :: "nat \<Rightarrow> nat multiset" |
44872 | 139 |
where |
60527 | 140 |
"multiset_prime_factorization n = |
141 |
(if n > 0 |
|
142 |
then THE M. (\<forall>p \<in> set_mset M. prime p) \<and> n = (\<Prod>i \<in># M. i) |
|
143 |
else {#})" |
|
31719 | 144 |
|
60527 | 145 |
lemma multiset_prime_factorization: "n > 0 \<Longrightarrow> |
146 |
(\<forall>p \<in> set_mset (multiset_prime_factorization n). prime p) \<and> |
|
147 |
n = (\<Prod>i \<in># (multiset_prime_factorization n). i)" |
|
31719 | 148 |
apply (unfold multiset_prime_factorization_def) |
149 |
apply clarsimp |
|
150 |
apply (frule multiset_prime_factorization_exists) |
|
151 |
apply clarify |
|
152 |
apply (rule theI) |
|
49719 | 153 |
apply (insert multiset_prime_factorization_unique) |
154 |
apply auto |
|
60527 | 155 |
done |
31719 | 156 |
|
157 |
||
60527 | 158 |
subsection \<open>Prime factors and multiplicity for nat and int\<close> |
31719 | 159 |
|
160 |
class unique_factorization = |
|
44872 | 161 |
fixes multiplicity :: "'a \<Rightarrow> 'a \<Rightarrow> nat" |
162 |
and prime_factors :: "'a \<Rightarrow> 'a set" |
|
31719 | 163 |
|
60527 | 164 |
text \<open>Definitions for the natural numbers.\<close> |
31719 | 165 |
instantiation nat :: unique_factorization |
166 |
begin |
|
167 |
||
44872 | 168 |
definition multiplicity_nat :: "nat \<Rightarrow> nat \<Rightarrow> nat" |
169 |
where "multiplicity_nat p n = count (multiset_prime_factorization n) p" |
|
31719 | 170 |
|
44872 | 171 |
definition prime_factors_nat :: "nat \<Rightarrow> nat set" |
60495 | 172 |
where "prime_factors_nat n = set_mset (multiset_prime_factorization n)" |
31719 | 173 |
|
44872 | 174 |
instance .. |
31719 | 175 |
|
176 |
end |
|
177 |
||
60527 | 178 |
text \<open>Definitions for the integers.\<close> |
31719 | 179 |
instantiation int :: unique_factorization |
180 |
begin |
|
181 |
||
44872 | 182 |
definition multiplicity_int :: "int \<Rightarrow> int \<Rightarrow> nat" |
183 |
where "multiplicity_int p n = multiplicity (nat p) (nat n)" |
|
31719 | 184 |
|
44872 | 185 |
definition prime_factors_int :: "int \<Rightarrow> int set" |
186 |
where "prime_factors_int n = int ` (prime_factors (nat n))" |
|
31719 | 187 |
|
44872 | 188 |
instance .. |
31719 | 189 |
|
190 |
end |
|
191 |
||
192 |
||
60526 | 193 |
subsection \<open>Set up transfer\<close> |
31719 | 194 |
|
44872 | 195 |
lemma transfer_nat_int_prime_factors: "prime_factors (nat n) = nat ` prime_factors n" |
196 |
unfolding prime_factors_int_def |
|
197 |
apply auto |
|
198 |
apply (subst transfer_int_nat_set_return_embed) |
|
199 |
apply assumption |
|
200 |
done |
|
31719 | 201 |
|
60527 | 202 |
lemma transfer_nat_int_prime_factors_closure: "n \<ge> 0 \<Longrightarrow> nat_set (prime_factors n)" |
31719 | 203 |
by (auto simp add: nat_set_def prime_factors_int_def) |
204 |
||
60527 | 205 |
lemma transfer_nat_int_multiplicity: |
206 |
"p \<ge> 0 \<Longrightarrow> n \<ge> 0 \<Longrightarrow> multiplicity (nat p) (nat n) = multiplicity p n" |
|
31719 | 207 |
by (auto simp add: multiplicity_int_def) |
208 |
||
60527 | 209 |
declare transfer_morphism_nat_int[transfer add return: |
31719 | 210 |
transfer_nat_int_prime_factors transfer_nat_int_prime_factors_closure |
211 |
transfer_nat_int_multiplicity] |
|
212 |
||
44872 | 213 |
lemma transfer_int_nat_prime_factors: "prime_factors (int n) = int ` prime_factors n" |
31719 | 214 |
unfolding prime_factors_int_def by auto |
215 |
||
60527 | 216 |
lemma transfer_int_nat_prime_factors_closure: "is_nat n \<Longrightarrow> nat_set (prime_factors n)" |
31719 | 217 |
by (simp only: transfer_nat_int_prime_factors_closure is_nat_def) |
218 |
||
60527 | 219 |
lemma transfer_int_nat_multiplicity: "multiplicity (int p) (int n) = multiplicity p n" |
31719 | 220 |
by (auto simp add: multiplicity_int_def) |
221 |
||
60527 | 222 |
declare transfer_morphism_int_nat[transfer add return: |
31719 | 223 |
transfer_int_nat_prime_factors transfer_int_nat_prime_factors_closure |
224 |
transfer_int_nat_multiplicity] |
|
225 |
||
226 |
||
60527 | 227 |
subsection \<open>Properties of prime factors and multiplicity for nat and int\<close> |
31719 | 228 |
|
60527 | 229 |
lemma prime_factors_ge_0_int [elim]: |
230 |
fixes n :: int |
|
231 |
shows "p \<in> prime_factors n \<Longrightarrow> p \<ge> 0" |
|
44872 | 232 |
unfolding prime_factors_int_def by auto |
31719 | 233 |
|
60527 | 234 |
lemma prime_factors_prime_nat [intro]: |
235 |
fixes n :: nat |
|
236 |
shows "p \<in> prime_factors n \<Longrightarrow> prime p" |
|
44872 | 237 |
apply (cases "n = 0") |
31719 | 238 |
apply (simp add: prime_factors_nat_def multiset_prime_factorization_def) |
239 |
apply (auto simp add: prime_factors_nat_def multiset_prime_factorization) |
|
41541 | 240 |
done |
31719 | 241 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
242 |
lemma prime_factors_prime_int [intro]: |
60527 | 243 |
fixes n :: int |
244 |
assumes "n \<ge> 0" and "p \<in> prime_factors n" |
|
31719 | 245 |
shows "prime p" |
55242
413ec965f95d
Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents:
55130
diff
changeset
|
246 |
apply (rule prime_factors_prime_nat [transferred, of n p, simplified]) |
41541 | 247 |
using assms apply auto |
248 |
done |
|
31719 | 249 |
|
60527 | 250 |
lemma prime_factors_gt_0_nat [elim]: |
251 |
fixes p :: nat |
|
252 |
shows "p \<in> prime_factors x \<Longrightarrow> p > 0" |
|
253 |
by (auto dest!: prime_factors_prime_nat) |
|
31719 | 254 |
|
60527 | 255 |
lemma prime_factors_gt_0_int [elim]: |
256 |
shows "x \<ge> 0 \<Longrightarrow> p \<in> prime_factors x \<Longrightarrow> int p > (0::int)" |
|
257 |
by auto |
|
31719 | 258 |
|
60527 | 259 |
lemma prime_factors_finite_nat [iff]: |
260 |
fixes n :: nat |
|
261 |
shows "finite (prime_factors n)" |
|
44872 | 262 |
unfolding prime_factors_nat_def by auto |
31719 | 263 |
|
60527 | 264 |
lemma prime_factors_finite_int [iff]: |
265 |
fixes n :: int |
|
266 |
shows "finite (prime_factors n)" |
|
44872 | 267 |
unfolding prime_factors_int_def by auto |
31719 | 268 |
|
60527 | 269 |
lemma prime_factors_altdef_nat: |
270 |
fixes n :: nat |
|
271 |
shows "prime_factors n = {p. multiplicity p n > 0}" |
|
31719 | 272 |
by (force simp add: prime_factors_nat_def multiplicity_nat_def) |
273 |
||
60527 | 274 |
lemma prime_factors_altdef_int: |
275 |
fixes n :: int |
|
276 |
shows "prime_factors n = {p. p \<ge> 0 \<and> multiplicity p n > 0}" |
|
31719 | 277 |
apply (unfold prime_factors_int_def multiplicity_int_def) |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
278 |
apply (subst prime_factors_altdef_nat) |
31719 | 279 |
apply (auto simp add: image_def) |
41541 | 280 |
done |
31719 | 281 |
|
60527 | 282 |
lemma prime_factorization_nat: |
283 |
fixes n :: nat |
|
284 |
shows "n > 0 \<Longrightarrow> n = (\<Prod>p \<in> prime_factors n. p ^ multiplicity p n)" |
|
44872 | 285 |
apply (frule multiset_prime_factorization) |
49824 | 286 |
apply (simp add: prime_factors_nat_def multiplicity_nat_def msetprod_multiplicity) |
44872 | 287 |
done |
31719 | 288 |
|
60527 | 289 |
lemma prime_factorization_int: |
290 |
fixes n :: int |
|
291 |
assumes "n > 0" |
|
292 |
shows "n = (\<Prod>p \<in> prime_factors n. p ^ multiplicity p n)" |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
293 |
apply (rule prime_factorization_nat [transferred, of n]) |
41541 | 294 |
using assms apply auto |
295 |
done |
|
31719 | 296 |
|
60527 | 297 |
lemma prime_factorization_unique_nat: |
49718 | 298 |
fixes f :: "nat \<Rightarrow> _" |
60527 | 299 |
assumes S_eq: "S = {p. 0 < f p}" |
300 |
and "finite S" |
|
301 |
and "\<forall>p\<in>S. prime p" |
|
302 |
and "n = (\<Prod>p\<in>S. p ^ f p)" |
|
49718 | 303 |
shows "S = prime_factors n \<and> (\<forall>p. f p = multiplicity p n)" |
304 |
proof - |
|
305 |
from assms have "f \<in> multiset" |
|
306 |
by (auto simp add: multiset_def) |
|
307 |
moreover from assms have "n > 0" by force |
|
308 |
ultimately have "multiset_prime_factorization n = Abs_multiset f" |
|
309 |
apply (unfold multiset_prime_factorization_def) |
|
310 |
apply (subst if_P, assumption) |
|
311 |
apply (rule the1_equality) |
|
312 |
apply (rule ex_ex1I) |
|
313 |
apply (rule multiset_prime_factorization_exists, assumption) |
|
314 |
apply (rule multiset_prime_factorization_unique) |
|
315 |
apply force |
|
316 |
apply force |
|
317 |
apply force |
|
60527 | 318 |
using assms apply (simp add: set_mset_def msetprod_multiplicity) |
49718 | 319 |
done |
60526 | 320 |
with \<open>f \<in> multiset\<close> have "count (multiset_prime_factorization n) = f" |
59010 | 321 |
by simp |
49718 | 322 |
with S_eq show ?thesis |
60495 | 323 |
by (simp add: set_mset_def multiset_def prime_factors_nat_def multiplicity_nat_def) |
49718 | 324 |
qed |
31719 | 325 |
|
60527 | 326 |
lemma prime_factors_characterization_nat: |
327 |
"S = {p. 0 < f (p::nat)} \<Longrightarrow> |
|
328 |
finite S \<Longrightarrow> \<forall>p\<in>S. prime p \<Longrightarrow> n = (\<Prod>p\<in>S. p ^ f p) \<Longrightarrow> prime_factors n = S" |
|
329 |
by (rule prime_factorization_unique_nat [THEN conjunct1, symmetric]) |
|
31719 | 330 |
|
60527 | 331 |
lemma prime_factors_characterization'_nat: |
31719 | 332 |
"finite {p. 0 < f (p::nat)} \<Longrightarrow> |
60527 | 333 |
(\<forall>p. 0 < f p \<longrightarrow> prime p) \<Longrightarrow> |
334 |
prime_factors (\<Prod>p | 0 < f p. p ^ f p) = {p. 0 < f p}" |
|
335 |
by (rule prime_factors_characterization_nat) auto |
|
31719 | 336 |
|
337 |
(* A minor glitch:*) |
|
60527 | 338 |
thm prime_factors_characterization'_nat |
339 |
[where f = "\<lambda>x. f (int (x::nat))", |
|
340 |
transferred direction: nat "op \<le> (0::int)", rule_format] |
|
31719 | 341 |
|
342 |
(* |
|
60527 | 343 |
Transfer isn't smart enough to know that the "0 < f p" should |
344 |
remain a comparison between nats. But the transfer still works. |
|
31719 | 345 |
*) |
346 |
||
60527 | 347 |
lemma primes_characterization'_int [rule_format]: |
348 |
"finite {p. p \<ge> 0 \<and> 0 < f (p::int)} \<Longrightarrow> \<forall>p. 0 < f p \<longrightarrow> prime p \<Longrightarrow> |
|
349 |
prime_factors (\<Prod>p | p \<ge> 0 \<and> 0 < f p. p ^ f p) = {p. p \<ge> 0 \<and> 0 < f p}" |
|
350 |
using prime_factors_characterization'_nat |
|
351 |
[where f = "\<lambda>x. f (int (x::nat))", |
|
352 |
transferred direction: nat "op \<le> (0::int)"] |
|
353 |
by auto |
|
31719 | 354 |
|
60527 | 355 |
lemma prime_factors_characterization_int: |
356 |
"S = {p. 0 < f (p::int)} \<Longrightarrow> finite S \<Longrightarrow> |
|
357 |
\<forall>p\<in>S. prime (nat p) \<Longrightarrow> n = (\<Prod>p\<in>S. p ^ f p) \<Longrightarrow> prime_factors n = S" |
|
31719 | 358 |
apply simp |
60527 | 359 |
apply (subgoal_tac "{p. 0 < f p} = {p. 0 \<le> p \<and> 0 < f p}") |
31719 | 360 |
apply (simp only:) |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
361 |
apply (subst primes_characterization'_int) |
31719 | 362 |
apply auto |
55242
413ec965f95d
Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents:
55130
diff
changeset
|
363 |
apply (metis nat_int) |
413ec965f95d
Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents:
55130
diff
changeset
|
364 |
apply (metis le_cases nat_le_0 zero_not_prime_nat) |
44872 | 365 |
done |
31719 | 366 |
|
60527 | 367 |
lemma multiplicity_characterization_nat: |
368 |
"S = {p. 0 < f (p::nat)} \<Longrightarrow> finite S \<Longrightarrow> \<forall>p\<in>S. prime p \<Longrightarrow> |
|
369 |
n = (\<Prod>p\<in>S. p ^ f p) \<Longrightarrow> multiplicity p n = f p" |
|
44872 | 370 |
apply (frule prime_factorization_unique_nat [THEN conjunct2, rule_format, symmetric]) |
371 |
apply auto |
|
372 |
done |
|
31719 | 373 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
374 |
lemma multiplicity_characterization'_nat: "finite {p. 0 < f (p::nat)} \<longrightarrow> |
60527 | 375 |
(\<forall>p. 0 < f p \<longrightarrow> prime p) \<longrightarrow> |
376 |
multiplicity p (\<Prod>p | 0 < f p. p ^ f p) = f p" |
|
44872 | 377 |
apply (intro impI) |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
378 |
apply (rule multiplicity_characterization_nat) |
31719 | 379 |
apply auto |
44872 | 380 |
done |
31719 | 381 |
|
60527 | 382 |
lemma multiplicity_characterization'_int [rule_format]: |
383 |
"finite {p. p \<ge> 0 \<and> 0 < f (p::int)} \<Longrightarrow> |
|
384 |
(\<forall>p. 0 < f p \<longrightarrow> prime p) \<Longrightarrow> p \<ge> 0 \<Longrightarrow> |
|
385 |
multiplicity p (\<Prod>p | p \<ge> 0 \<and> 0 < f p. p ^ f p) = f p" |
|
386 |
apply (insert multiplicity_characterization'_nat |
|
387 |
[where f = "\<lambda>x. f (int (x::nat))", |
|
388 |
transferred direction: nat "op \<le> (0::int)", rule_format]) |
|
31719 | 389 |
apply auto |
44872 | 390 |
done |
31719 | 391 |
|
60527 | 392 |
lemma multiplicity_characterization_int: "S = {p. 0 < f (p::int)} \<Longrightarrow> |
393 |
finite S \<Longrightarrow> \<forall>p\<in>S. prime (nat p) \<Longrightarrow> n = (\<Prod>p\<in>S. p ^ f p) \<Longrightarrow> |
|
394 |
p \<ge> 0 \<Longrightarrow> multiplicity p n = f p" |
|
31719 | 395 |
apply simp |
60527 | 396 |
apply (subgoal_tac "{p. 0 < f p} = {p. 0 \<le> p \<and> 0 < f p}") |
31719 | 397 |
apply (simp only:) |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
398 |
apply (subst multiplicity_characterization'_int) |
31719 | 399 |
apply auto |
55242
413ec965f95d
Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents:
55130
diff
changeset
|
400 |
apply (metis nat_int) |
413ec965f95d
Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents:
55130
diff
changeset
|
401 |
apply (metis le_cases nat_le_0 zero_not_prime_nat) |
44872 | 402 |
done |
31719 | 403 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
404 |
lemma multiplicity_zero_nat [simp]: "multiplicity (p::nat) 0 = 0" |
31719 | 405 |
by (simp add: multiplicity_nat_def multiset_prime_factorization_def) |
406 |
||
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
407 |
lemma multiplicity_zero_int [simp]: "multiplicity (p::int) 0 = 0" |
60527 | 408 |
by (simp add: multiplicity_int_def) |
31719 | 409 |
|
55130
70db8d380d62
Restored Suc rather than +1, and using Library/Binimial
paulson <lp15@cam.ac.uk>
parents:
54611
diff
changeset
|
410 |
lemma multiplicity_one_nat': "multiplicity p (1::nat) = 0" |
60527 | 411 |
by (subst multiplicity_characterization_nat [where f = "\<lambda>x. 0"], auto) |
31719 | 412 |
|
55130
70db8d380d62
Restored Suc rather than +1, and using Library/Binimial
paulson <lp15@cam.ac.uk>
parents:
54611
diff
changeset
|
413 |
lemma multiplicity_one_nat [simp]: "multiplicity p (Suc 0) = 0" |
70db8d380d62
Restored Suc rather than +1, and using Library/Binimial
paulson <lp15@cam.ac.uk>
parents:
54611
diff
changeset
|
414 |
by (metis One_nat_def multiplicity_one_nat') |
70db8d380d62
Restored Suc rather than +1, and using Library/Binimial
paulson <lp15@cam.ac.uk>
parents:
54611
diff
changeset
|
415 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
416 |
lemma multiplicity_one_int [simp]: "multiplicity p (1::int) = 0" |
55130
70db8d380d62
Restored Suc rather than +1, and using Library/Binimial
paulson <lp15@cam.ac.uk>
parents:
54611
diff
changeset
|
417 |
by (metis multiplicity_int_def multiplicity_one_nat' transfer_nat_int_numerals(2)) |
31719 | 418 |
|
55242
413ec965f95d
Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents:
55130
diff
changeset
|
419 |
lemma multiplicity_prime_nat [simp]: "prime p \<Longrightarrow> multiplicity p p = 1" |
60527 | 420 |
apply (subst multiplicity_characterization_nat [where f = "\<lambda>q. if q = p then 1 else 0"]) |
31719 | 421 |
apply auto |
60527 | 422 |
apply (metis (full_types) less_not_refl) |
423 |
done |
|
31719 | 424 |
|
60527 | 425 |
lemma multiplicity_prime_power_nat [simp]: "prime p \<Longrightarrow> multiplicity p (p ^ n) = n" |
44872 | 426 |
apply (cases "n = 0") |
31719 | 427 |
apply auto |
60527 | 428 |
apply (subst multiplicity_characterization_nat [where f = "\<lambda>q. if q = p then n else 0"]) |
31719 | 429 |
apply auto |
60527 | 430 |
apply (metis (full_types) less_not_refl) |
431 |
done |
|
31719 | 432 |
|
60527 | 433 |
lemma multiplicity_prime_power_int [simp]: "prime p \<Longrightarrow> multiplicity p (int p ^ n) = n" |
55242
413ec965f95d
Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents:
55130
diff
changeset
|
434 |
by (metis multiplicity_prime_power_nat of_nat_power transfer_int_nat_multiplicity) |
31719 | 435 |
|
60527 | 436 |
lemma multiplicity_nonprime_nat [simp]: |
437 |
fixes p n :: nat |
|
438 |
shows "\<not> prime p \<Longrightarrow> multiplicity p n = 0" |
|
44872 | 439 |
apply (cases "n = 0") |
31719 | 440 |
apply auto |
441 |
apply (frule multiset_prime_factorization) |
|
60495 | 442 |
apply (auto simp add: set_mset_def multiplicity_nat_def) |
44872 | 443 |
done |
31719 | 444 |
|
60527 | 445 |
lemma multiplicity_not_factor_nat [simp]: |
446 |
fixes p n :: nat |
|
447 |
shows "p \<notin> prime_factors n \<Longrightarrow> multiplicity p n = 0" |
|
44872 | 448 |
apply (subst (asm) prime_factors_altdef_nat) |
449 |
apply auto |
|
450 |
done |
|
31719 | 451 |
|
60527 | 452 |
lemma multiplicity_not_factor_int [simp]: |
453 |
fixes n :: int |
|
454 |
shows "p \<ge> 0 \<Longrightarrow> p \<notin> prime_factors n \<Longrightarrow> multiplicity p n = 0" |
|
44872 | 455 |
apply (subst (asm) prime_factors_altdef_int) |
456 |
apply auto |
|
457 |
done |
|
31719 | 458 |
|
55130
70db8d380d62
Restored Suc rather than +1, and using Library/Binimial
paulson <lp15@cam.ac.uk>
parents:
54611
diff
changeset
|
459 |
(*FIXME: messy*) |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
460 |
lemma multiplicity_product_aux_nat: "(k::nat) > 0 \<Longrightarrow> l > 0 \<Longrightarrow> |
60527 | 461 |
(prime_factors k) \<union> (prime_factors l) = prime_factors (k * l) \<and> |
462 |
(\<forall>p. multiplicity p k + multiplicity p l = multiplicity p (k * l))" |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
463 |
apply (rule prime_factorization_unique_nat) |
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
464 |
apply (simp only: prime_factors_altdef_nat) |
31719 | 465 |
apply auto |
466 |
apply (subst power_add) |
|
57418 | 467 |
apply (subst setprod.distrib) |
55130
70db8d380d62
Restored Suc rather than +1, and using Library/Binimial
paulson <lp15@cam.ac.uk>
parents:
54611
diff
changeset
|
468 |
apply (rule arg_cong2 [where f = "\<lambda>x y. x*y"]) |
60527 | 469 |
apply (subgoal_tac "prime_factors k \<union> prime_factors l = prime_factors k \<union> |
31719 | 470 |
(prime_factors l - prime_factors k)") |
471 |
apply (erule ssubst) |
|
57418 | 472 |
apply (subst setprod.union_disjoint) |
31719 | 473 |
apply auto |
55130
70db8d380d62
Restored Suc rather than +1, and using Library/Binimial
paulson <lp15@cam.ac.uk>
parents:
54611
diff
changeset
|
474 |
apply (metis One_nat_def nat_mult_1_right prime_factorization_nat setprod.neutral_const) |
60527 | 475 |
apply (subgoal_tac "prime_factors k \<union> prime_factors l = prime_factors l \<union> |
31719 | 476 |
(prime_factors k - prime_factors l)") |
477 |
apply (erule ssubst) |
|
57418 | 478 |
apply (subst setprod.union_disjoint) |
31719 | 479 |
apply auto |
60527 | 480 |
apply (subgoal_tac "(\<Prod>p\<in>prime_factors k - prime_factors l. p ^ multiplicity p l) = |
31719 | 481 |
(\<Prod>p\<in>prime_factors k - prime_factors l. 1)") |
55130
70db8d380d62
Restored Suc rather than +1, and using Library/Binimial
paulson <lp15@cam.ac.uk>
parents:
54611
diff
changeset
|
482 |
apply auto |
70db8d380d62
Restored Suc rather than +1, and using Library/Binimial
paulson <lp15@cam.ac.uk>
parents:
54611
diff
changeset
|
483 |
apply (metis One_nat_def nat_mult_1_right prime_factorization_nat setprod.neutral_const) |
44872 | 484 |
done |
31719 | 485 |
|
60527 | 486 |
(* transfer doesn't have the same problem here with the right |
31719 | 487 |
choice of rules. *) |
488 |
||
60527 | 489 |
lemma multiplicity_product_aux_int: |
31719 | 490 |
assumes "(k::int) > 0" and "l > 0" |
60527 | 491 |
shows "prime_factors k \<union> prime_factors l = prime_factors (k * l) \<and> |
492 |
(\<forall>p \<ge> 0. multiplicity p k + multiplicity p l = multiplicity p (k * l))" |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
493 |
apply (rule multiplicity_product_aux_nat [transferred, of l k]) |
41541 | 494 |
using assms apply auto |
495 |
done |
|
31719 | 496 |
|
60527 | 497 |
lemma prime_factors_product_nat: "(k::nat) > 0 \<Longrightarrow> l > 0 \<Longrightarrow> prime_factors (k * l) = |
498 |
prime_factors k \<union> prime_factors l" |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
499 |
by (rule multiplicity_product_aux_nat [THEN conjunct1, symmetric]) |
31719 | 500 |
|
60527 | 501 |
lemma prime_factors_product_int: "(k::int) > 0 \<Longrightarrow> l > 0 \<Longrightarrow> prime_factors (k * l) = |
502 |
prime_factors k \<union> prime_factors l" |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
503 |
by (rule multiplicity_product_aux_int [THEN conjunct1, symmetric]) |
31719 | 504 |
|
60527 | 505 |
lemma multiplicity_product_nat: "(k::nat) > 0 \<Longrightarrow> l > 0 \<Longrightarrow> multiplicity p (k * l) = |
31719 | 506 |
multiplicity p k + multiplicity p l" |
60527 | 507 |
by (rule multiplicity_product_aux_nat [THEN conjunct2, rule_format, symmetric]) |
31719 | 508 |
|
60527 | 509 |
lemma multiplicity_product_int: "(k::int) > 0 \<Longrightarrow> l > 0 \<Longrightarrow> p \<ge> 0 \<Longrightarrow> |
31719 | 510 |
multiplicity p (k * l) = multiplicity p k + multiplicity p l" |
60527 | 511 |
by (rule multiplicity_product_aux_int [THEN conjunct2, rule_format, symmetric]) |
31719 | 512 |
|
60527 | 513 |
lemma multiplicity_setprod_nat: "finite S \<Longrightarrow> \<forall>x\<in>S. f x > 0 \<Longrightarrow> |
514 |
multiplicity (p::nat) (\<Prod>x \<in> S. f x) = (\<Sum>x \<in> S. multiplicity p (f x))" |
|
31719 | 515 |
apply (induct set: finite) |
516 |
apply auto |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
517 |
apply (subst multiplicity_product_nat) |
31719 | 518 |
apply auto |
44872 | 519 |
done |
31719 | 520 |
|
521 |
(* Transfer is delicate here for two reasons: first, because there is |
|
60527 | 522 |
an implicit quantifier over functions (f), and, second, because the |
523 |
product over the multiplicity should not be translated to an integer |
|
31719 | 524 |
product. |
525 |
||
526 |
The way to handle the first is to use quantifier rules for functions. |
|
527 |
The way to handle the second is to turn off the offending rule. |
|
528 |
*) |
|
529 |
||
60527 | 530 |
lemma transfer_nat_int_sum_prod_closure3: "(\<Sum>x \<in> A. int (f x)) \<ge> 0" "(\<Prod>x \<in> A. int (f x)) \<ge> 0" |
531 |
apply (rule setsum_nonneg; auto) |
|
532 |
apply (rule setprod_nonneg; auto) |
|
44872 | 533 |
done |
31719 | 534 |
|
60527 | 535 |
declare transfer_morphism_nat_int[transfer |
31719 | 536 |
add return: transfer_nat_int_sum_prod_closure3 |
537 |
del: transfer_nat_int_sum_prod2 (1)] |
|
538 |
||
60527 | 539 |
lemma multiplicity_setprod_int: "p \<ge> 0 \<Longrightarrow> finite S \<Longrightarrow> \<forall>x\<in>S. f x > 0 \<Longrightarrow> |
540 |
multiplicity (p::int) (\<Prod>x \<in> S. f x) = (\<Sum>x \<in> S. multiplicity p (f x))" |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
541 |
apply (frule multiplicity_setprod_nat |
60527 | 542 |
[where f = "\<lambda>x. nat(int(nat(f x)))", |
543 |
transferred direction: nat "op \<le> (0::int)"]) |
|
31719 | 544 |
apply auto |
57418 | 545 |
apply (subst (asm) setprod.cong) |
31719 | 546 |
apply (rule refl) |
547 |
apply (rule if_P) |
|
548 |
apply auto |
|
57418 | 549 |
apply (rule setsum.cong) |
31719 | 550 |
apply auto |
44872 | 551 |
done |
31719 | 552 |
|
60527 | 553 |
declare transfer_morphism_nat_int[transfer |
31719 | 554 |
add return: transfer_nat_int_sum_prod2 (1)] |
555 |
||
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
556 |
lemma multiplicity_prod_prime_powers_nat: |
60527 | 557 |
"finite S \<Longrightarrow> \<forall>p\<in>S. prime (p::nat) \<Longrightarrow> |
558 |
multiplicity p (\<Prod>p \<in> S. p ^ f p) = (if p \<in> S then f p else 0)" |
|
559 |
apply (subgoal_tac "(\<Prod>p \<in> S. p ^ f p) = (\<Prod>p \<in> S. p ^ (\<lambda>x. if x \<in> S then f x else 0) p)") |
|
31719 | 560 |
apply (erule ssubst) |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
561 |
apply (subst multiplicity_characterization_nat) |
31719 | 562 |
prefer 5 apply (rule refl) |
563 |
apply (rule refl) |
|
564 |
apply auto |
|
57418 | 565 |
apply (subst setprod.mono_neutral_right) |
31719 | 566 |
apply assumption |
567 |
prefer 3 |
|
57418 | 568 |
apply (rule setprod.cong) |
31719 | 569 |
apply (rule refl) |
570 |
apply auto |
|
60527 | 571 |
done |
31719 | 572 |
|
573 |
(* Here the issue with transfer is the implicit quantifier over S *) |
|
574 |
||
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
575 |
lemma multiplicity_prod_prime_powers_int: |
60527 | 576 |
"(p::int) \<ge> 0 \<Longrightarrow> finite S \<Longrightarrow> \<forall>p\<in>S. prime (nat p) \<Longrightarrow> |
577 |
multiplicity p (\<Prod>p \<in> S. p ^ f p) = (if p \<in> S then f p else 0)" |
|
31719 | 578 |
apply (subgoal_tac "int ` nat ` S = S") |
60527 | 579 |
apply (frule multiplicity_prod_prime_powers_nat |
580 |
[where f = "\<lambda>x. f(int x)" and S = "nat ` S", transferred]) |
|
31719 | 581 |
apply auto |
55242
413ec965f95d
Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents:
55130
diff
changeset
|
582 |
apply (metis linear nat_0_iff zero_not_prime_nat) |
413ec965f95d
Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents:
55130
diff
changeset
|
583 |
apply (metis (full_types) image_iff int_nat_eq less_le less_linear nat_0_iff zero_not_prime_nat) |
44872 | 584 |
done |
31719 | 585 |
|
60527 | 586 |
lemma multiplicity_distinct_prime_power_nat: |
587 |
"prime p \<Longrightarrow> prime q \<Longrightarrow> p \<noteq> q \<Longrightarrow> multiplicity p (q ^ n) = 0" |
|
588 |
apply (subgoal_tac "q ^ n = setprod (\<lambda>x. x ^ n) {q}") |
|
31719 | 589 |
apply (erule ssubst) |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
590 |
apply (subst multiplicity_prod_prime_powers_nat) |
31719 | 591 |
apply auto |
44872 | 592 |
done |
31719 | 593 |
|
60527 | 594 |
lemma multiplicity_distinct_prime_power_int: |
595 |
"prime p \<Longrightarrow> prime q \<Longrightarrow> p \<noteq> q \<Longrightarrow> multiplicity p (int q ^ n) = 0" |
|
55242
413ec965f95d
Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents:
55130
diff
changeset
|
596 |
by (metis multiplicity_distinct_prime_power_nat of_nat_power transfer_int_nat_multiplicity) |
413ec965f95d
Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
paulson <lp15@cam.ac.uk>
parents:
55130
diff
changeset
|
597 |
|
44872 | 598 |
lemma dvd_multiplicity_nat: |
60527 | 599 |
fixes x y :: nat |
600 |
shows "0 < y \<Longrightarrow> x dvd y \<Longrightarrow> multiplicity p x \<le> multiplicity p y" |
|
44872 | 601 |
apply (cases "x = 0") |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
602 |
apply (auto simp add: dvd_def multiplicity_product_nat) |
44872 | 603 |
done |
31719 | 604 |
|
60527 | 605 |
lemma dvd_multiplicity_int: |
606 |
fixes p x y :: int |
|
607 |
shows "0 < y \<Longrightarrow> 0 \<le> x \<Longrightarrow> x dvd y \<Longrightarrow> p \<ge> 0 \<Longrightarrow> multiplicity p x \<le> multiplicity p y" |
|
44872 | 608 |
apply (cases "x = 0") |
31719 | 609 |
apply (auto simp add: dvd_def) |
610 |
apply (subgoal_tac "0 < k") |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
611 |
apply (auto simp add: multiplicity_product_int) |
31719 | 612 |
apply (erule zero_less_mult_pos) |
613 |
apply arith |
|
44872 | 614 |
done |
31719 | 615 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
616 |
lemma dvd_prime_factors_nat [intro]: |
60527 | 617 |
fixes x y :: nat |
618 |
shows "0 < y \<Longrightarrow> x dvd y \<Longrightarrow> prime_factors x \<le> prime_factors y" |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
619 |
apply (simp only: prime_factors_altdef_nat) |
31719 | 620 |
apply auto |
55130
70db8d380d62
Restored Suc rather than +1, and using Library/Binimial
paulson <lp15@cam.ac.uk>
parents:
54611
diff
changeset
|
621 |
apply (metis dvd_multiplicity_nat le_0_eq neq0_conv) |
44872 | 622 |
done |
31719 | 623 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
624 |
lemma dvd_prime_factors_int [intro]: |
60527 | 625 |
fixes x y :: int |
626 |
shows "0 < y \<Longrightarrow> 0 \<le> x \<Longrightarrow> x dvd y \<Longrightarrow> prime_factors x \<le> prime_factors y" |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
627 |
apply (auto simp add: prime_factors_altdef_int) |
55130
70db8d380d62
Restored Suc rather than +1, and using Library/Binimial
paulson <lp15@cam.ac.uk>
parents:
54611
diff
changeset
|
628 |
apply (metis dvd_multiplicity_int le_0_eq neq0_conv) |
44872 | 629 |
done |
31719 | 630 |
|
60527 | 631 |
lemma multiplicity_dvd_nat: |
632 |
fixes x y :: nat |
|
633 |
shows "0 < x \<Longrightarrow> 0 < y \<Longrightarrow> \<forall>p. multiplicity p x \<le> multiplicity p y \<Longrightarrow> x dvd y" |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
634 |
apply (subst prime_factorization_nat [of x], assumption) |
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
635 |
apply (subst prime_factorization_nat [of y], assumption) |
31719 | 636 |
apply (rule setprod_dvd_setprod_subset2) |
637 |
apply force |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
638 |
apply (subst prime_factors_altdef_nat)+ |
31719 | 639 |
apply auto |
40461 | 640 |
apply (metis gr0I le_0_eq less_not_refl) |
641 |
apply (metis le_imp_power_dvd) |
|
44872 | 642 |
done |
31719 | 643 |
|
60527 | 644 |
lemma multiplicity_dvd_int: |
645 |
fixes x y :: int |
|
646 |
shows "0 < x \<Longrightarrow> 0 < y \<Longrightarrow> \<forall>p\<ge>0. multiplicity p x \<le> multiplicity p y \<Longrightarrow> x dvd y" |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
647 |
apply (subst prime_factorization_int [of x], assumption) |
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
648 |
apply (subst prime_factorization_int [of y], assumption) |
31719 | 649 |
apply (rule setprod_dvd_setprod_subset2) |
650 |
apply force |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
651 |
apply (subst prime_factors_altdef_int)+ |
31719 | 652 |
apply auto |
40461 | 653 |
apply (metis le_imp_power_dvd prime_factors_ge_0_int) |
44872 | 654 |
done |
31719 | 655 |
|
60527 | 656 |
lemma multiplicity_dvd'_nat: |
657 |
fixes x y :: nat |
|
658 |
shows "0 < x \<Longrightarrow> \<forall>p. prime p \<longrightarrow> multiplicity p x \<le> multiplicity p y \<Longrightarrow> x dvd y" |
|
44872 | 659 |
by (metis gcd_lcm_complete_lattice_nat.top_greatest le_refl multiplicity_dvd_nat |
660 |
multiplicity_nonprime_nat neq0_conv) |
|
31719 | 661 |
|
60527 | 662 |
lemma multiplicity_dvd'_int: |
663 |
fixes x y :: int |
|
664 |
shows "0 < x \<Longrightarrow> 0 \<le> y \<Longrightarrow> |
|
31719 | 665 |
\<forall>p. prime p \<longrightarrow> multiplicity p x \<le> multiplicity p y \<Longrightarrow> x dvd y" |
60527 | 666 |
by (metis GCD.dvd_int_iff abs_int_eq multiplicity_dvd'_nat multiplicity_int_def nat_int |
667 |
zero_le_imp_eq_int zero_less_imp_eq_int) |
|
31719 | 668 |
|
60527 | 669 |
lemma dvd_multiplicity_eq_nat: |
670 |
fixes x y :: nat |
|
671 |
shows "0 < x \<Longrightarrow> 0 < y \<Longrightarrow> x dvd y \<longleftrightarrow> (\<forall>p. multiplicity p x \<le> multiplicity p y)" |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
672 |
by (auto intro: dvd_multiplicity_nat multiplicity_dvd_nat) |
31719 | 673 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
674 |
lemma dvd_multiplicity_eq_int: "0 < (x::int) \<Longrightarrow> 0 < y \<Longrightarrow> |
60527 | 675 |
(x dvd y) = (\<forall>p\<ge>0. multiplicity p x \<le> multiplicity p y)" |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
676 |
by (auto intro: dvd_multiplicity_int multiplicity_dvd_int) |
31719 | 677 |
|
60527 | 678 |
lemma prime_factors_altdef2_nat: |
679 |
fixes n :: nat |
|
680 |
shows "n > 0 \<Longrightarrow> p \<in> prime_factors n \<longleftrightarrow> prime p \<and> p dvd n" |
|
44872 | 681 |
apply (cases "prime p") |
31719 | 682 |
apply auto |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
683 |
apply (subst prime_factorization_nat [where n = n], assumption) |
60527 | 684 |
apply (rule dvd_trans) |
31719 | 685 |
apply (rule dvd_power [where x = p and n = "multiplicity p n"]) |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
686 |
apply (subst (asm) prime_factors_altdef_nat, force) |
59010 | 687 |
apply rule |
31719 | 688 |
apply auto |
60527 | 689 |
apply (metis One_nat_def Zero_not_Suc dvd_multiplicity_nat le0 |
690 |
le_antisym multiplicity_not_factor_nat multiplicity_prime_nat) |
|
44872 | 691 |
done |
31719 | 692 |
|
60527 | 693 |
lemma prime_factors_altdef2_int: |
694 |
fixes n :: int |
|
695 |
assumes "n > 0" |
|
696 |
shows "p \<in> prime_factors n \<longleftrightarrow> prime p \<and> p dvd n" |
|
697 |
using assms by (simp add: prime_factors_altdef2_nat [transferred]) |
|
31719 | 698 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
699 |
lemma multiplicity_eq_nat: |
60527 | 700 |
fixes x and y::nat |
701 |
assumes [arith]: "x > 0" "y > 0" |
|
702 |
and mult_eq [simp]: "\<And>p. prime p \<Longrightarrow> multiplicity p x = multiplicity p y" |
|
31719 | 703 |
shows "x = y" |
33657 | 704 |
apply (rule dvd_antisym) |
60527 | 705 |
apply (auto intro: multiplicity_dvd'_nat) |
44872 | 706 |
done |
31719 | 707 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
708 |
lemma multiplicity_eq_int: |
60527 | 709 |
fixes x y :: int |
710 |
assumes [arith]: "x > 0" "y > 0" |
|
711 |
and mult_eq [simp]: "\<And>p. prime p \<Longrightarrow> multiplicity p x = multiplicity p y" |
|
31719 | 712 |
shows "x = y" |
33657 | 713 |
apply (rule dvd_antisym [transferred]) |
60527 | 714 |
apply (auto intro: multiplicity_dvd'_int) |
44872 | 715 |
done |
31719 | 716 |
|
717 |
||
60526 | 718 |
subsection \<open>An application\<close> |
31719 | 719 |
|
60527 | 720 |
lemma gcd_eq_nat: |
721 |
fixes x y :: nat |
|
31719 | 722 |
assumes pos [arith]: "x > 0" "y > 0" |
60527 | 723 |
shows "gcd x y = |
724 |
(\<Prod>p \<in> prime_factors x \<union> prime_factors y. p ^ min (multiplicity p x) (multiplicity p y))" |
|
725 |
(is "_ = ?z") |
|
31719 | 726 |
proof - |
60527 | 727 |
have [arith]: "?z > 0" |
60981 | 728 |
by auto |
60527 | 729 |
have aux: "\<And>p. prime p \<Longrightarrow> multiplicity p ?z = min (multiplicity p x) (multiplicity p y)" |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
730 |
apply (subst multiplicity_prod_prime_powers_nat) |
41541 | 731 |
apply auto |
31719 | 732 |
done |
60527 | 733 |
have "?z dvd x" |
734 |
by (intro multiplicity_dvd'_nat) (auto simp add: aux) |
|
735 |
moreover have "?z dvd y" |
|
736 |
by (intro multiplicity_dvd'_nat) (auto simp add: aux) |
|
737 |
moreover have "w dvd x \<and> w dvd y \<longrightarrow> w dvd ?z" for w |
|
738 |
proof (cases "w = 0") |
|
739 |
case True |
|
740 |
then show ?thesis by simp |
|
741 |
next |
|
742 |
case False |
|
743 |
then show ?thesis |
|
744 |
apply auto |
|
745 |
apply (erule multiplicity_dvd'_nat) |
|
746 |
apply (auto intro: dvd_multiplicity_nat simp add: aux) |
|
747 |
done |
|
748 |
qed |
|
749 |
ultimately have "?z = gcd x y" |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
750 |
by (subst gcd_unique_nat [symmetric], blast) |
44872 | 751 |
then show ?thesis |
60527 | 752 |
by auto |
31719 | 753 |
qed |
754 |
||
60527 | 755 |
lemma lcm_eq_nat: |
31719 | 756 |
assumes pos [arith]: "x > 0" "y > 0" |
60527 | 757 |
shows "lcm (x::nat) y = |
758 |
(\<Prod>p \<in> prime_factors x \<union> prime_factors y. p ^ max (multiplicity p x) (multiplicity p y))" |
|
759 |
(is "_ = ?z") |
|
31719 | 760 |
proof - |
60527 | 761 |
have [arith]: "?z > 0" |
60981 | 762 |
by auto |
60527 | 763 |
have aux: "\<And>p. prime p \<Longrightarrow> multiplicity p ?z = max (multiplicity p x) (multiplicity p y)" |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
764 |
apply (subst multiplicity_prod_prime_powers_nat) |
41541 | 765 |
apply auto |
31719 | 766 |
done |
60527 | 767 |
have "x dvd ?z" |
768 |
by (intro multiplicity_dvd'_nat) (auto simp add: aux) |
|
769 |
moreover have "y dvd ?z" |
|
770 |
by (intro multiplicity_dvd'_nat) (auto simp add: aux) |
|
771 |
moreover have "x dvd w \<and> y dvd w \<longrightarrow> ?z dvd w" for w |
|
772 |
proof (cases "w = 0") |
|
773 |
case True |
|
774 |
then show ?thesis by auto |
|
775 |
next |
|
776 |
case False |
|
777 |
then show ?thesis |
|
778 |
apply auto |
|
779 |
apply (rule multiplicity_dvd'_nat) |
|
780 |
apply (auto intro: dvd_multiplicity_nat simp add: aux) |
|
781 |
done |
|
782 |
qed |
|
783 |
ultimately have "?z = lcm x y" |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
784 |
by (subst lcm_unique_nat [symmetric], blast) |
44872 | 785 |
then show ?thesis |
60527 | 786 |
by auto |
31719 | 787 |
qed |
788 |
||
60527 | 789 |
lemma multiplicity_gcd_nat: |
790 |
fixes p x y :: nat |
|
31719 | 791 |
assumes [arith]: "x > 0" "y > 0" |
60527 | 792 |
shows "multiplicity p (gcd x y) = min (multiplicity p x) (multiplicity p y)" |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
793 |
apply (subst gcd_eq_nat) |
31719 | 794 |
apply auto |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
795 |
apply (subst multiplicity_prod_prime_powers_nat) |
31719 | 796 |
apply auto |
44872 | 797 |
done |
31719 | 798 |
|
60527 | 799 |
lemma multiplicity_lcm_nat: |
800 |
fixes p x y :: nat |
|
31719 | 801 |
assumes [arith]: "x > 0" "y > 0" |
60527 | 802 |
shows "multiplicity p (lcm x y) = max (multiplicity p x) (multiplicity p y)" |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
803 |
apply (subst lcm_eq_nat) |
31719 | 804 |
apply auto |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
805 |
apply (subst multiplicity_prod_prime_powers_nat) |
31719 | 806 |
apply auto |
44872 | 807 |
done |
31719 | 808 |
|
60527 | 809 |
lemma gcd_lcm_distrib_nat: |
810 |
fixes x y z :: nat |
|
811 |
shows "gcd x (lcm y z) = lcm (gcd x y) (gcd x z)" |
|
812 |
apply (cases "x = 0 | y = 0 | z = 0") |
|
31719 | 813 |
apply auto |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
814 |
apply (rule multiplicity_eq_nat) |
44872 | 815 |
apply (auto simp add: multiplicity_gcd_nat multiplicity_lcm_nat lcm_pos_nat) |
816 |
done |
|
31719 | 817 |
|
60527 | 818 |
lemma gcd_lcm_distrib_int: |
819 |
fixes x y z :: int |
|
820 |
shows "gcd x (lcm y z) = lcm (gcd x y) (gcd x z)" |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
821 |
apply (subst (1 2 3) gcd_abs_int) |
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
822 |
apply (subst lcm_abs_int) |
31719 | 823 |
apply (subst (2) abs_of_nonneg) |
824 |
apply force |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31719
diff
changeset
|
825 |
apply (rule gcd_lcm_distrib_nat [transferred]) |
31719 | 826 |
apply auto |
44872 | 827 |
done |
31719 | 828 |
|
829 |
end |