author | kuncar |
Fri, 27 Sep 2013 14:43:26 +0200 | |
changeset 53952 | b2781a3ce958 |
parent 53598 | 2bd8d459ebae |
child 54228 | 229282d53781 |
permissions | -rw-r--r-- |
32479 | 1 |
(* Authors: Christophe Tabacznyj, Lawrence C. Paulson, Amine Chaieb, |
31798 | 2 |
Thomas M. Rasmussen, Jeremy Avigad, Tobias Nipkow |
31706 | 3 |
|
4 |
||
32479 | 5 |
This file deals with properties of primes. Definitions and lemmas are |
6 |
proved uniformly for the natural numbers and integers. |
|
31706 | 7 |
|
8 |
This file combines and revises a number of prior developments. |
|
9 |
||
10 |
The original theories "GCD" and "Primes" were by Christophe Tabacznyj |
|
11 |
and Lawrence C. Paulson, based on \cite{davenport92}. They introduced |
|
12 |
gcd, lcm, and prime for the natural numbers. |
|
13 |
||
14 |
The original theory "IntPrimes" was by Thomas M. Rasmussen, and |
|
15 |
extended gcd, lcm, primes to the integers. Amine Chaieb provided |
|
16 |
another extension of the notions to the integers, and added a number |
|
17 |
of results to "Primes" and "GCD". IntPrimes also defined and developed |
|
18 |
the congruence relations on the integers. The notion was extended to |
|
33718 | 19 |
the natural numbers by Chaieb. |
31706 | 20 |
|
32036
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
31952
diff
changeset
|
21 |
Jeremy Avigad combined all of these, made everything uniform for the |
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
31952
diff
changeset
|
22 |
natural numbers and the integers, and added a number of new theorems. |
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
31952
diff
changeset
|
23 |
|
31798 | 24 |
Tobias Nipkow cleaned up a lot. |
21256 | 25 |
*) |
26 |
||
31706 | 27 |
|
32479 | 28 |
header {* Primes *} |
21256 | 29 |
|
32479 | 30 |
theory Primes |
37294
a2a8216999a2
absolute import -- must work with Main.thy / HOL-Proofs
haftmann
parents:
35644
diff
changeset
|
31 |
imports "~~/src/HOL/GCD" |
31706 | 32 |
begin |
33 |
||
34 |
class prime = one + |
|
44872 | 35 |
fixes prime :: "'a \<Rightarrow> bool" |
31706 | 36 |
|
37 |
instantiation nat :: prime |
|
38 |
begin |
|
21256 | 39 |
|
44872 | 40 |
definition prime_nat :: "nat \<Rightarrow> bool" |
41 |
where "prime_nat p = (1 < p \<and> (\<forall>m. m dvd p --> m = 1 \<or> m = p))" |
|
31706 | 42 |
|
44872 | 43 |
instance .. |
23687
06884f7ffb18
extended - convers now basic lcm properties also
haftmann
parents:
23431
diff
changeset
|
44 |
|
31706 | 45 |
end |
46 |
||
47 |
instantiation int :: prime |
|
48 |
begin |
|
49 |
||
44872 | 50 |
definition prime_int :: "int \<Rightarrow> bool" |
51 |
where "prime_int p = prime (nat p)" |
|
31706 | 52 |
|
44872 | 53 |
instance .. |
31706 | 54 |
|
55 |
end |
|
56 |
||
57 |
||
58 |
subsection {* Set up Transfer *} |
|
59 |
||
32479 | 60 |
lemma transfer_nat_int_prime: |
31706 | 61 |
"(x::int) >= 0 \<Longrightarrow> prime (nat x) = prime x" |
44872 | 62 |
unfolding gcd_int_def lcm_int_def prime_int_def by auto |
23687
06884f7ffb18
extended - convers now basic lcm properties also
haftmann
parents:
23431
diff
changeset
|
63 |
|
35644 | 64 |
declare transfer_morphism_nat_int[transfer add return: |
32479 | 65 |
transfer_nat_int_prime] |
31706 | 66 |
|
44872 | 67 |
lemma transfer_int_nat_prime: "prime (int x) = prime x" |
68 |
unfolding gcd_int_def lcm_int_def prime_int_def by auto |
|
31706 | 69 |
|
35644 | 70 |
declare transfer_morphism_int_nat[transfer add return: |
32479 | 71 |
transfer_int_nat_prime] |
31798 | 72 |
|
21256 | 73 |
|
32479 | 74 |
subsection {* Primes *} |
31706 | 75 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
76 |
lemma prime_odd_nat: "prime (p::nat) \<Longrightarrow> p > 2 \<Longrightarrow> odd p" |
31706 | 77 |
unfolding prime_nat_def |
40461 | 78 |
by (metis gcd_lcm_complete_lattice_nat.bot_least nat_even_iff_2_dvd nat_neq_iff odd_1_nat) |
31706 | 79 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
80 |
lemma prime_odd_int: "prime (p::int) \<Longrightarrow> p > 2 \<Longrightarrow> odd p" |
31706 | 81 |
unfolding prime_int_def |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
82 |
apply (frule prime_odd_nat) |
31706 | 83 |
apply (auto simp add: even_nat_def) |
44872 | 84 |
done |
31706 | 85 |
|
31992 | 86 |
(* FIXME Is there a better way to handle these, rather than making them elim rules? *) |
22027
e4a08629c4bd
A few lemmas about relative primes when dividing trough gcd
chaieb
parents:
21404
diff
changeset
|
87 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
88 |
lemma prime_ge_0_nat [elim]: "prime (p::nat) \<Longrightarrow> p >= 0" |
44872 | 89 |
unfolding prime_nat_def by auto |
22027
e4a08629c4bd
A few lemmas about relative primes when dividing trough gcd
chaieb
parents:
21404
diff
changeset
|
90 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
91 |
lemma prime_gt_0_nat [elim]: "prime (p::nat) \<Longrightarrow> p > 0" |
44872 | 92 |
unfolding prime_nat_def by auto |
22367 | 93 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
94 |
lemma prime_ge_1_nat [elim]: "prime (p::nat) \<Longrightarrow> p >= 1" |
44872 | 95 |
unfolding prime_nat_def by auto |
22027
e4a08629c4bd
A few lemmas about relative primes when dividing trough gcd
chaieb
parents:
21404
diff
changeset
|
96 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
97 |
lemma prime_gt_1_nat [elim]: "prime (p::nat) \<Longrightarrow> p > 1" |
44872 | 98 |
unfolding prime_nat_def by auto |
22367 | 99 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
100 |
lemma prime_ge_Suc_0_nat [elim]: "prime (p::nat) \<Longrightarrow> p >= Suc 0" |
44872 | 101 |
unfolding prime_nat_def by auto |
22367 | 102 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
103 |
lemma prime_gt_Suc_0_nat [elim]: "prime (p::nat) \<Longrightarrow> p > Suc 0" |
44872 | 104 |
unfolding prime_nat_def by auto |
31706 | 105 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
106 |
lemma prime_ge_2_nat [elim]: "prime (p::nat) \<Longrightarrow> p >= 2" |
44872 | 107 |
unfolding prime_nat_def by auto |
31706 | 108 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
109 |
lemma prime_ge_0_int [elim]: "prime (p::int) \<Longrightarrow> p >= 0" |
44872 | 110 |
unfolding prime_int_def prime_nat_def by auto |
22367 | 111 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
112 |
lemma prime_gt_0_int [elim]: "prime (p::int) \<Longrightarrow> p > 0" |
44872 | 113 |
unfolding prime_int_def prime_nat_def by auto |
31706 | 114 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
115 |
lemma prime_ge_1_int [elim]: "prime (p::int) \<Longrightarrow> p >= 1" |
44872 | 116 |
unfolding prime_int_def prime_nat_def by auto |
22027
e4a08629c4bd
A few lemmas about relative primes when dividing trough gcd
chaieb
parents:
21404
diff
changeset
|
117 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
118 |
lemma prime_gt_1_int [elim]: "prime (p::int) \<Longrightarrow> p > 1" |
44872 | 119 |
unfolding prime_int_def prime_nat_def by auto |
31706 | 120 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
121 |
lemma prime_ge_2_int [elim]: "prime (p::int) \<Longrightarrow> p >= 2" |
44872 | 122 |
unfolding prime_int_def prime_nat_def by auto |
22367 | 123 |
|
31706 | 124 |
|
125 |
lemma prime_int_altdef: "prime (p::int) = (1 < p \<and> (\<forall>m \<ge> 0. m dvd p \<longrightarrow> |
|
126 |
m = 1 \<or> m = p))" |
|
127 |
using prime_nat_def [transferred] |
|
44872 | 128 |
apply (cases "p >= 0") |
129 |
apply blast |
|
130 |
apply (auto simp add: prime_ge_0_int) |
|
131 |
done |
|
31706 | 132 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
133 |
lemma prime_imp_coprime_nat: "prime (p::nat) \<Longrightarrow> \<not> p dvd n \<Longrightarrow> coprime p n" |
31706 | 134 |
apply (unfold prime_nat_def) |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
135 |
apply (metis gcd_dvd1_nat gcd_dvd2_nat) |
31706 | 136 |
done |
137 |
||
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
138 |
lemma prime_imp_coprime_int: "prime (p::int) \<Longrightarrow> \<not> p dvd n \<Longrightarrow> coprime p n" |
31706 | 139 |
apply (unfold prime_int_altdef) |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
140 |
apply (metis gcd_dvd1_int gcd_dvd2_int gcd_ge_0_int) |
27568
9949dc7a24de
Theorem names as in IntPrimes.thy, also several theorems moved from there
chaieb
parents:
27556
diff
changeset
|
141 |
done |
9949dc7a24de
Theorem names as in IntPrimes.thy, also several theorems moved from there
chaieb
parents:
27556
diff
changeset
|
142 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
143 |
lemma prime_dvd_mult_nat: "prime (p::nat) \<Longrightarrow> p dvd m * n \<Longrightarrow> p dvd m \<or> p dvd n" |
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
144 |
by (blast intro: coprime_dvd_mult_nat prime_imp_coprime_nat) |
31706 | 145 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
146 |
lemma prime_dvd_mult_int: "prime (p::int) \<Longrightarrow> p dvd m * n \<Longrightarrow> p dvd m \<or> p dvd n" |
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
147 |
by (blast intro: coprime_dvd_mult_int prime_imp_coprime_int) |
31706 | 148 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
149 |
lemma prime_dvd_mult_eq_nat [simp]: "prime (p::nat) \<Longrightarrow> |
31706 | 150 |
p dvd m * n = (p dvd m \<or> p dvd n)" |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
151 |
by (rule iffI, rule prime_dvd_mult_nat, auto) |
27568
9949dc7a24de
Theorem names as in IntPrimes.thy, also several theorems moved from there
chaieb
parents:
27556
diff
changeset
|
152 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
153 |
lemma prime_dvd_mult_eq_int [simp]: "prime (p::int) \<Longrightarrow> |
31706 | 154 |
p dvd m * n = (p dvd m \<or> p dvd n)" |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
155 |
by (rule iffI, rule prime_dvd_mult_int, auto) |
27568
9949dc7a24de
Theorem names as in IntPrimes.thy, also several theorems moved from there
chaieb
parents:
27556
diff
changeset
|
156 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
157 |
lemma not_prime_eq_prod_nat: "(n::nat) > 1 \<Longrightarrow> ~ prime n \<Longrightarrow> |
31706 | 158 |
EX m k. n = m * k & 1 < m & m < n & 1 < k & k < n" |
159 |
unfolding prime_nat_def dvd_def apply auto |
|
44872 | 160 |
by (metis mult_commute linorder_neq_iff linorder_not_le mult_1 |
161 |
n_less_n_mult_m one_le_mult_iff less_imp_le_nat) |
|
27568
9949dc7a24de
Theorem names as in IntPrimes.thy, also several theorems moved from there
chaieb
parents:
27556
diff
changeset
|
162 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
163 |
lemma not_prime_eq_prod_int: "(n::int) > 1 \<Longrightarrow> ~ prime n \<Longrightarrow> |
31706 | 164 |
EX m k. n = m * k & 1 < m & m < n & 1 < k & k < n" |
165 |
unfolding prime_int_altdef dvd_def |
|
166 |
apply auto |
|
44872 | 167 |
by (metis div_mult_self1_is_id div_mult_self2_is_id |
168 |
int_div_less_self int_one_le_iff_zero_less zero_less_mult_pos less_le) |
|
27568
9949dc7a24de
Theorem names as in IntPrimes.thy, also several theorems moved from there
chaieb
parents:
27556
diff
changeset
|
169 |
|
53598
2bd8d459ebae
remove unneeded assumption from prime_dvd_power lemmas;
huffman
parents:
47108
diff
changeset
|
170 |
lemma prime_dvd_power_nat: "prime (p::nat) \<Longrightarrow> p dvd x^n \<Longrightarrow> p dvd x" |
2bd8d459ebae
remove unneeded assumption from prime_dvd_power lemmas;
huffman
parents:
47108
diff
changeset
|
171 |
by (induct n) auto |
27568
9949dc7a24de
Theorem names as in IntPrimes.thy, also several theorems moved from there
chaieb
parents:
27556
diff
changeset
|
172 |
|
53598
2bd8d459ebae
remove unneeded assumption from prime_dvd_power lemmas;
huffman
parents:
47108
diff
changeset
|
173 |
lemma prime_dvd_power_int: "prime (p::int) \<Longrightarrow> p dvd x^n \<Longrightarrow> p dvd x" |
2bd8d459ebae
remove unneeded assumption from prime_dvd_power lemmas;
huffman
parents:
47108
diff
changeset
|
174 |
apply (induct n) |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
175 |
apply (frule prime_ge_0_int) |
31706 | 176 |
apply auto |
44872 | 177 |
done |
31706 | 178 |
|
53598
2bd8d459ebae
remove unneeded assumption from prime_dvd_power lemmas;
huffman
parents:
47108
diff
changeset
|
179 |
lemma prime_dvd_power_nat_iff: "prime (p::nat) \<Longrightarrow> n > 0 \<Longrightarrow> |
2bd8d459ebae
remove unneeded assumption from prime_dvd_power lemmas;
huffman
parents:
47108
diff
changeset
|
180 |
p dvd x^n \<longleftrightarrow> p dvd x" |
2bd8d459ebae
remove unneeded assumption from prime_dvd_power lemmas;
huffman
parents:
47108
diff
changeset
|
181 |
by (cases n) (auto elim: prime_dvd_power_nat) |
2bd8d459ebae
remove unneeded assumption from prime_dvd_power lemmas;
huffman
parents:
47108
diff
changeset
|
182 |
|
2bd8d459ebae
remove unneeded assumption from prime_dvd_power lemmas;
huffman
parents:
47108
diff
changeset
|
183 |
lemma prime_dvd_power_int_iff: "prime (p::int) \<Longrightarrow> n > 0 \<Longrightarrow> |
2bd8d459ebae
remove unneeded assumption from prime_dvd_power lemmas;
huffman
parents:
47108
diff
changeset
|
184 |
p dvd x^n \<longleftrightarrow> p dvd x" |
2bd8d459ebae
remove unneeded assumption from prime_dvd_power lemmas;
huffman
parents:
47108
diff
changeset
|
185 |
by (cases n) (auto elim: prime_dvd_power_int) |
2bd8d459ebae
remove unneeded assumption from prime_dvd_power lemmas;
huffman
parents:
47108
diff
changeset
|
186 |
|
2bd8d459ebae
remove unneeded assumption from prime_dvd_power lemmas;
huffman
parents:
47108
diff
changeset
|
187 |
|
44872 | 188 |
subsubsection {* Make prime naively executable *} |
32007 | 189 |
|
190 |
lemma zero_not_prime_nat [simp]: "~prime (0::nat)" |
|
191 |
by (simp add: prime_nat_def) |
|
192 |
||
193 |
lemma zero_not_prime_int [simp]: "~prime (0::int)" |
|
194 |
by (simp add: prime_int_def) |
|
195 |
||
196 |
lemma one_not_prime_nat [simp]: "~prime (1::nat)" |
|
197 |
by (simp add: prime_nat_def) |
|
198 |
||
199 |
lemma Suc_0_not_prime_nat [simp]: "~prime (Suc 0)" |
|
200 |
by (simp add: prime_nat_def One_nat_def) |
|
201 |
||
202 |
lemma one_not_prime_int [simp]: "~prime (1::int)" |
|
203 |
by (simp add: prime_int_def) |
|
204 |
||
37607 | 205 |
lemma prime_nat_code [code]: |
44872 | 206 |
"prime (p::nat) \<longleftrightarrow> p > 1 \<and> (\<forall>n \<in> {1<..<p}. ~ n dvd p)" |
207 |
apply (simp add: Ball_def) |
|
208 |
apply (metis less_not_refl prime_nat_def dvd_triv_right not_prime_eq_prod_nat) |
|
209 |
done |
|
32007 | 210 |
|
211 |
lemma prime_nat_simp: |
|
44872 | 212 |
"prime (p::nat) \<longleftrightarrow> p > 1 \<and> (\<forall>n \<in> set [2..<p]. \<not> n dvd p)" |
213 |
by (auto simp add: prime_nat_code) |
|
32007 | 214 |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45605
diff
changeset
|
215 |
lemmas prime_nat_simp_numeral [simp] = prime_nat_simp [of "numeral m"] for m |
32007 | 216 |
|
37607 | 217 |
lemma prime_int_code [code]: |
218 |
"prime (p::int) \<longleftrightarrow> p > 1 \<and> (\<forall>n \<in> {1<..<p}. ~ n dvd p)" (is "?L = ?R") |
|
32007 | 219 |
proof |
44872 | 220 |
assume "?L" |
221 |
then show "?R" |
|
44821 | 222 |
by (clarsimp simp: prime_gt_1_int) (metis int_one_le_iff_zero_less prime_int_altdef less_le) |
32007 | 223 |
next |
44872 | 224 |
assume "?R" |
225 |
then show "?L" by (clarsimp simp: Ball_def) (metis dvdI not_prime_eq_prod_int) |
|
32007 | 226 |
qed |
227 |
||
44872 | 228 |
lemma prime_int_simp: "prime (p::int) \<longleftrightarrow> p > 1 \<and> (\<forall>n \<in> set [2..p - 1]. ~ n dvd p)" |
229 |
by (auto simp add: prime_int_code) |
|
32007 | 230 |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
45605
diff
changeset
|
231 |
lemmas prime_int_simp_numeral [simp] = prime_int_simp [of "numeral m"] for m |
32007 | 232 |
|
233 |
lemma two_is_prime_nat [simp]: "prime (2::nat)" |
|
44872 | 234 |
by simp |
32007 | 235 |
|
236 |
lemma two_is_prime_int [simp]: "prime (2::int)" |
|
44872 | 237 |
by simp |
32007 | 238 |
|
32111 | 239 |
text{* A bit of regression testing: *} |
240 |
||
44872 | 241 |
lemma "prime(97::nat)" by simp |
242 |
lemma "prime(97::int)" by simp |
|
243 |
lemma "prime(997::nat)" by eval |
|
244 |
lemma "prime(997::int)" by eval |
|
32111 | 245 |
|
32007 | 246 |
|
247 |
lemma prime_imp_power_coprime_nat: "prime (p::nat) \<Longrightarrow> ~ p dvd a \<Longrightarrow> coprime a (p^m)" |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
248 |
apply (rule coprime_exp_nat) |
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
249 |
apply (subst gcd_commute_nat) |
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
250 |
apply (erule (1) prime_imp_coprime_nat) |
44872 | 251 |
done |
27568
9949dc7a24de
Theorem names as in IntPrimes.thy, also several theorems moved from there
chaieb
parents:
27556
diff
changeset
|
252 |
|
32007 | 253 |
lemma prime_imp_power_coprime_int: "prime (p::int) \<Longrightarrow> ~ p dvd a \<Longrightarrow> coprime a (p^m)" |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
254 |
apply (rule coprime_exp_int) |
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
255 |
apply (subst gcd_commute_int) |
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
256 |
apply (erule (1) prime_imp_coprime_int) |
44872 | 257 |
done |
27568
9949dc7a24de
Theorem names as in IntPrimes.thy, also several theorems moved from there
chaieb
parents:
27556
diff
changeset
|
258 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
259 |
lemma primes_coprime_nat: "prime (p::nat) \<Longrightarrow> prime q \<Longrightarrow> p \<noteq> q \<Longrightarrow> coprime p q" |
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
260 |
apply (rule prime_imp_coprime_nat, assumption) |
44872 | 261 |
apply (unfold prime_nat_def) |
262 |
apply auto |
|
263 |
done |
|
27568
9949dc7a24de
Theorem names as in IntPrimes.thy, also several theorems moved from there
chaieb
parents:
27556
diff
changeset
|
264 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
265 |
lemma primes_coprime_int: "prime (p::int) \<Longrightarrow> prime q \<Longrightarrow> p \<noteq> q \<Longrightarrow> coprime p q" |
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
266 |
apply (rule prime_imp_coprime_int, assumption) |
40461 | 267 |
apply (unfold prime_int_altdef) |
44821 | 268 |
apply (metis int_one_le_iff_zero_less less_le) |
44872 | 269 |
done |
27568
9949dc7a24de
Theorem names as in IntPrimes.thy, also several theorems moved from there
chaieb
parents:
27556
diff
changeset
|
270 |
|
44872 | 271 |
lemma primes_imp_powers_coprime_nat: |
272 |
"prime (p::nat) \<Longrightarrow> prime q \<Longrightarrow> p ~= q \<Longrightarrow> coprime (p^m) (q^n)" |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
273 |
by (rule coprime_exp2_nat, rule primes_coprime_nat) |
27568
9949dc7a24de
Theorem names as in IntPrimes.thy, also several theorems moved from there
chaieb
parents:
27556
diff
changeset
|
274 |
|
44872 | 275 |
lemma primes_imp_powers_coprime_int: |
276 |
"prime (p::int) \<Longrightarrow> prime q \<Longrightarrow> p ~= q \<Longrightarrow> coprime (p^m) (q^n)" |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
277 |
by (rule coprime_exp2_int, rule primes_coprime_int) |
27568
9949dc7a24de
Theorem names as in IntPrimes.thy, also several theorems moved from there
chaieb
parents:
27556
diff
changeset
|
278 |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
279 |
lemma prime_factor_nat: "n \<noteq> (1::nat) \<Longrightarrow> \<exists> p. prime p \<and> p dvd n" |
31706 | 280 |
apply (induct n rule: nat_less_induct) |
281 |
apply (case_tac "n = 0") |
|
44872 | 282 |
using two_is_prime_nat |
283 |
apply blast |
|
284 |
apply (metis One_nat_def dvd.order_trans dvd_refl less_Suc0 linorder_neqE_nat |
|
285 |
nat_dvd_not_less neq0_conv prime_nat_def) |
|
286 |
done |
|
23244
1630951f0512
added lcm, ilcm (lcm for integers) and some lemmas about them;
chaieb
parents:
22367
diff
changeset
|
287 |
|
31706 | 288 |
(* An Isar version: |
289 |
||
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
290 |
lemma prime_factor_b_nat: |
31706 | 291 |
fixes n :: nat |
292 |
assumes "n \<noteq> 1" |
|
293 |
shows "\<exists>p. prime p \<and> p dvd n" |
|
23983 | 294 |
|
31706 | 295 |
using `n ~= 1` |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
296 |
proof (induct n rule: less_induct_nat) |
31706 | 297 |
fix n :: nat |
298 |
assume "n ~= 1" and |
|
299 |
ih: "\<forall>m<n. m \<noteq> 1 \<longrightarrow> (\<exists>p. prime p \<and> p dvd m)" |
|
44872 | 300 |
then show "\<exists>p. prime p \<and> p dvd n" |
31706 | 301 |
proof - |
302 |
{ |
|
303 |
assume "n = 0" |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
304 |
moreover note two_is_prime_nat |
31706 | 305 |
ultimately have ?thesis |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
306 |
by (auto simp del: two_is_prime_nat) |
31706 | 307 |
} |
308 |
moreover |
|
309 |
{ |
|
310 |
assume "prime n" |
|
44872 | 311 |
then have ?thesis by auto |
31706 | 312 |
} |
313 |
moreover |
|
314 |
{ |
|
315 |
assume "n ~= 0" and "~ prime n" |
|
316 |
with `n ~= 1` have "n > 1" by auto |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
317 |
with `~ prime n` and not_prime_eq_prod_nat obtain m k where |
31706 | 318 |
"n = m * k" and "1 < m" and "m < n" by blast |
319 |
with ih obtain p where "prime p" and "p dvd m" by blast |
|
320 |
with `n = m * k` have ?thesis by auto |
|
321 |
} |
|
322 |
ultimately show ?thesis by blast |
|
323 |
qed |
|
23983 | 324 |
qed |
325 |
||
31706 | 326 |
*) |
327 |
||
328 |
text {* One property of coprimality is easier to prove via prime factors. *} |
|
329 |
||
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
330 |
lemma prime_divprod_pow_nat: |
31706 | 331 |
assumes p: "prime (p::nat)" and ab: "coprime a b" and pab: "p^n dvd a * b" |
332 |
shows "p^n dvd a \<or> p^n dvd b" |
|
333 |
proof- |
|
44872 | 334 |
{ assume "n = 0 \<or> a = 1 \<or> b = 1" with pab have ?thesis |
31706 | 335 |
apply (cases "n=0", simp_all) |
44872 | 336 |
apply (cases "a=1", simp_all) |
337 |
done } |
|
31706 | 338 |
moreover |
44872 | 339 |
{ assume n: "n \<noteq> 0" and a: "a\<noteq>1" and b: "b\<noteq>1" |
340 |
then obtain m where m: "n = Suc m" by (cases n) auto |
|
341 |
from n have "p dvd p^n" apply (intro dvd_power) apply auto done |
|
31706 | 342 |
also note pab |
343 |
finally have pab': "p dvd a * b". |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
344 |
from prime_dvd_mult_nat[OF p pab'] |
31706 | 345 |
have "p dvd a \<or> p dvd b" . |
346 |
moreover |
|
33946 | 347 |
{ assume pa: "p dvd a" |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
348 |
from coprime_common_divisor_nat [OF ab, OF pa] p have "\<not> p dvd b" by auto |
31706 | 349 |
with p have "coprime b p" |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
350 |
by (subst gcd_commute_nat, intro prime_imp_coprime_nat) |
44872 | 351 |
then have pnb: "coprime (p^n) b" |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
352 |
by (subst gcd_commute_nat, rule coprime_exp_nat) |
33946 | 353 |
from coprime_dvd_mult_nat[OF pnb pab] have ?thesis by blast } |
31706 | 354 |
moreover |
33946 | 355 |
{ assume pb: "p dvd b" |
31706 | 356 |
have pnba: "p^n dvd b*a" using pab by (simp add: mult_commute) |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
357 |
from coprime_common_divisor_nat [OF ab, of p] pb p have "\<not> p dvd a" |
31706 | 358 |
by auto |
359 |
with p have "coprime a p" |
|
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
360 |
by (subst gcd_commute_nat, intro prime_imp_coprime_nat) |
44872 | 361 |
then have pna: "coprime (p^n) a" |
31952
40501bb2d57c
renamed lemmas: nat_xyz/int_xyz -> xyz_nat/xyz_int
nipkow
parents:
31814
diff
changeset
|
362 |
by (subst gcd_commute_nat, rule coprime_exp_nat) |
33946 | 363 |
from coprime_dvd_mult_nat[OF pna pnba] have ?thesis by blast } |
44872 | 364 |
ultimately have ?thesis by blast } |
31706 | 365 |
ultimately show ?thesis by blast |
23983 | 366 |
qed |
367 |
||
44872 | 368 |
|
32036
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
31952
diff
changeset
|
369 |
subsection {* Infinitely many primes *} |
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
31952
diff
changeset
|
370 |
|
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
31952
diff
changeset
|
371 |
lemma next_prime_bound: "\<exists>(p::nat). prime p \<and> n < p \<and> p <= fact n + 1" |
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
31952
diff
changeset
|
372 |
proof- |
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
31952
diff
changeset
|
373 |
have f1: "fact n + 1 \<noteq> 1" using fact_ge_one_nat [of n] by arith |
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
31952
diff
changeset
|
374 |
from prime_factor_nat [OF f1] |
44872 | 375 |
obtain p where "prime p" and "p dvd fact n + 1" by auto |
376 |
then have "p \<le> fact n + 1" apply (intro dvd_imp_le) apply auto done |
|
377 |
{ assume "p \<le> n" |
|
32036
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
31952
diff
changeset
|
378 |
from `prime p` have "p \<ge> 1" |
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
31952
diff
changeset
|
379 |
by (cases p, simp_all) |
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
31952
diff
changeset
|
380 |
with `p <= n` have "p dvd fact n" |
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
31952
diff
changeset
|
381 |
by (intro dvd_fact_nat) |
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
31952
diff
changeset
|
382 |
with `p dvd fact n + 1` have "p dvd fact n + 1 - fact n" |
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
31952
diff
changeset
|
383 |
by (rule dvd_diff_nat) |
44872 | 384 |
then have "p dvd 1" by simp |
385 |
then have "p <= 1" by auto |
|
32036
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
31952
diff
changeset
|
386 |
moreover from `prime p` have "p > 1" by auto |
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
31952
diff
changeset
|
387 |
ultimately have False by auto} |
44872 | 388 |
then have "n < p" by presburger |
32036
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
31952
diff
changeset
|
389 |
with `prime p` and `p <= fact n + 1` show ?thesis by auto |
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
31952
diff
changeset
|
390 |
qed |
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
31952
diff
changeset
|
391 |
|
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
31952
diff
changeset
|
392 |
lemma bigger_prime: "\<exists>p. prime p \<and> p > (n::nat)" |
44872 | 393 |
using next_prime_bound by auto |
32036
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
31952
diff
changeset
|
394 |
|
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
31952
diff
changeset
|
395 |
lemma primes_infinite: "\<not> (finite {(p::nat). prime p})" |
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
31952
diff
changeset
|
396 |
proof |
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
31952
diff
changeset
|
397 |
assume "finite {(p::nat). prime p}" |
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
31952
diff
changeset
|
398 |
with Max_ge have "(EX b. (ALL x : {(p::nat). prime p}. x <= b))" |
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
31952
diff
changeset
|
399 |
by auto |
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
31952
diff
changeset
|
400 |
then obtain b where "ALL (x::nat). prime x \<longrightarrow> x <= b" |
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
31952
diff
changeset
|
401 |
by auto |
44872 | 402 |
with bigger_prime [of b] show False |
403 |
by auto |
|
32036
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
31952
diff
changeset
|
404 |
qed |
8a9228872fbd
Moved factorial lemmas from Binomial.thy to Fact.thy and merged.
avigad
parents:
31952
diff
changeset
|
405 |
|
21256 | 406 |
end |