| author | wenzelm | 
| Fri, 07 Jun 2024 15:01:16 +0200 | |
| changeset 80293 | 453eccb886f2 | 
| parent 80084 | 173548e4d5d0 | 
| permissions | -rw-r--r-- | 
| 65435 | 1  | 
(* Title: HOL/Computational_Algebra/Factorial_Ring.thy  | 
| 63924 | 2  | 
Author: Manuel Eberl, TU Muenchen  | 
| 60804 | 3  | 
Author: Florian Haftmann, TU Muenchen  | 
4  | 
*)  | 
|
5  | 
||
6  | 
section \<open>Factorial (semi)rings\<close>  | 
|
7  | 
||
8  | 
theory Factorial_Ring  | 
|
| 
65552
 
f533820e7248
theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
 
wenzelm 
parents: 
65435 
diff
changeset
 | 
9  | 
imports  | 
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
10  | 
Main  | 
| 
66453
 
cc19f7ca2ed6
session-qualified theory imports: isabelle imports -U -i -d '~~/src/Benchmarks' -a;
 
wenzelm 
parents: 
66276 
diff
changeset
 | 
11  | 
"HOL-Library.Multiset"  | 
| 63498 | 12  | 
begin  | 
13  | 
||
| 
76700
 
c48fe2be847f
added lifting_forget as suggested by Peter Lammich
 
blanchet 
parents: 
74885 
diff
changeset
 | 
14  | 
unbundle multiset.lifting  | 
| 
 
c48fe2be847f
added lifting_forget as suggested by Peter Lammich
 
blanchet 
parents: 
74885 
diff
changeset
 | 
15  | 
|
| 63924 | 16  | 
subsection \<open>Irreducible and prime elements\<close>  | 
| 63498 | 17  | 
|
18  | 
context comm_semiring_1  | 
|
| 62499 | 19  | 
begin  | 
20  | 
||
| 63498 | 21  | 
definition irreducible :: "'a \<Rightarrow> bool" where  | 
22  | 
"irreducible p \<longleftrightarrow> p \<noteq> 0 \<and> \<not>p dvd 1 \<and> (\<forall>a b. p = a * b \<longrightarrow> a dvd 1 \<or> b dvd 1)"  | 
|
23  | 
||
24  | 
lemma not_irreducible_zero [simp]: "\<not>irreducible 0"  | 
|
25  | 
by (simp add: irreducible_def)  | 
|
26  | 
||
27  | 
lemma irreducible_not_unit: "irreducible p \<Longrightarrow> \<not>p dvd 1"  | 
|
28  | 
by (simp add: irreducible_def)  | 
|
29  | 
||
30  | 
lemma not_irreducible_one [simp]: "\<not>irreducible 1"  | 
|
31  | 
by (simp add: irreducible_def)  | 
|
32  | 
||
33  | 
lemma irreducibleI:  | 
|
34  | 
"p \<noteq> 0 \<Longrightarrow> \<not>p dvd 1 \<Longrightarrow> (\<And>a b. p = a * b \<Longrightarrow> a dvd 1 \<or> b dvd 1) \<Longrightarrow> irreducible p"  | 
|
35  | 
by (simp add: irreducible_def)  | 
|
36  | 
||
37  | 
lemma irreducibleD: "irreducible p \<Longrightarrow> p = a * b \<Longrightarrow> a dvd 1 \<or> b dvd 1"  | 
|
38  | 
by (simp add: irreducible_def)  | 
|
39  | 
||
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
40  | 
lemma irreducible_mono:  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
41  | 
assumes irr: "irreducible b" and "a dvd b" "\<not>a dvd 1"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
42  | 
shows "irreducible a"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
43  | 
proof (rule irreducibleI)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
44  | 
fix c d assume "a = c * d"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
45  | 
from assms obtain k where [simp]: "b = a * k" by auto  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
46  | 
from \<open>a = c * d\<close> have "b = c * d * k"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
47  | 
by simp  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
48  | 
hence "c dvd 1 \<or> (d * k) dvd 1"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
49  | 
using irreducibleD[OF irr, of c "d * k"] by (auto simp: mult.assoc)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
50  | 
thus "c dvd 1 \<or> d dvd 1"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
51  | 
by auto  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
52  | 
qed (use assms in \<open>auto simp: irreducible_def\<close>)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
53  | 
|
| 
80084
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
54  | 
lemma irreducible_multD:  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
55  | 
assumes l: "irreducible (a*b)"  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
56  | 
shows "a dvd 1 \<and> irreducible b \<or> b dvd 1 \<and> irreducible a"  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
57  | 
proof-  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
58  | 
have *: "irreducible b" if l: "irreducible (a*b)" and a: "a dvd 1" for a b :: 'a  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
59  | 
proof (rule irreducibleI)  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
60  | 
show "\<not>(b dvd 1)"  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
61  | 
proof  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
62  | 
assume "b dvd 1"  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
63  | 
hence "a * b dvd 1 * 1"  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
64  | 
using \<open>a dvd 1\<close> by (intro mult_dvd_mono) auto  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
65  | 
with l show False  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
66  | 
by (auto simp: irreducible_def)  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
67  | 
qed  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
68  | 
next  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
69  | 
fix x y assume "b = x * y"  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
70  | 
have "a * x dvd 1 \<or> y dvd 1"  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
71  | 
using l by (rule irreducibleD) (use \<open>b = x * y\<close> in \<open>auto simp: mult_ac\<close>)  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
72  | 
thus "x dvd 1 \<or> y dvd 1"  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
73  | 
by auto  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
74  | 
qed (use l a in auto)  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
75  | 
|
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
76  | 
from irreducibleD[OF assms refl] have "a dvd 1 \<or> b dvd 1"  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
77  | 
by (auto simp: irreducible_def)  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
78  | 
with *[of a b] *[of b a] l show ?thesis  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
79  | 
by (auto simp: mult.commute)  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
80  | 
qed  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
81  | 
|
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
82  | 
lemma irreducible_power_iff [simp]:  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
83  | 
"irreducible (p ^ n) \<longleftrightarrow> irreducible p \<and> n = 1"  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
84  | 
proof  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
85  | 
assume *: "irreducible (p ^ n)"  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
86  | 
have "irreducible p"  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
87  | 
using * by (induction n) (auto dest!: irreducible_multD)  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
88  | 
hence [simp]: "\<not>p dvd 1"  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
89  | 
using * by (auto simp: irreducible_def)  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
90  | 
|
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
91  | 
consider "n = 0" | "n = 1" | "n > 1"  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
92  | 
by linarith  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
93  | 
thus "irreducible p \<and> n = 1"  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
94  | 
proof cases  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
95  | 
assume "n > 1"  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
96  | 
hence "p ^ n = p * p ^ (n - 1)"  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
97  | 
by (cases n) auto  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
98  | 
with * \<open>\<not> p dvd 1\<close> have "p ^ (n - 1) dvd 1"  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
99  | 
using irreducible_multD[of p "p ^ (n - 1)"] by auto  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
100  | 
with \<open>\<not>p dvd 1\<close> and \<open>n > 1\<close> have False  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
101  | 
by (meson dvd_power dvd_trans zero_less_diff)  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
102  | 
thus ?thesis ..  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
103  | 
qed (use * in auto)  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
104  | 
qed auto  | 
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
105  | 
|
| 
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
106  | 
|
| 63633 | 107  | 
definition prime_elem :: "'a \<Rightarrow> bool" where  | 
108  | 
"prime_elem p \<longleftrightarrow> p \<noteq> 0 \<and> \<not>p dvd 1 \<and> (\<forall>a b. p dvd (a * b) \<longrightarrow> p dvd a \<or> p dvd b)"  | 
|
| 63498 | 109  | 
|
| 63633 | 110  | 
lemma not_prime_elem_zero [simp]: "\<not>prime_elem 0"  | 
111  | 
by (simp add: prime_elem_def)  | 
|
| 63498 | 112  | 
|
| 63633 | 113  | 
lemma prime_elem_not_unit: "prime_elem p \<Longrightarrow> \<not>p dvd 1"  | 
114  | 
by (simp add: prime_elem_def)  | 
|
| 63498 | 115  | 
|
| 63633 | 116  | 
lemma prime_elemI:  | 
117  | 
"p \<noteq> 0 \<Longrightarrow> \<not>p dvd 1 \<Longrightarrow> (\<And>a b. p dvd (a * b) \<Longrightarrow> p dvd a \<or> p dvd b) \<Longrightarrow> prime_elem p"  | 
|
118  | 
by (simp add: prime_elem_def)  | 
|
| 63498 | 119  | 
|
| 63633 | 120  | 
lemma prime_elem_dvd_multD:  | 
121  | 
"prime_elem p \<Longrightarrow> p dvd (a * b) \<Longrightarrow> p dvd a \<or> p dvd b"  | 
|
122  | 
by (simp add: prime_elem_def)  | 
|
| 63498 | 123  | 
|
| 63633 | 124  | 
lemma prime_elem_dvd_mult_iff:  | 
125  | 
"prime_elem p \<Longrightarrow> p dvd (a * b) \<longleftrightarrow> p dvd a \<or> p dvd b"  | 
|
126  | 
by (auto simp: prime_elem_def)  | 
|
| 63498 | 127  | 
|
| 63633 | 128  | 
lemma not_prime_elem_one [simp]:  | 
129  | 
"\<not> prime_elem 1"  | 
|
130  | 
by (auto dest: prime_elem_not_unit)  | 
|
| 63498 | 131  | 
|
| 63633 | 132  | 
lemma prime_elem_not_zeroI:  | 
133  | 
assumes "prime_elem p"  | 
|
| 63498 | 134  | 
shows "p \<noteq> 0"  | 
135  | 
using assms by (auto intro: ccontr)  | 
|
136  | 
||
| 
65552
 
f533820e7248
theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
 
wenzelm 
parents: 
65435 
diff
changeset
 | 
137  | 
lemma prime_elem_dvd_power:  | 
| 63633 | 138  | 
"prime_elem p \<Longrightarrow> p dvd x ^ n \<Longrightarrow> p dvd x"  | 
139  | 
by (induction n) (auto dest: prime_elem_dvd_multD intro: dvd_trans[of _ 1])  | 
|
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
140  | 
|
| 63633 | 141  | 
lemma prime_elem_dvd_power_iff:  | 
142  | 
"prime_elem p \<Longrightarrow> n > 0 \<Longrightarrow> p dvd x ^ n \<longleftrightarrow> p dvd x"  | 
|
143  | 
by (auto dest: prime_elem_dvd_power intro: dvd_trans)  | 
|
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
144  | 
|
| 63633 | 145  | 
lemma prime_elem_imp_nonzero [simp]:  | 
146  | 
"ASSUMPTION (prime_elem x) \<Longrightarrow> x \<noteq> 0"  | 
|
147  | 
unfolding ASSUMPTION_def by (rule prime_elem_not_zeroI)  | 
|
| 63498 | 148  | 
|
| 63633 | 149  | 
lemma prime_elem_imp_not_one [simp]:  | 
150  | 
"ASSUMPTION (prime_elem x) \<Longrightarrow> x \<noteq> 1"  | 
|
| 63498 | 151  | 
unfolding ASSUMPTION_def by auto  | 
152  | 
||
153  | 
end  | 
|
154  | 
||
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
155  | 
|
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
156  | 
lemma (in normalization_semidom) irreducible_cong:  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
157  | 
assumes "normalize a = normalize b"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
158  | 
shows "irreducible a \<longleftrightarrow> irreducible b"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
159  | 
proof (cases "a = 0 \<or> a dvd 1")  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
160  | 
case True  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
161  | 
hence "\<not>irreducible a" by (auto simp: irreducible_def)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
162  | 
from True have "normalize a = 0 \<or> normalize a dvd 1"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
163  | 
by auto  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
164  | 
also note assms  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
165  | 
finally have "b = 0 \<or> b dvd 1" by simp  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
166  | 
hence "\<not>irreducible b" by (auto simp: irreducible_def)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
167  | 
with \<open>\<not>irreducible a\<close> show ?thesis by simp  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
168  | 
next  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
169  | 
case False  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
170  | 
hence b: "b \<noteq> 0" "\<not>is_unit b" using assms  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
171  | 
by (auto simp: is_unit_normalize[of b])  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
172  | 
show ?thesis  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
173  | 
proof  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
174  | 
assume "irreducible a"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
175  | 
thus "irreducible b"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
176  | 
by (rule irreducible_mono) (use assms False b in \<open>auto dest: associatedD2\<close>)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
177  | 
next  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
178  | 
assume "irreducible b"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
179  | 
thus "irreducible a"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
180  | 
by (rule irreducible_mono) (use assms False b in \<open>auto dest: associatedD1\<close>)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
181  | 
qed  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
182  | 
qed  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
183  | 
|
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
184  | 
lemma (in normalization_semidom) associatedE1:  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
185  | 
assumes "normalize a = normalize b"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
186  | 
obtains u where "is_unit u" "a = u * b"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
187  | 
proof (cases "a = 0")  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
188  | 
case [simp]: False  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
189  | 
from assms have [simp]: "b \<noteq> 0" by auto  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
190  | 
show ?thesis  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
191  | 
proof (rule that)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
192  | 
show "is_unit (unit_factor a div unit_factor b)"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
193  | 
by auto  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
194  | 
have "unit_factor a div unit_factor b * b = unit_factor a * (b div unit_factor b)"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
195  | 
using \<open>b \<noteq> 0\<close> unit_div_commute unit_div_mult_swap unit_factor_is_unit by metis  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
196  | 
also have "b div unit_factor b = normalize b" by simp  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
197  | 
finally show "a = unit_factor a div unit_factor b * b"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
198  | 
by (metis assms unit_factor_mult_normalize)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
199  | 
qed  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
200  | 
next  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
201  | 
case [simp]: True  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
202  | 
hence [simp]: "b = 0"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
203  | 
using assms[symmetric] by auto  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
204  | 
show ?thesis  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
205  | 
by (intro that[of 1]) auto  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
206  | 
qed  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
207  | 
|
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
208  | 
lemma (in normalization_semidom) associatedE2:  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
209  | 
assumes "normalize a = normalize b"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
210  | 
obtains u where "is_unit u" "b = u * a"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
211  | 
proof -  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
212  | 
from assms have "normalize b = normalize a"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
213  | 
by simp  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
214  | 
then obtain u where "is_unit u" "b = u * a"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
215  | 
by (elim associatedE1)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
216  | 
thus ?thesis using that by blast  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
217  | 
qed  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
218  | 
|
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
219  | 
|
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
220  | 
(* TODO Move *)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
221  | 
lemma (in normalization_semidom) normalize_power_normalize:  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
222  | 
"normalize (normalize x ^ n) = normalize (x ^ n)"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
223  | 
proof (induction n)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
224  | 
case (Suc n)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
225  | 
have "normalize (normalize x ^ Suc n) = normalize (x * normalize (normalize x ^ n))"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
226  | 
by simp  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
227  | 
also note Suc.IH  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
228  | 
finally show ?case by simp  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
229  | 
qed auto  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
230  | 
|
| 62499 | 231  | 
context algebraic_semidom  | 
| 60804 | 232  | 
begin  | 
233  | 
||
| 63633 | 234  | 
lemma prime_elem_imp_irreducible:  | 
235  | 
assumes "prime_elem p"  | 
|
| 63498 | 236  | 
shows "irreducible p"  | 
237  | 
proof (rule irreducibleI)  | 
|
238  | 
fix a b  | 
|
239  | 
assume p_eq: "p = a * b"  | 
|
240  | 
with assms have nz: "a \<noteq> 0" "b \<noteq> 0" by auto  | 
|
241  | 
from p_eq have "p dvd a * b" by simp  | 
|
| 63633 | 242  | 
with \<open>prime_elem p\<close> have "p dvd a \<or> p dvd b" by (rule prime_elem_dvd_multD)  | 
| 63498 | 243  | 
with \<open>p = a * b\<close> have "a * b dvd 1 * b \<or> a * b dvd a * 1" by auto  | 
244  | 
thus "a dvd 1 \<or> b dvd 1"  | 
|
245  | 
by (simp only: dvd_times_left_cancel_iff[OF nz(1)] dvd_times_right_cancel_iff[OF nz(2)])  | 
|
| 63633 | 246  | 
qed (insert assms, simp_all add: prime_elem_def)  | 
| 63498 | 247  | 
|
| 63924 | 248  | 
lemma (in algebraic_semidom) unit_imp_no_irreducible_divisors:  | 
249  | 
assumes "is_unit x" "irreducible p"  | 
|
250  | 
shows "\<not>p dvd x"  | 
|
251  | 
proof (rule notI)  | 
|
252  | 
assume "p dvd x"  | 
|
253  | 
with \<open>is_unit x\<close> have "is_unit p"  | 
|
254  | 
by (auto intro: dvd_trans)  | 
|
255  | 
with \<open>irreducible p\<close> show False  | 
|
256  | 
by (simp add: irreducible_not_unit)  | 
|
257  | 
qed  | 
|
| 
65552
 
f533820e7248
theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
 
wenzelm 
parents: 
65435 
diff
changeset
 | 
258  | 
|
| 63924 | 259  | 
lemma unit_imp_no_prime_divisors:  | 
260  | 
assumes "is_unit x" "prime_elem p"  | 
|
261  | 
shows "\<not>p dvd x"  | 
|
262  | 
using unit_imp_no_irreducible_divisors[OF assms(1) prime_elem_imp_irreducible[OF assms(2)]] .  | 
|
263  | 
||
| 63633 | 264  | 
lemma prime_elem_mono:  | 
265  | 
assumes "prime_elem p" "\<not>q dvd 1" "q dvd p"  | 
|
266  | 
shows "prime_elem q"  | 
|
| 63498 | 267  | 
proof -  | 
268  | 
from \<open>q dvd p\<close> obtain r where r: "p = q * r" by (elim dvdE)  | 
|
269  | 
hence "p dvd q * r" by simp  | 
|
| 63633 | 270  | 
with \<open>prime_elem p\<close> have "p dvd q \<or> p dvd r" by (rule prime_elem_dvd_multD)  | 
| 63498 | 271  | 
hence "p dvd q"  | 
272  | 
proof  | 
|
273  | 
assume "p dvd r"  | 
|
274  | 
then obtain s where s: "r = p * s" by (elim dvdE)  | 
|
275  | 
from r have "p * 1 = p * (q * s)" by (subst (asm) s) (simp add: mult_ac)  | 
|
| 63633 | 276  | 
with \<open>prime_elem p\<close> have "q dvd 1"  | 
| 63498 | 277  | 
by (subst (asm) mult_cancel_left) auto  | 
278  | 
with \<open>\<not>q dvd 1\<close> show ?thesis by contradiction  | 
|
279  | 
qed  | 
|
280  | 
||
281  | 
show ?thesis  | 
|
| 63633 | 282  | 
proof (rule prime_elemI)  | 
| 63498 | 283  | 
fix a b assume "q dvd (a * b)"  | 
284  | 
with \<open>p dvd q\<close> have "p dvd (a * b)" by (rule dvd_trans)  | 
|
| 63633 | 285  | 
with \<open>prime_elem p\<close> have "p dvd a \<or> p dvd b" by (rule prime_elem_dvd_multD)  | 
| 63498 | 286  | 
with \<open>q dvd p\<close> show "q dvd a \<or> q dvd b" by (blast intro: dvd_trans)  | 
287  | 
qed (insert assms, auto)  | 
|
| 62499 | 288  | 
qed  | 
289  | 
||
| 63498 | 290  | 
lemma irreducibleD':  | 
291  | 
assumes "irreducible a" "b dvd a"  | 
|
292  | 
shows "a dvd b \<or> is_unit b"  | 
|
293  | 
proof -  | 
|
294  | 
from assms obtain c where c: "a = b * c" by (elim dvdE)  | 
|
295  | 
from irreducibleD[OF assms(1) this] have "is_unit b \<or> is_unit c" .  | 
|
296  | 
thus ?thesis by (auto simp: c mult_unit_dvd_iff)  | 
|
297  | 
qed  | 
|
| 60804 | 298  | 
|
| 63498 | 299  | 
lemma irreducibleI':  | 
300  | 
assumes "a \<noteq> 0" "\<not>is_unit a" "\<And>b. b dvd a \<Longrightarrow> a dvd b \<or> is_unit b"  | 
|
301  | 
shows "irreducible a"  | 
|
302  | 
proof (rule irreducibleI)  | 
|
303  | 
fix b c assume a_eq: "a = b * c"  | 
|
304  | 
hence "a dvd b \<or> is_unit b" by (intro assms) simp_all  | 
|
305  | 
thus "is_unit b \<or> is_unit c"  | 
|
306  | 
proof  | 
|
307  | 
assume "a dvd b"  | 
|
308  | 
hence "b * c dvd b * 1" by (simp add: a_eq)  | 
|
309  | 
moreover from \<open>a \<noteq> 0\<close> a_eq have "b \<noteq> 0" by auto  | 
|
310  | 
ultimately show ?thesis by (subst (asm) dvd_times_left_cancel_iff) auto  | 
|
311  | 
qed blast  | 
|
312  | 
qed (simp_all add: assms(1,2))  | 
|
| 60804 | 313  | 
|
| 63498 | 314  | 
lemma irreducible_altdef:  | 
315  | 
"irreducible x \<longleftrightarrow> x \<noteq> 0 \<and> \<not>is_unit x \<and> (\<forall>b. b dvd x \<longrightarrow> x dvd b \<or> is_unit b)"  | 
|
316  | 
using irreducibleI'[of x] irreducibleD'[of x] irreducible_not_unit[of x] by auto  | 
|
| 60804 | 317  | 
|
| 63633 | 318  | 
lemma prime_elem_multD:  | 
319  | 
assumes "prime_elem (a * b)"  | 
|
| 60804 | 320  | 
shows "is_unit a \<or> is_unit b"  | 
321  | 
proof -  | 
|
| 63633 | 322  | 
from assms have "a \<noteq> 0" "b \<noteq> 0" by (auto dest!: prime_elem_not_zeroI)  | 
323  | 
moreover from assms prime_elem_dvd_multD [of "a * b"] have "a * b dvd a \<or> a * b dvd b"  | 
|
| 60804 | 324  | 
by auto  | 
325  | 
ultimately show ?thesis  | 
|
326  | 
using dvd_times_left_cancel_iff [of a b 1]  | 
|
327  | 
dvd_times_right_cancel_iff [of b a 1]  | 
|
328  | 
by auto  | 
|
329  | 
qed  | 
|
330  | 
||
| 63633 | 331  | 
lemma prime_elemD2:  | 
332  | 
assumes "prime_elem p" and "a dvd p" and "\<not> is_unit a"  | 
|
| 60804 | 333  | 
shows "p dvd a"  | 
334  | 
proof -  | 
|
335  | 
from \<open>a dvd p\<close> obtain b where "p = a * b" ..  | 
|
| 63633 | 336  | 
with \<open>prime_elem p\<close> prime_elem_multD \<open>\<not> is_unit a\<close> have "is_unit b" by auto  | 
| 60804 | 337  | 
with \<open>p = a * b\<close> show ?thesis  | 
338  | 
by (auto simp add: mult_unit_dvd_iff)  | 
|
339  | 
qed  | 
|
340  | 
||
| 63830 | 341  | 
lemma prime_elem_dvd_prod_msetE:  | 
| 63633 | 342  | 
assumes "prime_elem p"  | 
| 63830 | 343  | 
assumes dvd: "p dvd prod_mset A"  | 
| 63633 | 344  | 
obtains a where "a \<in># A" and "p dvd a"  | 
345  | 
proof -  | 
|
346  | 
from dvd have "\<exists>a. a \<in># A \<and> p dvd a"  | 
|
347  | 
proof (induct A)  | 
|
348  | 
case empty then show ?case  | 
|
349  | 
using \<open>prime_elem p\<close> by (simp add: prime_elem_not_unit)  | 
|
350  | 
next  | 
|
| 
63793
 
e68a0b651eb5
add_mset constructor in multisets
 
fleury <Mathias.Fleury@mpi-inf.mpg.de> 
parents: 
63633 
diff
changeset
 | 
351  | 
case (add a A)  | 
| 63830 | 352  | 
then have "p dvd a * prod_mset A" by simp  | 
353  | 
with \<open>prime_elem p\<close> consider (A) "p dvd prod_mset A" | (B) "p dvd a"  | 
|
| 63633 | 354  | 
by (blast dest: prime_elem_dvd_multD)  | 
355  | 
then show ?case proof cases  | 
|
356  | 
case B then show ?thesis by auto  | 
|
357  | 
next  | 
|
358  | 
case A  | 
|
359  | 
with add.hyps obtain b where "b \<in># A" "p dvd b"  | 
|
360  | 
by auto  | 
|
361  | 
then show ?thesis by auto  | 
|
362  | 
qed  | 
|
363  | 
qed  | 
|
364  | 
with that show thesis by blast  | 
|
| 
66276
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
365  | 
|
| 63633 | 366  | 
qed  | 
367  | 
||
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
368  | 
context  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
369  | 
begin  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
370  | 
|
| 
74542
 
d592354c4a26
removed some 'private' modifiers from HOL-Computational_Algebra
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
74362 
diff
changeset
 | 
371  | 
lemma prime_elem_powerD:  | 
| 63633 | 372  | 
assumes "prime_elem (p ^ n)"  | 
373  | 
shows "prime_elem p \<and> n = 1"  | 
|
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
374  | 
proof (cases n)  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
375  | 
case (Suc m)  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
376  | 
note assms  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
377  | 
also from Suc have "p ^ n = p * p^m" by simp  | 
| 63633 | 378  | 
finally have "is_unit p \<or> is_unit (p^m)" by (rule prime_elem_multD)  | 
379  | 
moreover from assms have "\<not>is_unit p" by (simp add: prime_elem_def is_unit_power_iff)  | 
|
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
380  | 
ultimately have "is_unit (p ^ m)" by simp  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
381  | 
with \<open>\<not>is_unit p\<close> have "m = 0" by (simp add: is_unit_power_iff)  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
382  | 
with Suc assms show ?thesis by simp  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
383  | 
qed (insert assms, simp_all)  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
384  | 
|
| 63633 | 385  | 
lemma prime_elem_power_iff:  | 
386  | 
"prime_elem (p ^ n) \<longleftrightarrow> prime_elem p \<and> n = 1"  | 
|
387  | 
by (auto dest: prime_elem_powerD)  | 
|
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
388  | 
|
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
389  | 
end  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
390  | 
|
| 63498 | 391  | 
lemma irreducible_mult_unit_left:  | 
392  | 
"is_unit a \<Longrightarrow> irreducible (a * p) \<longleftrightarrow> irreducible p"  | 
|
393  | 
by (auto simp: irreducible_altdef mult.commute[of a] is_unit_mult_iff  | 
|
394  | 
mult_unit_dvd_iff dvd_mult_unit_iff)  | 
|
395  | 
||
| 63633 | 396  | 
lemma prime_elem_mult_unit_left:  | 
397  | 
"is_unit a \<Longrightarrow> prime_elem (a * p) \<longleftrightarrow> prime_elem p"  | 
|
398  | 
by (auto simp: prime_elem_def mult.commute[of a] is_unit_mult_iff mult_unit_dvd_iff)  | 
|
| 63498 | 399  | 
|
| 63633 | 400  | 
lemma prime_elem_dvd_cases:  | 
401  | 
assumes pk: "p*k dvd m*n" and p: "prime_elem p"  | 
|
| 
63537
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
402  | 
shows "(\<exists>x. k dvd x*n \<and> m = p*x) \<or> (\<exists>y. k dvd m*y \<and> n = p*y)"  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
403  | 
proof -  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
404  | 
have "p dvd m*n" using dvd_mult_left pk by blast  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
405  | 
then consider "p dvd m" | "p dvd n"  | 
| 63633 | 406  | 
using p prime_elem_dvd_mult_iff by blast  | 
| 
63537
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
407  | 
then show ?thesis  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
408  | 
proof cases  | 
| 
65552
 
f533820e7248
theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
 
wenzelm 
parents: 
65435 
diff
changeset
 | 
409  | 
case 1 then obtain a where "m = p * a" by (metis dvd_mult_div_cancel)  | 
| 
63537
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
410  | 
then have "\<exists>x. k dvd x * n \<and> m = p * x"  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
411  | 
using p pk by (auto simp: mult.assoc)  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
412  | 
then show ?thesis ..  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
413  | 
next  | 
| 
65552
 
f533820e7248
theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
 
wenzelm 
parents: 
65435 
diff
changeset
 | 
414  | 
case 2 then obtain b where "n = p * b" by (metis dvd_mult_div_cancel)  | 
| 
 
f533820e7248
theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
 
wenzelm 
parents: 
65435 
diff
changeset
 | 
415  | 
with p pk have "\<exists>y. k dvd m*y \<and> n = p*y"  | 
| 
63537
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
416  | 
by (metis dvd_mult_right dvd_times_left_cancel_iff mult.left_commute mult_zero_left)  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
417  | 
then show ?thesis ..  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
418  | 
qed  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
419  | 
qed  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
420  | 
|
| 63633 | 421  | 
lemma prime_elem_power_dvd_prod:  | 
422  | 
assumes pc: "p^c dvd m*n" and p: "prime_elem p"  | 
|
| 
63537
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
423  | 
shows "\<exists>a b. a+b = c \<and> p^a dvd m \<and> p^b dvd n"  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
424  | 
using pc  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
425  | 
proof (induct c arbitrary: m n)  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
426  | 
case 0 show ?case by simp  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
427  | 
next  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
428  | 
case (Suc c)  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
429  | 
consider x where "p^c dvd x*n" "m = p*x" | y where "p^c dvd m*y" "n = p*y"  | 
| 63633 | 430  | 
using prime_elem_dvd_cases [of _ "p^c", OF _ p] Suc.prems by force  | 
| 
63537
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
431  | 
then show ?case  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
432  | 
proof cases  | 
| 
65552
 
f533820e7248
theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
 
wenzelm 
parents: 
65435 
diff
changeset
 | 
433  | 
case (1 x)  | 
| 
63537
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
434  | 
with Suc.hyps[of x n] obtain a b where "a + b = c \<and> p ^ a dvd x \<and> p ^ b dvd n" by blast  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
435  | 
with 1 have "Suc a + b = Suc c \<and> p ^ Suc a dvd m \<and> p ^ b dvd n"  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
436  | 
by (auto intro: mult_dvd_mono)  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
437  | 
thus ?thesis by blast  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
438  | 
next  | 
| 
65552
 
f533820e7248
theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
 
wenzelm 
parents: 
65435 
diff
changeset
 | 
439  | 
case (2 y)  | 
| 
63537
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
440  | 
with Suc.hyps[of m y] obtain a b where "a + b = c \<and> p ^ a dvd m \<and> p ^ b dvd y" by blast  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
441  | 
with 2 have "a + Suc b = Suc c \<and> p ^ a dvd m \<and> p ^ Suc b dvd n"  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
442  | 
by (auto intro: mult_dvd_mono)  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
443  | 
with Suc.hyps [of m y] show "\<exists>a b. a + b = Suc c \<and> p ^ a dvd m \<and> p ^ b dvd n"  | 
| 
68606
 
96a49db47c97
removal of smt and certain refinements
 
paulson <lp15@cam.ac.uk> 
parents: 
67051 
diff
changeset
 | 
444  | 
by blast  | 
| 
63537
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
445  | 
qed  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
446  | 
qed  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
447  | 
|
| 63633 | 448  | 
lemma prime_elem_power_dvd_cases:  | 
| 63924 | 449  | 
assumes "p ^ c dvd m * n" and "a + b = Suc c" and "prime_elem p"  | 
450  | 
shows "p ^ a dvd m \<or> p ^ b dvd n"  | 
|
451  | 
proof -  | 
|
452  | 
from assms obtain r s  | 
|
453  | 
where "r + s = c \<and> p ^ r dvd m \<and> p ^ s dvd n"  | 
|
454  | 
by (blast dest: prime_elem_power_dvd_prod)  | 
|
455  | 
moreover with assms have  | 
|
456  | 
"a \<le> r \<or> b \<le> s" by arith  | 
|
457  | 
ultimately show ?thesis by (auto intro: power_le_dvd)  | 
|
458  | 
qed  | 
|
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
459  | 
|
| 63633 | 460  | 
lemma prime_elem_not_unit' [simp]:  | 
461  | 
"ASSUMPTION (prime_elem x) \<Longrightarrow> \<not>is_unit x"  | 
|
462  | 
unfolding ASSUMPTION_def by (rule prime_elem_not_unit)  | 
|
| 63498 | 463  | 
|
| 63633 | 464  | 
lemma prime_elem_dvd_power_iff:  | 
465  | 
assumes "prime_elem p"  | 
|
| 62499 | 466  | 
shows "p dvd a ^ n \<longleftrightarrow> p dvd a \<and> n > 0"  | 
| 63633 | 467  | 
using assms by (induct n) (auto dest: prime_elem_not_unit prime_elem_dvd_multD)  | 
| 62499 | 468  | 
|
469  | 
lemma prime_power_dvd_multD:  | 
|
| 63633 | 470  | 
assumes "prime_elem p"  | 
| 62499 | 471  | 
assumes "p ^ n dvd a * b" and "n > 0" and "\<not> p dvd a"  | 
472  | 
shows "p ^ n dvd b"  | 
|
| 
65552
 
f533820e7248
theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
 
wenzelm 
parents: 
65435 
diff
changeset
 | 
473  | 
using \<open>p ^ n dvd a * b\<close> and \<open>n > 0\<close>  | 
| 63633 | 474  | 
proof (induct n arbitrary: b)  | 
| 62499 | 475  | 
case 0 then show ?case by simp  | 
476  | 
next  | 
|
477  | 
case (Suc n) show ?case  | 
|
478  | 
proof (cases "n = 0")  | 
|
| 63633 | 479  | 
case True with Suc \<open>prime_elem p\<close> \<open>\<not> p dvd a\<close> show ?thesis  | 
480  | 
by (simp add: prime_elem_dvd_mult_iff)  | 
|
| 62499 | 481  | 
next  | 
482  | 
case False then have "n > 0" by simp  | 
|
| 63633 | 483  | 
from \<open>prime_elem p\<close> have "p \<noteq> 0" by auto  | 
| 62499 | 484  | 
from Suc.prems have *: "p * p ^ n dvd a * b"  | 
485  | 
by simp  | 
|
486  | 
then have "p dvd a * b"  | 
|
487  | 
by (rule dvd_mult_left)  | 
|
| 63633 | 488  | 
with Suc \<open>prime_elem p\<close> \<open>\<not> p dvd a\<close> have "p dvd b"  | 
489  | 
by (simp add: prime_elem_dvd_mult_iff)  | 
|
| 63040 | 490  | 
moreover define c where "c = b div p"  | 
| 62499 | 491  | 
ultimately have b: "b = p * c" by simp  | 
492  | 
with * have "p * p ^ n dvd p * (a * c)"  | 
|
493  | 
by (simp add: ac_simps)  | 
|
494  | 
with \<open>p \<noteq> 0\<close> have "p ^ n dvd a * c"  | 
|
495  | 
by simp  | 
|
496  | 
with Suc.hyps \<open>n > 0\<close> have "p ^ n dvd c"  | 
|
497  | 
by blast  | 
|
498  | 
with \<open>p \<noteq> 0\<close> show ?thesis  | 
|
499  | 
by (simp add: b)  | 
|
500  | 
qed  | 
|
501  | 
qed  | 
|
502  | 
||
| 63633 | 503  | 
end  | 
504  | 
||
| 63924 | 505  | 
|
506  | 
subsection \<open>Generalized primes: normalized prime elements\<close>  | 
|
507  | 
||
| 63633 | 508  | 
context normalization_semidom  | 
509  | 
begin  | 
|
510  | 
||
| 63924 | 511  | 
lemma irreducible_normalized_divisors:  | 
512  | 
assumes "irreducible x" "y dvd x" "normalize y = y"  | 
|
513  | 
shows "y = 1 \<or> y = normalize x"  | 
|
514  | 
proof -  | 
|
515  | 
from assms have "is_unit y \<or> x dvd y" by (auto simp: irreducible_altdef)  | 
|
516  | 
thus ?thesis  | 
|
517  | 
proof (elim disjE)  | 
|
518  | 
assume "is_unit y"  | 
|
519  | 
hence "normalize y = 1" by (simp add: is_unit_normalize)  | 
|
520  | 
with assms show ?thesis by simp  | 
|
521  | 
next  | 
|
522  | 
assume "x dvd y"  | 
|
523  | 
with \<open>y dvd x\<close> have "normalize y = normalize x" by (rule associatedI)  | 
|
524  | 
with assms show ?thesis by simp  | 
|
525  | 
qed  | 
|
526  | 
qed  | 
|
527  | 
||
| 63633 | 528  | 
lemma irreducible_normalize_iff [simp]: "irreducible (normalize x) = irreducible x"  | 
529  | 
using irreducible_mult_unit_left[of "1 div unit_factor x" x]  | 
|
530  | 
by (cases "x = 0") (simp_all add: unit_div_commute)  | 
|
531  | 
||
532  | 
lemma prime_elem_normalize_iff [simp]: "prime_elem (normalize x) = prime_elem x"  | 
|
533  | 
using prime_elem_mult_unit_left[of "1 div unit_factor x" x]  | 
|
534  | 
by (cases "x = 0") (simp_all add: unit_div_commute)  | 
|
535  | 
||
536  | 
lemma prime_elem_associated:  | 
|
537  | 
assumes "prime_elem p" and "prime_elem q" and "q dvd p"  | 
|
538  | 
shows "normalize q = normalize p"  | 
|
539  | 
using \<open>q dvd p\<close> proof (rule associatedI)  | 
|
540  | 
from \<open>prime_elem q\<close> have "\<not> is_unit q"  | 
|
541  | 
by (auto simp add: prime_elem_not_unit)  | 
|
542  | 
with \<open>prime_elem p\<close> \<open>q dvd p\<close> show "p dvd q"  | 
|
543  | 
by (blast intro: prime_elemD2)  | 
|
544  | 
qed  | 
|
545  | 
||
546  | 
definition prime :: "'a \<Rightarrow> bool" where  | 
|
547  | 
"prime p \<longleftrightarrow> prime_elem p \<and> normalize p = p"  | 
|
548  | 
||
549  | 
lemma not_prime_0 [simp]: "\<not>prime 0" by (simp add: prime_def)  | 
|
550  | 
||
551  | 
lemma not_prime_unit: "is_unit x \<Longrightarrow> \<not>prime x"  | 
|
552  | 
using prime_elem_not_unit[of x] by (auto simp add: prime_def)  | 
|
553  | 
||
554  | 
lemma not_prime_1 [simp]: "\<not>prime 1" by (simp add: not_prime_unit)  | 
|
555  | 
||
556  | 
lemma primeI: "prime_elem x \<Longrightarrow> normalize x = x \<Longrightarrow> prime x"  | 
|
557  | 
by (simp add: prime_def)  | 
|
558  | 
||
559  | 
lemma prime_imp_prime_elem [dest]: "prime p \<Longrightarrow> prime_elem p"  | 
|
560  | 
by (simp add: prime_def)  | 
|
561  | 
||
562  | 
lemma normalize_prime: "prime p \<Longrightarrow> normalize p = p"  | 
|
563  | 
by (simp add: prime_def)  | 
|
564  | 
||
565  | 
lemma prime_normalize_iff [simp]: "prime (normalize p) \<longleftrightarrow> prime_elem p"  | 
|
566  | 
by (auto simp add: prime_def)  | 
|
567  | 
||
568  | 
lemma prime_power_iff:  | 
|
569  | 
"prime (p ^ n) \<longleftrightarrow> prime p \<and> n = 1"  | 
|
570  | 
by (auto simp: prime_def prime_elem_power_iff)  | 
|
571  | 
||
572  | 
lemma prime_imp_nonzero [simp]:  | 
|
573  | 
"ASSUMPTION (prime x) \<Longrightarrow> x \<noteq> 0"  | 
|
574  | 
unfolding ASSUMPTION_def prime_def by auto  | 
|
575  | 
||
576  | 
lemma prime_imp_not_one [simp]:  | 
|
577  | 
"ASSUMPTION (prime x) \<Longrightarrow> x \<noteq> 1"  | 
|
578  | 
unfolding ASSUMPTION_def by auto  | 
|
579  | 
||
580  | 
lemma prime_not_unit' [simp]:  | 
|
581  | 
"ASSUMPTION (prime x) \<Longrightarrow> \<not>is_unit x"  | 
|
582  | 
unfolding ASSUMPTION_def prime_def by auto  | 
|
583  | 
||
584  | 
lemma prime_normalize' [simp]: "ASSUMPTION (prime x) \<Longrightarrow> normalize x = x"  | 
|
585  | 
unfolding ASSUMPTION_def prime_def by simp  | 
|
586  | 
||
587  | 
lemma unit_factor_prime: "prime x \<Longrightarrow> unit_factor x = 1"  | 
|
588  | 
using unit_factor_normalize[of x] unfolding prime_def by auto  | 
|
589  | 
||
590  | 
lemma unit_factor_prime' [simp]: "ASSUMPTION (prime x) \<Longrightarrow> unit_factor x = 1"  | 
|
591  | 
unfolding ASSUMPTION_def by (rule unit_factor_prime)  | 
|
592  | 
||
593  | 
lemma prime_imp_prime_elem' [simp]: "ASSUMPTION (prime x) \<Longrightarrow> prime_elem x"  | 
|
594  | 
by (simp add: prime_def ASSUMPTION_def)  | 
|
595  | 
||
596  | 
lemma prime_dvd_multD: "prime p \<Longrightarrow> p dvd a * b \<Longrightarrow> p dvd a \<or> p dvd b"  | 
|
597  | 
by (intro prime_elem_dvd_multD) simp_all  | 
|
598  | 
||
| 
64631
 
7705926ee595
removed dangerous simp rule: prime computations can be excessively long
 
haftmann 
parents: 
64272 
diff
changeset
 | 
599  | 
lemma prime_dvd_mult_iff: "prime p \<Longrightarrow> p dvd a * b \<longleftrightarrow> p dvd a \<or> p dvd b"  | 
| 63633 | 600  | 
by (auto dest: prime_dvd_multD)  | 
601  | 
||
| 
65552
 
f533820e7248
theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
 
wenzelm 
parents: 
65435 
diff
changeset
 | 
602  | 
lemma prime_dvd_power:  | 
| 63633 | 603  | 
"prime p \<Longrightarrow> p dvd x ^ n \<Longrightarrow> p dvd x"  | 
604  | 
by (auto dest!: prime_elem_dvd_power simp: prime_def)  | 
|
605  | 
||
606  | 
lemma prime_dvd_power_iff:  | 
|
607  | 
"prime p \<Longrightarrow> n > 0 \<Longrightarrow> p dvd x ^ n \<longleftrightarrow> p dvd x"  | 
|
608  | 
by (subst prime_elem_dvd_power_iff) simp_all  | 
|
609  | 
||
| 63830 | 610  | 
lemma prime_dvd_prod_mset_iff: "prime p \<Longrightarrow> p dvd prod_mset A \<longleftrightarrow> (\<exists>x. x \<in># A \<and> p dvd x)"  | 
| 63633 | 611  | 
by (induction A) (simp_all add: prime_elem_dvd_mult_iff prime_imp_prime_elem, blast+)  | 
612  | 
||
| 
66276
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
613  | 
lemma prime_dvd_prod_iff: "finite A \<Longrightarrow> prime p \<Longrightarrow> p dvd prod f A \<longleftrightarrow> (\<exists>x\<in>A. p dvd f x)"  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
614  | 
by (auto simp: prime_dvd_prod_mset_iff prod_unfold_prod_mset)  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
615  | 
|
| 63633 | 616  | 
lemma primes_dvd_imp_eq:  | 
617  | 
assumes "prime p" "prime q" "p dvd q"  | 
|
618  | 
shows "p = q"  | 
|
619  | 
proof -  | 
|
620  | 
from assms have "irreducible q" by (simp add: prime_elem_imp_irreducible prime_def)  | 
|
621  | 
from irreducibleD'[OF this \<open>p dvd q\<close>] assms have "q dvd p" by simp  | 
|
622  | 
with \<open>p dvd q\<close> have "normalize p = normalize q" by (rule associatedI)  | 
|
623  | 
with assms show "p = q" by simp  | 
|
624  | 
qed  | 
|
625  | 
||
| 63830 | 626  | 
lemma prime_dvd_prod_mset_primes_iff:  | 
| 63633 | 627  | 
assumes "prime p" "\<And>q. q \<in># A \<Longrightarrow> prime q"  | 
| 63830 | 628  | 
shows "p dvd prod_mset A \<longleftrightarrow> p \<in># A"  | 
| 63633 | 629  | 
proof -  | 
| 63830 | 630  | 
from assms(1) have "p dvd prod_mset A \<longleftrightarrow> (\<exists>x. x \<in># A \<and> p dvd x)" by (rule prime_dvd_prod_mset_iff)  | 
| 63633 | 631  | 
also from assms have "\<dots> \<longleftrightarrow> p \<in># A" by (auto dest: primes_dvd_imp_eq)  | 
632  | 
finally show ?thesis .  | 
|
633  | 
qed  | 
|
634  | 
||
| 63830 | 635  | 
lemma prod_mset_primes_dvd_imp_subset:  | 
636  | 
assumes "prod_mset A dvd prod_mset B" "\<And>p. p \<in># A \<Longrightarrow> prime p" "\<And>p. p \<in># B \<Longrightarrow> prime p"  | 
|
| 63633 | 637  | 
shows "A \<subseteq># B"  | 
638  | 
using assms  | 
|
639  | 
proof (induction A arbitrary: B)  | 
|
640  | 
case empty  | 
|
641  | 
thus ?case by simp  | 
|
642  | 
next  | 
|
| 
63793
 
e68a0b651eb5
add_mset constructor in multisets
 
fleury <Mathias.Fleury@mpi-inf.mpg.de> 
parents: 
63633 
diff
changeset
 | 
643  | 
case (add p A B)  | 
| 63633 | 644  | 
hence p: "prime p" by simp  | 
645  | 
  define B' where "B' = B - {#p#}"
 | 
|
| 63830 | 646  | 
from add.prems have "p dvd prod_mset B" by (simp add: dvd_mult_left)  | 
| 63633 | 647  | 
with add.prems have "p \<in># B"  | 
| 63830 | 648  | 
by (subst (asm) (2) prime_dvd_prod_mset_primes_iff) simp_all  | 
| 63633 | 649  | 
  hence B: "B = B' + {#p#}" by (simp add: B'_def)
 | 
650  | 
from add.prems p have "A \<subseteq># B'" by (intro add.IH) (simp_all add: B)  | 
|
651  | 
thus ?case by (simp add: B)  | 
|
652  | 
qed  | 
|
653  | 
||
| 63830 | 654  | 
lemma prod_mset_dvd_prod_mset_primes_iff:  | 
| 63633 | 655  | 
assumes "\<And>x. x \<in># A \<Longrightarrow> prime x" "\<And>x. x \<in># B \<Longrightarrow> prime x"  | 
| 63830 | 656  | 
shows "prod_mset A dvd prod_mset B \<longleftrightarrow> A \<subseteq># B"  | 
657  | 
using assms by (auto intro: prod_mset_subset_imp_dvd prod_mset_primes_dvd_imp_subset)  | 
|
| 63633 | 658  | 
|
| 63830 | 659  | 
lemma is_unit_prod_mset_primes_iff:  | 
| 63633 | 660  | 
assumes "\<And>x. x \<in># A \<Longrightarrow> prime x"  | 
| 63830 | 661  | 
  shows   "is_unit (prod_mset A) \<longleftrightarrow> A = {#}"
 | 
| 63924 | 662  | 
by (auto simp add: is_unit_prod_mset_iff)  | 
663  | 
(meson all_not_in_conv assms not_prime_unit set_mset_eq_empty_iff)  | 
|
| 63498 | 664  | 
|
| 63830 | 665  | 
lemma prod_mset_primes_irreducible_imp_prime:  | 
666  | 
assumes irred: "irreducible (prod_mset A)"  | 
|
| 63633 | 667  | 
assumes A: "\<And>x. x \<in># A \<Longrightarrow> prime x"  | 
668  | 
assumes B: "\<And>x. x \<in># B \<Longrightarrow> prime x"  | 
|
669  | 
assumes C: "\<And>x. x \<in># C \<Longrightarrow> prime x"  | 
|
| 63830 | 670  | 
assumes dvd: "prod_mset A dvd prod_mset B * prod_mset C"  | 
671  | 
shows "prod_mset A dvd prod_mset B \<or> prod_mset A dvd prod_mset C"  | 
|
| 63498 | 672  | 
proof -  | 
| 63830 | 673  | 
from dvd have "prod_mset A dvd prod_mset (B + C)"  | 
| 63498 | 674  | 
by simp  | 
675  | 
with A B C have subset: "A \<subseteq># B + C"  | 
|
| 63830 | 676  | 
by (subst (asm) prod_mset_dvd_prod_mset_primes_iff) auto  | 
| 
63919
 
9aed2da07200
# after multiset intersection and union symbol
 
fleury <Mathias.Fleury@mpi-inf.mpg.de> 
parents: 
63905 
diff
changeset
 | 
677  | 
define A1 and A2 where "A1 = A \<inter># B" and "A2 = A - A1"  | 
| 63498 | 678  | 
have "A = A1 + A2" unfolding A1_def A2_def  | 
679  | 
by (rule sym, intro subset_mset.add_diff_inverse) simp_all  | 
|
680  | 
from subset have "A1 \<subseteq># B" "A2 \<subseteq># C"  | 
|
681  | 
by (auto simp: A1_def A2_def Multiset.subset_eq_diff_conv Multiset.union_commute)  | 
|
| 63830 | 682  | 
from \<open>A = A1 + A2\<close> have "prod_mset A = prod_mset A1 * prod_mset A2" by simp  | 
683  | 
from irred and this have "is_unit (prod_mset A1) \<or> is_unit (prod_mset A2)"  | 
|
| 63498 | 684  | 
by (rule irreducibleD)  | 
685  | 
  with A have "A1 = {#} \<or> A2 = {#}" unfolding A1_def A2_def
 | 
|
| 63830 | 686  | 
by (subst (asm) (1 2) is_unit_prod_mset_primes_iff) (auto dest: Multiset.in_diffD)  | 
| 63498 | 687  | 
with dvd \<open>A = A1 + A2\<close> \<open>A1 \<subseteq># B\<close> \<open>A2 \<subseteq># C\<close> show ?thesis  | 
| 63830 | 688  | 
by (auto intro: prod_mset_subset_imp_dvd)  | 
| 63498 | 689  | 
qed  | 
690  | 
||
| 63830 | 691  | 
lemma prod_mset_primes_finite_divisor_powers:  | 
| 63633 | 692  | 
assumes A: "\<And>x. x \<in># A \<Longrightarrow> prime x"  | 
693  | 
assumes B: "\<And>x. x \<in># B \<Longrightarrow> prime x"  | 
|
| 63498 | 694  | 
  assumes "A \<noteq> {#}"
 | 
| 63830 | 695  | 
  shows   "finite {n. prod_mset A ^ n dvd prod_mset B}"
 | 
| 63498 | 696  | 
proof -  | 
697  | 
  from \<open>A \<noteq> {#}\<close> obtain x where x: "x \<in># A" by blast
 | 
|
698  | 
define m where "m = count B x"  | 
|
| 63830 | 699  | 
  have "{n. prod_mset A ^ n dvd prod_mset B} \<subseteq> {..m}"
 | 
| 63498 | 700  | 
proof safe  | 
| 63830 | 701  | 
fix n assume dvd: "prod_mset A ^ n dvd prod_mset B"  | 
702  | 
from x have "x ^ n dvd prod_mset A ^ n" by (intro dvd_power_same dvd_prod_mset)  | 
|
| 63498 | 703  | 
also note dvd  | 
| 63830 | 704  | 
also have "x ^ n = prod_mset (replicate_mset n x)" by simp  | 
| 63498 | 705  | 
finally have "replicate_mset n x \<subseteq># B"  | 
| 63830 | 706  | 
by (rule prod_mset_primes_dvd_imp_subset) (insert A B x, simp_all split: if_splits)  | 
| 63498 | 707  | 
thus "n \<le> m" by (simp add: count_le_replicate_mset_subset_eq m_def)  | 
| 60804 | 708  | 
qed  | 
| 63498 | 709  | 
  moreover have "finite {..m}" by simp
 | 
710  | 
ultimately show ?thesis by (rule finite_subset)  | 
|
711  | 
qed  | 
|
712  | 
||
| 63924 | 713  | 
end  | 
| 63498 | 714  | 
|
| 63924 | 715  | 
|
| 67051 | 716  | 
subsection \<open>In a semiring with GCD, each irreducible element is a prime element\<close>  | 
| 63498 | 717  | 
|
718  | 
context semiring_gcd  | 
|
719  | 
begin  | 
|
720  | 
||
| 63633 | 721  | 
lemma irreducible_imp_prime_elem_gcd:  | 
| 63498 | 722  | 
assumes "irreducible x"  | 
| 63633 | 723  | 
shows "prime_elem x"  | 
724  | 
proof (rule prime_elemI)  | 
|
| 63498 | 725  | 
fix a b assume "x dvd a * b"  | 
726  | 
from dvd_productE[OF this] obtain y z where yz: "x = y * z" "y dvd a" "z dvd b" .  | 
|
727  | 
from \<open>irreducible x\<close> and \<open>x = y * z\<close> have "is_unit y \<or> is_unit z" by (rule irreducibleD)  | 
|
728  | 
with yz show "x dvd a \<or> x dvd b"  | 
|
729  | 
by (auto simp: mult_unit_dvd_iff mult_unit_dvd_iff')  | 
|
730  | 
qed (insert assms, auto simp: irreducible_not_unit)  | 
|
731  | 
||
| 63633 | 732  | 
lemma prime_elem_imp_coprime:  | 
733  | 
assumes "prime_elem p" "\<not>p dvd n"  | 
|
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
734  | 
shows "coprime p n"  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
735  | 
proof (rule coprimeI)  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
736  | 
fix d assume "d dvd p" "d dvd n"  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
737  | 
show "is_unit d"  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
738  | 
proof (rule ccontr)  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
739  | 
assume "\<not>is_unit d"  | 
| 63633 | 740  | 
from \<open>prime_elem p\<close> and \<open>d dvd p\<close> and this have "p dvd d"  | 
741  | 
by (rule prime_elemD2)  | 
|
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
742  | 
from this and \<open>d dvd n\<close> have "p dvd n" by (rule dvd_trans)  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
743  | 
with \<open>\<not>p dvd n\<close> show False by contradiction  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
744  | 
qed  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
745  | 
qed  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
746  | 
|
| 63633 | 747  | 
lemma prime_imp_coprime:  | 
748  | 
assumes "prime p" "\<not>p dvd n"  | 
|
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
749  | 
shows "coprime p n"  | 
| 63633 | 750  | 
using assms by (simp add: prime_elem_imp_coprime)  | 
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
751  | 
|
| 
65552
 
f533820e7248
theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
 
wenzelm 
parents: 
65435 
diff
changeset
 | 
752  | 
lemma prime_elem_imp_power_coprime:  | 
| 67051 | 753  | 
"prime_elem p \<Longrightarrow> \<not> p dvd a \<Longrightarrow> coprime a (p ^ m)"  | 
754  | 
by (cases "m > 0") (auto dest: prime_elem_imp_coprime simp add: ac_simps)  | 
|
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
755  | 
|
| 
65552
 
f533820e7248
theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
 
wenzelm 
parents: 
65435 
diff
changeset
 | 
756  | 
lemma prime_imp_power_coprime:  | 
| 67051 | 757  | 
"prime p \<Longrightarrow> \<not> p dvd a \<Longrightarrow> coprime a (p ^ m)"  | 
758  | 
by (rule prime_elem_imp_power_coprime) simp_all  | 
|
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
759  | 
|
| 63633 | 760  | 
lemma prime_elem_divprod_pow:  | 
761  | 
assumes p: "prime_elem p" and ab: "coprime a b" and pab: "p^n dvd a * b"  | 
|
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
762  | 
shows "p^n dvd a \<or> p^n dvd b"  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
763  | 
using assms  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
764  | 
proof -  | 
| 67051 | 765  | 
from p have "\<not> is_unit p"  | 
766  | 
by simp  | 
|
767  | 
with ab p have "\<not> p dvd a \<or> \<not> p dvd b"  | 
|
768  | 
using not_coprimeI by blast  | 
|
769  | 
with p have "coprime (p ^ n) a \<or> coprime (p ^ n) b"  | 
|
770  | 
by (auto dest: prime_elem_imp_power_coprime simp add: ac_simps)  | 
|
771  | 
with pab show ?thesis  | 
|
772  | 
by (auto simp add: coprime_dvd_mult_left_iff coprime_dvd_mult_right_iff)  | 
|
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
773  | 
qed  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
774  | 
|
| 
65552
 
f533820e7248
theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
 
wenzelm 
parents: 
65435 
diff
changeset
 | 
775  | 
lemma primes_coprime:  | 
| 63633 | 776  | 
"prime p \<Longrightarrow> prime q \<Longrightarrow> p \<noteq> q \<Longrightarrow> coprime p q"  | 
777  | 
using prime_imp_coprime primes_dvd_imp_eq by blast  | 
|
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
778  | 
|
| 63498 | 779  | 
end  | 
780  | 
||
781  | 
||
| 63924 | 782  | 
subsection \<open>Factorial semirings: algebraic structures with unique prime factorizations\<close>  | 
783  | 
||
| 63498 | 784  | 
class factorial_semiring = normalization_semidom +  | 
785  | 
assumes prime_factorization_exists:  | 
|
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
786  | 
"x \<noteq> 0 \<Longrightarrow> \<exists>A. (\<forall>x. x \<in># A \<longrightarrow> prime_elem x) \<and> normalize (prod_mset A) = normalize x"  | 
| 63924 | 787  | 
|
788  | 
text \<open>Alternative characterization\<close>  | 
|
| 
65552
 
f533820e7248
theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
 
wenzelm 
parents: 
65435 
diff
changeset
 | 
789  | 
|
| 63924 | 790  | 
lemma (in normalization_semidom) factorial_semiring_altI_aux:  | 
791  | 
  assumes finite_divisors: "\<And>x. x \<noteq> 0 \<Longrightarrow> finite {y. y dvd x \<and> normalize y = y}"
 | 
|
792  | 
assumes irreducible_imp_prime_elem: "\<And>x. irreducible x \<Longrightarrow> prime_elem x"  | 
|
793  | 
assumes "x \<noteq> 0"  | 
|
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
794  | 
shows "\<exists>A. (\<forall>x. x \<in># A \<longrightarrow> prime_elem x) \<and> normalize (prod_mset A) = normalize x"  | 
| 63924 | 795  | 
using \<open>x \<noteq> 0\<close>  | 
796  | 
proof (induction "card {b. b dvd x \<and> normalize b = b}" arbitrary: x rule: less_induct)
 | 
|
797  | 
case (less a)  | 
|
798  | 
  let ?fctrs = "\<lambda>a. {b. b dvd a \<and> normalize b = b}"
 | 
|
799  | 
show ?case  | 
|
800  | 
proof (cases "is_unit a")  | 
|
801  | 
case True  | 
|
802  | 
    thus ?thesis by (intro exI[of _ "{#}"]) (auto simp: is_unit_normalize)
 | 
|
803  | 
next  | 
|
804  | 
case False  | 
|
805  | 
show ?thesis  | 
|
806  | 
proof (cases "\<exists>b. b dvd a \<and> \<not>is_unit b \<and> \<not>a dvd b")  | 
|
807  | 
case False  | 
|
808  | 
with \<open>\<not>is_unit a\<close> less.prems have "irreducible a" by (auto simp: irreducible_altdef)  | 
|
809  | 
hence "prime_elem a" by (rule irreducible_imp_prime_elem)  | 
|
810  | 
      thus ?thesis by (intro exI[of _ "{#normalize a#}"]) auto
 | 
|
811  | 
next  | 
|
812  | 
case True  | 
|
| 74362 | 813  | 
then obtain b where b: "b dvd a" "\<not> is_unit b" "\<not> a dvd b" by auto  | 
| 63924 | 814  | 
from b have "?fctrs b \<subseteq> ?fctrs a" by (auto intro: dvd_trans)  | 
815  | 
moreover from b have "normalize a \<notin> ?fctrs b" "normalize a \<in> ?fctrs a" by simp_all  | 
|
816  | 
hence "?fctrs b \<noteq> ?fctrs a" by blast  | 
|
817  | 
ultimately have "?fctrs b \<subset> ?fctrs a" by (subst subset_not_subset_eq) blast  | 
|
818  | 
with finite_divisors[OF \<open>a \<noteq> 0\<close>] have "card (?fctrs b) < card (?fctrs a)"  | 
|
819  | 
by (rule psubset_card_mono)  | 
|
820  | 
moreover from \<open>a \<noteq> 0\<close> b have "b \<noteq> 0" by auto  | 
|
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
821  | 
ultimately have "\<exists>A. (\<forall>x. x \<in># A \<longrightarrow> prime_elem x) \<and> normalize (prod_mset A) = normalize b"  | 
| 63924 | 822  | 
by (intro less) auto  | 
| 74362 | 823  | 
then obtain A where A: "(\<forall>x. x \<in># A \<longrightarrow> prime_elem x) \<and> normalize (\<Prod>\<^sub># A) = normalize b"  | 
824  | 
by auto  | 
|
| 63924 | 825  | 
|
826  | 
define c where "c = a div b"  | 
|
827  | 
from b have c: "a = b * c" by (simp add: c_def)  | 
|
828  | 
from less.prems c have "c \<noteq> 0" by auto  | 
|
829  | 
from b c have "?fctrs c \<subseteq> ?fctrs a" by (auto intro: dvd_trans)  | 
|
830  | 
moreover have "normalize a \<notin> ?fctrs c"  | 
|
831  | 
proof safe  | 
|
832  | 
assume "normalize a dvd c"  | 
|
833  | 
hence "b * c dvd 1 * c" by (simp add: c)  | 
|
834  | 
hence "b dvd 1" by (subst (asm) dvd_times_right_cancel_iff) fact+  | 
|
835  | 
with b show False by simp  | 
|
836  | 
qed  | 
|
837  | 
with \<open>normalize a \<in> ?fctrs a\<close> have "?fctrs a \<noteq> ?fctrs c" by blast  | 
|
838  | 
ultimately have "?fctrs c \<subset> ?fctrs a" by (subst subset_not_subset_eq) blast  | 
|
839  | 
with finite_divisors[OF \<open>a \<noteq> 0\<close>] have "card (?fctrs c) < card (?fctrs a)"  | 
|
840  | 
by (rule psubset_card_mono)  | 
|
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
841  | 
with \<open>c \<noteq> 0\<close> have "\<exists>A. (\<forall>x. x \<in># A \<longrightarrow> prime_elem x) \<and> normalize (prod_mset A) = normalize c"  | 
| 63924 | 842  | 
by (intro less) auto  | 
| 74362 | 843  | 
then obtain B where B: "(\<forall>x. x \<in># B \<longrightarrow> prime_elem x) \<and> normalize (\<Prod>\<^sub># B) = normalize c"  | 
844  | 
by auto  | 
|
| 63924 | 845  | 
|
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
846  | 
show ?thesis  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
847  | 
proof (rule exI[of _ "A + B"]; safe)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
848  | 
have "normalize (prod_mset (A + B)) =  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
849  | 
normalize (normalize (prod_mset A) * normalize (prod_mset B))"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
850  | 
by simp  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
851  | 
also have "\<dots> = normalize (b * c)"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
852  | 
by (simp only: A B) auto  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
853  | 
also have "b * c = a"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
854  | 
using c by simp  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
855  | 
finally show "normalize (prod_mset (A + B)) = normalize a" .  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
856  | 
next  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
857  | 
qed (use A B in auto)  | 
| 63924 | 858  | 
qed  | 
859  | 
qed  | 
|
| 
65552
 
f533820e7248
theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
 
wenzelm 
parents: 
65435 
diff
changeset
 | 
860  | 
qed  | 
| 63924 | 861  | 
|
862  | 
lemma factorial_semiring_altI:  | 
|
863  | 
  assumes finite_divisors: "\<And>x::'a. x \<noteq> 0 \<Longrightarrow> finite {y. y dvd x \<and> normalize y = y}"
 | 
|
864  | 
assumes irreducible_imp_prime: "\<And>x::'a. irreducible x \<Longrightarrow> prime_elem x"  | 
|
865  | 
  shows   "OFCLASS('a :: normalization_semidom, factorial_semiring_class)"
 | 
|
866  | 
by intro_classes (rule factorial_semiring_altI_aux[OF assms])  | 
|
| 
65552
 
f533820e7248
theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
 
wenzelm 
parents: 
65435 
diff
changeset
 | 
867  | 
|
| 63924 | 868  | 
text \<open>Properties\<close>  | 
869  | 
||
870  | 
context factorial_semiring  | 
|
| 63498 | 871  | 
begin  | 
872  | 
||
873  | 
lemma prime_factorization_exists':  | 
|
874  | 
assumes "x \<noteq> 0"  | 
|
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
875  | 
obtains A where "\<And>x. x \<in># A \<Longrightarrow> prime x" "normalize (prod_mset A) = normalize x"  | 
| 63498 | 876  | 
proof -  | 
877  | 
from prime_factorization_exists[OF assms] obtain A  | 
|
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
878  | 
where A: "\<And>x. x \<in># A \<Longrightarrow> prime_elem x" "normalize (prod_mset A) = normalize x" by blast  | 
| 63498 | 879  | 
define A' where "A' = image_mset normalize A"  | 
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
880  | 
have "normalize (prod_mset A') = normalize (prod_mset A)"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
881  | 
by (simp add: A'_def normalize_prod_mset_normalize)  | 
| 63498 | 882  | 
also note A(2)  | 
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
883  | 
finally have "normalize (prod_mset A') = normalize x" by simp  | 
| 63633 | 884  | 
moreover from A(1) have "\<forall>x. x \<in># A' \<longrightarrow> prime x" by (auto simp: prime_def A'_def)  | 
| 63498 | 885  | 
ultimately show ?thesis by (intro that[of A']) blast  | 
886  | 
qed  | 
|
887  | 
||
| 63633 | 888  | 
lemma irreducible_imp_prime_elem:  | 
| 63498 | 889  | 
assumes "irreducible x"  | 
| 63633 | 890  | 
shows "prime_elem x"  | 
891  | 
proof (rule prime_elemI)  | 
|
| 63498 | 892  | 
fix a b assume dvd: "x dvd a * b"  | 
893  | 
from assms have "x \<noteq> 0" by auto  | 
|
894  | 
show "x dvd a \<or> x dvd b"  | 
|
895  | 
proof (cases "a = 0 \<or> b = 0")  | 
|
896  | 
case False  | 
|
897  | 
hence "a \<noteq> 0" "b \<noteq> 0" by blast+  | 
|
898  | 
note nz = \<open>x \<noteq> 0\<close> this  | 
|
| 74362 | 899  | 
from nz[THEN prime_factorization_exists'] obtain A B C  | 
900  | 
where ABC:  | 
|
901  | 
"\<And>z. z \<in># A \<Longrightarrow> prime z"  | 
|
902  | 
"normalize (\<Prod>\<^sub># A) = normalize x"  | 
|
903  | 
"\<And>z. z \<in># B \<Longrightarrow> prime z"  | 
|
904  | 
"normalize (\<Prod>\<^sub># B) = normalize a"  | 
|
905  | 
"\<And>z. z \<in># C \<Longrightarrow> prime z"  | 
|
906  | 
"normalize (\<Prod>\<^sub># C) = normalize b"  | 
|
907  | 
by this blast  | 
|
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
908  | 
|
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
909  | 
have "irreducible (prod_mset A)"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
910  | 
by (subst irreducible_cong[OF ABC(2)]) fact  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
911  | 
moreover have "normalize (prod_mset A) dvd  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
912  | 
normalize (normalize (prod_mset B) * normalize (prod_mset C))"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
913  | 
unfolding ABC using dvd by simp  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
914  | 
hence "prod_mset A dvd prod_mset B * prod_mset C"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
915  | 
unfolding normalize_mult_normalize_left normalize_mult_normalize_right by simp  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
916  | 
ultimately have "prod_mset A dvd prod_mset B \<or> prod_mset A dvd prod_mset C"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
917  | 
by (intro prod_mset_primes_irreducible_imp_prime) (use ABC in auto)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
918  | 
hence "normalize (prod_mset A) dvd normalize (prod_mset B) \<or>  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
919  | 
normalize (prod_mset A) dvd normalize (prod_mset C)" by simp  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
920  | 
thus ?thesis unfolding ABC by simp  | 
| 63498 | 921  | 
qed auto  | 
| 74362 | 922  | 
qed (use assms in \<open>simp_all add: irreducible_def\<close>)  | 
| 63498 | 923  | 
|
924  | 
lemma finite_divisor_powers:  | 
|
925  | 
assumes "y \<noteq> 0" "\<not>is_unit x"  | 
|
926  | 
  shows   "finite {n. x ^ n dvd y}"
 | 
|
927  | 
proof (cases "x = 0")  | 
|
928  | 
case True  | 
|
929  | 
  with assms have "{n. x ^ n dvd y} = {0}" by (auto simp: power_0_left)
 | 
|
930  | 
thus ?thesis by simp  | 
|
931  | 
next  | 
|
932  | 
case False  | 
|
933  | 
note nz = this \<open>y \<noteq> 0\<close>  | 
|
| 74362 | 934  | 
from nz[THEN prime_factorization_exists'] obtain A B  | 
935  | 
where AB:  | 
|
936  | 
"\<And>z. z \<in># A \<Longrightarrow> prime z"  | 
|
937  | 
"normalize (\<Prod>\<^sub># A) = normalize x"  | 
|
938  | 
"\<And>z. z \<in># B \<Longrightarrow> prime z"  | 
|
939  | 
"normalize (\<Prod>\<^sub># B) = normalize y"  | 
|
940  | 
by this blast  | 
|
941  | 
||
| 63498 | 942  | 
  from AB assms have "A \<noteq> {#}" by (auto simp: normalize_1_iff)
 | 
| 63830 | 943  | 
from AB(2,4) prod_mset_primes_finite_divisor_powers [of A B, OF AB(1,3) this]  | 
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
944  | 
    have "finite {n. prod_mset A ^ n dvd prod_mset B}" by simp
 | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
945  | 
  also have "{n. prod_mset A ^ n dvd prod_mset B} =
 | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
946  | 
             {n. normalize (normalize (prod_mset A) ^ n) dvd normalize (prod_mset B)}"
 | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
947  | 
unfolding normalize_power_normalize by simp  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
948  | 
  also have "\<dots> = {n. x ^ n dvd y}"
 | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
949  | 
unfolding AB unfolding normalize_power_normalize by simp  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
950  | 
finally show ?thesis .  | 
| 63498 | 951  | 
qed  | 
952  | 
||
953  | 
lemma finite_prime_divisors:  | 
|
954  | 
assumes "x \<noteq> 0"  | 
|
| 63633 | 955  | 
  shows   "finite {p. prime p \<and> p dvd x}"
 | 
| 63498 | 956  | 
proof -  | 
| 74362 | 957  | 
from prime_factorization_exists'[OF assms] obtain A  | 
958  | 
where A: "\<And>z. z \<in># A \<Longrightarrow> prime z" "normalize (\<Prod>\<^sub># A) = normalize x" by this blast  | 
|
| 63633 | 959  | 
  have "{p. prime p \<and> p dvd x} \<subseteq> set_mset A"
 | 
| 63498 | 960  | 
proof safe  | 
| 63633 | 961  | 
fix p assume p: "prime p" and dvd: "p dvd x"  | 
| 63498 | 962  | 
from dvd have "p dvd normalize x" by simp  | 
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
963  | 
also from A have "normalize x = normalize (prod_mset A)" by simp  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
964  | 
finally have "p dvd prod_mset A"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
965  | 
by simp  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
966  | 
thus "p \<in># A" using p A  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
967  | 
by (subst (asm) prime_dvd_prod_mset_primes_iff)  | 
| 63498 | 968  | 
qed  | 
969  | 
moreover have "finite (set_mset A)" by simp  | 
|
970  | 
ultimately show ?thesis by (rule finite_subset)  | 
|
| 60804 | 971  | 
qed  | 
972  | 
||
| 
73127
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
973  | 
lemma infinite_unit_divisor_powers:  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
974  | 
assumes "y \<noteq> 0"  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
975  | 
assumes "is_unit x"  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
976  | 
 shows "infinite {n. x^n dvd y}"
 | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
977  | 
proof -  | 
| 74885 | 978  | 
from \<open>is_unit x\<close> have "is_unit (x^n)" for n  | 
| 
73127
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
979  | 
using is_unit_power_iff by auto  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
980  | 
hence "x^n dvd y" for n  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
981  | 
by auto  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
982  | 
 hence "{n. x^n dvd y} = UNIV"
 | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
983  | 
by auto  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
984  | 
thus ?thesis  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
985  | 
by auto  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
986  | 
qed  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
987  | 
|
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
988  | 
corollary is_unit_iff_infinite_divisor_powers:  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
989  | 
assumes "y \<noteq> 0"  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
990  | 
 shows "is_unit x \<longleftrightarrow> infinite {n. x^n dvd y}"
 | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
991  | 
using infinite_unit_divisor_powers finite_divisor_powers assms by auto  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
992  | 
|
| 63633 | 993  | 
lemma prime_elem_iff_irreducible: "prime_elem x \<longleftrightarrow> irreducible x"  | 
994  | 
by (blast intro: irreducible_imp_prime_elem prime_elem_imp_irreducible)  | 
|
| 62499 | 995  | 
|
| 63498 | 996  | 
lemma prime_divisor_exists:  | 
997  | 
assumes "a \<noteq> 0" "\<not>is_unit a"  | 
|
| 63633 | 998  | 
shows "\<exists>b. b dvd a \<and> prime b"  | 
| 63498 | 999  | 
proof -  | 
| 74362 | 1000  | 
from prime_factorization_exists'[OF assms(1)]  | 
1001  | 
obtain A where A: "\<And>z. z \<in># A \<Longrightarrow> prime z" "normalize (\<Prod>\<^sub># A) = normalize a"  | 
|
1002  | 
by this blast  | 
|
1003  | 
  with assms have "A \<noteq> {#}" by auto
 | 
|
| 63498 | 1004  | 
then obtain x where "x \<in># A" by blast  | 
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1005  | 
with A(1) have *: "x dvd normalize (prod_mset A)" "prime x"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1006  | 
by (auto simp: dvd_prod_mset)  | 
| 74362 | 1007  | 
hence "x dvd a" by (simp add: A(2))  | 
| 63539 | 1008  | 
with * show ?thesis by blast  | 
| 63498 | 1009  | 
qed  | 
| 60804 | 1010  | 
|
| 63498 | 1011  | 
lemma prime_divisors_induct [case_names zero unit factor]:  | 
| 63633 | 1012  | 
assumes "P 0" "\<And>x. is_unit x \<Longrightarrow> P x" "\<And>p x. prime p \<Longrightarrow> P x \<Longrightarrow> P (p * x)"  | 
| 63498 | 1013  | 
shows "P x"  | 
1014  | 
proof (cases "x = 0")  | 
|
1015  | 
case False  | 
|
| 74362 | 1016  | 
from prime_factorization_exists'[OF this]  | 
1017  | 
obtain A where A: "\<And>z. z \<in># A \<Longrightarrow> prime z" "normalize (\<Prod>\<^sub># A) = normalize x"  | 
|
1018  | 
by this blast  | 
|
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1019  | 
from A obtain u where u: "is_unit u" "x = u * prod_mset A"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1020  | 
by (elim associatedE2)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1021  | 
|
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1022  | 
from A(1) have "P (u * prod_mset A)"  | 
| 63498 | 1023  | 
proof (induction A)  | 
| 
63793
 
e68a0b651eb5
add_mset constructor in multisets
 
fleury <Mathias.Fleury@mpi-inf.mpg.de> 
parents: 
63633 
diff
changeset
 | 
1024  | 
case (add p A)  | 
| 63633 | 1025  | 
from add.prems have "prime p" by simp  | 
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1026  | 
moreover from add.prems have "P (u * prod_mset A)" by (intro add.IH) simp_all  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1027  | 
ultimately have "P (p * (u * prod_mset A))" by (rule assms(3))  | 
| 63498 | 1028  | 
thus ?case by (simp add: mult_ac)  | 
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1029  | 
qed (simp_all add: assms False u)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1030  | 
with A u show ?thesis by simp  | 
| 63498 | 1031  | 
qed (simp_all add: assms(1))  | 
1032  | 
||
1033  | 
lemma no_prime_divisors_imp_unit:  | 
|
| 63633 | 1034  | 
assumes "a \<noteq> 0" "\<And>b. b dvd a \<Longrightarrow> normalize b = b \<Longrightarrow> \<not> prime_elem b"  | 
| 63498 | 1035  | 
shows "is_unit a"  | 
1036  | 
proof (rule ccontr)  | 
|
1037  | 
assume "\<not>is_unit a"  | 
|
| 74362 | 1038  | 
from prime_divisor_exists[OF assms(1) this] obtain b where "b dvd a" "prime b" by auto  | 
| 63633 | 1039  | 
with assms(2)[of b] show False by (simp add: prime_def)  | 
| 60804 | 1040  | 
qed  | 
| 62499 | 1041  | 
|
| 63498 | 1042  | 
lemma prime_divisorE:  | 
1043  | 
assumes "a \<noteq> 0" and "\<not> is_unit a"  | 
|
| 63633 | 1044  | 
obtains p where "prime p" and "p dvd a"  | 
1045  | 
using assms no_prime_divisors_imp_unit unfolding prime_def by blast  | 
|
| 63498 | 1046  | 
|
1047  | 
definition multiplicity :: "'a \<Rightarrow> 'a \<Rightarrow> nat" where  | 
|
1048  | 
  "multiplicity p x = (if finite {n. p ^ n dvd x} then Max {n. p ^ n dvd x} else 0)"
 | 
|
1049  | 
||
1050  | 
lemma multiplicity_dvd: "p ^ multiplicity p x dvd x"  | 
|
1051  | 
proof (cases "finite {n. p ^ n dvd x}")
 | 
|
1052  | 
case True  | 
|
1053  | 
  hence "multiplicity p x = Max {n. p ^ n dvd x}"
 | 
|
1054  | 
by (simp add: multiplicity_def)  | 
|
1055  | 
  also have "\<dots> \<in> {n. p ^ n dvd x}"
 | 
|
1056  | 
by (rule Max_in) (auto intro!: True exI[of _ "0::nat"])  | 
|
1057  | 
finally show ?thesis by simp  | 
|
1058  | 
qed (simp add: multiplicity_def)  | 
|
1059  | 
||
1060  | 
lemma multiplicity_dvd': "n \<le> multiplicity p x \<Longrightarrow> p ^ n dvd x"  | 
|
1061  | 
by (rule dvd_trans[OF le_imp_power_dvd multiplicity_dvd])  | 
|
1062  | 
||
1063  | 
context  | 
|
1064  | 
fixes x p :: 'a  | 
|
1065  | 
assumes xp: "x \<noteq> 0" "\<not>is_unit p"  | 
|
1066  | 
begin  | 
|
1067  | 
||
1068  | 
lemma multiplicity_eq_Max: "multiplicity p x = Max {n. p ^ n dvd x}"
 | 
|
1069  | 
using finite_divisor_powers[OF xp] by (simp add: multiplicity_def)  | 
|
1070  | 
||
1071  | 
lemma multiplicity_geI:  | 
|
1072  | 
assumes "p ^ n dvd x"  | 
|
1073  | 
shows "multiplicity p x \<ge> n"  | 
|
1074  | 
proof -  | 
|
1075  | 
  from assms have "n \<le> Max {n. p ^ n dvd x}"
 | 
|
1076  | 
by (intro Max_ge finite_divisor_powers xp) simp_all  | 
|
1077  | 
thus ?thesis by (subst multiplicity_eq_Max)  | 
|
1078  | 
qed  | 
|
1079  | 
||
1080  | 
lemma multiplicity_lessI:  | 
|
1081  | 
assumes "\<not>p ^ n dvd x"  | 
|
1082  | 
shows "multiplicity p x < n"  | 
|
1083  | 
proof (rule ccontr)  | 
|
1084  | 
assume "\<not>(n > multiplicity p x)"  | 
|
1085  | 
hence "p ^ n dvd x" by (intro multiplicity_dvd') simp  | 
|
1086  | 
with assms show False by contradiction  | 
|
| 62499 | 1087  | 
qed  | 
1088  | 
||
| 63498 | 1089  | 
lemma power_dvd_iff_le_multiplicity:  | 
1090  | 
"p ^ n dvd x \<longleftrightarrow> n \<le> multiplicity p x"  | 
|
1091  | 
using multiplicity_geI[of n] multiplicity_lessI[of n] by (cases "p ^ n dvd x") auto  | 
|
1092  | 
||
1093  | 
lemma multiplicity_eq_zero_iff:  | 
|
1094  | 
shows "multiplicity p x = 0 \<longleftrightarrow> \<not>p dvd x"  | 
|
1095  | 
using power_dvd_iff_le_multiplicity[of 1] by auto  | 
|
1096  | 
||
1097  | 
lemma multiplicity_gt_zero_iff:  | 
|
1098  | 
shows "multiplicity p x > 0 \<longleftrightarrow> p dvd x"  | 
|
1099  | 
using power_dvd_iff_le_multiplicity[of 1] by auto  | 
|
1100  | 
||
1101  | 
lemma multiplicity_decompose:  | 
|
1102  | 
"\<not>p dvd (x div p ^ multiplicity p x)"  | 
|
1103  | 
proof  | 
|
1104  | 
assume *: "p dvd x div p ^ multiplicity p x"  | 
|
1105  | 
have "x = x div p ^ multiplicity p x * (p ^ multiplicity p x)"  | 
|
1106  | 
using multiplicity_dvd[of p x] by simp  | 
|
1107  | 
also from * have "x div p ^ multiplicity p x = (x div p ^ multiplicity p x div p) * p" by simp  | 
|
1108  | 
also have "x div p ^ multiplicity p x div p * p * p ^ multiplicity p x =  | 
|
1109  | 
x div p ^ multiplicity p x div p * p ^ Suc (multiplicity p x)"  | 
|
1110  | 
by (simp add: mult_assoc)  | 
|
1111  | 
also have "p ^ Suc (multiplicity p x) dvd \<dots>" by (rule dvd_triv_right)  | 
|
1112  | 
finally show False by (subst (asm) power_dvd_iff_le_multiplicity) simp  | 
|
1113  | 
qed  | 
|
1114  | 
||
1115  | 
lemma multiplicity_decompose':  | 
|
1116  | 
obtains y where "x = p ^ multiplicity p x * y" "\<not>p dvd y"  | 
|
1117  | 
using that[of "x div p ^ multiplicity p x"]  | 
|
1118  | 
by (simp add: multiplicity_decompose multiplicity_dvd)  | 
|
1119  | 
||
1120  | 
end  | 
|
1121  | 
||
1122  | 
lemma multiplicity_zero [simp]: "multiplicity p 0 = 0"  | 
|
1123  | 
by (simp add: multiplicity_def)  | 
|
1124  | 
||
| 63633 | 1125  | 
lemma prime_elem_multiplicity_eq_zero_iff:  | 
1126  | 
"prime_elem p \<Longrightarrow> x \<noteq> 0 \<Longrightarrow> multiplicity p x = 0 \<longleftrightarrow> \<not>p dvd x"  | 
|
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1127  | 
by (rule multiplicity_eq_zero_iff) simp_all  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1128  | 
|
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1129  | 
lemma prime_multiplicity_other:  | 
| 63633 | 1130  | 
assumes "prime p" "prime q" "p \<noteq> q"  | 
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1131  | 
shows "multiplicity p q = 0"  | 
| 
65552
 
f533820e7248
theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
 
wenzelm 
parents: 
65435 
diff
changeset
 | 
1132  | 
using assms by (subst prime_elem_multiplicity_eq_zero_iff) (auto dest: primes_dvd_imp_eq)  | 
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1133  | 
|
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1134  | 
lemma prime_multiplicity_gt_zero_iff:  | 
| 63633 | 1135  | 
"prime_elem p \<Longrightarrow> x \<noteq> 0 \<Longrightarrow> multiplicity p x > 0 \<longleftrightarrow> p dvd x"  | 
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1136  | 
by (rule multiplicity_gt_zero_iff) simp_all  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1137  | 
|
| 63498 | 1138  | 
lemma multiplicity_unit_left: "is_unit p \<Longrightarrow> multiplicity p x = 0"  | 
1139  | 
by (simp add: multiplicity_def is_unit_power_iff unit_imp_dvd)  | 
|
| 62499 | 1140  | 
|
| 63498 | 1141  | 
lemma multiplicity_unit_right:  | 
1142  | 
assumes "is_unit x"  | 
|
1143  | 
shows "multiplicity p x = 0"  | 
|
1144  | 
proof (cases "is_unit p \<or> x = 0")  | 
|
1145  | 
case False  | 
|
1146  | 
with multiplicity_lessI[of x p 1] this assms  | 
|
1147  | 
show ?thesis by (auto dest: dvd_unit_imp_unit)  | 
|
1148  | 
qed (auto simp: multiplicity_unit_left)  | 
|
1149  | 
||
1150  | 
lemma multiplicity_one [simp]: "multiplicity p 1 = 0"  | 
|
1151  | 
by (rule multiplicity_unit_right) simp_all  | 
|
1152  | 
||
1153  | 
lemma multiplicity_eqI:  | 
|
1154  | 
assumes "p ^ n dvd x" "\<not>p ^ Suc n dvd x"  | 
|
1155  | 
shows "multiplicity p x = n"  | 
|
1156  | 
proof -  | 
|
1157  | 
consider "x = 0" | "is_unit p" | "x \<noteq> 0" "\<not>is_unit p" by blast  | 
|
1158  | 
thus ?thesis  | 
|
1159  | 
proof cases  | 
|
1160  | 
assume xp: "x \<noteq> 0" "\<not>is_unit p"  | 
|
1161  | 
from xp assms(1) have "multiplicity p x \<ge> n" by (intro multiplicity_geI)  | 
|
1162  | 
moreover from assms(2) xp have "multiplicity p x < Suc n" by (intro multiplicity_lessI)  | 
|
1163  | 
ultimately show ?thesis by simp  | 
|
1164  | 
next  | 
|
1165  | 
assume "is_unit p"  | 
|
1166  | 
hence "is_unit (p ^ Suc n)" by (simp add: is_unit_power_iff del: power_Suc)  | 
|
1167  | 
hence "p ^ Suc n dvd x" by (rule unit_imp_dvd)  | 
|
1168  | 
with \<open>\<not>p ^ Suc n dvd x\<close> show ?thesis by contradiction  | 
|
1169  | 
qed (insert assms, simp_all)  | 
|
1170  | 
qed  | 
|
1171  | 
||
1172  | 
||
1173  | 
context  | 
|
1174  | 
fixes x p :: 'a  | 
|
1175  | 
assumes xp: "x \<noteq> 0" "\<not>is_unit p"  | 
|
1176  | 
begin  | 
|
1177  | 
||
1178  | 
lemma multiplicity_times_same:  | 
|
1179  | 
assumes "p \<noteq> 0"  | 
|
1180  | 
shows "multiplicity p (p * x) = Suc (multiplicity p x)"  | 
|
1181  | 
proof (rule multiplicity_eqI)  | 
|
1182  | 
show "p ^ Suc (multiplicity p x) dvd p * x"  | 
|
1183  | 
by (auto intro!: mult_dvd_mono multiplicity_dvd)  | 
|
1184  | 
from xp assms show "\<not> p ^ Suc (Suc (multiplicity p x)) dvd p * x"  | 
|
1185  | 
using power_dvd_iff_le_multiplicity[OF xp, of "Suc (multiplicity p x)"] by simp  | 
|
| 62499 | 1186  | 
qed  | 
1187  | 
||
1188  | 
end  | 
|
1189  | 
||
| 63498 | 1190  | 
lemma multiplicity_same_power': "multiplicity p (p ^ n) = (if p = 0 \<or> is_unit p then 0 else n)"  | 
1191  | 
proof -  | 
|
1192  | 
consider "p = 0" | "is_unit p" |"p \<noteq> 0" "\<not>is_unit p" by blast  | 
|
1193  | 
thus ?thesis  | 
|
1194  | 
proof cases  | 
|
1195  | 
assume "p \<noteq> 0" "\<not>is_unit p"  | 
|
1196  | 
thus ?thesis by (induction n) (simp_all add: multiplicity_times_same)  | 
|
1197  | 
qed (simp_all add: power_0_left multiplicity_unit_left)  | 
|
1198  | 
qed  | 
|
| 62499 | 1199  | 
|
| 63498 | 1200  | 
lemma multiplicity_same_power:  | 
1201  | 
"p \<noteq> 0 \<Longrightarrow> \<not>is_unit p \<Longrightarrow> multiplicity p (p ^ n) = n"  | 
|
1202  | 
by (simp add: multiplicity_same_power')  | 
|
1203  | 
||
| 63633 | 1204  | 
lemma multiplicity_prime_elem_times_other:  | 
1205  | 
assumes "prime_elem p" "\<not>p dvd q"  | 
|
| 63498 | 1206  | 
shows "multiplicity p (q * x) = multiplicity p x"  | 
1207  | 
proof (cases "x = 0")  | 
|
1208  | 
case False  | 
|
1209  | 
show ?thesis  | 
|
1210  | 
proof (rule multiplicity_eqI)  | 
|
1211  | 
have "1 * p ^ multiplicity p x dvd q * x"  | 
|
1212  | 
by (intro mult_dvd_mono multiplicity_dvd) simp_all  | 
|
1213  | 
thus "p ^ multiplicity p x dvd q * x" by simp  | 
|
| 62499 | 1214  | 
next  | 
| 63498 | 1215  | 
define n where "n = multiplicity p x"  | 
1216  | 
from assms have "\<not>is_unit p" by simp  | 
|
| 74362 | 1217  | 
from multiplicity_decompose'[OF False this]  | 
1218  | 
obtain y where y [folded n_def]: "x = p ^ multiplicity p x * y" "\<not> p dvd y" .  | 
|
| 63498 | 1219  | 
from y have "p ^ Suc n dvd q * x \<longleftrightarrow> p ^ n * p dvd p ^ n * (q * y)" by (simp add: mult_ac)  | 
1220  | 
also from assms have "\<dots> \<longleftrightarrow> p dvd q * y" by simp  | 
|
| 63633 | 1221  | 
also have "\<dots> \<longleftrightarrow> p dvd q \<or> p dvd y" by (rule prime_elem_dvd_mult_iff) fact+  | 
| 63498 | 1222  | 
also from assms y have "\<dots> \<longleftrightarrow> False" by simp  | 
1223  | 
finally show "\<not>(p ^ Suc n dvd q * x)" by blast  | 
|
| 62499 | 1224  | 
qed  | 
| 63498 | 1225  | 
qed simp_all  | 
1226  | 
||
| 63924 | 1227  | 
lemma multiplicity_self:  | 
1228  | 
assumes "p \<noteq> 0" "\<not>is_unit p"  | 
|
1229  | 
shows "multiplicity p p = 1"  | 
|
1230  | 
proof -  | 
|
1231  | 
  from assms have "multiplicity p p = Max {n. p ^ n dvd p}"
 | 
|
1232  | 
by (simp add: multiplicity_eq_Max)  | 
|
1233  | 
also from assms have "p ^ n dvd p \<longleftrightarrow> n \<le> 1" for n  | 
|
1234  | 
using dvd_power_iff[of p n 1] by auto  | 
|
1235  | 
  hence "{n. p ^ n dvd p} = {..1}" by auto
 | 
|
1236  | 
  also have "\<dots> = {0,1}" by auto
 | 
|
1237  | 
finally show ?thesis by simp  | 
|
1238  | 
qed  | 
|
1239  | 
||
1240  | 
lemma multiplicity_times_unit_left:  | 
|
1241  | 
assumes "is_unit c"  | 
|
1242  | 
shows "multiplicity (c * p) x = multiplicity p x"  | 
|
1243  | 
proof -  | 
|
1244  | 
  from assms have "{n. (c * p) ^ n dvd x} = {n. p ^ n dvd x}"
 | 
|
1245  | 
by (subst mult.commute) (simp add: mult_unit_dvd_iff power_mult_distrib is_unit_power_iff)  | 
|
1246  | 
thus ?thesis by (simp add: multiplicity_def)  | 
|
1247  | 
qed  | 
|
1248  | 
||
1249  | 
lemma multiplicity_times_unit_right:  | 
|
1250  | 
assumes "is_unit c"  | 
|
1251  | 
shows "multiplicity p (c * x) = multiplicity p x"  | 
|
1252  | 
proof -  | 
|
1253  | 
  from assms have "{n. p ^ n dvd c * x} = {n. p ^ n dvd x}"
 | 
|
1254  | 
by (subst mult.commute) (simp add: dvd_mult_unit_iff)  | 
|
1255  | 
thus ?thesis by (simp add: multiplicity_def)  | 
|
1256  | 
qed  | 
|
1257  | 
||
1258  | 
lemma multiplicity_normalize_left [simp]:  | 
|
1259  | 
"multiplicity (normalize p) x = multiplicity p x"  | 
|
1260  | 
proof (cases "p = 0")  | 
|
1261  | 
case [simp]: False  | 
|
1262  | 
have "normalize p = (1 div unit_factor p) * p"  | 
|
1263  | 
by (simp add: unit_div_commute is_unit_unit_factor)  | 
|
1264  | 
also have "multiplicity \<dots> x = multiplicity p x"  | 
|
1265  | 
by (rule multiplicity_times_unit_left) (simp add: is_unit_unit_factor)  | 
|
1266  | 
finally show ?thesis .  | 
|
1267  | 
qed simp_all  | 
|
1268  | 
||
1269  | 
lemma multiplicity_normalize_right [simp]:  | 
|
1270  | 
"multiplicity p (normalize x) = multiplicity p x"  | 
|
1271  | 
proof (cases "x = 0")  | 
|
1272  | 
case [simp]: False  | 
|
1273  | 
have "normalize x = (1 div unit_factor x) * x"  | 
|
1274  | 
by (simp add: unit_div_commute is_unit_unit_factor)  | 
|
1275  | 
also have "multiplicity p \<dots> = multiplicity p x"  | 
|
1276  | 
by (rule multiplicity_times_unit_right) (simp add: is_unit_unit_factor)  | 
|
1277  | 
finally show ?thesis .  | 
|
| 
65552
 
f533820e7248
theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
 
wenzelm 
parents: 
65435 
diff
changeset
 | 
1278  | 
qed simp_all  | 
| 63924 | 1279  | 
|
1280  | 
lemma multiplicity_prime [simp]: "prime_elem p \<Longrightarrow> multiplicity p p = 1"  | 
|
1281  | 
by (rule multiplicity_self) auto  | 
|
1282  | 
||
1283  | 
lemma multiplicity_prime_power [simp]: "prime_elem p \<Longrightarrow> multiplicity p (p ^ n) = n"  | 
|
1284  | 
by (subst multiplicity_same_power') auto  | 
|
1285  | 
||
| 63498 | 1286  | 
lift_definition prime_factorization :: "'a \<Rightarrow> 'a multiset" is  | 
| 63633 | 1287  | 
"\<lambda>x p. if prime p then multiplicity p x else 0"  | 
| 73270 | 1288  | 
proof -  | 
| 63498 | 1289  | 
fix x :: 'a  | 
| 63633 | 1290  | 
  show "finite {p. 0 < (if prime p then multiplicity p x else 0)}" (is "finite ?A")
 | 
| 63498 | 1291  | 
proof (cases "x = 0")  | 
1292  | 
case False  | 
|
| 63633 | 1293  | 
    from False have "?A \<subseteq> {p. prime p \<and> p dvd x}"
 | 
| 63498 | 1294  | 
by (auto simp: multiplicity_gt_zero_iff)  | 
| 63633 | 1295  | 
    moreover from False have "finite {p. prime p \<and> p dvd x}"
 | 
| 63498 | 1296  | 
by (rule finite_prime_divisors)  | 
1297  | 
ultimately show ?thesis by (rule finite_subset)  | 
|
1298  | 
qed simp_all  | 
|
1299  | 
qed  | 
|
1300  | 
||
| 63905 | 1301  | 
abbreviation prime_factors :: "'a \<Rightarrow> 'a set" where  | 
1302  | 
"prime_factors a \<equiv> set_mset (prime_factorization a)"  | 
|
1303  | 
||
| 63498 | 1304  | 
lemma count_prime_factorization_nonprime:  | 
| 63633 | 1305  | 
"\<not>prime p \<Longrightarrow> count (prime_factorization x) p = 0"  | 
| 63498 | 1306  | 
by transfer simp  | 
1307  | 
||
1308  | 
lemma count_prime_factorization_prime:  | 
|
| 63633 | 1309  | 
"prime p \<Longrightarrow> count (prime_factorization x) p = multiplicity p x"  | 
| 63498 | 1310  | 
by transfer simp  | 
1311  | 
||
1312  | 
lemma count_prime_factorization:  | 
|
| 63633 | 1313  | 
"count (prime_factorization x) p = (if prime p then multiplicity p x else 0)"  | 
| 63498 | 1314  | 
by transfer simp  | 
1315  | 
||
| 63924 | 1316  | 
lemma dvd_imp_multiplicity_le:  | 
1317  | 
assumes "a dvd b" "b \<noteq> 0"  | 
|
1318  | 
shows "multiplicity p a \<le> multiplicity p b"  | 
|
1319  | 
proof (cases "is_unit p")  | 
|
1320  | 
case False  | 
|
1321  | 
with assms show ?thesis  | 
|
1322  | 
by (intro multiplicity_geI ) (auto intro: dvd_trans[OF multiplicity_dvd' assms(1)])  | 
|
1323  | 
qed (insert assms, auto simp: multiplicity_unit_left)  | 
|
| 63498 | 1324  | 
|
| 
66276
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1325  | 
lemma prime_power_inj:  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1326  | 
assumes "prime a" "a ^ m = a ^ n"  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1327  | 
shows "m = n"  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1328  | 
proof -  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1329  | 
have "multiplicity a (a ^ m) = multiplicity a (a ^ n)" by (simp only: assms)  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1330  | 
thus ?thesis using assms by (subst (asm) (1 2) multiplicity_prime_power) simp_all  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1331  | 
qed  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1332  | 
|
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1333  | 
lemma prime_power_inj':  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1334  | 
assumes "prime p" "prime q"  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1335  | 
assumes "p ^ m = q ^ n" "m > 0" "n > 0"  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1336  | 
shows "p = q" "m = n"  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1337  | 
proof -  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1338  | 
from assms have "p ^ 1 dvd p ^ m" by (intro le_imp_power_dvd) simp  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1339  | 
also have "p ^ m = q ^ n" by fact  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1340  | 
finally have "p dvd q ^ n" by simp  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1341  | 
with assms have "p dvd q" using prime_dvd_power[of p q] by simp  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1342  | 
with assms show "p = q" by (simp add: primes_dvd_imp_eq)  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1343  | 
with assms show "m = n" by (simp add: prime_power_inj)  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1344  | 
qed  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1345  | 
|
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1346  | 
lemma prime_power_eq_one_iff [simp]: "prime p \<Longrightarrow> p ^ n = 1 \<longleftrightarrow> n = 0"  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1347  | 
using prime_power_inj[of p n 0] by auto  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1348  | 
|
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1349  | 
lemma one_eq_prime_power_iff [simp]: "prime p \<Longrightarrow> 1 = p ^ n \<longleftrightarrow> n = 0"  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1350  | 
using prime_power_inj[of p 0 n] by auto  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1351  | 
|
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1352  | 
lemma prime_power_inj'':  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1353  | 
assumes "prime p" "prime q"  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1354  | 
shows "p ^ m = q ^ n \<longleftrightarrow> (m = 0 \<and> n = 0) \<or> (p = q \<and> m = n)"  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1355  | 
using assms  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1356  | 
by (cases "m = 0"; cases "n = 0")  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1357  | 
(auto dest: prime_power_inj'[OF assms])  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1358  | 
|
| 63498 | 1359  | 
lemma prime_factorization_0 [simp]: "prime_factorization 0 = {#}"
 | 
1360  | 
by (simp add: multiset_eq_iff count_prime_factorization)  | 
|
1361  | 
||
1362  | 
lemma prime_factorization_empty_iff:  | 
|
1363  | 
  "prime_factorization x = {#} \<longleftrightarrow> x = 0 \<or> is_unit x"
 | 
|
1364  | 
proof  | 
|
1365  | 
  assume *: "prime_factorization x = {#}"
 | 
|
1366  | 
  {
 | 
|
1367  | 
assume x: "x \<noteq> 0" "\<not>is_unit x"  | 
|
1368  | 
    {
 | 
|
| 63633 | 1369  | 
fix p assume p: "prime p"  | 
| 63498 | 1370  | 
have "count (prime_factorization x) p = 0" by (simp add: *)  | 
1371  | 
also from p have "count (prime_factorization x) p = multiplicity p x"  | 
|
1372  | 
by (rule count_prime_factorization_prime)  | 
|
1373  | 
also from x p have "\<dots> = 0 \<longleftrightarrow> \<not>p dvd x" by (simp add: multiplicity_eq_zero_iff)  | 
|
1374  | 
finally have "\<not>p dvd x" .  | 
|
1375  | 
}  | 
|
1376  | 
with prime_divisor_exists[OF x] have False by blast  | 
|
1377  | 
}  | 
|
1378  | 
thus "x = 0 \<or> is_unit x" by blast  | 
|
1379  | 
next  | 
|
1380  | 
assume "x = 0 \<or> is_unit x"  | 
|
1381  | 
  thus "prime_factorization x = {#}"
 | 
|
1382  | 
proof  | 
|
1383  | 
assume x: "is_unit x"  | 
|
1384  | 
    {
 | 
|
| 63633 | 1385  | 
fix p assume p: "prime p"  | 
| 63498 | 1386  | 
from p x have "multiplicity p x = 0"  | 
1387  | 
by (subst multiplicity_eq_zero_iff)  | 
|
1388  | 
(auto simp: multiplicity_eq_zero_iff dest: unit_imp_no_prime_divisors)  | 
|
1389  | 
}  | 
|
1390  | 
thus ?thesis by (simp add: multiset_eq_iff count_prime_factorization)  | 
|
1391  | 
qed simp_all  | 
|
1392  | 
qed  | 
|
1393  | 
||
1394  | 
lemma prime_factorization_unit:  | 
|
1395  | 
assumes "is_unit x"  | 
|
1396  | 
  shows   "prime_factorization x = {#}"
 | 
|
1397  | 
proof (rule multiset_eqI)  | 
|
1398  | 
fix p :: 'a  | 
|
1399  | 
  show "count (prime_factorization x) p = count {#} p"
 | 
|
| 63633 | 1400  | 
proof (cases "prime p")  | 
| 63498 | 1401  | 
case True  | 
1402  | 
with assms have "multiplicity p x = 0"  | 
|
1403  | 
by (subst multiplicity_eq_zero_iff)  | 
|
1404  | 
(auto simp: multiplicity_eq_zero_iff dest: unit_imp_no_prime_divisors)  | 
|
1405  | 
with True show ?thesis by (simp add: count_prime_factorization_prime)  | 
|
1406  | 
qed (simp_all add: count_prime_factorization_nonprime)  | 
|
1407  | 
qed  | 
|
1408  | 
||
1409  | 
lemma prime_factorization_1 [simp]: "prime_factorization 1 = {#}"
 | 
|
1410  | 
by (simp add: prime_factorization_unit)  | 
|
1411  | 
||
1412  | 
lemma prime_factorization_times_prime:  | 
|
| 63633 | 1413  | 
assumes "x \<noteq> 0" "prime p"  | 
| 63498 | 1414  | 
  shows   "prime_factorization (p * x) = {#p#} + prime_factorization x"
 | 
1415  | 
proof (rule multiset_eqI)  | 
|
1416  | 
fix q :: 'a  | 
|
| 63633 | 1417  | 
consider "\<not>prime q" | "p = q" | "prime q" "p \<noteq> q" by blast  | 
| 63498 | 1418  | 
  thus "count (prime_factorization (p * x)) q = count ({#p#} + prime_factorization x) q"
 | 
1419  | 
proof cases  | 
|
| 63633 | 1420  | 
assume q: "prime q" "p \<noteq> q"  | 
| 63498 | 1421  | 
with assms primes_dvd_imp_eq[of q p] have "\<not>q dvd p" by auto  | 
1422  | 
with q assms show ?thesis  | 
|
| 63633 | 1423  | 
by (simp add: multiplicity_prime_elem_times_other count_prime_factorization)  | 
| 63498 | 1424  | 
qed (insert assms, auto simp: count_prime_factorization multiplicity_times_same)  | 
1425  | 
qed  | 
|
1426  | 
||
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1427  | 
lemma prod_mset_prime_factorization_weak:  | 
| 63498 | 1428  | 
assumes "x \<noteq> 0"  | 
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1429  | 
shows "normalize (prod_mset (prime_factorization x)) = normalize x"  | 
| 63498 | 1430  | 
using assms  | 
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1431  | 
proof (induction x rule: prime_divisors_induct)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1432  | 
case (factor p x)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1433  | 
have "normalize (prod_mset (prime_factorization (p * x))) =  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1434  | 
normalize (p * normalize (prod_mset (prime_factorization x)))"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1435  | 
using factor.prems factor.hyps by (simp add: prime_factorization_times_prime)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1436  | 
also have "normalize (prod_mset (prime_factorization x)) = normalize x"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1437  | 
by (rule factor.IH) (use factor in auto)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1438  | 
finally show ?case by simp  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1439  | 
qed (auto simp: prime_factorization_unit is_unit_normalize)  | 
| 63498 | 1440  | 
|
| 63905 | 1441  | 
lemma in_prime_factors_iff:  | 
1442  | 
"p \<in> prime_factors x \<longleftrightarrow> x \<noteq> 0 \<and> p dvd x \<and> prime p"  | 
|
| 63498 | 1443  | 
proof -  | 
| 63905 | 1444  | 
have "p \<in> prime_factors x \<longleftrightarrow> count (prime_factorization x) p > 0" by simp  | 
| 63633 | 1445  | 
also have "\<dots> \<longleftrightarrow> x \<noteq> 0 \<and> p dvd x \<and> prime p"  | 
| 63498 | 1446  | 
by (subst count_prime_factorization, cases "x = 0")  | 
1447  | 
(auto simp: multiplicity_eq_zero_iff multiplicity_gt_zero_iff)  | 
|
1448  | 
finally show ?thesis .  | 
|
1449  | 
qed  | 
|
1450  | 
||
| 63905 | 1451  | 
lemma in_prime_factors_imp_prime [intro]:  | 
1452  | 
"p \<in> prime_factors x \<Longrightarrow> prime p"  | 
|
1453  | 
by (simp add: in_prime_factors_iff)  | 
|
| 63498 | 1454  | 
|
| 63905 | 1455  | 
lemma in_prime_factors_imp_dvd [dest]:  | 
1456  | 
"p \<in> prime_factors x \<Longrightarrow> p dvd x"  | 
|
1457  | 
by (simp add: in_prime_factors_iff)  | 
|
| 63498 | 1458  | 
|
| 63924 | 1459  | 
lemma prime_factorsI:  | 
1460  | 
"x \<noteq> 0 \<Longrightarrow> prime p \<Longrightarrow> p dvd x \<Longrightarrow> p \<in> prime_factors x"  | 
|
1461  | 
by (auto simp: in_prime_factors_iff)  | 
|
1462  | 
||
1463  | 
lemma prime_factors_dvd:  | 
|
1464  | 
  "x \<noteq> 0 \<Longrightarrow> prime_factors x = {p. prime p \<and> p dvd x}"
 | 
|
1465  | 
by (auto intro: prime_factorsI)  | 
|
1466  | 
||
1467  | 
lemma prime_factors_multiplicity:  | 
|
1468  | 
  "prime_factors n = {p. prime p \<and> multiplicity p n > 0}"
 | 
|
1469  | 
by (cases "n = 0") (auto simp add: prime_factors_dvd prime_multiplicity_gt_zero_iff)  | 
|
| 63498 | 1470  | 
|
1471  | 
lemma prime_factorization_prime:  | 
|
| 63633 | 1472  | 
assumes "prime p"  | 
| 63498 | 1473  | 
  shows   "prime_factorization p = {#p#}"
 | 
1474  | 
proof (rule multiset_eqI)  | 
|
1475  | 
fix q :: 'a  | 
|
| 63633 | 1476  | 
consider "\<not>prime q" | "q = p" | "prime q" "q \<noteq> p" by blast  | 
| 63498 | 1477  | 
  thus "count (prime_factorization p) q = count {#p#} q"
 | 
1478  | 
by cases (insert assms, auto dest: primes_dvd_imp_eq  | 
|
1479  | 
simp: count_prime_factorization multiplicity_self multiplicity_eq_zero_iff)  | 
|
1480  | 
qed  | 
|
1481  | 
||
| 63830 | 1482  | 
lemma prime_factorization_prod_mset_primes:  | 
| 63633 | 1483  | 
assumes "\<And>p. p \<in># A \<Longrightarrow> prime p"  | 
| 63830 | 1484  | 
shows "prime_factorization (prod_mset A) = A"  | 
| 63498 | 1485  | 
using assms  | 
1486  | 
proof (induction A)  | 
|
| 
63793
 
e68a0b651eb5
add_mset constructor in multisets
 
fleury <Mathias.Fleury@mpi-inf.mpg.de> 
parents: 
63633 
diff
changeset
 | 
1487  | 
case (add p A)  | 
| 63498 | 1488  | 
from add.prems[of 0] have "0 \<notin># A" by auto  | 
| 63830 | 1489  | 
hence "prod_mset A \<noteq> 0" by auto  | 
| 63498 | 1490  | 
with add show ?case  | 
1491  | 
by (simp_all add: mult_ac prime_factorization_times_prime Multiset.union_commute)  | 
|
1492  | 
qed simp_all  | 
|
1493  | 
||
1494  | 
lemma prime_factorization_cong:  | 
|
1495  | 
"normalize x = normalize y \<Longrightarrow> prime_factorization x = prime_factorization y"  | 
|
1496  | 
by (simp add: multiset_eq_iff count_prime_factorization  | 
|
1497  | 
multiplicity_normalize_right [of _ x, symmetric]  | 
|
1498  | 
multiplicity_normalize_right [of _ y, symmetric]  | 
|
1499  | 
del: multiplicity_normalize_right)  | 
|
1500  | 
||
1501  | 
lemma prime_factorization_unique:  | 
|
1502  | 
assumes "x \<noteq> 0" "y \<noteq> 0"  | 
|
1503  | 
shows "prime_factorization x = prime_factorization y \<longleftrightarrow> normalize x = normalize y"  | 
|
1504  | 
proof  | 
|
1505  | 
assume "prime_factorization x = prime_factorization y"  | 
|
| 63830 | 1506  | 
hence "prod_mset (prime_factorization x) = prod_mset (prime_factorization y)" by simp  | 
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1507  | 
hence "normalize (prod_mset (prime_factorization x)) =  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1508  | 
normalize (prod_mset (prime_factorization y))"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1509  | 
by (simp only: )  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1510  | 
with assms show "normalize x = normalize y"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1511  | 
by (simp add: prod_mset_prime_factorization_weak)  | 
| 63498 | 1512  | 
qed (rule prime_factorization_cong)  | 
1513  | 
||
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1514  | 
lemma prime_factorization_normalize [simp]:  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1515  | 
"prime_factorization (normalize x) = prime_factorization x"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1516  | 
by (cases "x = 0", simp, subst prime_factorization_unique) auto  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1517  | 
|
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1518  | 
lemma prime_factorization_eqI_strong:  | 
| 
69785
 
9e326f6f8a24
More material for HOL-Number_Theory: ord, Carmichael's function, primitive roots
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
68606 
diff
changeset
 | 
1519  | 
assumes "\<And>p. p \<in># P \<Longrightarrow> prime p" "prod_mset P = n"  | 
| 
 
9e326f6f8a24
More material for HOL-Number_Theory: ord, Carmichael's function, primitive roots
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
68606 
diff
changeset
 | 
1520  | 
shows "prime_factorization n = P"  | 
| 
 
9e326f6f8a24
More material for HOL-Number_Theory: ord, Carmichael's function, primitive roots
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
68606 
diff
changeset
 | 
1521  | 
using prime_factorization_prod_mset_primes[of P] assms by simp  | 
| 
 
9e326f6f8a24
More material for HOL-Number_Theory: ord, Carmichael's function, primitive roots
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
68606 
diff
changeset
 | 
1522  | 
|
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1523  | 
lemma prime_factorization_eqI:  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1524  | 
assumes "\<And>p. p \<in># P \<Longrightarrow> prime p" "normalize (prod_mset P) = normalize n"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1525  | 
shows "prime_factorization n = P"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1526  | 
proof -  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1527  | 
have "P = prime_factorization (normalize (prod_mset P))"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1528  | 
using prime_factorization_prod_mset_primes[of P] assms(1) by simp  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1529  | 
with assms(2) show ?thesis by simp  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1530  | 
qed  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1531  | 
|
| 63498 | 1532  | 
lemma prime_factorization_mult:  | 
1533  | 
assumes "x \<noteq> 0" "y \<noteq> 0"  | 
|
1534  | 
shows "prime_factorization (x * y) = prime_factorization x + prime_factorization y"  | 
|
1535  | 
proof -  | 
|
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1536  | 
have "normalize (prod_mset (prime_factorization x) * prod_mset (prime_factorization y)) =  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1537  | 
normalize (normalize (prod_mset (prime_factorization x)) *  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1538  | 
normalize (prod_mset (prime_factorization y)))"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1539  | 
by (simp only: normalize_mult_normalize_left normalize_mult_normalize_right)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1540  | 
also have "\<dots> = normalize (x * y)"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1541  | 
by (subst (1 2) prod_mset_prime_factorization_weak) (use assms in auto)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1542  | 
finally show ?thesis  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1543  | 
by (intro prime_factorization_eqI) auto  | 
| 62499 | 1544  | 
qed  | 
1545  | 
||
| 
66276
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1546  | 
lemma prime_factorization_prod:  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1547  | 
assumes "finite A" "\<And>x. x \<in> A \<Longrightarrow> f x \<noteq> 0"  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1548  | 
shows "prime_factorization (prod f A) = (\<Sum>n\<in>A. prime_factorization (f n))"  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1549  | 
using assms by (induction A rule: finite_induct)  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1550  | 
(auto simp: Sup_multiset_empty prime_factorization_mult)  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1551  | 
|
| 63924 | 1552  | 
lemma prime_elem_multiplicity_mult_distrib:  | 
1553  | 
assumes "prime_elem p" "x \<noteq> 0" "y \<noteq> 0"  | 
|
1554  | 
shows "multiplicity p (x * y) = multiplicity p x + multiplicity p y"  | 
|
1555  | 
proof -  | 
|
1556  | 
have "multiplicity p (x * y) = count (prime_factorization (x * y)) (normalize p)"  | 
|
1557  | 
by (subst count_prime_factorization_prime) (simp_all add: assms)  | 
|
| 
65552
 
f533820e7248
theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
 
wenzelm 
parents: 
65435 
diff
changeset
 | 
1558  | 
also from assms  | 
| 63924 | 1559  | 
have "prime_factorization (x * y) = prime_factorization x + prime_factorization y"  | 
1560  | 
by (intro prime_factorization_mult)  | 
|
| 
65552
 
f533820e7248
theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
 
wenzelm 
parents: 
65435 
diff
changeset
 | 
1561  | 
also have "count \<dots> (normalize p) =  | 
| 63924 | 1562  | 
count (prime_factorization x) (normalize p) + count (prime_factorization y) (normalize p)"  | 
1563  | 
by simp  | 
|
| 
65552
 
f533820e7248
theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
 
wenzelm 
parents: 
65435 
diff
changeset
 | 
1564  | 
also have "\<dots> = multiplicity p x + multiplicity p y"  | 
| 63924 | 1565  | 
by (subst (1 2) count_prime_factorization_prime) (simp_all add: assms)  | 
1566  | 
finally show ?thesis .  | 
|
1567  | 
qed  | 
|
1568  | 
||
1569  | 
lemma prime_elem_multiplicity_prod_mset_distrib:  | 
|
1570  | 
assumes "prime_elem p" "0 \<notin># A"  | 
|
1571  | 
shows "multiplicity p (prod_mset A) = sum_mset (image_mset (multiplicity p) A)"  | 
|
1572  | 
using assms by (induction A) (auto simp: prime_elem_multiplicity_mult_distrib)  | 
|
1573  | 
||
1574  | 
lemma prime_elem_multiplicity_power_distrib:  | 
|
1575  | 
assumes "prime_elem p" "x \<noteq> 0"  | 
|
1576  | 
shows "multiplicity p (x ^ n) = n * multiplicity p x"  | 
|
1577  | 
using assms prime_elem_multiplicity_prod_mset_distrib [of p "replicate_mset n x"]  | 
|
1578  | 
by simp  | 
|
1579  | 
||
| 64272 | 1580  | 
lemma prime_elem_multiplicity_prod_distrib:  | 
| 63924 | 1581  | 
assumes "prime_elem p" "0 \<notin> f ` A" "finite A"  | 
| 64272 | 1582  | 
shows "multiplicity p (prod f A) = (\<Sum>x\<in>A. multiplicity p (f x))"  | 
| 63924 | 1583  | 
proof -  | 
| 64272 | 1584  | 
have "multiplicity p (prod f A) = (\<Sum>x\<in>#mset_set A. multiplicity p (f x))"  | 
1585  | 
using assms by (subst prod_unfold_prod_mset)  | 
|
| 
65552
 
f533820e7248
theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
 
wenzelm 
parents: 
65435 
diff
changeset
 | 
1586  | 
(simp_all add: prime_elem_multiplicity_prod_mset_distrib sum_unfold_sum_mset  | 
| 63924 | 1587  | 
multiset.map_comp o_def)  | 
1588  | 
also from \<open>finite A\<close> have "\<dots> = (\<Sum>x\<in>A. multiplicity p (f x))"  | 
|
1589  | 
by (induction A rule: finite_induct) simp_all  | 
|
1590  | 
finally show ?thesis .  | 
|
1591  | 
qed  | 
|
1592  | 
||
1593  | 
lemma multiplicity_distinct_prime_power:  | 
|
1594  | 
"prime p \<Longrightarrow> prime q \<Longrightarrow> p \<noteq> q \<Longrightarrow> multiplicity p (q ^ n) = 0"  | 
|
1595  | 
by (subst prime_elem_multiplicity_power_distrib) (auto simp: prime_multiplicity_other)  | 
|
1596  | 
||
| 63498 | 1597  | 
lemma prime_factorization_prime_power:  | 
| 63633 | 1598  | 
"prime p \<Longrightarrow> prime_factorization (p ^ n) = replicate_mset n p"  | 
| 63498 | 1599  | 
by (induction n)  | 
1600  | 
(simp_all add: prime_factorization_mult prime_factorization_prime Multiset.union_commute)  | 
|
1601  | 
||
1602  | 
lemma prime_factorization_subset_iff_dvd:  | 
|
1603  | 
assumes [simp]: "x \<noteq> 0" "y \<noteq> 0"  | 
|
1604  | 
shows "prime_factorization x \<subseteq># prime_factorization y \<longleftrightarrow> x dvd y"  | 
|
1605  | 
proof -  | 
|
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1606  | 
have "x dvd y \<longleftrightarrow>  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1607  | 
normalize (prod_mset (prime_factorization x)) dvd normalize (prod_mset (prime_factorization y))"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1608  | 
using assms by (subst (1 2) prod_mset_prime_factorization_weak) auto  | 
| 63498 | 1609  | 
also have "\<dots> \<longleftrightarrow> prime_factorization x \<subseteq># prime_factorization y"  | 
| 63905 | 1610  | 
by (auto intro!: prod_mset_primes_dvd_imp_subset prod_mset_subset_imp_dvd)  | 
| 63498 | 1611  | 
finally show ?thesis ..  | 
1612  | 
qed  | 
|
1613  | 
||
| 
65552
 
f533820e7248
theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
 
wenzelm 
parents: 
65435 
diff
changeset
 | 
1614  | 
lemma prime_factorization_subset_imp_dvd:  | 
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1615  | 
"x \<noteq> 0 \<Longrightarrow> (prime_factorization x \<subseteq># prime_factorization y) \<Longrightarrow> x dvd y"  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1616  | 
by (cases "y = 0") (simp_all add: prime_factorization_subset_iff_dvd)  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1617  | 
|
| 63498 | 1618  | 
lemma prime_factorization_divide:  | 
1619  | 
assumes "b dvd a"  | 
|
1620  | 
shows "prime_factorization (a div b) = prime_factorization a - prime_factorization b"  | 
|
1621  | 
proof (cases "a = 0")  | 
|
1622  | 
case [simp]: False  | 
|
1623  | 
from assms have [simp]: "b \<noteq> 0" by auto  | 
|
1624  | 
have "prime_factorization ((a div b) * b) = prime_factorization (a div b) + prime_factorization b"  | 
|
1625  | 
by (intro prime_factorization_mult) (insert assms, auto elim!: dvdE)  | 
|
1626  | 
with assms show ?thesis by simp  | 
|
1627  | 
qed simp_all  | 
|
1628  | 
||
| 63905 | 1629  | 
lemma zero_not_in_prime_factors [simp]: "0 \<notin> prime_factors x"  | 
1630  | 
by (auto dest: in_prime_factors_imp_prime)  | 
|
| 63498 | 1631  | 
|
| 63904 | 1632  | 
lemma prime_prime_factors:  | 
| 63905 | 1633  | 
  "prime p \<Longrightarrow> prime_factors p = {p}"
 | 
1634  | 
by (drule prime_factorization_prime) simp  | 
|
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1635  | 
|
| 
65552
 
f533820e7248
theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
 
wenzelm 
parents: 
65435 
diff
changeset
 | 
1636  | 
lemma prime_factors_product:  | 
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1637  | 
"x \<noteq> 0 \<Longrightarrow> y \<noteq> 0 \<Longrightarrow> prime_factors (x * y) = prime_factors x \<union> prime_factors y"  | 
| 63905 | 1638  | 
by (simp add: prime_factorization_mult)  | 
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1639  | 
|
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1640  | 
lemma dvd_prime_factors [intro]:  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1641  | 
"y \<noteq> 0 \<Longrightarrow> x dvd y \<Longrightarrow> prime_factors x \<subseteq> prime_factors y"  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1642  | 
by (intro set_mset_mono, subst prime_factorization_subset_iff_dvd) auto  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1643  | 
|
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1644  | 
(* RENAMED multiplicity_dvd *)  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1645  | 
lemma multiplicity_le_imp_dvd:  | 
| 63633 | 1646  | 
assumes "x \<noteq> 0" "\<And>p. prime p \<Longrightarrow> multiplicity p x \<le> multiplicity p y"  | 
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1647  | 
shows "x dvd y"  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1648  | 
proof (cases "y = 0")  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1649  | 
case False  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1650  | 
from assms this have "prime_factorization x \<subseteq># prime_factorization y"  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1651  | 
by (intro mset_subset_eqI) (auto simp: count_prime_factorization)  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1652  | 
with assms False show ?thesis by (subst (asm) prime_factorization_subset_iff_dvd)  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1653  | 
qed auto  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1654  | 
|
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1655  | 
lemma dvd_multiplicity_eq:  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1656  | 
"x \<noteq> 0 \<Longrightarrow> y \<noteq> 0 \<Longrightarrow> x dvd y \<longleftrightarrow> (\<forall>p. multiplicity p x \<le> multiplicity p y)"  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1657  | 
by (auto intro: dvd_imp_multiplicity_le multiplicity_le_imp_dvd)  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1658  | 
|
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1659  | 
lemma multiplicity_eq_imp_eq:  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1660  | 
assumes "x \<noteq> 0" "y \<noteq> 0"  | 
| 63633 | 1661  | 
assumes "\<And>p. prime p \<Longrightarrow> multiplicity p x = multiplicity p y"  | 
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1662  | 
shows "normalize x = normalize y"  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1663  | 
using assms by (intro associatedI multiplicity_le_imp_dvd) simp_all  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1664  | 
|
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1665  | 
lemma prime_factorization_unique':  | 
| 63633 | 1666  | 
assumes "\<forall>p \<in># M. prime p" "\<forall>p \<in># N. prime p" "(\<Prod>i \<in># M. i) = (\<Prod>i \<in># N. i)"  | 
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1667  | 
shows "M = N"  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1668  | 
proof -  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1669  | 
have "prime_factorization (\<Prod>i \<in># M. i) = prime_factorization (\<Prod>i \<in># N. i)"  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1670  | 
by (simp only: assms)  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1671  | 
also from assms have "prime_factorization (\<Prod>i \<in># M. i) = M"  | 
| 63830 | 1672  | 
by (subst prime_factorization_prod_mset_primes) simp_all  | 
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1673  | 
also from assms have "prime_factorization (\<Prod>i \<in># N. i) = N"  | 
| 63830 | 1674  | 
by (subst prime_factorization_prod_mset_primes) simp_all  | 
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1675  | 
finally show ?thesis .  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1676  | 
qed  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1677  | 
|
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1678  | 
lemma prime_factorization_unique'':  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1679  | 
assumes "\<forall>p \<in># M. prime p" "\<forall>p \<in># N. prime p" "normalize (\<Prod>i \<in># M. i) = normalize (\<Prod>i \<in># N. i)"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1680  | 
shows "M = N"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1681  | 
proof -  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1682  | 
have "prime_factorization (normalize (\<Prod>i \<in># M. i)) =  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1683  | 
prime_factorization (normalize (\<Prod>i \<in># N. i))"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1684  | 
by (simp only: assms)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1685  | 
also from assms have "prime_factorization (normalize (\<Prod>i \<in># M. i)) = M"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1686  | 
by (subst prime_factorization_normalize, subst prime_factorization_prod_mset_primes) simp_all  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1687  | 
also from assms have "prime_factorization (normalize (\<Prod>i \<in># N. i)) = N"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1688  | 
by (subst prime_factorization_normalize, subst prime_factorization_prod_mset_primes) simp_all  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1689  | 
finally show ?thesis .  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1690  | 
qed  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1691  | 
|
| 
63537
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
1692  | 
lemma multiplicity_cong:  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
1693  | 
"(\<And>r. p ^ r dvd a \<longleftrightarrow> p ^ r dvd b) \<Longrightarrow> multiplicity p a = multiplicity p b"  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
1694  | 
by (simp add: multiplicity_def)  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
1695  | 
|
| 
65552
 
f533820e7248
theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
 
wenzelm 
parents: 
65435 
diff
changeset
 | 
1696  | 
lemma not_dvd_imp_multiplicity_0:  | 
| 
63537
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
1697  | 
assumes "\<not>p dvd x"  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
1698  | 
shows "multiplicity p x = 0"  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
1699  | 
proof -  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
1700  | 
from assms have "multiplicity p x < 1"  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
1701  | 
by (intro multiplicity_lessI) auto  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
1702  | 
thus ?thesis by simp  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
1703  | 
qed  | 
| 
 
831816778409
Removed redundant material related to primes
 
eberlm <eberlm@in.tum.de> 
parents: 
63534 
diff
changeset
 | 
1704  | 
|
| 
73127
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
1705  | 
lemma multiplicity_zero_left [simp]: "multiplicity 0 x = 0"  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
1706  | 
by (cases "x = 0") (auto intro: not_dvd_imp_multiplicity_0)  | 
| 73103 | 1707  | 
|
| 
66276
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1708  | 
lemma inj_on_Prod_primes:  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1709  | 
assumes "\<And>P p. P \<in> A \<Longrightarrow> p \<in> P \<Longrightarrow> prime p"  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1710  | 
assumes "\<And>P. P \<in> A \<Longrightarrow> finite P"  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1711  | 
shows "inj_on Prod A"  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1712  | 
proof (rule inj_onI)  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1713  | 
fix P Q assume PQ: "P \<in> A" "Q \<in> A" "\<Prod>P = \<Prod>Q"  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1714  | 
with prime_factorization_unique'[of "mset_set P" "mset_set Q"] assms[of P] assms[of Q]  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1715  | 
have "mset_set P = mset_set Q" by (auto simp: prod_unfold_prod_mset)  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1716  | 
with assms[of P] assms[of Q] PQ show "P = Q" by simp  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1717  | 
qed  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1718  | 
|
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1719  | 
lemma divides_primepow_weak:  | 
| 67051 | 1720  | 
assumes "prime p" and "a dvd p ^ n"  | 
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1721  | 
obtains m where "m \<le> n" and "normalize a = normalize (p ^ m)"  | 
| 67051 | 1722  | 
proof -  | 
1723  | 
from assms have "a \<noteq> 0"  | 
|
1724  | 
by auto  | 
|
1725  | 
with assms  | 
|
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1726  | 
have "normalize (prod_mset (prime_factorization a)) dvd  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1727  | 
normalize (prod_mset (prime_factorization (p ^ n)))"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1728  | 
by (subst (1 2) prod_mset_prime_factorization_weak) auto  | 
| 67051 | 1729  | 
then have "prime_factorization a \<subseteq># prime_factorization (p ^ n)"  | 
1730  | 
by (simp add: in_prime_factors_imp_prime prod_mset_dvd_prod_mset_primes_iff)  | 
|
1731  | 
with assms have "prime_factorization a \<subseteq># replicate_mset n p"  | 
|
1732  | 
by (simp add: prime_factorization_prime_power)  | 
|
1733  | 
then obtain m where "m \<le> n" and "prime_factorization a = replicate_mset m p"  | 
|
1734  | 
by (rule msubseteq_replicate_msetE)  | 
|
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1735  | 
then have *: "normalize (prod_mset (prime_factorization a)) =  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1736  | 
normalize (prod_mset (replicate_mset m p))" by metis  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1737  | 
also have "normalize (prod_mset (prime_factorization a)) = normalize a"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1738  | 
using \<open>a \<noteq> 0\<close> by (simp add: prod_mset_prime_factorization_weak)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1739  | 
also have "prod_mset (replicate_mset m p) = p ^ m"  | 
| 67051 | 1740  | 
by simp  | 
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1741  | 
finally show ?thesis using \<open>m \<le> n\<close>  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1742  | 
by (intro that[of m])  | 
| 67051 | 1743  | 
qed  | 
| 
66276
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
1744  | 
|
| 
69785
 
9e326f6f8a24
More material for HOL-Number_Theory: ord, Carmichael's function, primitive roots
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
68606 
diff
changeset
 | 
1745  | 
lemma divide_out_primepow_ex:  | 
| 
 
9e326f6f8a24
More material for HOL-Number_Theory: ord, Carmichael's function, primitive roots
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
68606 
diff
changeset
 | 
1746  | 
assumes "n \<noteq> 0" "\<exists>p\<in>prime_factors n. P p"  | 
| 
 
9e326f6f8a24
More material for HOL-Number_Theory: ord, Carmichael's function, primitive roots
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
68606 
diff
changeset
 | 
1747  | 
obtains p k n' where "P p" "prime p" "p dvd n" "\<not>p dvd n'" "k > 0" "n = p ^ k * n'"  | 
| 
 
9e326f6f8a24
More material for HOL-Number_Theory: ord, Carmichael's function, primitive roots
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
68606 
diff
changeset
 | 
1748  | 
proof -  | 
| 
 
9e326f6f8a24
More material for HOL-Number_Theory: ord, Carmichael's function, primitive roots
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
68606 
diff
changeset
 | 
1749  | 
from assms obtain p where p: "P p" "prime p" "p dvd n"  | 
| 
 
9e326f6f8a24
More material for HOL-Number_Theory: ord, Carmichael's function, primitive roots
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
68606 
diff
changeset
 | 
1750  | 
by auto  | 
| 
 
9e326f6f8a24
More material for HOL-Number_Theory: ord, Carmichael's function, primitive roots
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
68606 
diff
changeset
 | 
1751  | 
define k where "k = multiplicity p n"  | 
| 
 
9e326f6f8a24
More material for HOL-Number_Theory: ord, Carmichael's function, primitive roots
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
68606 
diff
changeset
 | 
1752  | 
define n' where "n' = n div p ^ k"  | 
| 
 
9e326f6f8a24
More material for HOL-Number_Theory: ord, Carmichael's function, primitive roots
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
68606 
diff
changeset
 | 
1753  | 
have n': "n = p ^ k * n'" "\<not>p dvd n'"  | 
| 
 
9e326f6f8a24
More material for HOL-Number_Theory: ord, Carmichael's function, primitive roots
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
68606 
diff
changeset
 | 
1754  | 
using assms p multiplicity_decompose[of n p]  | 
| 
 
9e326f6f8a24
More material for HOL-Number_Theory: ord, Carmichael's function, primitive roots
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
68606 
diff
changeset
 | 
1755  | 
by (auto simp: n'_def k_def multiplicity_dvd)  | 
| 
 
9e326f6f8a24
More material for HOL-Number_Theory: ord, Carmichael's function, primitive roots
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
68606 
diff
changeset
 | 
1756  | 
from n' p have "k > 0" by (intro Nat.gr0I) auto  | 
| 
 
9e326f6f8a24
More material for HOL-Number_Theory: ord, Carmichael's function, primitive roots
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
68606 
diff
changeset
 | 
1757  | 
with n' p that[of p n' k] show ?thesis by auto  | 
| 
 
9e326f6f8a24
More material for HOL-Number_Theory: ord, Carmichael's function, primitive roots
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
68606 
diff
changeset
 | 
1758  | 
qed  | 
| 
 
9e326f6f8a24
More material for HOL-Number_Theory: ord, Carmichael's function, primitive roots
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
68606 
diff
changeset
 | 
1759  | 
|
| 
 
9e326f6f8a24
More material for HOL-Number_Theory: ord, Carmichael's function, primitive roots
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
68606 
diff
changeset
 | 
1760  | 
lemma divide_out_primepow:  | 
| 
 
9e326f6f8a24
More material for HOL-Number_Theory: ord, Carmichael's function, primitive roots
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
68606 
diff
changeset
 | 
1761  | 
assumes "n \<noteq> 0" "\<not>is_unit n"  | 
| 
 
9e326f6f8a24
More material for HOL-Number_Theory: ord, Carmichael's function, primitive roots
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
68606 
diff
changeset
 | 
1762  | 
obtains p k n' where "prime p" "p dvd n" "\<not>p dvd n'" "k > 0" "n = p ^ k * n'"  | 
| 
 
9e326f6f8a24
More material for HOL-Number_Theory: ord, Carmichael's function, primitive roots
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
68606 
diff
changeset
 | 
1763  | 
using divide_out_primepow_ex[OF assms(1), of "\<lambda>_. True"] prime_divisor_exists[OF assms] assms  | 
| 
 
9e326f6f8a24
More material for HOL-Number_Theory: ord, Carmichael's function, primitive roots
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
68606 
diff
changeset
 | 
1764  | 
prime_factorsI by metis  | 
| 
 
9e326f6f8a24
More material for HOL-Number_Theory: ord, Carmichael's function, primitive roots
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
68606 
diff
changeset
 | 
1765  | 
|
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
1766  | 
|
| 63924 | 1767  | 
subsection \<open>GCD and LCM computation with unique factorizations\<close>  | 
1768  | 
||
| 63498 | 1769  | 
definition "gcd_factorial a b = (if a = 0 then normalize b  | 
1770  | 
else if b = 0 then normalize a  | 
|
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1771  | 
else normalize (prod_mset (prime_factorization a \<inter># prime_factorization b)))"  | 
| 63498 | 1772  | 
|
1773  | 
definition "lcm_factorial a b = (if a = 0 \<or> b = 0 then 0  | 
|
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1774  | 
else normalize (prod_mset (prime_factorization a \<union># prime_factorization b)))"  | 
| 63498 | 1775  | 
|
1776  | 
definition "Gcd_factorial A =  | 
|
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1777  | 
  (if A \<subseteq> {0} then 0 else normalize (prod_mset (Inf (prime_factorization ` (A - {0})))))"
 | 
| 63498 | 1778  | 
|
1779  | 
definition "Lcm_factorial A =  | 
|
1780  | 
  (if A = {} then 1
 | 
|
1781  | 
   else if 0 \<notin> A \<and> subset_mset.bdd_above (prime_factorization ` (A - {0})) then
 | 
|
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1782  | 
normalize (prod_mset (Sup (prime_factorization ` A)))  | 
| 63498 | 1783  | 
else  | 
1784  | 
0)"  | 
|
1785  | 
||
1786  | 
lemma prime_factorization_gcd_factorial:  | 
|
1787  | 
assumes [simp]: "a \<noteq> 0" "b \<noteq> 0"  | 
|
| 
63919
 
9aed2da07200
# after multiset intersection and union symbol
 
fleury <Mathias.Fleury@mpi-inf.mpg.de> 
parents: 
63905 
diff
changeset
 | 
1788  | 
shows "prime_factorization (gcd_factorial a b) = prime_factorization a \<inter># prime_factorization b"  | 
| 63498 | 1789  | 
proof -  | 
1790  | 
have "prime_factorization (gcd_factorial a b) =  | 
|
| 
63919
 
9aed2da07200
# after multiset intersection and union symbol
 
fleury <Mathias.Fleury@mpi-inf.mpg.de> 
parents: 
63905 
diff
changeset
 | 
1791  | 
prime_factorization (prod_mset (prime_factorization a \<inter># prime_factorization b))"  | 
| 63498 | 1792  | 
by (simp add: gcd_factorial_def)  | 
| 
63919
 
9aed2da07200
# after multiset intersection and union symbol
 
fleury <Mathias.Fleury@mpi-inf.mpg.de> 
parents: 
63905 
diff
changeset
 | 
1793  | 
also have "\<dots> = prime_factorization a \<inter># prime_factorization b"  | 
| 63905 | 1794  | 
by (subst prime_factorization_prod_mset_primes) auto  | 
| 63498 | 1795  | 
finally show ?thesis .  | 
1796  | 
qed  | 
|
1797  | 
||
1798  | 
lemma prime_factorization_lcm_factorial:  | 
|
1799  | 
assumes [simp]: "a \<noteq> 0" "b \<noteq> 0"  | 
|
| 
63919
 
9aed2da07200
# after multiset intersection and union symbol
 
fleury <Mathias.Fleury@mpi-inf.mpg.de> 
parents: 
63905 
diff
changeset
 | 
1800  | 
shows "prime_factorization (lcm_factorial a b) = prime_factorization a \<union># prime_factorization b"  | 
| 63498 | 1801  | 
proof -  | 
1802  | 
have "prime_factorization (lcm_factorial a b) =  | 
|
| 
63919
 
9aed2da07200
# after multiset intersection and union symbol
 
fleury <Mathias.Fleury@mpi-inf.mpg.de> 
parents: 
63905 
diff
changeset
 | 
1803  | 
prime_factorization (prod_mset (prime_factorization a \<union># prime_factorization b))"  | 
| 63498 | 1804  | 
by (simp add: lcm_factorial_def)  | 
| 
63919
 
9aed2da07200
# after multiset intersection and union symbol
 
fleury <Mathias.Fleury@mpi-inf.mpg.de> 
parents: 
63905 
diff
changeset
 | 
1805  | 
also have "\<dots> = prime_factorization a \<union># prime_factorization b"  | 
| 63905 | 1806  | 
by (subst prime_factorization_prod_mset_primes) auto  | 
| 63498 | 1807  | 
finally show ?thesis .  | 
1808  | 
qed  | 
|
1809  | 
||
1810  | 
lemma prime_factorization_Gcd_factorial:  | 
|
1811  | 
  assumes "\<not>A \<subseteq> {0}"
 | 
|
1812  | 
  shows   "prime_factorization (Gcd_factorial A) = Inf (prime_factorization ` (A - {0}))"
 | 
|
1813  | 
proof -  | 
|
1814  | 
  from assms obtain x where x: "x \<in> A - {0}" by auto
 | 
|
1815  | 
  hence "Inf (prime_factorization ` (A - {0})) \<subseteq># prime_factorization x"
 | 
|
1816  | 
by (intro subset_mset.cInf_lower) simp_all  | 
|
| 63905 | 1817  | 
  hence "\<forall>y. y \<in># Inf (prime_factorization ` (A - {0})) \<longrightarrow> y \<in> prime_factors x"
 | 
| 63498 | 1818  | 
by (auto dest: mset_subset_eqD)  | 
| 63905 | 1819  | 
with in_prime_factors_imp_prime[of _ x]  | 
| 63633 | 1820  | 
    have "\<forall>p. p \<in># Inf (prime_factorization ` (A - {0})) \<longrightarrow> prime p" by blast
 | 
| 63498 | 1821  | 
with assms show ?thesis  | 
| 63830 | 1822  | 
by (simp add: Gcd_factorial_def prime_factorization_prod_mset_primes)  | 
| 63498 | 1823  | 
qed  | 
1824  | 
||
1825  | 
lemma prime_factorization_Lcm_factorial:  | 
|
1826  | 
assumes "0 \<notin> A" "subset_mset.bdd_above (prime_factorization ` A)"  | 
|
1827  | 
shows "prime_factorization (Lcm_factorial A) = Sup (prime_factorization ` A)"  | 
|
1828  | 
proof (cases "A = {}")
 | 
|
1829  | 
case True  | 
|
1830  | 
  hence "prime_factorization ` A = {}" by auto
 | 
|
1831  | 
  also have "Sup \<dots> = {#}" by (simp add: Sup_multiset_empty)
 | 
|
1832  | 
finally show ?thesis by (simp add: Lcm_factorial_def)  | 
|
1833  | 
next  | 
|
1834  | 
case False  | 
|
| 63633 | 1835  | 
have "\<forall>y. y \<in># Sup (prime_factorization ` A) \<longrightarrow> prime y"  | 
| 63905 | 1836  | 
by (auto simp: in_Sup_multiset_iff assms)  | 
| 63498 | 1837  | 
with assms False show ?thesis  | 
| 63830 | 1838  | 
by (simp add: Lcm_factorial_def prime_factorization_prod_mset_primes)  | 
| 63498 | 1839  | 
qed  | 
1840  | 
||
1841  | 
lemma gcd_factorial_commute: "gcd_factorial a b = gcd_factorial b a"  | 
|
1842  | 
by (simp add: gcd_factorial_def multiset_inter_commute)  | 
|
1843  | 
||
1844  | 
lemma gcd_factorial_dvd1: "gcd_factorial a b dvd a"  | 
|
1845  | 
proof (cases "a = 0 \<or> b = 0")  | 
|
1846  | 
case False  | 
|
1847  | 
hence "gcd_factorial a b \<noteq> 0" by (auto simp: gcd_factorial_def)  | 
|
1848  | 
with False show ?thesis  | 
|
1849  | 
by (subst prime_factorization_subset_iff_dvd [symmetric])  | 
|
1850  | 
(auto simp: prime_factorization_gcd_factorial)  | 
|
1851  | 
qed (auto simp: gcd_factorial_def)  | 
|
1852  | 
||
1853  | 
lemma gcd_factorial_dvd2: "gcd_factorial a b dvd b"  | 
|
1854  | 
by (subst gcd_factorial_commute) (rule gcd_factorial_dvd1)  | 
|
1855  | 
||
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1856  | 
lemma normalize_gcd_factorial [simp]: "normalize (gcd_factorial a b) = gcd_factorial a b"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1857  | 
by (simp add: gcd_factorial_def)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1858  | 
|
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1859  | 
lemma normalize_lcm_factorial [simp]: "normalize (lcm_factorial a b) = lcm_factorial a b"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1860  | 
by (simp add: lcm_factorial_def)  | 
| 63498 | 1861  | 
|
1862  | 
lemma gcd_factorial_greatest: "c dvd gcd_factorial a b" if "c dvd a" "c dvd b" for a b c  | 
|
1863  | 
proof (cases "a = 0 \<or> b = 0")  | 
|
1864  | 
case False  | 
|
1865  | 
with that have [simp]: "c \<noteq> 0" by auto  | 
|
1866  | 
let ?p = "prime_factorization"  | 
|
1867  | 
from that False have "?p c \<subseteq># ?p a" "?p c \<subseteq># ?p b"  | 
|
1868  | 
by (simp_all add: prime_factorization_subset_iff_dvd)  | 
|
1869  | 
hence "prime_factorization c \<subseteq>#  | 
|
| 
63919
 
9aed2da07200
# after multiset intersection and union symbol
 
fleury <Mathias.Fleury@mpi-inf.mpg.de> 
parents: 
63905 
diff
changeset
 | 
1870  | 
prime_factorization (prod_mset (prime_factorization a \<inter># prime_factorization b))"  | 
| 63905 | 1871  | 
using False by (subst prime_factorization_prod_mset_primes) auto  | 
| 63498 | 1872  | 
with False show ?thesis  | 
1873  | 
by (auto simp: gcd_factorial_def prime_factorization_subset_iff_dvd [symmetric])  | 
|
1874  | 
qed (auto simp: gcd_factorial_def that)  | 
|
1875  | 
||
1876  | 
lemma lcm_factorial_gcd_factorial:  | 
|
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1877  | 
"lcm_factorial a b = normalize (a * b div gcd_factorial a b)" for a b  | 
| 63498 | 1878  | 
proof (cases "a = 0 \<or> b = 0")  | 
1879  | 
case False  | 
|
1880  | 
let ?p = "prime_factorization"  | 
|
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1881  | 
have 1: "normalize x * normalize y dvd z \<longleftrightarrow> x * y dvd z" for x y z :: 'a  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1882  | 
proof -  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1883  | 
have "normalize (normalize x * normalize y) dvd z \<longleftrightarrow> x * y dvd z"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1884  | 
unfolding normalize_mult_normalize_left normalize_mult_normalize_right by simp  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1885  | 
thus ?thesis unfolding normalize_dvd_iff by simp  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1886  | 
qed  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1887  | 
|
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1888  | 
have "?p (a * b) = (?p a \<union># ?p b) + (?p a \<inter># ?p b)"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1889  | 
using False by (subst prime_factorization_mult) (auto intro!: multiset_eqI)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1890  | 
hence "normalize (prod_mset (?p (a * b))) =  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1891  | 
normalize (prod_mset ((?p a \<union># ?p b) + (?p a \<inter># ?p b)))"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1892  | 
by (simp only:)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1893  | 
hence *: "normalize (a * b) = normalize (lcm_factorial a b * gcd_factorial a b)" using False  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1894  | 
by (subst (asm) prod_mset_prime_factorization_weak)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1895  | 
(auto simp: lcm_factorial_def gcd_factorial_def)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1896  | 
|
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1897  | 
have [simp]: "gcd_factorial a b dvd a * b" "lcm_factorial a b dvd a * b"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1898  | 
using associatedD2[OF *] by auto  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1899  | 
from False have [simp]: "gcd_factorial a b \<noteq> 0" "lcm_factorial a b \<noteq> 0"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1900  | 
by (auto simp: gcd_factorial_def lcm_factorial_def)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1901  | 
|
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1902  | 
show ?thesis  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1903  | 
by (rule associated_eqI)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1904  | 
(use * in \<open>auto simp: dvd_div_iff_mult div_dvd_iff_mult dest: associatedD1 associatedD2\<close>)  | 
| 63498 | 1905  | 
qed (auto simp: lcm_factorial_def)  | 
1906  | 
||
1907  | 
lemma normalize_Gcd_factorial:  | 
|
1908  | 
"normalize (Gcd_factorial A) = Gcd_factorial A"  | 
|
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1909  | 
by (simp add: Gcd_factorial_def)  | 
| 63498 | 1910  | 
|
1911  | 
lemma Gcd_factorial_eq_0_iff:  | 
|
1912  | 
  "Gcd_factorial A = 0 \<longleftrightarrow> A \<subseteq> {0}"
 | 
|
1913  | 
by (auto simp: Gcd_factorial_def in_Inf_multiset_iff split: if_splits)  | 
|
1914  | 
||
1915  | 
lemma Gcd_factorial_dvd:  | 
|
1916  | 
assumes "x \<in> A"  | 
|
1917  | 
shows "Gcd_factorial A dvd x"  | 
|
1918  | 
proof (cases "x = 0")  | 
|
1919  | 
case False  | 
|
1920  | 
  with assms have "prime_factorization (Gcd_factorial A) = Inf (prime_factorization ` (A - {0}))"
 | 
|
1921  | 
by (intro prime_factorization_Gcd_factorial) auto  | 
|
1922  | 
also from False assms have "\<dots> \<subseteq># prime_factorization x"  | 
|
1923  | 
by (intro subset_mset.cInf_lower) auto  | 
|
1924  | 
finally show ?thesis  | 
|
1925  | 
by (subst (asm) prime_factorization_subset_iff_dvd)  | 
|
1926  | 
(insert assms False, auto simp: Gcd_factorial_eq_0_iff)  | 
|
1927  | 
qed simp_all  | 
|
1928  | 
||
1929  | 
lemma Gcd_factorial_greatest:  | 
|
1930  | 
assumes "\<And>y. y \<in> A \<Longrightarrow> x dvd y"  | 
|
1931  | 
shows "x dvd Gcd_factorial A"  | 
|
1932  | 
proof (cases "A \<subseteq> {0}")
 | 
|
1933  | 
case False  | 
|
1934  | 
from False obtain y where "y \<in> A" "y \<noteq> 0" by auto  | 
|
1935  | 
with assms[of y] have nz: "x \<noteq> 0" by auto  | 
|
1936  | 
  from nz assms have "prime_factorization x \<subseteq># prime_factorization y" if "y \<in> A - {0}" for y
 | 
|
1937  | 
using that by (subst prime_factorization_subset_iff_dvd) auto  | 
|
1938  | 
  with False have "prime_factorization x \<subseteq># Inf (prime_factorization ` (A - {0}))"
 | 
|
1939  | 
by (intro subset_mset.cInf_greatest) auto  | 
|
1940  | 
also from False have "\<dots> = prime_factorization (Gcd_factorial A)"  | 
|
1941  | 
by (rule prime_factorization_Gcd_factorial [symmetric])  | 
|
1942  | 
finally show ?thesis  | 
|
1943  | 
by (subst (asm) prime_factorization_subset_iff_dvd)  | 
|
1944  | 
(insert nz False, auto simp: Gcd_factorial_eq_0_iff)  | 
|
1945  | 
qed (simp_all add: Gcd_factorial_def)  | 
|
1946  | 
||
1947  | 
lemma normalize_Lcm_factorial:  | 
|
1948  | 
"normalize (Lcm_factorial A) = Lcm_factorial A"  | 
|
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
1949  | 
by (simp add: Lcm_factorial_def)  | 
| 63498 | 1950  | 
|
1951  | 
lemma Lcm_factorial_eq_0_iff:  | 
|
1952  | 
"Lcm_factorial A = 0 \<longleftrightarrow> 0 \<in> A \<or> \<not>subset_mset.bdd_above (prime_factorization ` A)"  | 
|
1953  | 
by (auto simp: Lcm_factorial_def in_Sup_multiset_iff)  | 
|
1954  | 
||
1955  | 
lemma dvd_Lcm_factorial:  | 
|
1956  | 
assumes "x \<in> A"  | 
|
1957  | 
shows "x dvd Lcm_factorial A"  | 
|
1958  | 
proof (cases "0 \<notin> A \<and> subset_mset.bdd_above (prime_factorization ` A)")  | 
|
1959  | 
case True  | 
|
1960  | 
  with assms have [simp]: "0 \<notin> A" "x \<noteq> 0" "A \<noteq> {}" by auto
 | 
|
1961  | 
from assms True have "prime_factorization x \<subseteq># Sup (prime_factorization ` A)"  | 
|
1962  | 
by (intro subset_mset.cSup_upper) auto  | 
|
1963  | 
also have "\<dots> = prime_factorization (Lcm_factorial A)"  | 
|
1964  | 
by (rule prime_factorization_Lcm_factorial [symmetric]) (insert True, simp_all)  | 
|
1965  | 
finally show ?thesis  | 
|
1966  | 
by (subst (asm) prime_factorization_subset_iff_dvd)  | 
|
1967  | 
(insert True, auto simp: Lcm_factorial_eq_0_iff)  | 
|
1968  | 
qed (insert assms, auto simp: Lcm_factorial_def)  | 
|
1969  | 
||
1970  | 
lemma Lcm_factorial_least:  | 
|
1971  | 
assumes "\<And>y. y \<in> A \<Longrightarrow> y dvd x"  | 
|
1972  | 
shows "Lcm_factorial A dvd x"  | 
|
1973  | 
proof -  | 
|
1974  | 
  consider "A = {}" | "0 \<in> A" | "x = 0" | "A \<noteq> {}" "0 \<notin> A" "x \<noteq> 0" by blast
 | 
|
1975  | 
thus ?thesis  | 
|
1976  | 
proof cases  | 
|
1977  | 
    assume *: "A \<noteq> {}" "0 \<notin> A" "x \<noteq> 0"
 | 
|
1978  | 
hence nz: "x \<noteq> 0" if "x \<in> A" for x using that by auto  | 
|
1979  | 
from * have bdd: "subset_mset.bdd_above (prime_factorization ` A)"  | 
|
1980  | 
by (intro subset_mset.bdd_aboveI[of _ "prime_factorization x"])  | 
|
1981  | 
(auto simp: prime_factorization_subset_iff_dvd nz dest: assms)  | 
|
1982  | 
have "prime_factorization (Lcm_factorial A) = Sup (prime_factorization ` A)"  | 
|
1983  | 
by (rule prime_factorization_Lcm_factorial) fact+  | 
|
1984  | 
also from * have "\<dots> \<subseteq># prime_factorization x"  | 
|
1985  | 
by (intro subset_mset.cSup_least)  | 
|
1986  | 
(auto simp: prime_factorization_subset_iff_dvd nz dest: assms)  | 
|
1987  | 
finally show ?thesis  | 
|
1988  | 
by (subst (asm) prime_factorization_subset_iff_dvd)  | 
|
1989  | 
(insert * bdd, auto simp: Lcm_factorial_eq_0_iff)  | 
|
1990  | 
qed (auto simp: Lcm_factorial_def dest: assms)  | 
|
1991  | 
qed  | 
|
1992  | 
||
1993  | 
lemmas gcd_lcm_factorial =  | 
|
1994  | 
gcd_factorial_dvd1 gcd_factorial_dvd2 gcd_factorial_greatest  | 
|
1995  | 
normalize_gcd_factorial lcm_factorial_gcd_factorial  | 
|
1996  | 
normalize_Gcd_factorial Gcd_factorial_dvd Gcd_factorial_greatest  | 
|
1997  | 
normalize_Lcm_factorial dvd_Lcm_factorial Lcm_factorial_least  | 
|
1998  | 
||
| 60804 | 1999  | 
end  | 
2000  | 
||
| 63498 | 2001  | 
class factorial_semiring_gcd = factorial_semiring + gcd + Gcd +  | 
2002  | 
assumes gcd_eq_gcd_factorial: "gcd a b = gcd_factorial a b"  | 
|
2003  | 
and lcm_eq_lcm_factorial: "lcm a b = lcm_factorial a b"  | 
|
2004  | 
and Gcd_eq_Gcd_factorial: "Gcd A = Gcd_factorial A"  | 
|
2005  | 
and Lcm_eq_Lcm_factorial: "Lcm A = Lcm_factorial A"  | 
|
| 60804 | 2006  | 
begin  | 
2007  | 
||
| 63498 | 2008  | 
lemma prime_factorization_gcd:  | 
2009  | 
assumes [simp]: "a \<noteq> 0" "b \<noteq> 0"  | 
|
| 
63919
 
9aed2da07200
# after multiset intersection and union symbol
 
fleury <Mathias.Fleury@mpi-inf.mpg.de> 
parents: 
63905 
diff
changeset
 | 
2010  | 
shows "prime_factorization (gcd a b) = prime_factorization a \<inter># prime_factorization b"  | 
| 63498 | 2011  | 
by (simp add: gcd_eq_gcd_factorial prime_factorization_gcd_factorial)  | 
| 60804 | 2012  | 
|
| 63498 | 2013  | 
lemma prime_factorization_lcm:  | 
2014  | 
assumes [simp]: "a \<noteq> 0" "b \<noteq> 0"  | 
|
| 
63919
 
9aed2da07200
# after multiset intersection and union symbol
 
fleury <Mathias.Fleury@mpi-inf.mpg.de> 
parents: 
63905 
diff
changeset
 | 
2015  | 
shows "prime_factorization (lcm a b) = prime_factorization a \<union># prime_factorization b"  | 
| 63498 | 2016  | 
by (simp add: lcm_eq_lcm_factorial prime_factorization_lcm_factorial)  | 
| 60804 | 2017  | 
|
| 63498 | 2018  | 
lemma prime_factorization_Gcd:  | 
2019  | 
assumes "Gcd A \<noteq> 0"  | 
|
2020  | 
  shows   "prime_factorization (Gcd A) = Inf (prime_factorization ` (A - {0}))"
 | 
|
2021  | 
using assms  | 
|
2022  | 
by (simp add: prime_factorization_Gcd_factorial Gcd_eq_Gcd_factorial Gcd_factorial_eq_0_iff)  | 
|
2023  | 
||
2024  | 
lemma prime_factorization_Lcm:  | 
|
2025  | 
assumes "Lcm A \<noteq> 0"  | 
|
2026  | 
shows "prime_factorization (Lcm A) = Sup (prime_factorization ` A)"  | 
|
2027  | 
using assms  | 
|
2028  | 
by (simp add: prime_factorization_Lcm_factorial Lcm_eq_Lcm_factorial Lcm_factorial_eq_0_iff)  | 
|
2029  | 
||
| 
66276
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
2030  | 
lemma prime_factors_gcd [simp]:  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
2031  | 
"a \<noteq> 0 \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> prime_factors (gcd a b) =  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
2032  | 
prime_factors a \<inter> prime_factors b"  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
2033  | 
by (subst prime_factorization_gcd) auto  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
2034  | 
|
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
2035  | 
lemma prime_factors_lcm [simp]:  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
2036  | 
"a \<noteq> 0 \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> prime_factors (lcm a b) =  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
2037  | 
prime_factors a \<union> prime_factors b"  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
2038  | 
by (subst prime_factorization_lcm) auto  | 
| 
 
acc3b7dd0b21
More material on powers for HOL-Computational_Algebra/HOL-Number_Theory
 
eberlm <eberlm@in.tum.de> 
parents: 
65552 
diff
changeset
 | 
2039  | 
|
| 63498 | 2040  | 
subclass semiring_gcd  | 
2041  | 
by (standard, unfold gcd_eq_gcd_factorial lcm_eq_lcm_factorial)  | 
|
2042  | 
(rule gcd_lcm_factorial; assumption)+  | 
|
2043  | 
||
2044  | 
subclass semiring_Gcd  | 
|
2045  | 
by (standard, unfold Gcd_eq_Gcd_factorial Lcm_eq_Lcm_factorial)  | 
|
2046  | 
(rule gcd_lcm_factorial; assumption)+  | 
|
| 60804 | 2047  | 
|
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2048  | 
lemma  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2049  | 
assumes "x \<noteq> 0" "y \<noteq> 0"  | 
| 
65552
 
f533820e7248
theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
 
wenzelm 
parents: 
65435 
diff
changeset
 | 
2050  | 
shows gcd_eq_factorial':  | 
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2051  | 
"gcd x y = normalize (\<Prod>p \<in> prime_factors x \<inter> prime_factors y.  | 
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2052  | 
p ^ min (multiplicity p x) (multiplicity p y))" (is "_ = ?rhs1")  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2053  | 
and lcm_eq_factorial':  | 
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2054  | 
"lcm x y = normalize (\<Prod>p \<in> prime_factors x \<union> prime_factors y.  | 
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2055  | 
p ^ max (multiplicity p x) (multiplicity p y))" (is "_ = ?rhs2")  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2056  | 
proof -  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2057  | 
have "gcd x y = gcd_factorial x y" by (rule gcd_eq_gcd_factorial)  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2058  | 
also have "\<dots> = ?rhs1"  | 
| 63905 | 2059  | 
by (auto simp: gcd_factorial_def assms prod_mset_multiplicity  | 
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2060  | 
count_prime_factorization_prime  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2061  | 
intro!: arg_cong[of _ _ normalize] dest: in_prime_factors_imp_prime intro!: prod.cong)  | 
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2062  | 
finally show "gcd x y = ?rhs1" .  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2063  | 
have "lcm x y = lcm_factorial x y" by (rule lcm_eq_lcm_factorial)  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2064  | 
also have "\<dots> = ?rhs2"  | 
| 63905 | 2065  | 
by (auto simp: lcm_factorial_def assms prod_mset_multiplicity  | 
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2066  | 
count_prime_factorization_prime intro!: arg_cong[of _ _ normalize]  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2067  | 
dest: in_prime_factors_imp_prime intro!: prod.cong)  | 
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2068  | 
finally show "lcm x y = ?rhs2" .  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2069  | 
qed  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2070  | 
|
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2071  | 
lemma  | 
| 63633 | 2072  | 
assumes "x \<noteq> 0" "y \<noteq> 0" "prime p"  | 
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2073  | 
shows multiplicity_gcd: "multiplicity p (gcd x y) = min (multiplicity p x) (multiplicity p y)"  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2074  | 
and multiplicity_lcm: "multiplicity p (lcm x y) = max (multiplicity p x) (multiplicity p y)"  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2075  | 
proof -  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2076  | 
have "gcd x y = gcd_factorial x y" by (rule gcd_eq_gcd_factorial)  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2077  | 
also from assms have "multiplicity p \<dots> = min (multiplicity p x) (multiplicity p y)"  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2078  | 
by (simp add: count_prime_factorization_prime [symmetric] prime_factorization_gcd_factorial)  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2079  | 
finally show "multiplicity p (gcd x y) = min (multiplicity p x) (multiplicity p y)" .  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2080  | 
have "lcm x y = lcm_factorial x y" by (rule lcm_eq_lcm_factorial)  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2081  | 
also from assms have "multiplicity p \<dots> = max (multiplicity p x) (multiplicity p y)"  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2082  | 
by (simp add: count_prime_factorization_prime [symmetric] prime_factorization_lcm_factorial)  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2083  | 
finally show "multiplicity p (lcm x y) = max (multiplicity p x) (multiplicity p y)" .  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2084  | 
qed  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2085  | 
|
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2086  | 
lemma gcd_lcm_distrib:  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2087  | 
"gcd x (lcm y z) = lcm (gcd x y) (gcd x z)"  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2088  | 
proof (cases "x = 0 \<or> y = 0 \<or> z = 0")  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2089  | 
case True  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2090  | 
thus ?thesis  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2091  | 
by (auto simp: lcm_proj1_if_dvd lcm_proj2_if_dvd)  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2092  | 
next  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2093  | 
case False  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2094  | 
hence "normalize (gcd x (lcm y z)) = normalize (lcm (gcd x y) (gcd x z))"  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2095  | 
by (intro associatedI prime_factorization_subset_imp_dvd)  | 
| 
65552
 
f533820e7248
theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
 
wenzelm 
parents: 
65435 
diff
changeset
 | 
2096  | 
(auto simp: lcm_eq_0_iff prime_factorization_gcd prime_factorization_lcm  | 
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2097  | 
subset_mset.inf_sup_distrib1)  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2098  | 
thus ?thesis by simp  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2099  | 
qed  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2100  | 
|
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2101  | 
lemma lcm_gcd_distrib:  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2102  | 
"lcm x (gcd y z) = gcd (lcm x y) (lcm x z)"  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2103  | 
proof (cases "x = 0 \<or> y = 0 \<or> z = 0")  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2104  | 
case True  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2105  | 
thus ?thesis  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2106  | 
by (auto simp: lcm_proj1_if_dvd lcm_proj2_if_dvd)  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2107  | 
next  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2108  | 
case False  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2109  | 
hence "normalize (lcm x (gcd y z)) = normalize (gcd (lcm x y) (lcm x z))"  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2110  | 
by (intro associatedI prime_factorization_subset_imp_dvd)  | 
| 
65552
 
f533820e7248
theories "GCD" and "Binomial" are already included in "Main": this avoids improper imports in applications;
 
wenzelm 
parents: 
65435 
diff
changeset
 | 
2111  | 
(auto simp: lcm_eq_0_iff prime_factorization_gcd prime_factorization_lcm  | 
| 
63534
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2112  | 
subset_mset.sup_inf_distrib1)  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2113  | 
thus ?thesis by simp  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2114  | 
qed  | 
| 
 
523b488b15c9
Overhaul of prime/multiplicity/prime_factors
 
eberlm <eberlm@in.tum.de> 
parents: 
63498 
diff
changeset
 | 
2115  | 
|
| 60804 | 2116  | 
end  | 
2117  | 
||
| 63498 | 2118  | 
class factorial_ring_gcd = factorial_semiring_gcd + idom  | 
| 60804 | 2119  | 
begin  | 
2120  | 
||
| 63498 | 2121  | 
subclass ring_gcd ..  | 
| 60804 | 2122  | 
|
| 63498 | 2123  | 
subclass idom_divide ..  | 
| 60804 | 2124  | 
|
2125  | 
end  | 
|
2126  | 
||
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2127  | 
|
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2128  | 
class factorial_semiring_multiplicative =  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2129  | 
factorial_semiring + normalization_semidom_multiplicative  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2130  | 
begin  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2131  | 
|
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2132  | 
lemma normalize_prod_mset_primes:  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2133  | 
"(\<And>p. p \<in># A \<Longrightarrow> prime p) \<Longrightarrow> normalize (prod_mset A) = prod_mset A"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2134  | 
proof (induction A)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2135  | 
case (add p A)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2136  | 
hence "prime p" by simp  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2137  | 
hence "normalize p = p" by simp  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2138  | 
with add show ?case by (simp add: normalize_mult)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2139  | 
qed simp_all  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2140  | 
|
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2141  | 
lemma prod_mset_prime_factorization:  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2142  | 
assumes "x \<noteq> 0"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2143  | 
shows "prod_mset (prime_factorization x) = normalize x"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2144  | 
using assms  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2145  | 
by (induction x rule: prime_divisors_induct)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2146  | 
(simp_all add: prime_factorization_unit prime_factorization_times_prime  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2147  | 
is_unit_normalize normalize_mult)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2148  | 
|
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2149  | 
lemma prime_decomposition: "unit_factor x * prod_mset (prime_factorization x) = x"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2150  | 
by (cases "x = 0") (simp_all add: prod_mset_prime_factorization)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2151  | 
|
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2152  | 
lemma prod_prime_factors:  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2153  | 
assumes "x \<noteq> 0"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2154  | 
shows "(\<Prod>p \<in> prime_factors x. p ^ multiplicity p x) = normalize x"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2155  | 
proof -  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2156  | 
have "normalize x = prod_mset (prime_factorization x)"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2157  | 
by (simp add: prod_mset_prime_factorization assms)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2158  | 
also have "\<dots> = (\<Prod>p \<in> prime_factors x. p ^ count (prime_factorization x) p)"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2159  | 
by (subst prod_mset_multiplicity) simp_all  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2160  | 
also have "\<dots> = (\<Prod>p \<in> prime_factors x. p ^ multiplicity p x)"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2161  | 
by (intro prod.cong)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2162  | 
(simp_all add: assms count_prime_factorization_prime in_prime_factors_imp_prime)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2163  | 
finally show ?thesis ..  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2164  | 
qed  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2165  | 
|
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2166  | 
lemma prime_factorization_unique'':  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2167  | 
  assumes S_eq: "S = {p. 0 < f p}"
 | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2168  | 
and "finite S"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2169  | 
and S: "\<forall>p\<in>S. prime p" "normalize n = (\<Prod>p\<in>S. p ^ f p)"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2170  | 
shows "S = prime_factors n \<and> (\<forall>p. prime p \<longrightarrow> f p = multiplicity p n)"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2171  | 
proof  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2172  | 
define A where "A = Abs_multiset f"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2173  | 
from \<open>finite S\<close> S(1) have "(\<Prod>p\<in>S. p ^ f p) \<noteq> 0" by auto  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2174  | 
with S(2) have nz: "n \<noteq> 0" by auto  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2175  | 
from S_eq \<open>finite S\<close> have count_A: "count A = f"  | 
| 73270 | 2176  | 
unfolding A_def by (subst multiset.Abs_multiset_inverse) simp_all  | 
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2177  | 
from S_eq count_A have set_mset_A: "set_mset A = S"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2178  | 
by (simp only: set_mset_def)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2179  | 
from S(2) have "normalize n = (\<Prod>p\<in>S. p ^ f p)" .  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2180  | 
also have "\<dots> = prod_mset A" by (simp add: prod_mset_multiplicity S_eq set_mset_A count_A)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2181  | 
also from nz have "normalize n = prod_mset (prime_factorization n)"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2182  | 
by (simp add: prod_mset_prime_factorization)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2183  | 
finally have "prime_factorization (prod_mset A) =  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2184  | 
prime_factorization (prod_mset (prime_factorization n))" by simp  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2185  | 
also from S(1) have "prime_factorization (prod_mset A) = A"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2186  | 
by (intro prime_factorization_prod_mset_primes) (auto simp: set_mset_A)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2187  | 
also have "prime_factorization (prod_mset (prime_factorization n)) = prime_factorization n"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2188  | 
by (intro prime_factorization_prod_mset_primes) auto  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2189  | 
finally show "S = prime_factors n" by (simp add: set_mset_A [symmetric])  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2190  | 
|
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2191  | 
show "(\<forall>p. prime p \<longrightarrow> f p = multiplicity p n)"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2192  | 
proof safe  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2193  | 
fix p :: 'a assume p: "prime p"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2194  | 
have "multiplicity p n = multiplicity p (normalize n)" by simp  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2195  | 
also have "normalize n = prod_mset A"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2196  | 
by (simp add: prod_mset_multiplicity S_eq set_mset_A count_A S)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2197  | 
also from p set_mset_A S(1)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2198  | 
have "multiplicity p \<dots> = sum_mset (image_mset (multiplicity p) A)"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2199  | 
by (intro prime_elem_multiplicity_prod_mset_distrib) auto  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2200  | 
also from S(1) p  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2201  | 
have "image_mset (multiplicity p) A = image_mset (\<lambda>q. if p = q then 1 else 0) A"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2202  | 
by (intro image_mset_cong) (auto simp: set_mset_A multiplicity_self prime_multiplicity_other)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2203  | 
also have "sum_mset \<dots> = f p"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2204  | 
by (simp add: semiring_1_class.sum_mset_delta' count_A)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2205  | 
finally show "f p = multiplicity p n" ..  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2206  | 
qed  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2207  | 
qed  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2208  | 
|
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2209  | 
lemma divides_primepow:  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2210  | 
assumes "prime p" and "a dvd p ^ n"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2211  | 
obtains m where "m \<le> n" and "normalize a = p ^ m"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2212  | 
using divides_primepow_weak[OF assms] that assms  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2213  | 
by (auto simp add: normalize_power)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2214  | 
|
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2215  | 
lemma Ex_other_prime_factor:  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2216  | 
assumes "n \<noteq> 0" and "\<not>(\<exists>k. normalize n = p ^ k)" "prime p"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2217  | 
shows "\<exists>q\<in>prime_factors n. q \<noteq> p"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2218  | 
proof (rule ccontr)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2219  | 
assume *: "\<not>(\<exists>q\<in>prime_factors n. q \<noteq> p)"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2220  | 
have "normalize n = (\<Prod>p\<in>prime_factors n. p ^ multiplicity p n)"  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2221  | 
using assms(1) by (intro prod_prime_factors [symmetric]) auto  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2222  | 
  also from * have "\<dots> = (\<Prod>p\<in>{p}. p ^ multiplicity p n)"
 | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2223  | 
using assms(3) by (intro prod.mono_neutral_left) (auto simp: prime_factors_multiplicity)  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2224  | 
finally have "normalize n = p ^ multiplicity p n" by auto  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2225  | 
with assms show False by auto  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2226  | 
qed  | 
| 
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2227  | 
|
| 
80084
 
173548e4d5d0
moved over material from the AFP to HOL, HOL-Computational_Algebra, and HOL-Number_Theory
 
Manuel Eberl <manuel@pruvisto.org> 
parents: 
76700 
diff
changeset
 | 
2228  | 
text \<open>Now a string of results due to Maya Kądziołka\<close>  | 
| 
73127
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2229  | 
|
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2230  | 
lemma multiplicity_dvd_iff_dvd:  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2231  | 
assumes "x \<noteq> 0"  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2232  | 
shows "p^k dvd x \<longleftrightarrow> p^k dvd p^multiplicity p x"  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2233  | 
proof (cases "is_unit p")  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2234  | 
case True  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2235  | 
then have "is_unit (p^k)"  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2236  | 
using is_unit_power_iff by simp  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2237  | 
hence "p^k dvd x"  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2238  | 
by auto  | 
| 74885 | 2239  | 
moreover from \<open>is_unit p\<close> have "p^k dvd p^multiplicity p x"  | 
| 
73127
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2240  | 
using multiplicity_unit_left is_unit_power_iff by simp  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2241  | 
ultimately show ?thesis by simp  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2242  | 
next  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2243  | 
case False  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2244  | 
show ?thesis  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2245  | 
proof (cases "p = 0")  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2246  | 
case True  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2247  | 
then have "p^multiplicity p x = 1"  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2248  | 
by simp  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2249  | 
moreover have "p^k dvd x \<Longrightarrow> k = 0"  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2250  | 
proof (rule ccontr)  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2251  | 
assume "p^k dvd x" and "k \<noteq> 0"  | 
| 74885 | 2252  | 
with \<open>p = 0\<close> have "p^k = 0" by auto  | 
2253  | 
with \<open>p^k dvd x\<close> have "0 dvd x" by auto  | 
|
| 
73127
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2254  | 
hence "x = 0" by auto  | 
| 74885 | 2255  | 
with \<open>x \<noteq> 0\<close> show False by auto  | 
| 
73127
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2256  | 
qed  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2257  | 
ultimately show ?thesis  | 
| 74885 | 2258  | 
by (auto simp add: is_unit_power_iff \<open>\<not> is_unit p\<close>)  | 
| 
73127
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2259  | 
next  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2260  | 
case False  | 
| 74885 | 2261  | 
with \<open>x \<noteq> 0\<close> \<open>\<not> is_unit p\<close> show ?thesis  | 
| 
73127
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2262  | 
by (simp add: power_dvd_iff_le_multiplicity dvd_power_iff multiplicity_same_power)  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2263  | 
qed  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2264  | 
qed  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2265  | 
|
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2266  | 
lemma multiplicity_decomposeI:  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2267  | 
assumes "x = p^k * x'" and "\<not> p dvd x'" and "p \<noteq> 0"  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2268  | 
shows "multiplicity p x = k"  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2269  | 
using assms local.multiplicity_eqI local.power_Suc2 by force  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2270  | 
|
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2271  | 
lemma multiplicity_sum_lt:  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2272  | 
assumes "multiplicity p a < multiplicity p b" "a \<noteq> 0" "b \<noteq> 0"  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2273  | 
shows "multiplicity p (a + b) = multiplicity p a"  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2274  | 
proof -  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2275  | 
let ?vp = "multiplicity p"  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2276  | 
have unit: "\<not> is_unit p"  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2277  | 
proof  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2278  | 
assume "is_unit p"  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2279  | 
then have "?vp a = 0" and "?vp b = 0" using multiplicity_unit_left by auto  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2280  | 
with assms show False by auto  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2281  | 
qed  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2282  | 
|
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2283  | 
from multiplicity_decompose' obtain a' where a': "a = p^?vp a * a'" "\<not> p dvd a'"  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2284  | 
using unit assms by metis  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2285  | 
from multiplicity_decompose' obtain b' where b': "b = p^?vp b * b'"  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2286  | 
using unit assms by metis  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2287  | 
|
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2288  | 
show "?vp (a + b) = ?vp a"  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2289  | 
proof (rule multiplicity_decomposeI)  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2290  | 
let ?k = "?vp b - ?vp a"  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2291  | 
from assms have k: "?k > 0" by simp  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2292  | 
with b' have "b = p^?vp a * p^?k * b'"  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2293  | 
by (simp flip: power_add)  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2294  | 
with a' show *: "a + b = p^?vp a * (a' + p^?k * b')"  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2295  | 
by (simp add: ac_simps distrib_left)  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2296  | 
moreover show "\<not> p dvd a' + p^?k * b'"  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2297  | 
using a' k dvd_add_left_iff by auto  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2298  | 
show "p \<noteq> 0" using assms by auto  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2299  | 
qed  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2300  | 
qed  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2301  | 
|
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2302  | 
corollary multiplicity_sum_min:  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2303  | 
assumes "multiplicity p a \<noteq> multiplicity p b" "a \<noteq> 0" "b \<noteq> 0"  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2304  | 
shows "multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b)"  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2305  | 
proof -  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2306  | 
let ?vp = "multiplicity p"  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2307  | 
from assms have "?vp a < ?vp b \<or> ?vp a > ?vp b"  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2308  | 
by auto  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2309  | 
then show ?thesis  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2310  | 
by (metis assms multiplicity_sum_lt min.commute add_commute min.strict_order_iff)  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2311  | 
qed  | 
| 
 
4c4d479b097d
new magerial from Jakub Kądziołka
 
paulson <lp15@cam.ac.uk> 
parents: 
73103 
diff
changeset
 | 
2312  | 
|
| 60804 | 2313  | 
end  | 
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2314  | 
|
| 
76700
 
c48fe2be847f
added lifting_forget as suggested by Peter Lammich
 
blanchet 
parents: 
74885 
diff
changeset
 | 
2315  | 
lifting_update multiset.lifting  | 
| 
 
c48fe2be847f
added lifting_forget as suggested by Peter Lammich
 
blanchet 
parents: 
74885 
diff
changeset
 | 
2316  | 
lifting_forget multiset.lifting  | 
| 
 
c48fe2be847f
added lifting_forget as suggested by Peter Lammich
 
blanchet 
parents: 
74885 
diff
changeset
 | 
2317  | 
|
| 
71398
 
e0237f2eb49d
Removed multiplicativity assumption from normalization_semidom
 
Manuel Eberl <eberlm@in.tum.de> 
parents: 
69785 
diff
changeset
 | 
2318  | 
end  |