author | wenzelm |
Fri, 10 Nov 2006 10:42:28 +0100 | |
changeset 21288 | 2c7d3d120418 |
parent 21233 | 5a5c8ea5f66a |
child 21404 | eb85850d3eb7 |
permissions | -rw-r--r-- |
20346 | 1 |
(* Title: HOL/NumberTheory/Quadratic_Reciprocity.thy |
14981 | 2 |
ID: $Id$ |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
3 |
Authors: Jeremy Avigad, David Gray, and Adam Kramer |
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 |
|
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
6 |
header {* The law of Quadratic reciprocity *} |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
7 |
|
15392 | 8 |
theory Quadratic_Reciprocity |
9 |
imports Gauss |
|
10 |
begin |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
11 |
|
19670 | 12 |
text {* |
13 |
Lemmas leading up to the proof of theorem 3.3 in Niven and |
|
14 |
Zuckerman's presentation. |
|
15 |
*} |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
16 |
|
21233 | 17 |
context GAUSS |
18 |
begin |
|
19 |
||
20 |
lemma QRLemma1: "a * setsum id A = |
|
15392 | 21 |
p * setsum (%x. ((x * a) div p)) A + setsum id D + setsum id E" |
22 |
proof - |
|
18369 | 23 |
from finite_A have "a * setsum id A = setsum (%x. a * x) A" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
24 |
by (auto simp add: setsum_const_mult id_def) |
18369 | 25 |
also have "setsum (%x. a * x) = setsum (%x. x * a)" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
26 |
by (auto simp add: zmult_commute) |
15392 | 27 |
also have "setsum (%x. x * a) A = setsum id B" |
16733
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
nipkow
parents:
16663
diff
changeset
|
28 |
by (simp add: B_def setsum_reindex_id[OF inj_on_xa_A]) |
15392 | 29 |
also have "... = setsum (%x. p * (x div p) + StandardRes p x) B" |
16733
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
nipkow
parents:
16663
diff
changeset
|
30 |
by (auto simp add: StandardRes_def zmod_zdiv_equality) |
15392 | 31 |
also have "... = setsum (%x. p * (x div p)) B + setsum (StandardRes p) B" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
32 |
by (rule setsum_addf) |
15392 | 33 |
also have "setsum (StandardRes p) B = setsum id C" |
16733
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
nipkow
parents:
16663
diff
changeset
|
34 |
by (auto simp add: C_def setsum_reindex_id[OF SR_B_inj]) |
15392 | 35 |
also from C_eq have "... = setsum id (D \<union> E)" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
36 |
by auto |
15392 | 37 |
also from finite_D finite_E have "... = setsum id D + setsum id E" |
18369 | 38 |
by (rule setsum_Un_disjoint) (auto simp add: D_def E_def) |
39 |
also have "setsum (%x. p * (x div p)) B = |
|
15392 | 40 |
setsum ((%x. p * (x div p)) o (%x. (x * a))) A" |
16733
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
nipkow
parents:
16663
diff
changeset
|
41 |
by (auto simp add: B_def setsum_reindex inj_on_xa_A) |
15392 | 42 |
also have "... = setsum (%x. p * ((x * a) div p)) A" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
43 |
by (auto simp add: o_def) |
18369 | 44 |
also from finite_A have "setsum (%x. p * ((x * a) div p)) A = |
15392 | 45 |
p * setsum (%x. ((x * a) div p)) A" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
46 |
by (auto simp add: setsum_const_mult) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
47 |
finally show ?thesis by arith |
15392 | 48 |
qed |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
49 |
|
21233 | 50 |
lemma QRLemma2: "setsum id A = p * int (card E) - setsum id E + |
18369 | 51 |
setsum id D" |
15392 | 52 |
proof - |
53 |
from F_Un_D_eq_A have "setsum id A = setsum id (D \<union> F)" |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
54 |
by (simp add: Un_commute) |
18369 | 55 |
also from F_D_disj finite_D finite_F |
56 |
have "... = setsum id D + setsum id F" |
|
57 |
by (auto simp add: Int_commute intro: setsum_Un_disjoint) |
|
15392 | 58 |
also from F_def have "F = (%x. (p - x)) ` E" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
59 |
by auto |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
60 |
also from finite_E inj_on_pminusx_E have "setsum id ((%x. (p - x)) ` E) = |
15392 | 61 |
setsum (%x. (p - x)) E" |
62 |
by (auto simp add: setsum_reindex) |
|
63 |
also from finite_E have "setsum (op - p) E = setsum (%x. p) E - setsum id E" |
|
64 |
by (auto simp add: setsum_subtractf id_def) |
|
65 |
also from finite_E have "setsum (%x. p) E = p * int(card E)" |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
66 |
by (intro setsum_const) |
15392 | 67 |
finally show ?thesis |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
68 |
by arith |
15392 | 69 |
qed |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
70 |
|
21233 | 71 |
lemma QRLemma3: "(a - 1) * setsum id A = |
15392 | 72 |
p * (setsum (%x. ((x * a) div p)) A - int(card E)) + 2 * setsum id E" |
73 |
proof - |
|
74 |
have "(a - 1) * setsum id A = a * setsum id A - setsum id A" |
|
18369 | 75 |
by (auto simp add: zdiff_zmult_distrib) |
15392 | 76 |
also note QRLemma1 |
18369 | 77 |
also from QRLemma2 have "p * (\<Sum>x \<in> A. x * a div p) + setsum id D + |
78 |
setsum id E - setsum id A = |
|
79 |
p * (\<Sum>x \<in> A. x * a div p) + setsum id D + |
|
15392 | 80 |
setsum id E - (p * int (card E) - setsum id E + setsum id D)" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
81 |
by auto |
18369 | 82 |
also have "... = p * (\<Sum>x \<in> A. x * a div p) - |
83 |
p * int (card E) + 2 * setsum id E" |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
84 |
by arith |
15392 | 85 |
finally show ?thesis |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
86 |
by (auto simp only: zdiff_zmult_distrib2) |
15392 | 87 |
qed |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
88 |
|
21233 | 89 |
lemma QRLemma4: "a \<in> zOdd ==> |
15392 | 90 |
(setsum (%x. ((x * a) div p)) A \<in> zEven) = (int(card E): zEven)" |
91 |
proof - |
|
92 |
assume a_odd: "a \<in> zOdd" |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
93 |
from QRLemma3 have a: "p * (setsum (%x. ((x * a) div p)) A - int(card E)) = |
18369 | 94 |
(a - 1) * setsum id A - 2 * setsum id E" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
95 |
by arith |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
96 |
from a_odd have "a - 1 \<in> zEven" |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
97 |
by (rule odd_minus_one_even) |
15392 | 98 |
hence "(a - 1) * setsum id A \<in> zEven" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
99 |
by (rule even_times_either) |
15392 | 100 |
moreover have "2 * setsum id E \<in> zEven" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
101 |
by (auto simp add: zEven_def) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
102 |
ultimately have "(a - 1) * setsum id A - 2 * setsum id E \<in> zEven" |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
103 |
by (rule even_minus_even) |
15392 | 104 |
with a have "p * (setsum (%x. ((x * a) div p)) A - int(card E)): zEven" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
105 |
by simp |
15392 | 106 |
hence "p \<in> zEven | (setsum (%x. ((x * a) div p)) A - int(card E)): zEven" |
14434 | 107 |
by (rule EvenOdd.even_product) |
15392 | 108 |
with p_odd have "(setsum (%x. ((x * a) div p)) A - int(card E)): zEven" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
109 |
by (auto simp add: odd_iff_not_even) |
15392 | 110 |
thus ?thesis |
18369 | 111 |
by (auto simp only: even_diff [symmetric]) |
15392 | 112 |
qed |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
113 |
|
21233 | 114 |
lemma QRLemma5: "a \<in> zOdd ==> |
15392 | 115 |
(-1::int)^(card E) = (-1::int)^(nat(setsum (%x. ((x * a) div p)) A))" |
116 |
proof - |
|
117 |
assume "a \<in> zOdd" |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
118 |
from QRLemma4 have |
15392 | 119 |
"(int(card E): zEven) = (setsum (%x. ((x * a) div p)) A \<in> zEven)".. |
120 |
moreover have "0 \<le> int(card E)" |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
121 |
by auto |
15392 | 122 |
moreover have "0 \<le> setsum (%x. ((x * a) div p)) A" |
123 |
proof (intro setsum_nonneg) |
|
15537 | 124 |
show "\<forall>x \<in> A. 0 \<le> x * a div p" |
15392 | 125 |
proof |
126 |
fix x |
|
127 |
assume "x \<in> A" |
|
128 |
then have "0 \<le> x" |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
129 |
by (auto simp add: A_def) |
15392 | 130 |
with a_nonzero have "0 \<le> x * a" |
14353
79f9fbef9106
Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents:
13871
diff
changeset
|
131 |
by (auto simp add: zero_le_mult_iff) |
18369 | 132 |
with p_g_2 show "0 \<le> x * a div p" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
133 |
by (auto simp add: pos_imp_zdiv_nonneg_iff) |
15392 | 134 |
qed |
135 |
qed |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
136 |
ultimately have "(-1::int)^nat((int (card E))) = |
15392 | 137 |
(-1)^nat(((\<Sum>x \<in> A. x * a div p)))" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
138 |
by (intro neg_one_power_parity, auto) |
15392 | 139 |
also have "nat (int(card E)) = card E" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
140 |
by auto |
15392 | 141 |
finally show ?thesis . |
142 |
qed |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
143 |
|
21233 | 144 |
end |
145 |
||
16663 | 146 |
lemma MainQRLemma: "[| a \<in> zOdd; 0 < a; ~([a = 0] (mod p)); zprime p; 2 < p; |
18369 | 147 |
A = {x. 0 < x & x \<le> (p - 1) div 2} |] ==> |
15392 | 148 |
(Legendre a p) = (-1::int)^(nat(setsum (%x. ((x * a) div p)) A))" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
149 |
apply (subst GAUSS.gauss_lemma) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
150 |
apply (auto simp add: GAUSS_def) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
151 |
apply (subst GAUSS.QRLemma5) |
18369 | 152 |
apply (auto simp add: GAUSS_def) |
21233 | 153 |
apply (simp add: GAUSS.A_def [OF GAUSS.intro] GAUSS_def) |
18369 | 154 |
done |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
155 |
|
19670 | 156 |
|
157 |
subsection {* Stuff about S, S1 and S2 *} |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
158 |
|
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
159 |
locale QRTEMP = |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
160 |
fixes p :: "int" |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
161 |
fixes q :: "int" |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
162 |
|
16663 | 163 |
assumes p_prime: "zprime p" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
164 |
assumes p_g_2: "2 < p" |
16663 | 165 |
assumes q_prime: "zprime q" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
166 |
assumes q_g_2: "2 < q" |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
167 |
assumes p_neq_q: "p \<noteq> q" |
21233 | 168 |
begin |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
169 |
|
21233 | 170 |
definition |
171 |
P_set :: "int set" |
|
172 |
"P_set = {x. 0 < x & x \<le> ((p - 1) div 2) }" |
|
173 |
||
174 |
Q_set :: "int set" |
|
175 |
"Q_set = {x. 0 < x & x \<le> ((q - 1) div 2) }" |
|
176 |
||
177 |
S :: "(int * int) set" |
|
178 |
"S = P_set <*> Q_set" |
|
179 |
||
180 |
S1 :: "(int * int) set" |
|
181 |
"S1 = { (x, y). (x, y):S & ((p * y) < (q * x)) }" |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
182 |
|
21233 | 183 |
S2 :: "(int * int) set" |
184 |
"S2 = { (x, y). (x, y):S & ((q * x) < (p * y)) }" |
|
185 |
||
186 |
f1 :: "int => (int * int) set" |
|
187 |
"f1 j = { (j1, y). (j1, y):S & j1 = j & (y \<le> (q * j) div p) }" |
|
188 |
||
189 |
f2 :: "int => (int * int) set" |
|
190 |
"f2 j = { (x, j1). (x, j1):S & j1 = j & (x \<le> (p * j) div q) }" |
|
191 |
||
192 |
lemma p_fact: "0 < (p - 1) div 2" |
|
15392 | 193 |
proof - |
21233 | 194 |
from p_g_2 have "2 \<le> p - 1" by arith |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
195 |
then have "2 div 2 \<le> (p - 1) div 2" by (rule zdiv_mono1, auto) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
196 |
then show ?thesis by auto |
15392 | 197 |
qed |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
198 |
|
21233 | 199 |
lemma q_fact: "0 < (q - 1) div 2" |
15392 | 200 |
proof - |
21233 | 201 |
from q_g_2 have "2 \<le> q - 1" by arith |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
202 |
then have "2 div 2 \<le> (q - 1) div 2" by (rule zdiv_mono1, auto) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
203 |
then show ?thesis by auto |
15392 | 204 |
qed |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
205 |
|
21233 | 206 |
lemma pb_neq_qa: "[|1 \<le> b; b \<le> (q - 1) div 2 |] ==> |
15392 | 207 |
(p * b \<noteq> q * a)" |
208 |
proof |
|
209 |
assume "p * b = q * a" and "1 \<le> b" and "b \<le> (q - 1) div 2" |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
210 |
then have "q dvd (p * b)" by (auto simp add: dvd_def) |
15392 | 211 |
with q_prime p_g_2 have "q dvd p | q dvd b" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
212 |
by (auto simp add: zprime_zdvd_zmult) |
15392 | 213 |
moreover have "~ (q dvd p)" |
214 |
proof |
|
215 |
assume "q dvd p" |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
216 |
with p_prime have "q = 1 | q = p" |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
217 |
apply (auto simp add: zprime_def QRTEMP_def) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
218 |
apply (drule_tac x = q and R = False in allE) |
18369 | 219 |
apply (simp add: QRTEMP_def) |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
220 |
apply (subgoal_tac "0 \<le> q", simp add: QRTEMP_def) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
221 |
apply (insert prems) |
18369 | 222 |
apply (auto simp add: QRTEMP_def) |
223 |
done |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
224 |
with q_g_2 p_neq_q show False by auto |
15392 | 225 |
qed |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
226 |
ultimately have "q dvd b" by auto |
15392 | 227 |
then have "q \<le> b" |
228 |
proof - |
|
229 |
assume "q dvd b" |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
230 |
moreover from prems have "0 < b" by auto |
18369 | 231 |
ultimately show ?thesis using zdvd_bounds [of q b] by auto |
15392 | 232 |
qed |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
233 |
with prems have "q \<le> (q - 1) div 2" by auto |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
234 |
then have "2 * q \<le> 2 * ((q - 1) div 2)" by arith |
15392 | 235 |
then have "2 * q \<le> q - 1" |
236 |
proof - |
|
237 |
assume "2 * q \<le> 2 * ((q - 1) div 2)" |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
238 |
with prems have "q \<in> zOdd" by (auto simp add: QRTEMP_def zprime_zOdd_eq_grt_2) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
239 |
with odd_minus_one_even have "(q - 1):zEven" by auto |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
240 |
with even_div_2_prop2 have "(q - 1) = 2 * ((q - 1) div 2)" by auto |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
241 |
with prems show ?thesis by auto |
15392 | 242 |
qed |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
243 |
then have p1: "q \<le> -1" by arith |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
244 |
with q_g_2 show False by auto |
15392 | 245 |
qed |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
246 |
|
21233 | 247 |
lemma P_set_finite: "finite (P_set)" |
18369 | 248 |
using p_fact by (auto simp add: P_set_def bdd_int_set_l_le_finite) |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
249 |
|
21233 | 250 |
lemma Q_set_finite: "finite (Q_set)" |
18369 | 251 |
using q_fact by (auto simp add: Q_set_def bdd_int_set_l_le_finite) |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
252 |
|
21233 | 253 |
lemma S_finite: "finite S" |
15402 | 254 |
by (auto simp add: S_def P_set_finite Q_set_finite finite_cartesian_product) |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
255 |
|
21233 | 256 |
lemma S1_finite: "finite S1" |
15392 | 257 |
proof - |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
258 |
have "finite S" by (auto simp add: S_finite) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
259 |
moreover have "S1 \<subseteq> S" by (auto simp add: S1_def S_def) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
260 |
ultimately show ?thesis by (auto simp add: finite_subset) |
15392 | 261 |
qed |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
262 |
|
21233 | 263 |
lemma S2_finite: "finite S2" |
15392 | 264 |
proof - |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
265 |
have "finite S" by (auto simp add: S_finite) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
266 |
moreover have "S2 \<subseteq> S" by (auto simp add: S2_def S_def) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
267 |
ultimately show ?thesis by (auto simp add: finite_subset) |
15392 | 268 |
qed |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
269 |
|
21233 | 270 |
lemma P_set_card: "(p - 1) div 2 = int (card (P_set))" |
18369 | 271 |
using p_fact by (auto simp add: P_set_def card_bdd_int_set_l_le) |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
272 |
|
21233 | 273 |
lemma Q_set_card: "(q - 1) div 2 = int (card (Q_set))" |
18369 | 274 |
using q_fact by (auto simp add: Q_set_def card_bdd_int_set_l_le) |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
275 |
|
21233 | 276 |
lemma S_card: "((p - 1) div 2) * ((q - 1) div 2) = int (card(S))" |
18369 | 277 |
using P_set_card Q_set_card P_set_finite Q_set_finite |
278 |
by (auto simp add: S_def zmult_int setsum_constant) |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
279 |
|
21233 | 280 |
lemma S1_Int_S2_prop: "S1 \<inter> S2 = {}" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
281 |
by (auto simp add: S1_def S2_def) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
282 |
|
21233 | 283 |
lemma S1_Union_S2_prop: "S = S1 \<union> S2" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
284 |
apply (auto simp add: S_def P_set_def Q_set_def S1_def S2_def) |
18369 | 285 |
proof - |
286 |
fix a and b |
|
287 |
assume "~ q * a < p * b" and b1: "0 < b" and b2: "b \<le> (q - 1) div 2" |
|
288 |
with zless_linear have "(p * b < q * a) | (p * b = q * a)" by auto |
|
289 |
moreover from pb_neq_qa b1 b2 have "(p * b \<noteq> q * a)" by auto |
|
290 |
ultimately show "p * b < q * a" by auto |
|
291 |
qed |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
292 |
|
21233 | 293 |
lemma card_sum_S1_S2: "((p - 1) div 2) * ((q - 1) div 2) = |
15392 | 294 |
int(card(S1)) + int(card(S2))" |
18369 | 295 |
proof - |
15392 | 296 |
have "((p - 1) div 2) * ((q - 1) div 2) = int (card(S))" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
297 |
by (auto simp add: S_card) |
15392 | 298 |
also have "... = int( card(S1) + card(S2))" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
299 |
apply (insert S1_finite S2_finite S1_Int_S2_prop S1_Union_S2_prop) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
300 |
apply (drule card_Un_disjoint, auto) |
18369 | 301 |
done |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
302 |
also have "... = int(card(S1)) + int(card(S2))" by auto |
15392 | 303 |
finally show ?thesis . |
304 |
qed |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
305 |
|
21233 | 306 |
lemma aux1a: "[| 0 < a; a \<le> (p - 1) div 2; |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
307 |
0 < b; b \<le> (q - 1) div 2 |] ==> |
15392 | 308 |
(p * b < q * a) = (b \<le> q * a div p)" |
309 |
proof - |
|
310 |
assume "0 < a" and "a \<le> (p - 1) div 2" and "0 < b" and "b \<le> (q - 1) div 2" |
|
311 |
have "p * b < q * a ==> b \<le> q * a div p" |
|
312 |
proof - |
|
313 |
assume "p * b < q * a" |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
314 |
then have "p * b \<le> q * a" by auto |
15392 | 315 |
then have "(p * b) div p \<le> (q * a) div p" |
18369 | 316 |
by (rule zdiv_mono1) (insert p_g_2, auto) |
15392 | 317 |
then show "b \<le> (q * a) div p" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
318 |
apply (subgoal_tac "p \<noteq> 0") |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
319 |
apply (frule zdiv_zmult_self2, force) |
18369 | 320 |
apply (insert p_g_2, auto) |
321 |
done |
|
15392 | 322 |
qed |
323 |
moreover have "b \<le> q * a div p ==> p * b < q * a" |
|
324 |
proof - |
|
325 |
assume "b \<le> q * a div p" |
|
326 |
then have "p * b \<le> p * ((q * a) div p)" |
|
18369 | 327 |
using p_g_2 by (auto simp add: mult_le_cancel_left) |
15392 | 328 |
also have "... \<le> q * a" |
18369 | 329 |
by (rule zdiv_leq_prop) (insert p_g_2, auto) |
15392 | 330 |
finally have "p * b \<le> q * a" . |
331 |
then have "p * b < q * a | p * b = q * a" |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
332 |
by (simp only: order_le_imp_less_or_eq) |
15392 | 333 |
moreover have "p * b \<noteq> q * a" |
18369 | 334 |
by (rule pb_neq_qa) (insert prems, auto) |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
335 |
ultimately show ?thesis by auto |
15392 | 336 |
qed |
337 |
ultimately show ?thesis .. |
|
338 |
qed |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
339 |
|
21233 | 340 |
lemma aux1b: "[| 0 < a; a \<le> (p - 1) div 2; |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
341 |
0 < b; b \<le> (q - 1) div 2 |] ==> |
15392 | 342 |
(q * a < p * b) = (a \<le> p * b div q)" |
343 |
proof - |
|
344 |
assume "0 < a" and "a \<le> (p - 1) div 2" and "0 < b" and "b \<le> (q - 1) div 2" |
|
345 |
have "q * a < p * b ==> a \<le> p * b div q" |
|
346 |
proof - |
|
347 |
assume "q * a < p * b" |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
348 |
then have "q * a \<le> p * b" by auto |
15392 | 349 |
then have "(q * a) div q \<le> (p * b) div q" |
18369 | 350 |
by (rule zdiv_mono1) (insert q_g_2, auto) |
15392 | 351 |
then show "a \<le> (p * b) div q" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
352 |
apply (subgoal_tac "q \<noteq> 0") |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
353 |
apply (frule zdiv_zmult_self2, force) |
18369 | 354 |
apply (insert q_g_2, auto) |
355 |
done |
|
15392 | 356 |
qed |
357 |
moreover have "a \<le> p * b div q ==> q * a < p * b" |
|
358 |
proof - |
|
359 |
assume "a \<le> p * b div q" |
|
360 |
then have "q * a \<le> q * ((p * b) div q)" |
|
18369 | 361 |
using q_g_2 by (auto simp add: mult_le_cancel_left) |
15392 | 362 |
also have "... \<le> p * b" |
18369 | 363 |
by (rule zdiv_leq_prop) (insert q_g_2, auto) |
15392 | 364 |
finally have "q * a \<le> p * b" . |
365 |
then have "q * a < p * b | q * a = p * b" |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
366 |
by (simp only: order_le_imp_less_or_eq) |
15392 | 367 |
moreover have "p * b \<noteq> q * a" |
18369 | 368 |
by (rule pb_neq_qa) (insert prems, auto) |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
369 |
ultimately show ?thesis by auto |
15392 | 370 |
qed |
371 |
ultimately show ?thesis .. |
|
372 |
qed |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
373 |
|
21288 | 374 |
lemma (in -) aux2: "[| zprime p; zprime q; 2 < p; 2 < q |] ==> |
15392 | 375 |
(q * ((p - 1) div 2)) div p \<le> (q - 1) div 2" |
376 |
proof- |
|
16663 | 377 |
assume "zprime p" and "zprime q" and "2 < p" and "2 < q" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
378 |
(* Set up what's even and odd *) |
15392 | 379 |
then have "p \<in> zOdd & q \<in> zOdd" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
380 |
by (auto simp add: zprime_zOdd_eq_grt_2) |
15392 | 381 |
then have even1: "(p - 1):zEven & (q - 1):zEven" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
382 |
by (auto simp add: odd_minus_one_even) |
15392 | 383 |
then have even2: "(2 * p):zEven & ((q - 1) * p):zEven" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
384 |
by (auto simp add: zEven_def) |
15392 | 385 |
then have even3: "(((q - 1) * p) + (2 * p)):zEven" |
14434 | 386 |
by (auto simp: EvenOdd.even_plus_even) |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
387 |
(* using these prove it *) |
15392 | 388 |
from prems have "q * (p - 1) < ((q - 1) * p) + (2 * p)" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
389 |
by (auto simp add: int_distrib) |
15392 | 390 |
then have "((p - 1) * q) div 2 < (((q - 1) * p) + (2 * p)) div 2" |
391 |
apply (rule_tac x = "((p - 1) * q)" in even_div_2_l) |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
392 |
by (auto simp add: even3, auto simp add: zmult_ac) |
15392 | 393 |
also have "((p - 1) * q) div 2 = q * ((p - 1) div 2)" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
394 |
by (auto simp add: even1 even_prod_div_2) |
15392 | 395 |
also have "(((q - 1) * p) + (2 * p)) div 2 = (((q - 1) div 2) * p) + p" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
396 |
by (auto simp add: even1 even2 even_prod_div_2 even_sum_div_2) |
18369 | 397 |
finally show ?thesis |
398 |
apply (rule_tac x = " q * ((p - 1) div 2)" and |
|
15392 | 399 |
y = "(q - 1) div 2" in div_prop2) |
18369 | 400 |
using prems by auto |
15392 | 401 |
qed |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
402 |
|
21233 | 403 |
lemma aux3a: "\<forall>j \<in> P_set. int (card (f1 j)) = (q * j) div p" |
15392 | 404 |
proof |
405 |
fix j |
|
406 |
assume j_fact: "j \<in> P_set" |
|
407 |
have "int (card (f1 j)) = int (card {y. y \<in> Q_set & y \<le> (q * j) div p})" |
|
408 |
proof - |
|
409 |
have "finite (f1 j)" |
|
410 |
proof - |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
411 |
have "(f1 j) \<subseteq> S" by (auto simp add: f1_def) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
412 |
with S_finite show ?thesis by (auto simp add: finite_subset) |
15392 | 413 |
qed |
414 |
moreover have "inj_on (%(x,y). y) (f1 j)" |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
415 |
by (auto simp add: f1_def inj_on_def) |
15392 | 416 |
ultimately have "card ((%(x,y). y) ` (f1 j)) = card (f1 j)" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
417 |
by (auto simp add: f1_def card_image) |
15392 | 418 |
moreover have "((%(x,y). y) ` (f1 j)) = {y. y \<in> Q_set & y \<le> (q * j) div p}" |
18369 | 419 |
using prems by (auto simp add: f1_def S_def Q_set_def P_set_def image_def) |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
420 |
ultimately show ?thesis by (auto simp add: f1_def) |
15392 | 421 |
qed |
422 |
also have "... = int (card {y. 0 < y & y \<le> (q * j) div p})" |
|
423 |
proof - |
|
18369 | 424 |
have "{y. y \<in> Q_set & y \<le> (q * j) div p} = |
15392 | 425 |
{y. 0 < y & y \<le> (q * j) div p}" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
426 |
apply (auto simp add: Q_set_def) |
18369 | 427 |
proof - |
428 |
fix x |
|
429 |
assume "0 < x" and "x \<le> q * j div p" |
|
430 |
with j_fact P_set_def have "j \<le> (p - 1) div 2" by auto |
|
431 |
with q_g_2 have "q * j \<le> q * ((p - 1) div 2)" |
|
432 |
by (auto simp add: mult_le_cancel_left) |
|
433 |
with p_g_2 have "q * j div p \<le> q * ((p - 1) div 2) div p" |
|
434 |
by (auto simp add: zdiv_mono1) |
|
21233 | 435 |
also from prems P_set_def have "... \<le> (q - 1) div 2" |
18369 | 436 |
apply simp |
437 |
apply (insert aux2) |
|
438 |
apply (simp add: QRTEMP_def) |
|
439 |
done |
|
440 |
finally show "x \<le> (q - 1) div 2" using prems by auto |
|
441 |
qed |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
442 |
then show ?thesis by auto |
15392 | 443 |
qed |
444 |
also have "... = (q * j) div p" |
|
445 |
proof - |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
446 |
from j_fact P_set_def have "0 \<le> j" by auto |
14387
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14353
diff
changeset
|
447 |
with q_g_2 have "q * 0 \<le> q * j" by (auto simp only: mult_left_mono) |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
448 |
then have "0 \<le> q * j" by auto |
15392 | 449 |
then have "0 div p \<le> (q * j) div p" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
450 |
apply (rule_tac a = 0 in zdiv_mono1) |
18369 | 451 |
apply (insert p_g_2, auto) |
452 |
done |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
453 |
also have "0 div p = 0" by auto |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
454 |
finally show ?thesis by (auto simp add: card_bdd_int_set_l_le) |
15392 | 455 |
qed |
456 |
finally show "int (card (f1 j)) = q * j div p" . |
|
457 |
qed |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
458 |
|
21233 | 459 |
lemma aux3b: "\<forall>j \<in> Q_set. int (card (f2 j)) = (p * j) div q" |
15392 | 460 |
proof |
461 |
fix j |
|
462 |
assume j_fact: "j \<in> Q_set" |
|
463 |
have "int (card (f2 j)) = int (card {y. y \<in> P_set & y \<le> (p * j) div q})" |
|
464 |
proof - |
|
465 |
have "finite (f2 j)" |
|
466 |
proof - |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
467 |
have "(f2 j) \<subseteq> S" by (auto simp add: f2_def) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
468 |
with S_finite show ?thesis by (auto simp add: finite_subset) |
15392 | 469 |
qed |
470 |
moreover have "inj_on (%(x,y). x) (f2 j)" |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
471 |
by (auto simp add: f2_def inj_on_def) |
15392 | 472 |
ultimately have "card ((%(x,y). x) ` (f2 j)) = card (f2 j)" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
473 |
by (auto simp add: f2_def card_image) |
15392 | 474 |
moreover have "((%(x,y). x) ` (f2 j)) = {y. y \<in> P_set & y \<le> (p * j) div q}" |
18369 | 475 |
using prems by (auto simp add: f2_def S_def Q_set_def P_set_def image_def) |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
476 |
ultimately show ?thesis by (auto simp add: f2_def) |
15392 | 477 |
qed |
478 |
also have "... = int (card {y. 0 < y & y \<le> (p * j) div q})" |
|
479 |
proof - |
|
18369 | 480 |
have "{y. y \<in> P_set & y \<le> (p * j) div q} = |
15392 | 481 |
{y. 0 < y & y \<le> (p * j) div q}" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
482 |
apply (auto simp add: P_set_def) |
18369 | 483 |
proof - |
484 |
fix x |
|
485 |
assume "0 < x" and "x \<le> p * j div q" |
|
486 |
with j_fact Q_set_def have "j \<le> (q - 1) div 2" by auto |
|
487 |
with p_g_2 have "p * j \<le> p * ((q - 1) div 2)" |
|
488 |
by (auto simp add: mult_le_cancel_left) |
|
489 |
with q_g_2 have "p * j div q \<le> p * ((q - 1) div 2) div q" |
|
490 |
by (auto simp add: zdiv_mono1) |
|
491 |
also from prems have "... \<le> (p - 1) div 2" |
|
492 |
by (auto simp add: aux2 QRTEMP_def) |
|
493 |
finally show "x \<le> (p - 1) div 2" using prems by auto |
|
15392 | 494 |
qed |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
495 |
then show ?thesis by auto |
15392 | 496 |
qed |
497 |
also have "... = (p * j) div q" |
|
498 |
proof - |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
499 |
from j_fact Q_set_def have "0 \<le> j" by auto |
14387
e96d5c42c4b0
Polymorphic treatment of binary arithmetic using axclasses
paulson
parents:
14353
diff
changeset
|
500 |
with p_g_2 have "p * 0 \<le> p * j" by (auto simp only: mult_left_mono) |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
501 |
then have "0 \<le> p * j" by auto |
15392 | 502 |
then have "0 div q \<le> (p * j) div q" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
503 |
apply (rule_tac a = 0 in zdiv_mono1) |
18369 | 504 |
apply (insert q_g_2, auto) |
505 |
done |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
506 |
also have "0 div q = 0" by auto |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
507 |
finally show ?thesis by (auto simp add: card_bdd_int_set_l_le) |
15392 | 508 |
qed |
509 |
finally show "int (card (f2 j)) = p * j div q" . |
|
510 |
qed |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
511 |
|
21233 | 512 |
lemma S1_card: "int (card(S1)) = setsum (%j. (q * j) div p) P_set" |
15392 | 513 |
proof - |
514 |
have "\<forall>x \<in> P_set. finite (f1 x)" |
|
515 |
proof |
|
516 |
fix x |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
517 |
have "f1 x \<subseteq> S" by (auto simp add: f1_def) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
518 |
with S_finite show "finite (f1 x)" by (auto simp add: finite_subset) |
15392 | 519 |
qed |
520 |
moreover have "(\<forall>x \<in> P_set. \<forall>y \<in> P_set. x \<noteq> y --> (f1 x) \<inter> (f1 y) = {})" |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
521 |
by (auto simp add: f1_def) |
15392 | 522 |
moreover note P_set_finite |
18369 | 523 |
ultimately have "int(card (UNION P_set f1)) = |
15392 | 524 |
setsum (%x. int(card (f1 x))) P_set" |
15402 | 525 |
by(simp add:card_UN_disjoint int_setsum o_def) |
15392 | 526 |
moreover have "S1 = UNION P_set f1" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
527 |
by (auto simp add: f1_def S_def S1_def S2_def P_set_def Q_set_def aux1a) |
18369 | 528 |
ultimately have "int(card (S1)) = setsum (%j. int(card (f1 j))) P_set" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
529 |
by auto |
15392 | 530 |
also have "... = setsum (%j. q * j div p) P_set" |
531 |
using aux3a by(fastsimp intro: setsum_cong) |
|
532 |
finally show ?thesis . |
|
533 |
qed |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
534 |
|
21233 | 535 |
lemma S2_card: "int (card(S2)) = setsum (%j. (p * j) div q) Q_set" |
15392 | 536 |
proof - |
537 |
have "\<forall>x \<in> Q_set. finite (f2 x)" |
|
538 |
proof |
|
539 |
fix x |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
540 |
have "f2 x \<subseteq> S" by (auto simp add: f2_def) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
541 |
with S_finite show "finite (f2 x)" by (auto simp add: finite_subset) |
15392 | 542 |
qed |
18369 | 543 |
moreover have "(\<forall>x \<in> Q_set. \<forall>y \<in> Q_set. x \<noteq> y --> |
15392 | 544 |
(f2 x) \<inter> (f2 y) = {})" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
545 |
by (auto simp add: f2_def) |
15392 | 546 |
moreover note Q_set_finite |
18369 | 547 |
ultimately have "int(card (UNION Q_set f2)) = |
15392 | 548 |
setsum (%x. int(card (f2 x))) Q_set" |
15402 | 549 |
by(simp add:card_UN_disjoint int_setsum o_def) |
15392 | 550 |
moreover have "S2 = UNION Q_set f2" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
551 |
by (auto simp add: f2_def S_def S1_def S2_def P_set_def Q_set_def aux1b) |
18369 | 552 |
ultimately have "int(card (S2)) = setsum (%j. int(card (f2 j))) Q_set" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
553 |
by auto |
15392 | 554 |
also have "... = setsum (%j. p * j div q) Q_set" |
555 |
using aux3b by(fastsimp intro: setsum_cong) |
|
556 |
finally show ?thesis . |
|
557 |
qed |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
558 |
|
21233 | 559 |
lemma S1_carda: "int (card(S1)) = |
15392 | 560 |
setsum (%j. (j * q) div p) P_set" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
561 |
by (auto simp add: S1_card zmult_ac) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
562 |
|
21233 | 563 |
lemma S2_carda: "int (card(S2)) = |
15392 | 564 |
setsum (%j. (j * p) div q) Q_set" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
565 |
by (auto simp add: S2_card zmult_ac) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
566 |
|
21233 | 567 |
lemma pq_sum_prop: "(setsum (%j. (j * p) div q) Q_set) + |
15392 | 568 |
(setsum (%j. (j * q) div p) P_set) = ((p - 1) div 2) * ((q - 1) div 2)" |
569 |
proof - |
|
18369 | 570 |
have "(setsum (%j. (j * p) div q) Q_set) + |
15392 | 571 |
(setsum (%j. (j * q) div p) P_set) = int (card S2) + int (card S1)" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
572 |
by (auto simp add: S1_carda S2_carda) |
15392 | 573 |
also have "... = int (card S1) + int (card S2)" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
574 |
by auto |
15392 | 575 |
also have "... = ((p - 1) div 2) * ((q - 1) div 2)" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
576 |
by (auto simp add: card_sum_S1_S2) |
15392 | 577 |
finally show ?thesis . |
578 |
qed |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
579 |
|
21233 | 580 |
|
21288 | 581 |
lemma (in -) pq_prime_neq: "[| zprime p; zprime q; p \<noteq> q |] ==> (~[p = 0] (mod q))" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
582 |
apply (auto simp add: zcong_eq_zdvd_prop zprime_def) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
583 |
apply (drule_tac x = q in allE) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
584 |
apply (drule_tac x = p in allE) |
18369 | 585 |
apply auto |
586 |
done |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
587 |
|
21233 | 588 |
|
589 |
lemma QR_short: "(Legendre p q) * (Legendre q p) = |
|
15392 | 590 |
(-1::int)^nat(((p - 1) div 2)*((q - 1) div 2))" |
591 |
proof - |
|
592 |
from prems have "~([p = 0] (mod q))" |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
593 |
by (auto simp add: pq_prime_neq QRTEMP_def) |
21233 | 594 |
with prems Q_set_def have a1: "(Legendre p q) = (-1::int) ^ |
15392 | 595 |
nat(setsum (%x. ((x * p) div q)) Q_set)" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
596 |
apply (rule_tac p = q in MainQRLemma) |
18369 | 597 |
apply (auto simp add: zprime_zOdd_eq_grt_2 QRTEMP_def) |
598 |
done |
|
15392 | 599 |
from prems have "~([q = 0] (mod p))" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
600 |
apply (rule_tac p = q and q = p in pq_prime_neq) |
15392 | 601 |
apply (simp add: QRTEMP_def)+ |
16733
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
nipkow
parents:
16663
diff
changeset
|
602 |
done |
21233 | 603 |
with prems P_set_def have a2: "(Legendre q p) = |
15392 | 604 |
(-1::int) ^ nat(setsum (%x. ((x * q) div p)) P_set)" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
605 |
apply (rule_tac p = p in MainQRLemma) |
18369 | 606 |
apply (auto simp add: zprime_zOdd_eq_grt_2 QRTEMP_def) |
607 |
done |
|
608 |
from a1 a2 have "(Legendre p q) * (Legendre q p) = |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
609 |
(-1::int) ^ nat(setsum (%x. ((x * p) div q)) Q_set) * |
15392 | 610 |
(-1::int) ^ nat(setsum (%x. ((x * q) div p)) P_set)" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
611 |
by auto |
18369 | 612 |
also have "... = (-1::int) ^ (nat(setsum (%x. ((x * p) div q)) Q_set) + |
15392 | 613 |
nat(setsum (%x. ((x * q) div p)) P_set))" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
614 |
by (auto simp add: zpower_zadd_distrib) |
18369 | 615 |
also have "nat(setsum (%x. ((x * p) div q)) Q_set) + |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
616 |
nat(setsum (%x. ((x * q) div p)) P_set) = |
18369 | 617 |
nat((setsum (%x. ((x * p) div q)) Q_set) + |
15392 | 618 |
(setsum (%x. ((x * q) div p)) P_set))" |
20898 | 619 |
apply (rule_tac z = "setsum (%x. ((x * p) div q)) Q_set" in |
18369 | 620 |
nat_add_distrib [symmetric]) |
621 |
apply (auto simp add: S1_carda [symmetric] S2_carda [symmetric]) |
|
622 |
done |
|
15392 | 623 |
also have "... = nat(((p - 1) div 2) * ((q - 1) div 2))" |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
624 |
by (auto simp add: pq_sum_prop) |
15392 | 625 |
finally show ?thesis . |
626 |
qed |
|
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
627 |
|
21233 | 628 |
end |
629 |
||
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
630 |
theorem Quadratic_Reciprocity: |
18369 | 631 |
"[| p \<in> zOdd; zprime p; q \<in> zOdd; zprime q; |
632 |
p \<noteq> q |] |
|
633 |
==> (Legendre p q) * (Legendre q p) = |
|
15392 | 634 |
(-1::int)^nat(((p - 1) div 2)*((q - 1) div 2))" |
18369 | 635 |
by (auto simp add: QRTEMP.QR_short zprime_zOdd_eq_grt_2 [symmetric] |
13871
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
636 |
QRTEMP_def) |
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
637 |
|
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
paulson
parents:
diff
changeset
|
638 |
end |