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