| author | wenzelm | 
| Sat, 17 Jun 2006 19:37:57 +0200 | |
| changeset 19915 | b08e26fb247e | 
| parent 19670 | 2e4a143c73c5 | 
| child 21404 | eb85850d3eb7 | 
| permissions | -rw-r--r-- | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 1 | (* Title: HOL/NumberTheory/EulerFermat.thy | 
| 9508 
4d01dbf6ded7
Chinese Remainder Theorem, Wilsons Theorem, etc., by T M Masmussen
 paulson parents: diff
changeset | 2 | ID: $Id$ | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 3 | Author: Thomas M. Rasmussen | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 4 | Copyright 2000 University of Cambridge | 
| 9508 
4d01dbf6ded7
Chinese Remainder Theorem, Wilsons Theorem, etc., by T M Masmussen
 paulson parents: diff
changeset | 5 | *) | 
| 
4d01dbf6ded7
Chinese Remainder Theorem, Wilsons Theorem, etc., by T M Masmussen
 paulson parents: diff
changeset | 6 | |
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 7 | header {* Fermat's Little Theorem extended to Euler's Totient function *}
 | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 8 | |
| 16417 | 9 | theory EulerFermat imports BijectionRel IntFact begin | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 10 | |
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 11 | text {*
 | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 12 | Fermat's Little Theorem extended to Euler's Totient function. More | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 13 | abstract approach than Boyer-Moore (which seems necessary to achieve | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 14 | the extended version). | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 15 | *} | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 16 | |
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 17 | |
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 18 | subsection {* Definitions and lemmas *}
 | 
| 9508 
4d01dbf6ded7
Chinese Remainder Theorem, Wilsons Theorem, etc., by T M Masmussen
 paulson parents: diff
changeset | 19 | |
| 
4d01dbf6ded7
Chinese Remainder Theorem, Wilsons Theorem, etc., by T M Masmussen
 paulson parents: diff
changeset | 20 | consts | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 21 | RsetR :: "int => int set set" | 
| 9508 
4d01dbf6ded7
Chinese Remainder Theorem, Wilsons Theorem, etc., by T M Masmussen
 paulson parents: diff
changeset | 22 | |
| 
4d01dbf6ded7
Chinese Remainder Theorem, Wilsons Theorem, etc., by T M Masmussen
 paulson parents: diff
changeset | 23 | inductive "RsetR m" | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 24 | intros | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 25 |     empty [simp]: "{} \<in> RsetR m"
 | 
| 11868 
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
 paulson parents: 
11704diff
changeset | 26 | insert: "A \<in> RsetR m ==> zgcd (a, m) = 1 ==> | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 27 | \<forall>a'. a' \<in> A --> \<not> zcong a a' m ==> insert a A \<in> RsetR m" | 
| 9508 
4d01dbf6ded7
Chinese Remainder Theorem, Wilsons Theorem, etc., by T M Masmussen
 paulson parents: diff
changeset | 28 | |
| 19670 | 29 | consts | 
| 30 | BnorRset :: "int * int => int set" | |
| 31 | ||
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 32 | recdef BnorRset | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 33 | "measure ((\<lambda>(a, m). nat a) :: int * int => nat)" | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 34 | "BnorRset (a, m) = | 
| 11868 
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
 paulson parents: 
11704diff
changeset | 35 | (if 0 < a then | 
| 
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
 paulson parents: 
11704diff
changeset | 36 | let na = BnorRset (a - 1, m) | 
| 
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
 paulson parents: 
11704diff
changeset | 37 | in (if zgcd (a, m) = 1 then insert a na else na) | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 38 |     else {})"
 | 
| 9508 
4d01dbf6ded7
Chinese Remainder Theorem, Wilsons Theorem, etc., by T M Masmussen
 paulson parents: diff
changeset | 39 | |
| 19670 | 40 | definition | 
| 41 | norRRset :: "int => int set" | |
| 42 | "norRRset m = BnorRset (m - 1, m)" | |
| 43 | ||
| 44 | noXRRset :: "int => int => int set" | |
| 45 | "noXRRset m x = (\<lambda>a. a * x) ` norRRset m" | |
| 46 | ||
| 47 | phi :: "int => nat" | |
| 48 | "phi m = card (norRRset m)" | |
| 49 | ||
| 50 | is_RRset :: "int set => int => bool" | |
| 51 | "is_RRset A m = (A \<in> RsetR m \<and> card A = phi m)" | |
| 52 | ||
| 53 | RRset2norRR :: "int set => int => int => int" | |
| 54 | "RRset2norRR A m a = | |
| 11868 
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
 paulson parents: 
11704diff
changeset | 55 | (if 1 < m \<and> is_RRset A m \<and> a \<in> A then | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 56 | SOME b. zcong a b m \<and> b \<in> norRRset m | 
| 11868 
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
 paulson parents: 
11704diff
changeset | 57 | else 0)" | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 58 | |
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 59 | zcongm :: "int => int => int => bool" | 
| 19670 | 60 | "zcongm m = (\<lambda>a b. zcong a b m)" | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 61 | |
| 11868 
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
 paulson parents: 
11704diff
changeset | 62 | lemma abs_eq_1_iff [iff]: "(abs z = (1::int)) = (z = 1 \<or> z = -1)" | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 63 |   -- {* LCP: not sure why this lemma is needed now *}
 | 
| 18369 | 64 | by (auto simp add: abs_if) | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 65 | |
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 66 | |
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 67 | text {* \medskip @{text norRRset} *}
 | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 68 | |
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 69 | declare BnorRset.simps [simp del] | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 70 | |
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 71 | lemma BnorRset_induct: | 
| 18369 | 72 |   assumes "!!a m. P {} a m"
 | 
| 73 | and "!!a m. 0 < (a::int) ==> P (BnorRset (a - 1, m::int)) (a - 1) m | |
| 74 | ==> P (BnorRset(a,m)) a m" | |
| 75 | shows "P (BnorRset(u,v)) u v" | |
| 76 | apply (rule BnorRset.induct) | |
| 77 | apply safe | |
| 78 | apply (case_tac [2] "0 < a") | |
| 79 | apply (rule_tac [2] prems) | |
| 80 | apply simp_all | |
| 81 | apply (simp_all add: BnorRset.simps prems) | |
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 82 | done | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 83 | |
| 18369 | 84 | lemma Bnor_mem_zle [rule_format]: "b \<in> BnorRset (a, m) \<longrightarrow> b \<le> a" | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 85 | apply (induct a m rule: BnorRset_induct) | 
| 18369 | 86 | apply simp | 
| 87 | apply (subst BnorRset.simps) | |
| 13833 | 88 | apply (unfold Let_def, auto) | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 89 | done | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 90 | |
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 91 | lemma Bnor_mem_zle_swap: "a < b ==> b \<notin> BnorRset (a, m)" | 
| 18369 | 92 | by (auto dest: Bnor_mem_zle) | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 93 | |
| 11868 
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
 paulson parents: 
11704diff
changeset | 94 | lemma Bnor_mem_zg [rule_format]: "b \<in> BnorRset (a, m) --> 0 < b" | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 95 | apply (induct a m rule: BnorRset_induct) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 96 | prefer 2 | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 97 | apply (subst BnorRset.simps) | 
| 13833 | 98 | apply (unfold Let_def, auto) | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 99 | done | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 100 | |
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 101 | lemma Bnor_mem_if [rule_format]: | 
| 11868 
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
 paulson parents: 
11704diff
changeset | 102 | "zgcd (b, m) = 1 --> 0 < b --> b \<le> a --> b \<in> BnorRset (a, m)" | 
| 13833 | 103 | apply (induct a m rule: BnorRset.induct, auto) | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 104 | apply (subst BnorRset.simps) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 105 | defer | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 106 | apply (subst BnorRset.simps) | 
| 13833 | 107 | apply (unfold Let_def, auto) | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 108 | done | 
| 9508 
4d01dbf6ded7
Chinese Remainder Theorem, Wilsons Theorem, etc., by T M Masmussen
 paulson parents: diff
changeset | 109 | |
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 110 | lemma Bnor_in_RsetR [rule_format]: "a < m --> BnorRset (a, m) \<in> RsetR m" | 
| 13833 | 111 | apply (induct a m rule: BnorRset_induct, simp) | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 112 | apply (subst BnorRset.simps) | 
| 13833 | 113 | apply (unfold Let_def, auto) | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 114 | apply (rule RsetR.insert) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 115 | apply (rule_tac [3] allI) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 116 | apply (rule_tac [3] impI) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 117 | apply (rule_tac [3] zcong_not) | 
| 11868 
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
 paulson parents: 
11704diff
changeset | 118 | apply (subgoal_tac [6] "a' \<le> a - 1") | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 119 | apply (rule_tac [7] Bnor_mem_zle) | 
| 13833 | 120 | apply (rule_tac [5] Bnor_mem_zg, auto) | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 121 | done | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 122 | |
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 123 | lemma Bnor_fin: "finite (BnorRset (a, m))" | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 124 | apply (induct a m rule: BnorRset_induct) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 125 | prefer 2 | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 126 | apply (subst BnorRset.simps) | 
| 13833 | 127 | apply (unfold Let_def, auto) | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 128 | done | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 129 | |
| 13524 | 130 | lemma norR_mem_unique_aux: "a \<le> b - 1 ==> a < (b::int)" | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 131 | apply auto | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 132 | done | 
| 9508 
4d01dbf6ded7
Chinese Remainder Theorem, Wilsons Theorem, etc., by T M Masmussen
 paulson parents: diff
changeset | 133 | |
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 134 | lemma norR_mem_unique: | 
| 11868 
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
 paulson parents: 
11704diff
changeset | 135 | "1 < m ==> | 
| 
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
 paulson parents: 
11704diff
changeset | 136 | zgcd (a, m) = 1 ==> \<exists>!b. [a = b] (mod m) \<and> b \<in> norRRset m" | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 137 | apply (unfold norRRset_def) | 
| 13833 | 138 | apply (cut_tac a = a and m = m in zcong_zless_unique, auto) | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 139 | apply (rule_tac [2] m = m in zcong_zless_imp_eq) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 140 | apply (auto intro: Bnor_mem_zle Bnor_mem_zg zcong_trans | 
| 13524 | 141 | order_less_imp_le norR_mem_unique_aux simp add: zcong_sym) | 
| 14174 
f3cafd2929d5
Methods rule_tac etc support static (Isar) contexts.
 ballarin parents: 
13833diff
changeset | 142 | apply (rule_tac x = b in exI, safe) | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 143 | apply (rule Bnor_mem_if) | 
| 11868 
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
 paulson parents: 
11704diff
changeset | 144 | apply (case_tac [2] "b = 0") | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 145 | apply (auto intro: order_less_le [THEN iffD2]) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 146 | prefer 2 | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 147 | apply (simp only: zcong_def) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 148 | apply (subgoal_tac "zgcd (a, m) = m") | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 149 | prefer 2 | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 150 | apply (subst zdvd_iff_zgcd [symmetric]) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 151 | apply (rule_tac [4] zgcd_zcong_zgcd) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 152 | apply (simp_all add: zdvd_zminus_iff zcong_sym) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 153 | done | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 154 | |
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 155 | |
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 156 | text {* \medskip @{term noXRRset} *}
 | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 157 | |
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 158 | lemma RRset_gcd [rule_format]: | 
| 11868 
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
 paulson parents: 
11704diff
changeset | 159 | "is_RRset A m ==> a \<in> A --> zgcd (a, m) = 1" | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 160 | apply (unfold is_RRset_def) | 
| 13833 | 161 | apply (rule RsetR.induct, auto) | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 162 | done | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 163 | |
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 164 | lemma RsetR_zmult_mono: | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 165 | "A \<in> RsetR m ==> | 
| 11868 
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
 paulson parents: 
11704diff
changeset | 166 | 0 < m ==> zgcd (x, m) = 1 ==> (\<lambda>a. a * x) ` A \<in> RsetR m" | 
| 13833 | 167 | apply (erule RsetR.induct, simp_all) | 
| 168 | apply (rule RsetR.insert, auto) | |
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 169 | apply (blast intro: zgcd_zgcd_zmult) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 170 | apply (simp add: zcong_cancel) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 171 | done | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 172 | |
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 173 | lemma card_nor_eq_noX: | 
| 11868 
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
 paulson parents: 
11704diff
changeset | 174 | "0 < m ==> | 
| 
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
 paulson parents: 
11704diff
changeset | 175 | zgcd (x, m) = 1 ==> card (noXRRset m x) = card (norRRset m)" | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 176 | apply (unfold norRRset_def noXRRset_def) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 177 | apply (rule card_image) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 178 | apply (auto simp add: inj_on_def Bnor_fin) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 179 | apply (simp add: BnorRset.simps) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 180 | done | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 181 | |
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 182 | lemma noX_is_RRset: | 
| 11868 
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
 paulson parents: 
11704diff
changeset | 183 | "0 < m ==> zgcd (x, m) = 1 ==> is_RRset (noXRRset m x) m" | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 184 | apply (unfold is_RRset_def phi_def) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 185 | apply (auto simp add: card_nor_eq_noX) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 186 | apply (unfold noXRRset_def norRRset_def) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 187 | apply (rule RsetR_zmult_mono) | 
| 13833 | 188 | apply (rule Bnor_in_RsetR, simp_all) | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 189 | done | 
| 9508 
4d01dbf6ded7
Chinese Remainder Theorem, Wilsons Theorem, etc., by T M Masmussen
 paulson parents: diff
changeset | 190 | |
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 191 | lemma aux_some: | 
| 11868 
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
 paulson parents: 
11704diff
changeset | 192 | "1 < m ==> is_RRset A m ==> a \<in> A | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 193 | ==> zcong a (SOME b. [a = b] (mod m) \<and> b \<in> norRRset m) m \<and> | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 194 | (SOME b. [a = b] (mod m) \<and> b \<in> norRRset m) \<in> norRRset m" | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 195 | apply (rule norR_mem_unique [THEN ex1_implies_ex, THEN someI_ex]) | 
| 13833 | 196 | apply (rule_tac [2] RRset_gcd, simp_all) | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 197 | done | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 198 | |
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 199 | lemma RRset2norRR_correct: | 
| 11868 
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
 paulson parents: 
11704diff
changeset | 200 | "1 < m ==> is_RRset A m ==> a \<in> A ==> | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 201 | [a = RRset2norRR A m a] (mod m) \<and> RRset2norRR A m a \<in> norRRset m" | 
| 13833 | 202 | apply (unfold RRset2norRR_def, simp) | 
| 203 | apply (rule aux_some, simp_all) | |
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 204 | done | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 205 | |
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 206 | lemmas RRset2norRR_correct1 = | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 207 | RRset2norRR_correct [THEN conjunct1, standard] | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 208 | lemmas RRset2norRR_correct2 = | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 209 | RRset2norRR_correct [THEN conjunct2, standard] | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 210 | |
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 211 | lemma RsetR_fin: "A \<in> RsetR m ==> finite A" | 
| 18369 | 212 | by (induct set: RsetR) auto | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 213 | |
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 214 | lemma RRset_zcong_eq [rule_format]: | 
| 11868 
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
 paulson parents: 
11704diff
changeset | 215 | "1 < m ==> | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 216 | is_RRset A m ==> [a = b] (mod m) ==> a \<in> A --> b \<in> A --> a = b" | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 217 | apply (unfold is_RRset_def) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 218 | apply (rule RsetR.induct) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 219 | apply (auto simp add: zcong_sym) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 220 | done | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 221 | |
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 222 | lemma aux: | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 223 | "P (SOME a. P a) ==> Q (SOME a. Q a) ==> | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 224 | (SOME a. P a) = (SOME a. Q a) ==> \<exists>a. P a \<and> Q a" | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 225 | apply auto | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 226 | done | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 227 | |
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 228 | lemma RRset2norRR_inj: | 
| 11868 
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
 paulson parents: 
11704diff
changeset | 229 | "1 < m ==> is_RRset A m ==> inj_on (RRset2norRR A m) A" | 
| 13833 | 230 | apply (unfold RRset2norRR_def inj_on_def, auto) | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 231 | apply (subgoal_tac "\<exists>b. ([x = b] (mod m) \<and> b \<in> norRRset m) \<and> | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 232 | ([y = b] (mod m) \<and> b \<in> norRRset m)") | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 233 | apply (rule_tac [2] aux) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 234 | apply (rule_tac [3] aux_some) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 235 | apply (rule_tac [2] aux_some) | 
| 13833 | 236 | apply (rule RRset_zcong_eq, auto) | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 237 | apply (rule_tac b = b in zcong_trans) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 238 | apply (simp_all add: zcong_sym) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 239 | done | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 240 | |
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 241 | lemma RRset2norRR_eq_norR: | 
| 11868 
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
 paulson parents: 
11704diff
changeset | 242 | "1 < m ==> is_RRset A m ==> RRset2norRR A m ` A = norRRset m" | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 243 | apply (rule card_seteq) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 244 | prefer 3 | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 245 | apply (subst card_image) | 
| 15402 | 246 | apply (rule_tac RRset2norRR_inj, auto) | 
| 247 | apply (rule_tac [3] RRset2norRR_correct2, auto) | |
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 248 | apply (unfold is_RRset_def phi_def norRRset_def) | 
| 15402 | 249 | apply (auto simp add: Bnor_fin) | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 250 | done | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 251 | |
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 252 | |
| 13524 | 253 | lemma Bnor_prod_power_aux: "a \<notin> A ==> inj f ==> f a \<notin> f ` A" | 
| 13833 | 254 | by (unfold inj_on_def, auto) | 
| 9508 
4d01dbf6ded7
Chinese Remainder Theorem, Wilsons Theorem, etc., by T M Masmussen
 paulson parents: diff
changeset | 255 | |
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 256 | lemma Bnor_prod_power [rule_format]: | 
| 15392 | 257 | "x \<noteq> 0 ==> a < m --> \<Prod>((\<lambda>a. a * x) ` BnorRset (a, m)) = | 
| 258 | \<Prod>(BnorRset(a, m)) * x^card (BnorRset (a, m))" | |
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 259 | apply (induct a m rule: BnorRset_induct) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 260 | prefer 2 | 
| 15481 | 261 |    apply (simplesubst BnorRset.simps)  --{*multiple redexes*}
 | 
| 13833 | 262 | apply (unfold Let_def, auto) | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 263 | apply (simp add: Bnor_fin Bnor_mem_zle_swap) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 264 | apply (subst setprod_insert) | 
| 13524 | 265 | apply (rule_tac [2] Bnor_prod_power_aux) | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 266 | apply (unfold inj_on_def) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 267 | apply (simp_all add: zmult_ac Bnor_fin finite_imageI | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 268 | Bnor_mem_zle_swap) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 269 | done | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 270 | |
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 271 | |
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 272 | subsection {* Fermat *}
 | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 273 | |
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 274 | lemma bijzcong_zcong_prod: | 
| 15392 | 275 | "(A, B) \<in> bijR (zcongm m) ==> [\<Prod>A = \<Prod>B] (mod m)" | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 276 | apply (unfold zcongm_def) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 277 | apply (erule bijR.induct) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 278 | apply (subgoal_tac [2] "a \<notin> A \<and> b \<notin> B \<and> finite A \<and> finite B") | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 279 | apply (auto intro: fin_bijRl fin_bijRr zcong_zmult) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 280 | done | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 281 | |
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 282 | lemma Bnor_prod_zgcd [rule_format]: | 
| 15392 | 283 | "a < m --> zgcd (\<Prod>(BnorRset(a, m)), m) = 1" | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 284 | apply (induct a m rule: BnorRset_induct) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 285 | prefer 2 | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 286 | apply (subst BnorRset.simps) | 
| 13833 | 287 | apply (unfold Let_def, auto) | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 288 | apply (simp add: Bnor_fin Bnor_mem_zle_swap) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 289 | apply (blast intro: zgcd_zgcd_zmult) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 290 | done | 
| 9508 
4d01dbf6ded7
Chinese Remainder Theorem, Wilsons Theorem, etc., by T M Masmussen
 paulson parents: diff
changeset | 291 | |
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 292 | theorem Euler_Fermat: | 
| 11868 
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
 paulson parents: 
11704diff
changeset | 293 | "0 < m ==> zgcd (x, m) = 1 ==> [x^(phi m) = 1] (mod m)" | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 294 | apply (unfold norRRset_def phi_def) | 
| 11868 
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
 paulson parents: 
11704diff
changeset | 295 | apply (case_tac "x = 0") | 
| 
56db9f3a6b3e
Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
 paulson parents: 
11704diff
changeset | 296 | apply (case_tac [2] "m = 1") | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 297 | apply (rule_tac [3] iffD1) | 
| 15392 | 298 | apply (rule_tac [3] k = "\<Prod>(BnorRset(m - 1, m))" | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 299 | in zcong_cancel2) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 300 | prefer 5 | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 301 | apply (subst Bnor_prod_power [symmetric]) | 
| 13833 | 302 | apply (rule_tac [7] Bnor_prod_zgcd, simp_all) | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 303 | apply (rule bijzcong_zcong_prod) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 304 | apply (fold norRRset_def noXRRset_def) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 305 | apply (subst RRset2norRR_eq_norR [symmetric]) | 
| 13833 | 306 | apply (rule_tac [3] inj_func_bijR, auto) | 
| 13187 | 307 | apply (unfold zcongm_def) | 
| 308 | apply (rule_tac [2] RRset2norRR_correct1) | |
| 309 | apply (rule_tac [5] RRset2norRR_inj) | |
| 310 | apply (auto intro: order_less_le [THEN iffD2] | |
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 311 | simp add: noX_is_RRset) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 312 | apply (unfold noXRRset_def norRRset_def) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 313 | apply (rule finite_imageI) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 314 | apply (rule Bnor_fin) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 315 | done | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 316 | |
| 16733 
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
 nipkow parents: 
16663diff
changeset | 317 | lemma Bnor_prime: | 
| 
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
 nipkow parents: 
16663diff
changeset | 318 | "\<lbrakk> zprime p; a < p \<rbrakk> \<Longrightarrow> card (BnorRset (a, p)) = nat a" | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 319 | apply (induct a p rule: BnorRset.induct) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 320 | apply (subst BnorRset.simps) | 
| 16733 
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
 nipkow parents: 
16663diff
changeset | 321 | apply (unfold Let_def, auto simp add:zless_zprime_imp_zrelprime) | 
| 13833 | 322 | apply (subgoal_tac "finite (BnorRset (a - 1,m))") | 
| 323 | apply (subgoal_tac "a ~: BnorRset (a - 1,m)") | |
| 324 | apply (auto simp add: card_insert_disjoint Suc_nat_eq_nat_zadd1) | |
| 325 | apply (frule Bnor_mem_zle, arith) | |
| 326 | apply (frule Bnor_fin) | |
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 327 | done | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 328 | |
| 16663 | 329 | lemma phi_prime: "zprime p ==> phi p = nat (p - 1)" | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 330 | apply (unfold phi_def norRRset_def) | 
| 13833 | 331 | apply (rule Bnor_prime, auto) | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 332 | done | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 333 | |
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 334 | theorem Little_Fermat: | 
| 16663 | 335 | "zprime p ==> \<not> p dvd x ==> [x^(nat (p - 1)) = 1] (mod p)" | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 336 | apply (subst phi_prime [symmetric]) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 337 | apply (rule_tac [2] Euler_Fermat) | 
| 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 338 | apply (erule_tac [3] zprime_imp_zrelprime) | 
| 13833 | 339 | apply (unfold zprime_def, auto) | 
| 11049 
7eef34adb852
HOL-NumberTheory: converted to new-style format and proper document setup;
 wenzelm parents: 
10834diff
changeset | 340 | done | 
| 9508 
4d01dbf6ded7
Chinese Remainder Theorem, Wilsons Theorem, etc., by T M Masmussen
 paulson parents: diff
changeset | 341 | |
| 
4d01dbf6ded7
Chinese Remainder Theorem, Wilsons Theorem, etc., by T M Masmussen
 paulson parents: diff
changeset | 342 | end |