Our first proof of quadratic reciprocity is elementary.  The proof
involves keeping track of integer points in intervals.  Proving
Gauss's lemma is the first step; this lemma computes
 in terms of the number of integers of a certain type that
lie in a certain interval.  Next we prove Lemma 4.3.3, which
controls how the parity of the number of integer points in an interval
changes when an endpoint of the interval is changed.  Then we prove
that
 in terms of the number of integers of a certain type that
lie in a certain interval.  Next we prove Lemma 4.3.3, which
controls how the parity of the number of integer points in an interval
changes when an endpoint of the interval is changed.  Then we prove
that 
 depends only on
 depends only on  modulo
 modulo  by applying
Gauss's lemma and keeping careful track of intervals as
they are rescaled and their endpoints are changed.  Finally, in
Section 4.3.2 we use some basic algebra to deduce the
quadratic reciprocity law using the tools we've just developed.
Our proof follows the one given in [#!davenport!#] closely.
 by applying
Gauss's lemma and keeping careful track of intervals as
they are rescaled and their endpoints are changed.  Finally, in
Section 4.3.2 we use some basic algebra to deduce the
quadratic reciprocity law using the tools we've just developed.
Our proof follows the one given in [#!davenport!#] closely.
 be an odd prime and let
 be an odd prime and let  be an integer
 be an integer 
 . 
 Form the numbers
. 
 Form the numbers
 
and reduce them modulo
 to lie in the interval
 to lie in the interval 
 , i.e., for each of the above numbers
, i.e., for each of the above numbers  find a number
in the interval
 find a number
in the interval 
 that is congruent
to
 that is congruent
to  modulo
 modulo  .  
Let
.  
Let  be the number of negative numbers in the resulting set.  Then
 be the number of negative numbers in the resulting set.  Then
 
 , we expressed each number in
, we expressed each number in
 
as congruent to a number in the set
 
No number 
 appears more than once, with
either choice of sign, because if it did then either two elements
of
 appears more than once, with
either choice of sign, because if it did then either two elements
of  are congruent modulo
 are congruent modulo  or 0
 is the sum of two elements
of
 or 0
 is the sum of two elements
of  , and both events are impossible (the former case cannot occur
because of cancellation modulo
, and both events are impossible (the former case cannot occur
because of cancellation modulo  , and in the latter case we would
have that
, and in the latter case we would
have that 
 for
 for 
 , so
, so
 , a contradiction).  Thus the resulting set must
be of the form
, a contradiction).  Thus the resulting set must
be of the form
 
where each
 is either
 is either  or
 or  .  Multiplying together the elements of
.  Multiplying together the elements of  and of
 and of  , we see that
, we see that
|  | ||
|  |  | 
 
The lemma then follows from Proposition 4.2.1, since
 .
.
  
 .  In each case below,
.  In each case below, 
 .
.
sage: def gauss(a, p): ... # make the list of numbers reduced modulo p ... v = [(n*a)%p for n in range(1, (p-1)//2 + 1)] ... # normalize them to be in the range -p/2 to p/2 ... v = [(x if (x < p/2) else x - p) for x in v] ... # sort and print the resulting numbers ... v.sort() ... print v ... # count the number that are negative ... num_neg = len([x for x in v if x < 0]) ... return (-1)^num_neg sage: gauss(2, 13) [-5, -3, -1, 2, 4, 6] -1 sage: legendre_symbol(2,13) -1 sage: gauss(4, 13) [-6, -5, -2, -1, 3, 4] 1 sage: legendre_symbol(4,13) 1 sage: gauss(2,31) [-15, -13, -11, -9, -7, -5, -3, -1, 2, 4, 6, 8, 10, 12, 14] 1 sage: legendre_symbol(2,31) 1