author | blanchet |
Mon, 23 Aug 2010 12:13:58 +0200 | |
changeset 38649 | 14c207135eff |
parent 38159 | e9b4835a54ee |
child 40786 | 0a54cfc9add3 |
permissions | -rw-r--r-- |
38159 | 1 |
(* Title: HOL/Old_Number_Theory/Euler.thy |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
2 |
Authors: Jeremy Avigad, David Gray, and Adam Kramer |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
3 |
*) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
4 |
|
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
5 |
header {* Euler's criterion *} |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
6 |
|
38159 | 7 |
theory Euler |
8 |
imports Residues EvenOdd |
|
9 |
begin |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
10 |
|
38159 | 11 |
definition MultInvPair :: "int => int => int => int set" |
12 |
where "MultInvPair a p j = {StandardRes p j, StandardRes p (a * (MultInv p j))}" |
|
19670 | 13 |
|
38159 | 14 |
definition SetS :: "int => int => int set set" |
15 |
where "SetS a p = MultInvPair a p ` SRStar p" |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
16 |
|
19670 | 17 |
|
18 |
subsection {* Property for MultInvPair *} |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
19 |
|
19670 | 20 |
lemma MultInvPair_prop1a: |
21 |
"[| zprime p; 2 < p; ~([a = 0](mod p)); |
|
22 |
X \<in> (SetS a p); Y \<in> (SetS a p); |
|
23 |
~((X \<inter> Y) = {}) |] ==> X = Y" |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
24 |
apply (auto simp add: SetS_def) |
16974 | 25 |
apply (drule StandardRes_SRStar_prop1a)+ defer 1 |
26 |
apply (drule StandardRes_SRStar_prop1a)+ |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
27 |
apply (auto simp add: MultInvPair_def StandardRes_prop2 zcong_sym) |
20369 | 28 |
apply (drule notE, rule MultInv_zcong_prop1, auto)[] |
29 |
apply (drule notE, rule MultInv_zcong_prop2, auto simp add: zcong_sym)[] |
|
30 |
apply (drule MultInv_zcong_prop2, auto simp add: zcong_sym)[] |
|
31 |
apply (drule MultInv_zcong_prop3, auto simp add: zcong_sym)[] |
|
32 |
apply (drule MultInv_zcong_prop1, auto)[] |
|
33 |
apply (drule MultInv_zcong_prop2, auto simp add: zcong_sym)[] |
|
34 |
apply (drule MultInv_zcong_prop2, auto simp add: zcong_sym)[] |
|
35 |
apply (drule MultInv_zcong_prop3, auto simp add: zcong_sym)[] |
|
19670 | 36 |
done |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
37 |
|
19670 | 38 |
lemma MultInvPair_prop1b: |
39 |
"[| zprime p; 2 < p; ~([a = 0](mod p)); |
|
40 |
X \<in> (SetS a p); Y \<in> (SetS a p); |
|
41 |
X \<noteq> Y |] ==> X \<inter> Y = {}" |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
42 |
apply (rule notnotD) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
43 |
apply (rule notI) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
44 |
apply (drule MultInvPair_prop1a, auto) |
19670 | 45 |
done |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
46 |
|
16663 | 47 |
lemma MultInvPair_prop1c: "[| zprime p; 2 < p; ~([a = 0](mod p)) |] ==> |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
48 |
\<forall>X \<in> SetS a p. \<forall>Y \<in> SetS a p. X \<noteq> Y --> X\<inter>Y = {}" |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
49 |
by (auto simp add: MultInvPair_prop1b) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
50 |
|
16663 | 51 |
lemma MultInvPair_prop2: "[| zprime p; 2 < p; ~([a = 0](mod p)) |] ==> |
16974 | 52 |
Union ( SetS a p) = SRStar p" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
53 |
apply (auto simp add: SetS_def MultInvPair_def StandardRes_SRStar_prop4 |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
54 |
SRStar_mult_prop2) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
55 |
apply (frule StandardRes_SRStar_prop3) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
56 |
apply (rule bexI, auto) |
19670 | 57 |
done |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
58 |
|
16663 | 59 |
lemma MultInvPair_distinct: "[| zprime p; 2 < p; ~([a = 0] (mod p)); |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
60 |
~([j = 0] (mod p)); |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
61 |
~(QuadRes p a) |] ==> |
16974 | 62 |
~([j = a * MultInv p j] (mod p))" |
20369 | 63 |
proof |
16663 | 64 |
assume "zprime p" and "2 < p" and "~([a = 0] (mod p))" and |
16974 | 65 |
"~([j = 0] (mod p))" and "~(QuadRes p a)" |
66 |
assume "[j = a * MultInv p j] (mod p)" |
|
67 |
then have "[j * j = (a * MultInv p j) * j] (mod p)" |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
68 |
by (auto simp add: zcong_scalar) |
16974 | 69 |
then have a:"[j * j = a * (MultInv p j * j)] (mod p)" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
70 |
by (auto simp add: zmult_ac) |
16974 | 71 |
have "[j * j = a] (mod p)" |
72 |
proof - |
|
73 |
from prems have b: "[MultInv p j * j = 1] (mod p)" |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
74 |
by (simp add: MultInv_prop2a) |
16974 | 75 |
from b a show ?thesis |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
76 |
by (auto simp add: zcong_zmult_prop2) |
16974 | 77 |
qed |
78 |
then have "[j^2 = a] (mod p)" |
|
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25760
diff
changeset
|
79 |
by (metis number_of_is_id power2_eq_square succ_bin_simps) |
16974 | 80 |
with prems show False |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
81 |
by (simp add: QuadRes_def) |
16974 | 82 |
qed |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
83 |
|
16663 | 84 |
lemma MultInvPair_card_two: "[| zprime p; 2 < p; ~([a = 0] (mod p)); |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
85 |
~(QuadRes p a); ~([j = 0] (mod p)) |] ==> |
16974 | 86 |
card (MultInvPair a p j) = 2" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
87 |
apply (auto simp add: MultInvPair_def) |
16974 | 88 |
apply (subgoal_tac "~ (StandardRes p j = StandardRes p (a * MultInv p j))") |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
89 |
apply auto |
26510 | 90 |
apply (metis MultInvPair_distinct Pls_def StandardRes_def aux number_of_is_id one_is_num_one) |
20369 | 91 |
done |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
92 |
|
19670 | 93 |
|
94 |
subsection {* Properties of SetS *} |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
95 |
|
16974 | 96 |
lemma SetS_finite: "2 < p ==> finite (SetS a p)" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
97 |
by (auto simp add: SetS_def SRStar_finite [of p] finite_imageI) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
98 |
|
16974 | 99 |
lemma SetS_elems_finite: "\<forall>X \<in> SetS a p. finite X" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
100 |
by (auto simp add: SetS_def MultInvPair_def) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
101 |
|
16663 | 102 |
lemma SetS_elems_card: "[| zprime p; 2 < p; ~([a = 0] (mod p)); |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
103 |
~(QuadRes p a) |] ==> |
16974 | 104 |
\<forall>X \<in> SetS a p. card X = 2" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
105 |
apply (auto simp add: SetS_def) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
106 |
apply (frule StandardRes_SRStar_prop1a) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
107 |
apply (rule MultInvPair_card_two, auto) |
19670 | 108 |
done |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
109 |
|
16974 | 110 |
lemma Union_SetS_finite: "2 < p ==> finite (Union (SetS a p))" |
15402 | 111 |
by (auto simp add: SetS_finite SetS_elems_finite finite_Union) |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
112 |
|
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
113 |
lemma card_setsum_aux: "[| finite S; \<forall>X \<in> S. finite (X::int set); |
16974 | 114 |
\<forall>X \<in> S. card X = n |] ==> setsum card S = setsum (%x. n) S" |
22274 | 115 |
by (induct set: finite) auto |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
116 |
|
16663 | 117 |
lemma SetS_card: "[| zprime p; 2 < p; ~([a = 0] (mod p)); ~(QuadRes p a) |] ==> |
16974 | 118 |
int(card(SetS a p)) = (p - 1) div 2" |
119 |
proof - |
|
120 |
assume "zprime p" and "2 < p" and "~([a = 0] (mod p))" and "~(QuadRes p a)" |
|
121 |
then have "(p - 1) = 2 * int(card(SetS a p))" |
|
122 |
proof - |
|
123 |
have "p - 1 = int(card(Union (SetS a p)))" |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
124 |
by (auto simp add: prems MultInvPair_prop2 SRStar_card) |
16974 | 125 |
also have "... = int (setsum card (SetS a p))" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
126 |
by (auto simp add: prems SetS_finite SetS_elems_finite |
15402 | 127 |
MultInvPair_prop1c [of p a] card_Union_disjoint) |
16974 | 128 |
also have "... = int(setsum (%x.2) (SetS a p))" |
19670 | 129 |
using prems |
130 |
by (auto simp add: SetS_elems_card SetS_finite SetS_elems_finite |
|
15047 | 131 |
card_setsum_aux simp del: setsum_constant) |
16974 | 132 |
also have "... = 2 * int(card( SetS a p))" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
133 |
by (auto simp add: prems SetS_finite setsum_const2) |
16974 | 134 |
finally show ?thesis . |
135 |
qed |
|
136 |
from this show ?thesis |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
137 |
by auto |
16974 | 138 |
qed |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
139 |
|
16663 | 140 |
lemma SetS_setprod_prop: "[| zprime p; 2 < p; ~([a = 0] (mod p)); |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
141 |
~(QuadRes p a); x \<in> (SetS a p) |] ==> |
16974 | 142 |
[\<Prod>x = a] (mod p)" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
143 |
apply (auto simp add: SetS_def MultInvPair_def) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
144 |
apply (frule StandardRes_SRStar_prop1a) |
16974 | 145 |
apply (subgoal_tac "StandardRes p x \<noteq> StandardRes p (a * MultInv p x)") |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
146 |
apply (auto simp add: StandardRes_prop2 MultInvPair_distinct) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
147 |
apply (frule_tac m = p and x = x and y = "(a * MultInv p x)" in |
16974 | 148 |
StandardRes_prop4) |
149 |
apply (subgoal_tac "[x * (a * MultInv p x) = a * (x * MultInv p x)] (mod p)") |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
150 |
apply (drule_tac a = "StandardRes p x * StandardRes p (a * MultInv p x)" and |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
151 |
b = "x * (a * MultInv p x)" and |
16974 | 152 |
c = "a * (x * MultInv p x)" in zcong_trans, force) |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
153 |
apply (frule_tac p = p and x = x in MultInv_prop2, auto) |
25760 | 154 |
apply (metis StandardRes_SRStar_prop3 mult_1_right mult_commute zcong_sym zcong_zmult_prop1) |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
155 |
apply (auto simp add: zmult_ac) |
19670 | 156 |
done |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
157 |
|
16974 | 158 |
lemma aux1: "[| 0 < x; (x::int) < a; x \<noteq> (a - 1) |] ==> x < a - 1" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
159 |
by arith |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
160 |
|
16974 | 161 |
lemma aux2: "[| (a::int) < c; b < c |] ==> (a \<le> b | b \<le> a)" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
162 |
by auto |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
163 |
|
35544
342a448ae141
fix fragile proof using old induction rule (cf. bdf8ad377877)
krauss
parents:
32479
diff
changeset
|
164 |
lemma d22set_induct_old: "(\<And>a::int. 1 < a \<longrightarrow> P (a - 1) \<Longrightarrow> P a) \<Longrightarrow> P x" |
342a448ae141
fix fragile proof using old induction rule (cf. bdf8ad377877)
krauss
parents:
32479
diff
changeset
|
165 |
using d22set.induct by blast |
342a448ae141
fix fragile proof using old induction rule (cf. bdf8ad377877)
krauss
parents:
32479
diff
changeset
|
166 |
|
18369 | 167 |
lemma SRStar_d22set_prop: "2 < p \<Longrightarrow> (SRStar p) = {1} \<union> (d22set (p - 1))" |
35544
342a448ae141
fix fragile proof using old induction rule (cf. bdf8ad377877)
krauss
parents:
32479
diff
changeset
|
168 |
apply (induct p rule: d22set_induct_old) |
18369 | 169 |
apply auto |
16733
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
nipkow
parents:
16663
diff
changeset
|
170 |
apply (simp add: SRStar_def d22set.simps) |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
171 |
apply (simp add: SRStar_def d22set.simps, clarify) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
172 |
apply (frule aux1) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
173 |
apply (frule aux2, auto) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
174 |
apply (simp_all add: SRStar_def) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
175 |
apply (simp add: d22set.simps) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
176 |
apply (frule d22set_le) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
177 |
apply (frule d22set_g_1, auto) |
18369 | 178 |
done |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
179 |
|
16663 | 180 |
lemma Union_SetS_setprod_prop1: "[| zprime p; 2 < p; ~([a = 0] (mod p)); ~(QuadRes p a) |] ==> |
15392 | 181 |
[\<Prod>(Union (SetS a p)) = a ^ nat ((p - 1) div 2)] (mod p)" |
182 |
proof - |
|
16663 | 183 |
assume "zprime p" and "2 < p" and "~([a = 0] (mod p))" and "~(QuadRes p a)" |
15392 | 184 |
then have "[\<Prod>(Union (SetS a p)) = |
185 |
setprod (setprod (%x. x)) (SetS a p)] (mod p)" |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
186 |
by (auto simp add: SetS_finite SetS_elems_finite |
15392 | 187 |
MultInvPair_prop1c setprod_Union_disjoint) |
188 |
also have "[setprod (setprod (%x. x)) (SetS a p) = |
|
189 |
setprod (%x. a) (SetS a p)] (mod p)" |
|
18369 | 190 |
by (rule setprod_same_function_zcong) |
191 |
(auto simp add: prems SetS_setprod_prop SetS_finite) |
|
15392 | 192 |
also (zcong_trans) have "[setprod (%x. a) (SetS a p) = |
193 |
a^(card (SetS a p))] (mod p)" |
|
194 |
by (auto simp add: prems SetS_finite setprod_constant) |
|
195 |
finally (zcong_trans) show ?thesis |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
196 |
apply (rule zcong_trans) |
15392 | 197 |
apply (subgoal_tac "card(SetS a p) = nat((p - 1) div 2)", auto) |
198 |
apply (subgoal_tac "nat(int(card(SetS a p))) = nat((p - 1) div 2)", force) |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
199 |
apply (auto simp add: prems SetS_card) |
18369 | 200 |
done |
15392 | 201 |
qed |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
202 |
|
16663 | 203 |
lemma Union_SetS_setprod_prop2: "[| zprime p; 2 < p; ~([a = 0](mod p)) |] ==> |
16974 | 204 |
\<Prod>(Union (SetS a p)) = zfact (p - 1)" |
205 |
proof - |
|
206 |
assume "zprime p" and "2 < p" and "~([a = 0](mod p))" |
|
15392 | 207 |
then have "\<Prod>(Union (SetS a p)) = \<Prod>(SRStar p)" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
208 |
by (auto simp add: MultInvPair_prop2) |
15392 | 209 |
also have "... = \<Prod>({1} \<union> (d22set (p - 1)))" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
210 |
by (auto simp add: prems SRStar_d22set_prop) |
15392 | 211 |
also have "... = zfact(p - 1)" |
212 |
proof - |
|
18369 | 213 |
have "~(1 \<in> d22set (p - 1)) & finite( d22set (p - 1))" |
25760 | 214 |
by (metis d22set_fin d22set_g_1 linorder_neq_iff) |
18369 | 215 |
then have "\<Prod>({1} \<union> (d22set (p - 1))) = \<Prod>(d22set (p - 1))" |
216 |
by auto |
|
217 |
then show ?thesis |
|
218 |
by (auto simp add: d22set_prod_zfact) |
|
16974 | 219 |
qed |
15392 | 220 |
finally show ?thesis . |
16974 | 221 |
qed |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
222 |
|
16663 | 223 |
lemma zfact_prop: "[| zprime p; 2 < p; ~([a = 0] (mod p)); ~(QuadRes p a) |] ==> |
16974 | 224 |
[zfact (p - 1) = a ^ nat ((p - 1) div 2)] (mod p)" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
225 |
apply (frule Union_SetS_setprod_prop1) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
226 |
apply (auto simp add: Union_SetS_setprod_prop2) |
18369 | 227 |
done |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
228 |
|
19670 | 229 |
text {* \medskip Prove the first part of Euler's Criterion: *} |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
230 |
|
16663 | 231 |
lemma Euler_part1: "[| 2 < p; zprime p; ~([x = 0](mod p)); |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
232 |
~(QuadRes p x) |] ==> |
16974 | 233 |
[x^(nat (((p) - 1) div 2)) = -1](mod p)" |
25760 | 234 |
by (metis Wilson_Russ number_of_is_id zcong_sym zcong_trans zfact_prop) |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
235 |
|
19670 | 236 |
text {* \medskip Prove another part of Euler Criterion: *} |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
237 |
|
16974 | 238 |
lemma aux_1: "0 < p ==> (a::int) ^ nat (p) = a * a ^ (nat (p) - 1)" |
239 |
proof - |
|
240 |
assume "0 < p" |
|
241 |
then have "a ^ (nat p) = a ^ (1 + (nat p - 1))" |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
242 |
by (auto simp add: diff_add_assoc) |
16974 | 243 |
also have "... = (a ^ 1) * a ^ (nat(p) - 1)" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
244 |
by (simp only: zpower_zadd_distrib) |
16974 | 245 |
also have "... = a * a ^ (nat(p) - 1)" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
246 |
by auto |
16974 | 247 |
finally show ?thesis . |
248 |
qed |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
249 |
|
16974 | 250 |
lemma aux_2: "[| (2::int) < p; p \<in> zOdd |] ==> 0 < ((p - 1) div 2)" |
251 |
proof - |
|
252 |
assume "2 < p" and "p \<in> zOdd" |
|
253 |
then have "(p - 1):zEven" |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
254 |
by (auto simp add: zEven_def zOdd_def) |
16974 | 255 |
then have aux_1: "2 * ((p - 1) div 2) = (p - 1)" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
256 |
by (auto simp add: even_div_2_prop2) |
23373 | 257 |
with `2 < p` have "1 < (p - 1)" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
258 |
by auto |
16974 | 259 |
then have " 1 < (2 * ((p - 1) div 2))" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
260 |
by (auto simp add: aux_1) |
16974 | 261 |
then have "0 < (2 * ((p - 1) div 2)) div 2" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
262 |
by auto |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
263 |
then show ?thesis by auto |
16974 | 264 |
qed |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
265 |
|
19670 | 266 |
lemma Euler_part2: |
267 |
"[| 2 < p; zprime p; [a = 0] (mod p) |] ==> [0 = a ^ nat ((p - 1) div 2)] (mod p)" |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
268 |
apply (frule zprime_zOdd_eq_grt_2) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
269 |
apply (frule aux_2, auto) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
270 |
apply (frule_tac a = a in aux_1, auto) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
271 |
apply (frule zcong_zmult_prop1, auto) |
18369 | 272 |
done |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
273 |
|
19670 | 274 |
text {* \medskip Prove the final part of Euler's Criterion: *} |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
275 |
|
16974 | 276 |
lemma aux__1: "[| ~([x = 0] (mod p)); [y ^ 2 = x] (mod p)|] ==> ~(p dvd y)" |
30042 | 277 |
by (metis dvdI power2_eq_square zcong_sym zcong_trans zcong_zero_equiv_div dvd_trans) |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
278 |
|
16974 | 279 |
lemma aux__2: "2 * nat((p - 1) div 2) = nat (2 * ((p - 1) div 2))" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
280 |
by (auto simp add: nat_mult_distrib) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
281 |
|
16663 | 282 |
lemma Euler_part3: "[| 2 < p; zprime p; ~([x = 0](mod p)); QuadRes p x |] ==> |
16974 | 283 |
[x^(nat (((p) - 1) div 2)) = 1](mod p)" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
284 |
apply (subgoal_tac "p \<in> zOdd") |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
285 |
apply (auto simp add: QuadRes_def) |
25675 | 286 |
prefer 2 |
287 |
apply (metis number_of_is_id numeral_1_eq_1 zprime_zOdd_eq_grt_2) |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
288 |
apply (frule aux__1, auto) |
16974 | 289 |
apply (drule_tac z = "nat ((p - 1) div 2)" in zcong_zpower) |
25675 | 290 |
apply (auto simp add: zpower_zpower) |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
291 |
apply (rule zcong_trans) |
16974 | 292 |
apply (auto simp add: zcong_sym [of "x ^ nat ((p - 1) div 2)"]) |
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25760
diff
changeset
|
293 |
apply (metis Little_Fermat even_div_2_prop2 mult_Bit0 number_of_is_id odd_minus_one_even one_is_num_one zmult_1 aux__2) |
18369 | 294 |
done |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
295 |
|
19670 | 296 |
|
297 |
text {* \medskip Finally show Euler's Criterion: *} |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
298 |
|
16663 | 299 |
theorem Euler_Criterion: "[| 2 < p; zprime p |] ==> [(Legendre a p) = |
16974 | 300 |
a^(nat (((p) - 1) div 2))] (mod p)" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
301 |
apply (auto simp add: Legendre_def Euler_part2) |
20369 | 302 |
apply (frule Euler_part3, auto simp add: zcong_sym)[] |
303 |
apply (frule Euler_part1, auto simp add: zcong_sym)[] |
|
18369 | 304 |
done |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
305 |
|
18369 | 306 |
end |