equal
deleted
inserted
replaced
7 |
7 |
8 theory Primes imports ZF begin |
8 theory Primes imports ZF begin |
9 |
9 |
10 definition |
10 definition |
11 divides :: "[i,i]=>o" (infixl \<open>dvd\<close> 50) where |
11 divides :: "[i,i]=>o" (infixl \<open>dvd\<close> 50) where |
12 "m dvd n \<equiv> m \<in> nat & n \<in> nat & (\<exists>k \<in> nat. n = m#*k)" |
12 "m dvd n \<equiv> m \<in> nat \<and> n \<in> nat \<and> (\<exists>k \<in> nat. n = m#*k)" |
13 |
13 |
14 definition |
14 definition |
15 is_gcd :: "[i,i,i]=>o" \<comment> \<open>definition of great common divisor\<close> where |
15 is_gcd :: "[i,i,i]=>o" \<comment> \<open>definition of great common divisor\<close> where |
16 "is_gcd(p,m,n) \<equiv> ((p dvd m) & (p dvd n)) & |
16 "is_gcd(p,m,n) \<equiv> ((p dvd m) \<and> (p dvd n)) \<and> |
17 (\<forall>d\<in>nat. (d dvd m) & (d dvd n) \<longrightarrow> d dvd p)" |
17 (\<forall>d\<in>nat. (d dvd m) \<and> (d dvd n) \<longrightarrow> d dvd p)" |
18 |
18 |
19 definition |
19 definition |
20 gcd :: "[i,i]=>i" \<comment> \<open>Euclid's algorithm for the gcd\<close> where |
20 gcd :: "[i,i]=>i" \<comment> \<open>Euclid's algorithm for the gcd\<close> where |
21 "gcd(m,n) \<equiv> transrec(natify(n), |
21 "gcd(m,n) \<equiv> transrec(natify(n), |
22 %n f. \<lambda>m \<in> nat. |
22 %n f. \<lambda>m \<in> nat. |
26 coprime :: "[i,i]=>o" \<comment> \<open>the coprime relation\<close> where |
26 coprime :: "[i,i]=>o" \<comment> \<open>the coprime relation\<close> where |
27 "coprime(m,n) \<equiv> gcd(m,n) = 1" |
27 "coprime(m,n) \<equiv> gcd(m,n) = 1" |
28 |
28 |
29 definition |
29 definition |
30 prime :: i \<comment> \<open>the set of prime numbers\<close> where |
30 prime :: i \<comment> \<open>the set of prime numbers\<close> where |
31 "prime \<equiv> {p \<in> nat. 1<p & (\<forall>m \<in> nat. m dvd p \<longrightarrow> m=1 | m=p)}" |
31 "prime \<equiv> {p \<in> nat. 1<p \<and> (\<forall>m \<in> nat. m dvd p \<longrightarrow> m=1 | m=p)}" |
32 |
32 |
33 |
33 |
34 subsection\<open>The Divides Relation\<close> |
34 subsection\<open>The Divides Relation\<close> |
35 |
35 |
36 lemma dvdD: "m dvd n \<Longrightarrow> m \<in> nat & n \<in> nat & (\<exists>k \<in> nat. n = m#*k)" |
36 lemma dvdD: "m dvd n \<Longrightarrow> m \<in> nat \<and> n \<in> nat \<and> (\<exists>k \<in> nat. n = m#*k)" |
37 by (unfold divides_def, assumption) |
37 by (unfold divides_def, assumption) |
38 |
38 |
39 lemma dvdE: |
39 lemma dvdE: |
40 "\<lbrakk>m dvd n; \<And>k. \<lbrakk>m \<in> nat; n \<in> nat; k \<in> nat; n = m#*k\<rbrakk> \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P" |
40 "\<lbrakk>m dvd n; \<And>k. \<lbrakk>m \<in> nat; n \<in> nat; k \<in> nat; n = m#*k\<rbrakk> \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P" |
41 by (blast dest!: dvdD) |
41 by (blast dest!: dvdD) |
174 |
174 |
175 |
175 |
176 text\<open>Property 1: gcd(a,b) divides a and b\<close> |
176 text\<open>Property 1: gcd(a,b) divides a and b\<close> |
177 |
177 |
178 lemma gcd_dvd_both: |
178 lemma gcd_dvd_both: |
179 "\<lbrakk>m \<in> nat; n \<in> nat\<rbrakk> \<Longrightarrow> gcd (m, n) dvd m & gcd (m, n) dvd n" |
179 "\<lbrakk>m \<in> nat; n \<in> nat\<rbrakk> \<Longrightarrow> gcd (m, n) dvd m \<and> gcd (m, n) dvd n" |
180 apply (rule_tac m = m and n = n in gcd_induct) |
180 apply (rule_tac m = m and n = n in gcd_induct) |
181 apply (simp_all add: gcd_non_0) |
181 apply (simp_all add: gcd_non_0) |
182 apply (blast intro: dvd_mod_imp_dvd_raw nat_into_Ord [THEN Ord_0_lt]) |
182 apply (blast intro: dvd_mod_imp_dvd_raw nat_into_Ord [THEN Ord_0_lt]) |
183 done |
183 done |
184 |
184 |
215 apply (rule gcd_greatest_raw) |
215 apply (rule gcd_greatest_raw) |
216 apply (auto simp add: divides_def) |
216 apply (auto simp add: divides_def) |
217 done |
217 done |
218 |
218 |
219 lemma gcd_greatest_iff [simp]: "\<lbrakk>k \<in> nat; m \<in> nat; n \<in> nat\<rbrakk> |
219 lemma gcd_greatest_iff [simp]: "\<lbrakk>k \<in> nat; m \<in> nat; n \<in> nat\<rbrakk> |
220 \<Longrightarrow> (k dvd gcd (m, n)) \<longleftrightarrow> (k dvd m & k dvd n)" |
220 \<Longrightarrow> (k dvd gcd (m, n)) \<longleftrightarrow> (k dvd m \<and> k dvd n)" |
221 by (blast intro!: gcd_greatest gcd_dvd1 gcd_dvd2 intro: dvd_trans) |
221 by (blast intro!: gcd_greatest gcd_dvd1 gcd_dvd2 intro: dvd_trans) |
222 |
222 |
223 |
223 |
224 subsection\<open>The Greatest Common Divisor\<close> |
224 subsection\<open>The Greatest Common Divisor\<close> |
225 |
225 |
385 apply (auto simp add: prime_def) |
385 apply (auto simp add: prime_def) |
386 done |
386 done |
387 |
387 |
388 lemma reduction: |
388 lemma reduction: |
389 "\<lbrakk>k#*k = p#*(j#*j); p \<in> prime; 0 < k; j \<in> nat; k \<in> nat\<rbrakk> |
389 "\<lbrakk>k#*k = p#*(j#*j); p \<in> prime; 0 < k; j \<in> nat; k \<in> nat\<rbrakk> |
390 \<Longrightarrow> k < p#*j & 0 < j" |
390 \<Longrightarrow> k < p#*j \<and> 0 < j" |
391 apply (rule ccontr) |
391 apply (rule ccontr) |
392 apply (simp add: not_lt_iff_le prime_into_nat) |
392 apply (simp add: not_lt_iff_le prime_into_nat) |
393 apply (erule disjE) |
393 apply (erule disjE) |
394 apply (frule mult_le_mono, assumption+) |
394 apply (frule mult_le_mono, assumption+) |
395 apply (simp add: mult_ac) |
395 apply (simp add: mult_ac) |