| author | haftmann | 
| Wed, 14 Feb 2007 10:06:16 +0100 | |
| changeset 22320 | d5260836d662 | 
| parent 22274 | ce1459004c8d | 
| child 26289 | 9d2c375e242b | 
| permissions | -rw-r--r-- | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
1  | 
(* Title: HOL/Quadratic_Reciprocity/Gauss.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 {* Gauss' Lemma *}
 | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
7  | 
|
| 18369 | 8  | 
theory Gauss imports Euler begin  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
9  | 
|
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
10  | 
locale GAUSS =  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
11  | 
fixes p :: "int"  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
12  | 
fixes a :: "int"  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
13  | 
|
| 16663 | 14  | 
assumes p_prime: "zprime p"  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
15  | 
assumes p_g_2: "2 < p"  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
16  | 
assumes p_a_relprime: "~[a = 0](mod p)"  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
17  | 
assumes a_nonzero: "0 < a"  | 
| 21233 | 18  | 
begin  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
19  | 
|
| 21233 | 20  | 
definition  | 
| 
21404
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
21288 
diff
changeset
 | 
21  | 
A :: "int set" where  | 
| 21233 | 22  | 
  "A = {(x::int). 0 < x & x \<le> ((p - 1) div 2)}"
 | 
23  | 
||
| 
21404
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
21288 
diff
changeset
 | 
24  | 
definition  | 
| 
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
21288 
diff
changeset
 | 
25  | 
B :: "int set" where  | 
| 21233 | 26  | 
"B = (%x. x * a) ` A"  | 
27  | 
||
| 
21404
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
21288 
diff
changeset
 | 
28  | 
definition  | 
| 
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
21288 
diff
changeset
 | 
29  | 
C :: "int set" where  | 
| 21233 | 30  | 
"C = StandardRes p ` B"  | 
31  | 
||
| 
21404
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
21288 
diff
changeset
 | 
32  | 
definition  | 
| 
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
21288 
diff
changeset
 | 
33  | 
D :: "int set" where  | 
| 21233 | 34  | 
  "D = C \<inter> {x. x \<le> ((p - 1) div 2)}"
 | 
35  | 
||
| 
21404
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
21288 
diff
changeset
 | 
36  | 
definition  | 
| 
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
21288 
diff
changeset
 | 
37  | 
E :: "int set" where  | 
| 21233 | 38  | 
  "E = C \<inter> {x. ((p - 1) div 2) < x}"
 | 
39  | 
||
| 
21404
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
21288 
diff
changeset
 | 
40  | 
definition  | 
| 
 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 
wenzelm 
parents: 
21288 
diff
changeset
 | 
41  | 
F :: "int set" where  | 
| 21233 | 42  | 
"F = (%x. (p - x)) ` E"  | 
43  | 
||
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
44  | 
|
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
45  | 
subsection {* Basic properties of p *}
 | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
46  | 
|
| 21233 | 47  | 
lemma p_odd: "p \<in> zOdd"  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
48  | 
by (auto simp add: p_prime p_g_2 zprime_zOdd_eq_grt_2)  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
49  | 
|
| 21233 | 50  | 
lemma p_g_0: "0 < p"  | 
| 18369 | 51  | 
using p_g_2 by auto  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
52  | 
|
| 21233 | 53  | 
lemma int_nat: "int (nat ((p - 1) div 2)) = (p - 1) div 2"  | 
| 18369 | 54  | 
using insert p_g_2 by (auto simp add: pos_imp_zdiv_nonneg_iff)  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
55  | 
|
| 21233 | 56  | 
lemma p_minus_one_l: "(p - 1) div 2 < p"  | 
| 18369 | 57  | 
proof -  | 
58  | 
have "(p - 1) div 2 \<le> (p - 1) div 1"  | 
|
59  | 
by (rule zdiv_mono2) (auto simp add: p_g_0)  | 
|
60  | 
also have "\<dots> = p - 1" by simp  | 
|
61  | 
finally show ?thesis by simp  | 
|
62  | 
qed  | 
|
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
63  | 
|
| 21233 | 64  | 
lemma p_eq: "p = (2 * (p - 1) div 2) + 1"  | 
| 18369 | 65  | 
using zdiv_zmult_self2 [of 2 "p - 1"] by auto  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
66  | 
|
| 21233 | 67  | 
|
| 21288 | 68  | 
lemma (in -) zodd_imp_zdiv_eq: "x \<in> zOdd ==> 2 * (x - 1) div 2 = 2 * ((x - 1) div 2)"  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
69  | 
apply (frule odd_minus_one_even)  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
70  | 
apply (simp add: zEven_def)  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
71  | 
apply (subgoal_tac "2 \<noteq> 0")  | 
| 18369 | 72  | 
apply (frule_tac b = "2 :: int" and a = "x - 1" in zdiv_zmult_self2)  | 
73  | 
apply (auto simp add: even_div_2_prop2)  | 
|
74  | 
done  | 
|
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
75  | 
|
| 21233 | 76  | 
|
77  | 
lemma p_eq2: "p = (2 * ((p - 1) div 2)) + 1"  | 
|
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
78  | 
apply (insert p_eq p_prime p_g_2 zprime_zOdd_eq_grt_2 [of p], auto)  | 
| 18369 | 79  | 
apply (frule zodd_imp_zdiv_eq, auto)  | 
80  | 
done  | 
|
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
81  | 
|
| 21233 | 82  | 
|
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
83  | 
subsection {* Basic Properties of the Gauss Sets *}
 | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
84  | 
|
| 21233 | 85  | 
lemma finite_A: "finite (A)"  | 
| 18369 | 86  | 
apply (auto simp add: A_def)  | 
87  | 
  apply (subgoal_tac "{x. 0 < x & x \<le> (p - 1) div 2} \<subseteq> {x. 0 \<le> x & x < 1 + (p - 1) div 2}")
 | 
|
88  | 
apply (auto simp add: bdd_int_set_l_finite finite_subset)  | 
|
89  | 
done  | 
|
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
90  | 
|
| 21233 | 91  | 
lemma finite_B: "finite (B)"  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
92  | 
by (auto simp add: B_def finite_A finite_imageI)  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
93  | 
|
| 21233 | 94  | 
lemma finite_C: "finite (C)"  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
95  | 
by (auto simp add: C_def finite_B finite_imageI)  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
96  | 
|
| 21233 | 97  | 
lemma finite_D: "finite (D)"  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
98  | 
by (auto simp add: D_def finite_Int finite_C)  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
99  | 
|
| 21233 | 100  | 
lemma finite_E: "finite (E)"  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
101  | 
by (auto simp add: E_def finite_Int finite_C)  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
102  | 
|
| 21233 | 103  | 
lemma finite_F: "finite (F)"  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
104  | 
by (auto simp add: F_def finite_E finite_imageI)  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
105  | 
|
| 21233 | 106  | 
lemma C_eq: "C = D \<union> E"  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
107  | 
by (auto simp add: C_def D_def E_def)  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
108  | 
|
| 21233 | 109  | 
lemma A_card_eq: "card A = nat ((p - 1) div 2)"  | 
| 18369 | 110  | 
apply (auto simp add: A_def)  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
111  | 
apply (insert int_nat)  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
112  | 
apply (erule subst)  | 
| 18369 | 113  | 
apply (auto simp add: card_bdd_int_set_l_le)  | 
114  | 
done  | 
|
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
115  | 
|
| 21233 | 116  | 
lemma inj_on_xa_A: "inj_on (%x. x * a) A"  | 
| 18369 | 117  | 
using a_nonzero by (simp add: A_def inj_on_def)  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
118  | 
|
| 21233 | 119  | 
lemma A_res: "ResSet p A"  | 
| 18369 | 120  | 
apply (auto simp add: A_def ResSet_def)  | 
121  | 
apply (rule_tac m = p in zcong_less_eq)  | 
|
122  | 
apply (insert p_g_2, auto)  | 
|
123  | 
done  | 
|
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
124  | 
|
| 21233 | 125  | 
lemma B_res: "ResSet p B"  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
126  | 
apply (insert p_g_2 p_a_relprime p_minus_one_l)  | 
| 18369 | 127  | 
apply (auto simp add: B_def)  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
128  | 
apply (rule ResSet_image)  | 
| 18369 | 129  | 
apply (auto simp add: A_res)  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
130  | 
apply (auto simp add: A_def)  | 
| 18369 | 131  | 
proof -  | 
132  | 
fix x fix y  | 
|
133  | 
assume a: "[x * a = y * a] (mod p)"  | 
|
134  | 
assume b: "0 < x"  | 
|
135  | 
assume c: "x \<le> (p - 1) div 2"  | 
|
136  | 
assume d: "0 < y"  | 
|
137  | 
assume e: "y \<le> (p - 1) div 2"  | 
|
138  | 
from a p_a_relprime p_prime a_nonzero zcong_cancel [of p a x y]  | 
|
139  | 
have "[x = y](mod p)"  | 
|
140  | 
by (simp add: zprime_imp_zrelprime zcong_def p_g_0 order_le_less)  | 
|
141  | 
with zcong_less_eq [of x y p] p_minus_one_l  | 
|
142  | 
order_le_less_trans [of x "(p - 1) div 2" p]  | 
|
143  | 
order_le_less_trans [of y "(p - 1) div 2" p] show "x = y"  | 
|
144  | 
by (simp add: prems p_minus_one_l p_g_0)  | 
|
145  | 
qed  | 
|
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
146  | 
|
| 21233 | 147  | 
lemma SR_B_inj: "inj_on (StandardRes p) B"  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
148  | 
apply (auto simp add: B_def StandardRes_def inj_on_def A_def prems)  | 
| 18369 | 149  | 
proof -  | 
150  | 
fix x fix y  | 
|
151  | 
assume a: "x * a mod p = y * a mod p"  | 
|
152  | 
assume b: "0 < x"  | 
|
153  | 
assume c: "x \<le> (p - 1) div 2"  | 
|
154  | 
assume d: "0 < y"  | 
|
155  | 
assume e: "y \<le> (p - 1) div 2"  | 
|
156  | 
assume f: "x \<noteq> y"  | 
|
157  | 
from a have "[x * a = y * a](mod p)"  | 
|
158  | 
by (simp add: zcong_zmod_eq p_g_0)  | 
|
159  | 
with p_a_relprime p_prime a_nonzero zcong_cancel [of p a x y]  | 
|
160  | 
have "[x = y](mod p)"  | 
|
161  | 
by (simp add: zprime_imp_zrelprime zcong_def p_g_0 order_le_less)  | 
|
162  | 
with zcong_less_eq [of x y p] p_minus_one_l  | 
|
163  | 
order_le_less_trans [of x "(p - 1) div 2" p]  | 
|
164  | 
order_le_less_trans [of y "(p - 1) div 2" p] have "x = y"  | 
|
165  | 
by (simp add: prems p_minus_one_l p_g_0)  | 
|
166  | 
then have False  | 
|
167  | 
by (simp add: f)  | 
|
168  | 
then show "a = 0"  | 
|
169  | 
by simp  | 
|
170  | 
qed  | 
|
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
171  | 
|
| 21233 | 172  | 
lemma inj_on_pminusx_E: "inj_on (%x. p - x) E"  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
173  | 
apply (auto simp add: E_def C_def B_def A_def)  | 
| 18369 | 174  | 
apply (rule_tac g = "%x. -1 * (x - p)" in inj_on_inverseI)  | 
175  | 
apply auto  | 
|
176  | 
done  | 
|
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
177  | 
|
| 21233 | 178  | 
lemma A_ncong_p: "x \<in> A ==> ~[x = 0](mod p)"  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
179  | 
apply (auto simp add: A_def)  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
180  | 
apply (frule_tac m = p in zcong_not_zero)  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
181  | 
apply (insert p_minus_one_l)  | 
| 18369 | 182  | 
apply auto  | 
183  | 
done  | 
|
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
184  | 
|
| 21233 | 185  | 
lemma A_greater_zero: "x \<in> A ==> 0 < x"  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
186  | 
by (auto simp add: A_def)  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
187  | 
|
| 21233 | 188  | 
lemma B_ncong_p: "x \<in> B ==> ~[x = 0](mod p)"  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
189  | 
apply (auto simp add: B_def)  | 
| 18369 | 190  | 
apply (frule A_ncong_p)  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
191  | 
apply (insert p_a_relprime p_prime a_nonzero)  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
192  | 
apply (frule_tac a = x and b = a in zcong_zprime_prod_zero_contra)  | 
| 18369 | 193  | 
apply (auto simp add: A_greater_zero)  | 
194  | 
done  | 
|
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
195  | 
|
| 21233 | 196  | 
lemma B_greater_zero: "x \<in> B ==> 0 < x"  | 
| 18369 | 197  | 
using a_nonzero by (auto simp add: B_def mult_pos_pos A_greater_zero)  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
198  | 
|
| 21233 | 199  | 
lemma C_ncong_p: "x \<in> C ==> ~[x = 0](mod p)"  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
200  | 
apply (auto simp add: C_def)  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
201  | 
apply (frule B_ncong_p)  | 
| 18369 | 202  | 
apply (subgoal_tac "[x = StandardRes p x](mod p)")  | 
203  | 
defer apply (simp add: StandardRes_prop1)  | 
|
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
204  | 
apply (frule_tac a = x and b = "StandardRes p x" and c = 0 in zcong_trans)  | 
| 18369 | 205  | 
apply auto  | 
206  | 
done  | 
|
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
207  | 
|
| 21233 | 208  | 
lemma C_greater_zero: "y \<in> C ==> 0 < y"  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
209  | 
apply (auto simp add: C_def)  | 
| 18369 | 210  | 
proof -  | 
211  | 
fix x  | 
|
212  | 
assume a: "x \<in> B"  | 
|
213  | 
from p_g_0 have "0 \<le> StandardRes p x"  | 
|
214  | 
by (simp add: StandardRes_lbound)  | 
|
215  | 
moreover have "~[x = 0] (mod p)"  | 
|
216  | 
by (simp add: a B_ncong_p)  | 
|
217  | 
then have "StandardRes p x \<noteq> 0"  | 
|
218  | 
by (simp add: StandardRes_prop3)  | 
|
219  | 
ultimately show "0 < StandardRes p x"  | 
|
220  | 
by (simp add: order_le_less)  | 
|
221  | 
qed  | 
|
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
222  | 
|
| 21233 | 223  | 
lemma D_ncong_p: "x \<in> D ==> ~[x = 0](mod p)"  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
224  | 
by (auto simp add: D_def C_ncong_p)  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
225  | 
|
| 21233 | 226  | 
lemma E_ncong_p: "x \<in> E ==> ~[x = 0](mod p)"  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
227  | 
by (auto simp add: E_def C_ncong_p)  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
228  | 
|
| 21233 | 229  | 
lemma F_ncong_p: "x \<in> F ==> ~[x = 0](mod p)"  | 
| 18369 | 230  | 
apply (auto simp add: F_def)  | 
231  | 
proof -  | 
|
232  | 
fix x assume a: "x \<in> E" assume b: "[p - x = 0] (mod p)"  | 
|
233  | 
from E_ncong_p have "~[x = 0] (mod p)"  | 
|
234  | 
by (simp add: a)  | 
|
235  | 
moreover from a have "0 < x"  | 
|
236  | 
by (simp add: a E_def C_greater_zero)  | 
|
237  | 
moreover from a have "x < p"  | 
|
238  | 
by (auto simp add: E_def C_def p_g_0 StandardRes_ubound)  | 
|
239  | 
ultimately have "~[p - x = 0] (mod p)"  | 
|
240  | 
by (simp add: zcong_not_zero)  | 
|
241  | 
from this show False by (simp add: b)  | 
|
242  | 
qed  | 
|
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
243  | 
|
| 21233 | 244  | 
lemma F_subset: "F \<subseteq> {x. 0 < x & x \<le> ((p - 1) div 2)}"
 | 
| 18369 | 245  | 
apply (auto simp add: F_def E_def)  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
246  | 
apply (insert p_g_0)  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
247  | 
apply (frule_tac x = xa in StandardRes_ubound)  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
248  | 
apply (frule_tac x = x in StandardRes_ubound)  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
249  | 
apply (subgoal_tac "xa = StandardRes p xa")  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
250  | 
apply (auto simp add: C_def StandardRes_prop2 StandardRes_prop1)  | 
| 18369 | 251  | 
proof -  | 
252  | 
from zodd_imp_zdiv_eq p_prime p_g_2 zprime_zOdd_eq_grt_2 have  | 
|
253  | 
"2 * (p - 1) div 2 = 2 * ((p - 1) div 2)"  | 
|
254  | 
by simp  | 
|
255  | 
with p_eq2 show " !!x. [| (p - 1) div 2 < StandardRes p x; x \<in> B |]  | 
|
256  | 
==> p - StandardRes p x \<le> (p - 1) div 2"  | 
|
257  | 
by simp  | 
|
258  | 
qed  | 
|
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
259  | 
|
| 21233 | 260  | 
lemma D_subset: "D \<subseteq> {x. 0 < x & x \<le> ((p - 1) div 2)}"
 | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
261  | 
by (auto simp add: D_def C_greater_zero)  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
262  | 
|
| 21233 | 263  | 
lemma F_eq: "F = {x. \<exists>y \<in> A. ( x = p - (StandardRes p (y*a)) & (p - 1) div 2 < StandardRes p (y*a))}"
 | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
264  | 
by (auto simp add: F_def E_def D_def C_def B_def A_def)  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
265  | 
|
| 21233 | 266  | 
lemma D_eq: "D = {x. \<exists>y \<in> A. ( x = StandardRes p (y*a) & StandardRes p (y*a) \<le> (p - 1) div 2)}"
 | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
267  | 
by (auto simp add: D_def C_def B_def A_def)  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
268  | 
|
| 21233 | 269  | 
lemma D_leq: "x \<in> D ==> x \<le> (p - 1) div 2"  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
270  | 
by (auto simp add: D_eq)  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
271  | 
|
| 21233 | 272  | 
lemma F_ge: "x \<in> F ==> x \<le> (p - 1) div 2"  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
273  | 
apply (auto simp add: F_eq A_def)  | 
| 18369 | 274  | 
proof -  | 
275  | 
fix y  | 
|
276  | 
assume "(p - 1) div 2 < StandardRes p (y * a)"  | 
|
277  | 
then have "p - StandardRes p (y * a) < p - ((p - 1) div 2)"  | 
|
278  | 
by arith  | 
|
279  | 
also from p_eq2 have "... = 2 * ((p - 1) div 2) + 1 - ((p - 1) div 2)"  | 
|
280  | 
by auto  | 
|
281  | 
also have "2 * ((p - 1) div 2) + 1 - (p - 1) div 2 = (p - 1) div 2 + 1"  | 
|
282  | 
by arith  | 
|
283  | 
finally show "p - StandardRes p (y * a) \<le> (p - 1) div 2"  | 
|
284  | 
using zless_add1_eq [of "p - StandardRes p (y * a)" "(p - 1) div 2"] by auto  | 
|
285  | 
qed  | 
|
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
286  | 
|
| 21233 | 287  | 
lemma all_A_relprime: "\<forall>x \<in> A. zgcd(x, p) = 1"  | 
| 18369 | 288  | 
using p_prime p_minus_one_l by (auto simp add: A_def zless_zprime_imp_zrelprime)  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
289  | 
|
| 21233 | 290  | 
lemma A_prod_relprime: "zgcd((setprod id A),p) = 1"  | 
| 18369 | 291  | 
using all_A_relprime finite_A by (simp add: all_relprime_prod_relprime)  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
292  | 
|
| 21233 | 293  | 
|
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
294  | 
subsection {* Relationships Between Gauss Sets *}
 | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
295  | 
|
| 21233 | 296  | 
lemma B_card_eq_A: "card B = card A"  | 
| 18369 | 297  | 
using finite_A by (simp add: finite_A B_def inj_on_xa_A card_image)  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
298  | 
|
| 21233 | 299  | 
lemma B_card_eq: "card B = nat ((p - 1) div 2)"  | 
| 18369 | 300  | 
by (simp add: B_card_eq_A A_card_eq)  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
301  | 
|
| 21233 | 302  | 
lemma F_card_eq_E: "card F = card E"  | 
| 18369 | 303  | 
using finite_E by (simp add: F_def inj_on_pminusx_E card_image)  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
304  | 
|
| 21233 | 305  | 
lemma C_card_eq_B: "card C = card B"  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
306  | 
apply (insert finite_B)  | 
| 18369 | 307  | 
apply (subgoal_tac "inj_on (StandardRes p) B")  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
308  | 
apply (simp add: B_def C_def card_image)  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
309  | 
apply (rule StandardRes_inj_on_ResSet)  | 
| 18369 | 310  | 
apply (simp add: B_res)  | 
311  | 
done  | 
|
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
312  | 
|
| 21233 | 313  | 
lemma D_E_disj: "D \<inter> E = {}"
 | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
314  | 
by (auto simp add: D_def E_def)  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
315  | 
|
| 21233 | 316  | 
lemma C_card_eq_D_plus_E: "card C = card D + card E"  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
317  | 
by (auto simp add: C_eq card_Un_disjoint D_E_disj finite_D finite_E)  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
318  | 
|
| 21233 | 319  | 
lemma C_prod_eq_D_times_E: "setprod id E * setprod id D = setprod id C"  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
320  | 
apply (insert D_E_disj finite_D finite_E C_eq)  | 
| 15392 | 321  | 
apply (frule setprod_Un_disjoint [of D E id])  | 
| 18369 | 322  | 
apply auto  | 
323  | 
done  | 
|
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
324  | 
|
| 21233 | 325  | 
lemma C_B_zcong_prod: "[setprod id C = setprod id B] (mod p)"  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
326  | 
apply (auto simp add: C_def)  | 
| 18369 | 327  | 
apply (insert finite_B SR_B_inj)  | 
| 20898 | 328  | 
apply (frule_tac f = "StandardRes p" in setprod_reindex_id [symmetric], auto)  | 
| 15392 | 329  | 
apply (rule setprod_same_function_zcong)  | 
| 18369 | 330  | 
apply (auto simp add: StandardRes_prop1 zcong_sym p_g_0)  | 
331  | 
done  | 
|
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
332  | 
|
| 21233 | 333  | 
lemma F_Un_D_subset: "(F \<union> D) \<subseteq> A"  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
334  | 
apply (rule Un_least)  | 
| 18369 | 335  | 
apply (auto simp add: A_def F_subset D_subset)  | 
336  | 
done  | 
|
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
337  | 
|
| 21233 | 338  | 
lemma F_D_disj: "(F \<inter> D) = {}"
 | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
339  | 
apply (simp add: F_eq D_eq)  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
340  | 
apply (auto simp add: F_eq D_eq)  | 
| 18369 | 341  | 
proof -  | 
342  | 
fix y fix ya  | 
|
343  | 
assume "p - StandardRes p (y * a) = StandardRes p (ya * a)"  | 
|
344  | 
then have "p = StandardRes p (y * a) + StandardRes p (ya * a)"  | 
|
345  | 
by arith  | 
|
346  | 
moreover have "p dvd p"  | 
|
347  | 
by auto  | 
|
348  | 
ultimately have "p dvd (StandardRes p (y * a) + StandardRes p (ya * a))"  | 
|
349  | 
by auto  | 
|
350  | 
then have a: "[StandardRes p (y * a) + StandardRes p (ya * a) = 0] (mod p)"  | 
|
351  | 
by (auto simp add: zcong_def)  | 
|
352  | 
have "[y * a = StandardRes p (y * a)] (mod p)"  | 
|
353  | 
by (simp only: zcong_sym StandardRes_prop1)  | 
|
354  | 
moreover have "[ya * a = StandardRes p (ya * a)] (mod p)"  | 
|
355  | 
by (simp only: zcong_sym StandardRes_prop1)  | 
|
356  | 
ultimately have "[y * a + ya * a =  | 
|
357  | 
StandardRes p (y * a) + StandardRes p (ya * a)] (mod p)"  | 
|
358  | 
by (rule zcong_zadd)  | 
|
359  | 
with a have "[y * a + ya * a = 0] (mod p)"  | 
|
360  | 
apply (elim zcong_trans)  | 
|
361  | 
by (simp only: zcong_refl)  | 
|
362  | 
also have "y * a + ya * a = a * (y + ya)"  | 
|
363  | 
by (simp add: zadd_zmult_distrib2 zmult_commute)  | 
|
364  | 
finally have "[a * (y + ya) = 0] (mod p)" .  | 
|
365  | 
with p_prime a_nonzero zcong_zprime_prod_zero [of p a "y + ya"]  | 
|
366  | 
p_a_relprime  | 
|
367  | 
have a: "[y + ya = 0] (mod p)"  | 
|
368  | 
by auto  | 
|
369  | 
assume b: "y \<in> A" and c: "ya: A"  | 
|
370  | 
with A_def have "0 < y + ya"  | 
|
371  | 
by auto  | 
|
372  | 
moreover from b c A_def have "y + ya \<le> (p - 1) div 2 + (p - 1) div 2"  | 
|
373  | 
by auto  | 
|
374  | 
moreover from b c p_eq2 A_def have "y + ya < p"  | 
|
375  | 
by auto  | 
|
376  | 
ultimately show False  | 
|
377  | 
apply simp  | 
|
378  | 
apply (frule_tac m = p in zcong_not_zero)  | 
|
379  | 
apply (auto simp add: a)  | 
|
380  | 
done  | 
|
381  | 
qed  | 
|
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
382  | 
|
| 21233 | 383  | 
lemma F_Un_D_card: "card (F \<union> D) = nat ((p - 1) div 2)"  | 
| 18369 | 384  | 
proof -  | 
385  | 
have "card (F \<union> D) = card E + card D"  | 
|
386  | 
by (auto simp add: finite_F finite_D F_D_disj  | 
|
387  | 
card_Un_disjoint F_card_eq_E)  | 
|
388  | 
then have "card (F \<union> D) = card C"  | 
|
389  | 
by (simp add: C_card_eq_D_plus_E)  | 
|
390  | 
from this show "card (F \<union> D) = nat ((p - 1) div 2)"  | 
|
391  | 
by (simp add: C_card_eq_B B_card_eq)  | 
|
392  | 
qed  | 
|
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
393  | 
|
| 21233 | 394  | 
lemma F_Un_D_eq_A: "F \<union> D = A"  | 
| 18369 | 395  | 
using finite_A F_Un_D_subset A_card_eq F_Un_D_card by (auto simp add: card_seteq)  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
396  | 
|
| 21233 | 397  | 
lemma prod_D_F_eq_prod_A:  | 
| 18369 | 398  | 
"(setprod id D) * (setprod id F) = setprod id A"  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
399  | 
apply (insert F_D_disj finite_D finite_F)  | 
| 15392 | 400  | 
apply (frule setprod_Un_disjoint [of F D id])  | 
| 18369 | 401  | 
apply (auto simp add: F_Un_D_eq_A)  | 
402  | 
done  | 
|
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
403  | 
|
| 21233 | 404  | 
lemma prod_F_zcong:  | 
| 18369 | 405  | 
"[setprod id F = ((-1) ^ (card E)) * (setprod id E)] (mod p)"  | 
406  | 
proof -  | 
|
407  | 
have "setprod id F = setprod id (op - p ` E)"  | 
|
408  | 
by (auto simp add: F_def)  | 
|
409  | 
then have "setprod id F = setprod (op - p) E"  | 
|
410  | 
apply simp  | 
|
411  | 
apply (insert finite_E inj_on_pminusx_E)  | 
|
412  | 
apply (frule_tac f = "op - p" in setprod_reindex_id, auto)  | 
|
413  | 
done  | 
|
414  | 
then have one:  | 
|
415  | 
"[setprod id F = setprod (StandardRes p o (op - p)) E] (mod p)"  | 
|
416  | 
apply simp  | 
|
417  | 
apply (insert p_g_0 finite_E)  | 
|
418  | 
by (auto simp add: StandardRes_prod)  | 
|
419  | 
moreover have a: "\<forall>x \<in> E. [p - x = 0 - x] (mod p)"  | 
|
420  | 
apply clarify  | 
|
421  | 
apply (insert zcong_id [of p])  | 
|
422  | 
apply (rule_tac a = p and m = p and c = x and d = x in zcong_zdiff, auto)  | 
|
423  | 
done  | 
|
424  | 
moreover have b: "\<forall>x \<in> E. [StandardRes p (p - x) = p - x](mod p)"  | 
|
425  | 
apply clarify  | 
|
426  | 
apply (simp add: StandardRes_prop1 zcong_sym)  | 
|
427  | 
done  | 
|
428  | 
moreover have "\<forall>x \<in> E. [StandardRes p (p - x) = - x](mod p)"  | 
|
429  | 
apply clarify  | 
|
430  | 
apply (insert a b)  | 
|
431  | 
apply (rule_tac b = "p - x" in zcong_trans, auto)  | 
|
432  | 
done  | 
|
433  | 
ultimately have c:  | 
|
434  | 
"[setprod (StandardRes p o (op - p)) E = setprod (uminus) E](mod p)"  | 
|
435  | 
apply simp  | 
|
436  | 
apply (insert finite_E p_g_0)  | 
|
437  | 
apply (rule setprod_same_function_zcong  | 
|
438  | 
[of E "StandardRes p o (op - p)" uminus p], auto)  | 
|
439  | 
done  | 
|
440  | 
then have two: "[setprod id F = setprod (uminus) E](mod p)"  | 
|
441  | 
apply (insert one c)  | 
|
442  | 
apply (rule zcong_trans [of "setprod id F"  | 
|
| 15392 | 443  | 
"setprod (StandardRes p o op - p) E" p  | 
| 18369 | 444  | 
"setprod uminus E"], auto)  | 
445  | 
done  | 
|
446  | 
also have "setprod uminus E = (setprod id E) * (-1)^(card E)"  | 
|
| 22274 | 447  | 
using finite_E by (induct set: finite) auto  | 
| 18369 | 448  | 
then have "setprod uminus E = (-1) ^ (card E) * (setprod id E)"  | 
449  | 
by (simp add: zmult_commute)  | 
|
450  | 
with two show ?thesis  | 
|
451  | 
by simp  | 
|
| 15392 | 452  | 
qed  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
453  | 
|
| 21233 | 454  | 
|
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
455  | 
subsection {* Gauss' Lemma *}
 | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
456  | 
|
| 21233 | 457  | 
lemma aux: "setprod id A * -1 ^ card E * a ^ card A * -1 ^ card E = setprod id A * a ^ card A"  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
458  | 
by (auto simp add: finite_E neg_one_special)  | 
| 
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
459  | 
|
| 21233 | 460  | 
theorem pre_gauss_lemma:  | 
| 18369 | 461  | 
"[a ^ nat((p - 1) div 2) = (-1) ^ (card E)] (mod p)"  | 
462  | 
proof -  | 
|
463  | 
have "[setprod id A = setprod id F * setprod id D](mod p)"  | 
|
464  | 
by (auto simp add: prod_D_F_eq_prod_A zmult_commute)  | 
|
465  | 
then have "[setprod id A = ((-1)^(card E) * setprod id E) *  | 
|
466  | 
setprod id D] (mod p)"  | 
|
467  | 
apply (rule zcong_trans)  | 
|
468  | 
apply (auto simp add: prod_F_zcong zcong_scalar)  | 
|
469  | 
done  | 
|
470  | 
then have "[setprod id A = ((-1)^(card E) * setprod id C)] (mod p)"  | 
|
471  | 
apply (rule zcong_trans)  | 
|
472  | 
apply (insert C_prod_eq_D_times_E, erule subst)  | 
|
473  | 
apply (subst zmult_assoc, auto)  | 
|
474  | 
done  | 
|
475  | 
then have "[setprod id A = ((-1)^(card E) * setprod id B)] (mod p)"  | 
|
476  | 
apply (rule zcong_trans)  | 
|
477  | 
apply (simp add: C_B_zcong_prod zcong_scalar2)  | 
|
478  | 
done  | 
|
479  | 
then have "[setprod id A = ((-1)^(card E) *  | 
|
480  | 
(setprod id ((%x. x * a) ` A)))] (mod p)"  | 
|
481  | 
by (simp add: B_def)  | 
|
482  | 
then have "[setprod id A = ((-1)^(card E) * (setprod (%x. x * a) A))]  | 
|
483  | 
(mod p)"  | 
|
484  | 
by (simp add:finite_A inj_on_xa_A setprod_reindex_id[symmetric])  | 
|
485  | 
moreover have "setprod (%x. x * a) A =  | 
|
486  | 
setprod (%x. a) A * setprod id A"  | 
|
| 22274 | 487  | 
using finite_A by (induct set: finite) auto  | 
| 18369 | 488  | 
ultimately have "[setprod id A = ((-1)^(card E) * (setprod (%x. a) A *  | 
489  | 
setprod id A))] (mod p)"  | 
|
490  | 
by simp  | 
|
491  | 
then have "[setprod id A = ((-1)^(card E) * a^(card A) *  | 
|
492  | 
setprod id A)](mod p)"  | 
|
493  | 
apply (rule zcong_trans)  | 
|
494  | 
apply (simp add: zcong_scalar2 zcong_scalar finite_A setprod_constant zmult_assoc)  | 
|
495  | 
done  | 
|
496  | 
then have a: "[setprod id A * (-1)^(card E) =  | 
|
497  | 
((-1)^(card E) * a^(card A) * setprod id A * (-1)^(card E))](mod p)"  | 
|
498  | 
by (rule zcong_scalar)  | 
|
499  | 
then have "[setprod id A * (-1)^(card E) = setprod id A *  | 
|
500  | 
(-1)^(card E) * a^(card A) * (-1)^(card E)](mod p)"  | 
|
501  | 
apply (rule zcong_trans)  | 
|
502  | 
apply (simp add: a mult_commute mult_left_commute)  | 
|
503  | 
done  | 
|
504  | 
then have "[setprod id A * (-1)^(card E) = setprod id A *  | 
|
505  | 
a^(card A)](mod p)"  | 
|
506  | 
apply (rule zcong_trans)  | 
|
507  | 
apply (simp add: aux)  | 
|
508  | 
done  | 
|
509  | 
with this zcong_cancel2 [of p "setprod id A" "-1 ^ card E" "a ^ card A"]  | 
|
510  | 
p_g_0 A_prod_relprime have "[-1 ^ card E = a ^ card A](mod p)"  | 
|
511  | 
by (simp add: order_less_imp_le)  | 
|
512  | 
from this show ?thesis  | 
|
513  | 
by (simp add: A_card_eq zcong_sym)  | 
|
| 15392 | 514  | 
qed  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
515  | 
|
| 21233 | 516  | 
theorem gauss_lemma: "(Legendre a p) = (-1) ^ (card E)"  | 
| 15392 | 517  | 
proof -  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
518  | 
from Euler_Criterion p_prime p_g_2 have  | 
| 18369 | 519  | 
"[(Legendre a p) = a^(nat (((p) - 1) div 2))] (mod p)"  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
520  | 
by auto  | 
| 15392 | 521  | 
moreover note pre_gauss_lemma  | 
522  | 
ultimately have "[(Legendre a p) = (-1) ^ (card E)] (mod p)"  | 
|
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
523  | 
by (rule zcong_trans)  | 
| 15392 | 524  | 
moreover from p_a_relprime have "(Legendre a p) = 1 | (Legendre a p) = (-1)"  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
525  | 
by (auto simp add: Legendre_def)  | 
| 15392 | 526  | 
moreover have "(-1::int) ^ (card E) = 1 | (-1::int) ^ (card E) = -1"  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
527  | 
by (rule neg_one_power)  | 
| 15392 | 528  | 
ultimately show ?thesis  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
529  | 
by (auto simp add: p_g_2 one_not_neg_one_mod_m zcong_sym)  | 
| 15392 | 530  | 
qed  | 
| 
13871
 
26e5f5e624f6
Gauss's law of quadratic reciprocity by Avigad, Gray and Kramer
 
paulson 
parents:  
diff
changeset
 | 
531  | 
|
| 
16775
 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 
avigad 
parents: 
16733 
diff
changeset
 | 
532  | 
end  | 
| 21233 | 533  | 
|
534  | 
end  |