Folioby Interconnected
Log InSign Up

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.

FO
Folio Official
March 1, 2026

1 Quadratic Residues

Definition 1 (Quadratic residue).
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−1​if 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−1​a 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)/2​ia=((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. □

4 The First Supplement to Quadratic Reciprocity

Theorem 6 (First supplement).
For an odd prime p,
(p−1​)=(−1)(p−1)/2={1−1​if p≡1(mod4),if p≡3(mod4).​
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=p1​p2​⋯pk​ (where the pi​ are odd primes, not necessarily distinct), the Jacobi symbol is defined as (na​)=∏i=1k​(pi​a​).
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).
Number TheoryAlgebraTextbookQuadratic ResiduesReciprocity
FO
Folio Official

Mathematics "between the lines" — exploring the intuition textbooks leave out, written in LaTeX on Folio.

1 followers·107 articles
Number Theory TextbookPart 8 of 13
Previous
The Chinese Remainder Theorem and Its Applications — Systems of Congruences and Direct Products of Rings
Next
Arithmetic Functions and Multiplicative Functions — Functions on the Integers

Share your expertise with the world

Write articles with LaTeX support, build your audience, and earn from your knowledge.

Start Writing — It's Free

More from Folio Official

Folio Official·March 1, 2026

Introduction to Algebraic Integers — Extending the Notion of Integer

Using the Gaussian integers Z[i] and the Eisenstein integers Z[omega] as concrete examples, we introduce rings of algebraic integers. We demonstrate the failure of unique factorization in Z[sqrt(-5)] and show how ideals and prime ideal factorization restore uniqueness. We define the class number and discuss its significance.

Number TheoryAlgebraTextbook
2
Folio Official·March 1, 2026

Arithmetic Functions and Multiplicative Functions — Functions on the Integers

We systematically define the principal multiplicative functions (phi, sigma, mu, d), develop the ring structure of Dirichlet convolution, and give a rigorous proof of the Moebius inversion formula. We also clarify the connection to the inclusion-exclusion principle.

Number TheoryAlgebraTextbook
Folio Official·March 1, 2026

Primes and the Fundamental Theorem of Arithmetic — The Atomic Decomposition of Integers

We define prime numbers and establish their basic properties, including Euclid's proof of the infinitude of primes. We then give a rigorous proof of the fundamental theorem of arithmetic (existence and uniqueness of prime factorization), and discuss the sieve of Eratosthenes and the Miller--Rabin primality test.

Number TheoryAlgebraTextbook
Folio Official·March 1, 2026

Chebyshev's Estimates: 0.92 x/ln x < π(x) < 1.11 x/ln x and the Prime Number Theorem

Chebyshev proved that 0.92 x/ln x < π(x) < 1.11 x/ln x for sufficiently large x. This article gives a complete proof via binomial coefficients and the Chebyshev functions θ(x) and ψ(x), then traces the path to the prime number theorem π(x) ~ x/ln x.

Number TheoryAlgebraTextbook