Number Theory

Quadratic Reciprocity, Gauss's Golden Theorem

Learn what the law of quadratic reciprocity says, use it to test squares modulo a prime, and see the lattice-point idea behind a proof.

Key takeaways

  • For distinct odd primes p and q, the symbols (p/q) and (q/p) are equal unless both primes are 3 more than a multiple of 4.
  • Two supplementary laws settle when −1 and 2 are squares modulo an odd prime.
  • Repeatedly flipping and reducing a Legendre symbol decides solvability quickly, although it does not find the square root.
  • One of the clearest proofs counts grid points inside a rectangle that is cut by its diagonal.

Quadratic reciprocity links two questions that look unrelated. For two different odd primes p and q, it ties "is q a square modulo p?" to "is p a square modulo q?". The two answers always agree, except when p and q both leave remainder 3 on division by 4, and then they always disagree.

That single rule lets you decide, with a few lines of arithmetic, whether an equation such as x² ≡ 29 (mod 43) has a solution. Gauss gave the first complete proof and returned to the theorem again and again, calling it a golden theorem.

The question being answered

A nonzero number a is a quadratic residue modulo an odd prime p if some x satisfies x² ≡ a (mod p), meaning x² and a leave the same remainder on division by p. Modulo 11, squaring 1 through 10 produces only 1, 4, 9, 5 and 3. Those five are the residues and the other five nonzero classes are nonresidues.

The Legendre symbol records the verdict. Write (a/p) = 1 if a is a nonzero square modulo p, (a/p) = −1 if it is not, and (a/p) = 0 if p divides a. The notation is not a fraction. The basic properties are covered in quadratic residues and the Legendre symbol.

Two of those properties do most of the work here. The symbol depends only on a modulo p, and it is multiplicative: (ab/p) = (a/p)(b/p). So any symbol breaks into symbols of −1, 2 and odd primes smaller than p.

The law and its two supplements

For distinct odd primes p and q:

(p/q) · (q/p) = (−1)^( (p−1)/2 · (q−1)/2 )

The exponent is odd only when both (p−1)/2 and (q−1)/2 are odd, which means p and q are both of the form 4k + 3. In every other case the product is 1.

The two supplements handle the leftovers:

  • (−1/p) = 1 exactly when p ≡ 1 (mod 4).
  • (2/p) = 1 exactly when p ≡ 1 or 7 (mod 8).

You can test small cases by listing squares.

pair first symbol second symbol relation
3 and 5 (3/5) = −1 (5/3) = −1 equal, since 5 ≡ 1 (mod 4)
3 and 7 (3/7) = −1 (7/3) = 1 opposite, both 3 mod 4
5 and 11 (5/11) = 1 (11/5) = 1 equal
7 and 13 (7/13) = −1 (13/7) = −1 equal
How the two symbols relate
p ≡ 1, q ≡ 1 (mod 4) (p/q) equals (q/p) p ≡ 1, q ≡ 3 (mod 4) (p/q) equals (q/p) p ≡ 3, q ≡ 1 (mod 4) (p/q) equals (q/p) p ≡ 3, q ≡ 3 (mod 4) (p/q) equals the negative of (q/p) p ≡ 1, q ≡ 1 (mod 4) (p/q) equals (q/p) p ≡ 1, q ≡ 3 (mod 4) (p/q) equals (q/p) p ≡ 3, q ≡ 1 (mod 4) (p/q) equals (q/p) p ≡ 3, q ≡ 3 (mod 4) (p/q) equals the negative of (q/p)

A worked example

Is 29 a square modulo the prime 43? Searching would mean squaring up to 21 numbers. Reciprocity is faster.

(29/43) = (43/29)           since 29 ≡ 1 (mod 4)
        = (14/29)           reduce 43 modulo 29
        = (2/29) · (7/29)   multiplicativity
(2/29)  = −1                since 29 ≡ 5 (mod 8)
(7/29)  = (29/7)            since 29 ≡ 1 (mod 4)
        = (1/7) = 1         reduce 29 modulo 7
(29/43) = (−1) · 1 = −1

So x² ≡ 29 (mod 43) has no solution. The pattern resembles the Euclidean algorithm: flip, reduce, repeat, and watch the numbers shrink.

For a case with a positive answer, take (3/13). Since 13 ≡ 1 (mod 4), it equals (13/3) = (1/3) = 1. Indeed 4² = 16 ≡ 3 (mod 13).

A longer example, two ways

Try a number with several factors: is 105 = 3 × 5 × 7 a square modulo the prime 131? Note that 131 leaves remainder 3 both on division by 4 and on division by 8. Treat the three factors one at a time.

(3/131) = −(131/3) = −(2/3) = −(−1) = 1      both are 3 mod 4
(5/131) =  (131/5) =  (1/5) = 1              5 ≡ 1 mod 4
(7/131) = −(131/7) = −(5/7)                  both are 3 mod 4
 (5/7)  =  (7/5)   =  (2/5) = −1
(7/131) = 1
(105/131) = 1 · 1 · 1 = 1

So 105 is a square modulo 131. The Jacobi symbol, an extension described further below, gets there with no factoring of 105. Since 105 ≡ 1 (mod 4), you may flip at once to (131/105) = (26/105) = (2/105) · (13/105). Because 105 ≡ 1 (mod 8), the first factor is 1. The second flips to (105/13) = (1/13) = 1.

Two routes, one answer. Agreement between independent routes is a good way to catch a sign error, which is the most common slip in this kind of work.

Which primes accept a given number?

Reciprocity also answers a question in the other direction. Fix a number and ask for which primes it is a square. Without the law there would be no reason to expect a pattern.

Take 5. Because 5 ≡ 1 (mod 4), (5/p) = (p/5). The squares modulo 5 are 1 and 4, so 5 is a square modulo p exactly when p ends in 1 or 9, for primes other than 2 and 5. Check p = 11: 4² = 16 ≡ 5.

Take 3. Here the sign depends on p modulo 4 and the symbol (p/3) depends on p modulo 3. Combining the two gives (3/p) = 1 exactly when p ≡ 1 or 11 (mod 12), for p greater than 3. With p = 23, which is 11 modulo 12, you find 7² = 49 ≡ 3.

The answer is always governed by p modulo a fixed number. That regularity is the surprising content of the law. It connects with Dirichlet's theorem, which guarantees infinitely many primes in each of the suitable classes.

Why it is true: counting grid points

Many proofs start from Euler's criterion, (a/p) ≡ a^((p−1)/2) (mod p). From it follows Gauss's lemma, and from that a counting formula usually credited to Eisenstein. For distinct odd primes p and q,

(q/p) = (−1)^M,   M = ∑ floor(qx/p)   for x = 1 to (p−1)/2
(p/q) = (−1)^N,   N = ∑ floor(py/q)   for y = 1 to (q−1)/2

Now picture the grid points (x, y) with x from 1 to (p−1)/2 and y from 1 to (q−1)/2. Draw the line py = qx through the origin. No grid point in this block lies on the line, because p cannot divide x.

M counts the points below the line, and N counts the points above it. Together they fill the whole block, so M + N = (p−1)/2 · (q−1)/2. Multiplying the two symbols gives (−1)^(M+N), which is the law.

Try p = 7 and q = 11. M = 1 + 3 + 4 = 8, so (11/7) = 1. N = 0 + 1 + 1 + 2 + 3 = 7, so (7/11) = −1. And M + N = 15 = 3 × 5.

Shape of the grid-point proof
1 Euler's criterion A power of a decides whether it is a square 2 Floor sums Each symbol becomes the parity of a sum 3 Count points The two sums count dots on either side of a diagonal 4 Add them Together the dots fill a rectangle Euler's criterion A power of a decides whether it is a square 1 Floor sums Each symbol becomes the parity of a sum 2 Count points The two sums count dots on either side of a diagonal 3 Add them Together the dots fill a rectangle 4

Where the two supplements come from

Euler's criterion gives the first supplement immediately: (−1/p) ≡ (−1)^((p−1)/2), and the exponent is even exactly when p ≡ 1 (mod 4).

The second uses Gauss's lemma. Take the multiples a, 2a, 3a and so on up to ((p−1)/2) × a, reduce each to its remainder between 1 and p − 1, and let t be the number of remainders larger than p/2. Then (a/p) = (−1)^t.

For a = 2 and p = 11, the multiples are 2, 4, 6, 8 and 10. Three of them exceed 5.5, so (2/11) = −1. For p = 7 they are 2, 4 and 6, of which two exceed 3.5, so (2/7) = 1, matching 3² = 9 ≡ 2. Counting how many even numbers fall in the upper half for each remainder of p modulo 8 gives the general rule.

A short history

Euler observed the pattern in the eighteenth century from numerical evidence, and Legendre stated it in a recognizable form and offered an argument with gaps. Gauss found a complete proof as a young man in 1796 and published it in his Disquisitiones Arithmeticae of 1801.

He then produced further proofs by quite different methods. Part of his motive was to find an approach that would extend to cubes and fourth powers. Since then hundreds of proofs have been recorded, many of them variations on a few core ideas. You can read more about the man in a profile of Gauss, and about why settled results keep getting new arguments in why mathematicians reprove theorems.

What the law does and does not give you

Reciprocity tells you whether a square root exists. It does not hand you the root. For primes p ≡ 3 (mod 4) there is a shortcut: if a is a residue, then x = a^((p+1)/4) works. Modulo 11, 5^3 = 125 ≡ 4, and 4² = 16 ≡ 5. Other primes need a procedure such as the Tonelli–Shanks algorithm.

The method above also requires factoring the top number at each step. The Jacobi symbol removes that need. It extends the notation to any odd positive bottom number and obeys the same reciprocity rules, so you can flip without factoring anything except powers of 2. One caution: for a composite bottom number, a Jacobi symbol of 1 does not guarantee that a square root exists.

These tools appear in primality testing and in some cryptographic protocols. Deciding squareness modulo a product of two unknown large primes is believed to be hard, even though the Jacobi symbol remains easy to compute.

Where it leads

Gauss and later number theorists found cubic and biquadratic reciprocity laws, which are cleanest in larger number systems such as the Gaussian integers a + bi. That search was one of the forces behind algebraic number theory.

In the twentieth century, Emil Artin's reciprocity law gave a sweeping statement that contains the quadratic case as a special instance, within what is called class field theory. The ninth of Hilbert's problems had asked for exactly this kind of general law. Far-reaching extensions are a central theme of the Langlands program, large parts of which remain conjectural as of the mid-2020s.

Common mistakes

  • Applying the law when one of the numbers is not an odd prime. Factor first, or use the Jacobi symbol with care.
  • Treating 2 like other primes. It follows the supplement based on remainders modulo 8.
  • Forgetting the sign when both primes are 3 modulo 4.
  • Reducing the bottom number. You may replace the top by its remainder, but changing the bottom requires a flip.
  • Reading (a/p) as a ÷ p.

To practice, compute (13/31). Since 13 ≡ 1 (mod 4), it equals (31/13) = (5/13) = (13/5) = (3/5) = −1.

Written for 4Mathematics with AI writing tools and not reviewed line by line by a person. Check anything you rely on against a textbook or primary source. Report an error.

Keep reading

All 59 articles in Number Theory →

Latest news on this topic