equal
deleted
inserted
replaced
1 (* Title: HOL/Old_Number_Theory/WilsonRuss.thy |
1 (* Title: HOL/Old_Number_Theory/WilsonRuss.thy |
2 Author: Thomas M. Rasmussen |
2 Author: Thomas M. Rasmussen |
3 Copyright 2000 University of Cambridge |
3 Copyright 2000 University of Cambridge |
4 *) |
4 *) |
5 |
5 |
6 section {* Wilson's Theorem according to Russinoff *} |
6 section \<open>Wilson's Theorem according to Russinoff\<close> |
7 |
7 |
8 theory WilsonRuss |
8 theory WilsonRuss |
9 imports EulerFermat |
9 imports EulerFermat |
10 begin |
10 begin |
11 |
11 |
12 text {* |
12 text \<open> |
13 Wilson's Theorem following quite closely Russinoff's approach |
13 Wilson's Theorem following quite closely Russinoff's approach |
14 using Boyer-Moore (using finite sets instead of lists, though). |
14 using Boyer-Moore (using finite sets instead of lists, though). |
15 *} |
15 \<close> |
16 |
16 |
17 subsection {* Definitions and lemmas *} |
17 subsection \<open>Definitions and lemmas\<close> |
18 |
18 |
19 definition inv :: "int => int => int" |
19 definition inv :: "int => int => int" |
20 where "inv p a = (a^(nat (p - 2))) mod p" |
20 where "inv p a = (a^(nat (p - 2))) mod p" |
21 |
21 |
22 fun wset :: "int \<Rightarrow> int => int set" where |
22 fun wset :: "int \<Rightarrow> int => int set" where |
24 (if 1 < a then |
24 (if 1 < a then |
25 let ws = wset (a - 1) p |
25 let ws = wset (a - 1) p |
26 in (if a \<in> ws then ws else insert a (insert (inv p a) ws)) else {})" |
26 in (if a \<in> ws then ws else insert a (insert (inv p a) ws)) else {})" |
27 |
27 |
28 |
28 |
29 text {* \medskip @{term [source] inv} *} |
29 text \<open>\medskip @{term [source] inv}\<close> |
30 |
30 |
31 lemma inv_is_inv_aux: "1 < m ==> Suc (nat (m - 2)) = nat (m - 1)" |
31 lemma inv_is_inv_aux: "1 < m ==> Suc (nat (m - 2)) = nat (m - 1)" |
32 by (subst int_int_eq [symmetric]) auto |
32 by (subst int_int_eq [symmetric]) auto |
33 |
33 |
34 lemma inv_is_inv: |
34 lemma inv_is_inv: |
147 apply (erule_tac [4] Little_Fermat) |
147 apply (erule_tac [4] Little_Fermat) |
148 apply (rule_tac [4] zdvd_not_zless, simp_all) |
148 apply (rule_tac [4] zdvd_not_zless, simp_all) |
149 done |
149 done |
150 |
150 |
151 |
151 |
152 text {* \medskip @{term wset} *} |
152 text \<open>\medskip @{term wset}\<close> |
153 |
153 |
154 declare wset.simps [simp del] |
154 declare wset.simps [simp del] |
155 |
155 |
156 lemma wset_induct: |
156 lemma wset_induct: |
157 assumes "!!a p. P {} a p" |
157 assumes "!!a p. P {} a p" |
250 apply (induct a p rule: wset_induct) |
250 apply (induct a p rule: wset_induct) |
251 prefer 2 |
251 prefer 2 |
252 apply (subst wset.simps) |
252 apply (subst wset.simps) |
253 apply (auto, unfold Let_def, auto) |
253 apply (auto, unfold Let_def, auto) |
254 apply (subst setprod.insert) |
254 apply (subst setprod.insert) |
255 apply (tactic {* stac @{context} @{thm setprod.insert} 3 *}) |
255 apply (tactic \<open>stac @{context} @{thm setprod.insert} 3\<close>) |
256 apply (subgoal_tac [5] |
256 apply (subgoal_tac [5] |
257 "zcong (a * inv p a * (\<Prod>x\<in>wset (a - 1) p. x)) (1 * 1) p") |
257 "zcong (a * inv p a * (\<Prod>x\<in>wset (a - 1) p. x)) (1 * 1) p") |
258 prefer 5 |
258 prefer 5 |
259 apply (simp add: mult.assoc) |
259 apply (simp add: mult.assoc) |
260 apply (rule_tac [5] zcong_zmult) |
260 apply (rule_tac [5] zcong_zmult) |
279 apply (simp (no_asm_simp)) |
279 apply (simp (no_asm_simp)) |
280 apply (erule wset_less, auto) |
280 apply (erule wset_less, auto) |
281 done |
281 done |
282 |
282 |
283 |
283 |
284 subsection {* Wilson *} |
284 subsection \<open>Wilson\<close> |
285 |
285 |
286 lemma prime_g_5: "zprime p \<Longrightarrow> p \<noteq> 2 \<Longrightarrow> p \<noteq> 3 ==> 5 \<le> p" |
286 lemma prime_g_5: "zprime p \<Longrightarrow> p \<noteq> 2 \<Longrightarrow> p \<noteq> 3 ==> 5 \<le> p" |
287 apply (unfold zprime_def dvd_def) |
287 apply (unfold zprime_def dvd_def) |
288 apply (case_tac "p = 4", auto) |
288 apply (case_tac "p = 4", auto) |
289 apply (rule notE) |
289 apply (rule notE) |