Quadratic Residues and the Law of Reciprocity — The Theory of Quadratic Residues
We define the Legendre symbol, prove Euler's criterion, and establish Gauss's lemma. We then prove the law of quadratic reciprocity and discuss the Jacobi symbol and the Tonelli--Shanks algorithm for computing square roots modulo primes.
Let p be an odd prime and a an integer with p∤a. If the congruence x2≡a(modp) has a solution, then a is called a quadratic residue modulo p. Otherwise, a is a quadratic non-residue modulo p.
Definition 2 (Legendre symbol).
For an odd prime p and an integer a, the Legendre symbol is defined by
(pa)=⎩⎨⎧01−1if p∣a,if a is a quadratic residue mod p,if a is a quadratic non-residue mod p.
Theorem 3.
Among 1,2,…,p−1, exactly (p−1)/2 are quadratic residues modulo p and exactly (p−1)/2 are quadratic non-residues.
Proof.
Define f:(Z/pZ)∗→(Z/pZ)∗ by f(xˉ)=xˉ2. We have f(xˉ)=f(yˉ) if and only if xˉ2=yˉ2, equivalently xˉ=±yˉ. Thus each quadratic residue is the image of exactly two elements, so the number of quadratic residues is (p−1)/2.□
2 Euler's Criterion
Theorem 4 (Euler's criterion).
For an odd prime p and an integer a with p∤a,
(pa)≡a(p−1)/2(modp).
Proof.
If a is a quadratic residue, say a≡x2, then a(p−1)/2≡xp−1≡1 by Fermat's little theorem. The polynomial t(p−1)/2−1 has degree (p−1)/2 over (Z/pZ)∗ and therefore at most (p−1)/2 roots; the (p−1)/2 quadratic residues account for all of them. Hence a(p−1)/2≡1 if and only if a is a quadratic residue. Since ap−1≡1, we have (a(p−1)/2)2≡1, so a(p−1)/2≡±1. For a quadratic non-residue, we conclude a(p−1)/2≡−1.□
3 Gauss's Lemma
Lemma 5 (Gauss's lemma).
Let p be an odd prime and p∤a. Among the residues of a,2a,3a,…,2p−1a reduced to representatives in {−(p−1)/2,…,−1,1,…,(p−1)/2}, let μ denote the number of negative representatives. Then
(pa)=(−1)μ.
Proof.
Let s1,s2,…,s(p−1)/2 be the reduced representatives. Their absolute values ∣s1∣,∣s2∣,…,∣s(p−1)/2∣ form a permutation of {1,2,…,(p−1)/2}. (If ∣si∣=∣sj∣ with i=j, then ia≡±ja(modp), giving i=j or i+j≡0; the latter is impossible since 1≤i,j≤(p−1)/2.) Hence ∏si=(−1)μ⋅((p−1)/2)!, while ∏si≡∏i=1(p−1)/2ia=((p−1)/2)!⋅a(p−1)/2. Dividing both sides by ((p−1)/2)! yields a(p−1)/2≡(−1)μ. The result now follows from Euler's criterion.□
In other words, −1 is a quadratic residue modulo p if and only if p≡1(mod4).
Proof.
By Euler's criterion, (p−1)≡(−1)(p−1)/2(modp). Since (−1)(p−1)/2=±1 and p≥3 (so 1≡−1(modp)), the congruence holds as an equality of integers. When p≡1(mod4), the exponent (p−1)/2 is even, giving (p−1)=1. When p≡3(mod4), the exponent is odd, giving (p−1)=−1.□
5 The Law of Quadratic Reciprocity
Theorem 7 (Quadratic reciprocity).
For distinct odd primes p,q,
(qp)(pq)=(−1)2p−1⋅2q−1.
Proof.
Using Gauss's lemma, we write (pq)=(−1)μ and reduce the count μ to a lattice-point enumeration. Consider the rectangle R={(x,y)∣1≤x≤(p−1)/2,1≤y≤(q−1)/2}. The number μ of negative representatives of qxmodp equals the number of lattice points below the line y=qx/p that lie in a certain complementary region. A symmetric argument applies to μ′, where (qp)=(−1)μ′. Combining yields μ+μ′=(p−1)(q−1)/4, and therefore (qp)(pq)=(−1)(p−1)(q−1)/4.□
6 The Jacobi Symbol
Definition 8 (Jacobi symbol).
For an odd positive integer n=p1p2⋯pk (where the pi are odd primes, not necessarily distinct), the Jacobi symbol is defined as (na)=∏i=1k(pia).
Remark 9.
The Jacobi symbol inherits the reciprocity law and can be computed efficiently in O(log2n) time without factoring n. One must note, however, that (na)=1 does not in general imply that a is a quadratic residue modulo n.
7 The Tonelli–Shanks Algorithm
Remark 10.
When a is a quadratic residue modulo a prime p, the Tonelli–Shanks algorithm finds a solution to x2≡a(modp). It factors p−1=2sq with q odd, selects a quadratic non-residue z, and iteratively constructs the solution. The running time is O(log2p).