Quadratic Residues

Quadratic Residues

Quadratic residues are integers that are perfect squares modulo a given modulus. The study of quadratic residues is central to number theory and has applications in cryptography, primality testing, and the theory of quadratic forms.

The crown jewel of this theory is the Law of Quadratic Reciprocity, which Gauss called the golden theorem and proved multiple times using different methods.

Definition

Let p p be an odd prime and a a an integer not divisible by p p. Then a a is a quadratic residue modulo p p if the congruence x2≡a⁢mod⁡(p) x squared is identical to a mod p has a solution.

If no such solution exists, a a is called a quadratic nonresidue modulo p p.

Example

Modulo 7 7, the squares are 12=1 1 squared equals 1, 22=4 2 squared equals 4, 32=2 3 squared equals 2, 42=2 4 squared equals 2, 52=4 5 squared equals 4, 62=1 6 squared equals 1.

So the quadratic residues mod 7 7 are {1,2,4} the set 1 comma 2 comma 4 and the nonresidues are {3,5,6} the set 3 comma 5 comma 6.

The Legendre Symbol

The Legendre symbol (ap) open paren a over p close paren encodes whether a is a quadratic residue modulo the odd prime p p:

(ap)={1if a is a QR mod p−1if a is a QNR mod p0if p|a open paren a over p close paren equals 3 cases Case 1: 1 if a is a QR mod p Case 2: negative 1 if a is a QNR mod p Case 3: 0 if p divides a

Eulers Criterion

The Legendre symbol can be computed using Eulers criterion:

(ap)≡a(p−1)/2⁢(mod⁡(p)) open paren a over p close paren is identical to a raised to the open paren p minus 1 close paren divided by 2 power times mod p

This follows from Fermat's little theorem: ap−1≡1 a raised to the p minus 1 power is identical to 1, so a(p−1)/2≡±1 a raised to the open paren p minus 1 close paren divided by 2 power is identical to plus or minus 1.

Properties of the Legendre Symbol

The Legendre symbol is multiplicative:

(a⁢bp)=(ap)⁢(bp) open paren a b over p close paren equals open paren a over p close paren times open paren b over p close paren

This makes it a completely multiplicative function of a a.

Special Values

When is -1 a Quadratic Residue?

(−1p)=(−1)(p−1)/2={1if p≡1⁢(mod⁡(4))−1if p≡3⁢(mod⁡(4)) open paren negative 1 over p close paren equals open paren negative 1 close paren raised to the open paren p minus 1 close paren divided by 2 power equals 2 cases Case 1: 1 if p is identical to 1 times mod 4 Case 2: negative 1 if p is identical to 3 times mod 4

So -1 is a quadratic residue mod p if and only if p is congruent to 1 mod 4.

When is 2 a Quadratic Residue?

(2p)=(−1)(p2−1)/8={1if p≡±1⁢(mod⁡(8))−1if p≡±3⁢(mod⁡(8)) open paren 2 over p close paren equals open paren negative 1 close paren raised to the exponent open paren p squared minus 1 close paren divided by 8 end exponent equals 2 cases Case 1: 1 if p is identical to plus or minus 1 times mod 8 Case 2: negative 1 if p is identical to plus or minus 3 times mod 8

So 2 2 is a quadratic residue mod p p if and only if p p is congruent to plus or minus 1 1 mod 8 8.

The Law of Quadratic Reciprocity

Let p p and q q be distinct odd primes. Then:

(pq)⁢(qp)=(−1)p−12⋅q−12 open paren p over q close paren times open paren q over p close paren equals open paren negative 1 close paren raised to the fraction with numerator p minus 1 and denominator 2 times fraction with numerator q minus 1 and denominator 2 power

Equivalently, (pq)=(qp) open paren p over q close paren equals open paren q over p close paren unless both p p and q q are congruent to 3⁢mod⁡(4) 3 mod 4, in which case (pq)=−(qp) open paren p over q close paren equals negative open paren q over p close paren.

This remarkable theorem allows us to compute Legendre symbols efficiently by reducing large numbers modulo small primes.

The Jacobi Symbol

The Jacobi symbol generalizes the Legendre symbol to composite odd moduli. For n=p1a1⁢p2a2⋯ n equals p sub 1 raised to the a sub 1 power p sub 2 raised to the a sub 2 power dot dot dot (odd), define:

(an)=(ap1)a1⁢(ap2)a2⋯ open paren a over n close paren equals open paren the fraction with numerator a and denominator p sub 1 close paren raised to the a sub 1 power times open paren the fraction with numerator a and denominator p sub 2 close paren raised to the a sub 2 power dot dot dot

The Jacobi symbol retains the multiplicativity and reciprocity properties, making it useful for computation even when we do not know the factorization of n n.

Counting Quadratic Residues

Among the integers 1,2,…,p−1 1 comma 2 comma dot dot dot comma p minus 1, exactly (p−1)/2 open paren p minus 1 close paren divided by 2 are quadratic residues and (p−1)/2 open paren p minus 1 close paren divided by 2 are nonresidues.

This follows because the squaring map x↦x2 x right arrow from bar x squared is two-to-one on the nonzero elements: x x and −x negative x have the same square.

Applications

Primality Testing

The Solovay-Strassen primality test uses the Jacobi symbol and Euler's criterion. If n n is prime, then the Jacobi symbol (an) open paren a over n close paren equals a(n−1)/2⁢mod⁡(n) a raised to the open paren n minus 1 close paren divided by 2 power mod n for all a a. Composites usually fail this test.

Cryptography

Quadratic residuosity is the basis for several cryptographic systems. The Goldwasser-Micali cryptosystem uses the difficulty of distinguishing quadratic residues from nonresidues modulo a composite.

Solving Quadratic Congruences

To solve x2≡a⁢(mod⁡(p)) x squared is identical to a times mod p when a a is a quadratic residue, the Tonelli–Shanks algorithm efficiently finds square roots modulo primes.

Gaussian Periods and Gauss Sums

Gauss sums are exponential sums that encode information about quadratic residues:

g=∑a=0p−1(ap)⁢e2⁢π⁢i⁢a/p g equals the sum from a equals 0 to p minus 1 of open paren a over p close paren e raised to the 2 pi i a divided by p power

Gauss showed that g2=(−1p)⁢p g squared equals open paren negative 1 over p close paren times p. These sums are fundamental in algebraic number theory and the proof of quadratic reciprocity.

Historical Note

Euler and Legendre studied quadratic residues and conjectured the reciprocity law. Gauss provided the first complete proof in 1796 at age 18, later giving seven more proofs using different methods.

Quadratic reciprocity inspired the search for higher reciprocity laws, leading to class field theory and modern algebraic number theory.

Algorithm for Computing Legendre Symbol

To compute (ap) open paren a over p close paren efficiently:

Reduce a a modulo p p.

Factor out powers of 2 2 and use the formula for (2p) open paren 2 over p close paren.

For odd factors, use quadratic reciprocity to swap the arguments.

Reduce the arguments and repeat until the result is determined.

This is similar to the Euclidean algorithm and runs in polynomial time.

Distribution of Quadratic Residues

Quadratic residues are not randomly distributed. Consecutive quadratic residues and nonresidues exhibit patterns studied by number theorists.

The least quadratic nonresidue modulo p p is expected to be O⁢(log⁡p) O times log p for most primes, though proving good bounds unconditionally remains difficult.

Quadratic residues form a fundamental concept connecting number theory, algebra, and cryptography, with the Law of Quadratic Reciprocity standing as one of the most beautiful theorems in mathematics.

Quadratic Character

The Legendre symbol defines a group homomorphism from the multiplicative group of integers mod p p to {−1,1} the set negative 1 comma 1. This is the unique quadratic character modulo p p, a concept generalized by Dirichlet characters in analytic number theory.