Gauss's Lemma
Fix an odd prime and an integer not divisible by . Multiply the numbers by . Reduce each product to the residue in the range . Count how many of these residues come out negative. Gauss's Lemma asserts that the parity of this count determines the answer. It tells us exactly whether is a quadratic residue or nonresidue mod . This is a strange and beautiful fact. A purely arithmetic sign-counting exercise reproduces deep multiplicative structure. That structure is encoded in the Legendre Symbol. The result matters for two reasons. First, it converts an abstract question into a mechanical computation. The question "is a square mod ?" becomes: count sign changes. Second, it is the load-bearing lemma underneath the Law of Quadratic Reciprocity. Gauss himself used a version of this counting argument. It appears in several of his eight proofs of reciprocity. It bridges two ideas. One is Euler's Criterion, an existence-flavored characterization via . The other is geometric lattice-point counting, which eventually yields reciprocity. The big picture is this. Quadratic residues mod form an index-2 subgroup of . Legendre's symbol is the corresponding sign character. Euler's criterion identifies this character with . Gauss's Lemma gives a second, independent identification. This one works via parity of sign flips among least residues. The fact that these two characterizations agree is itself a small miracle. It is worth proving carefully. Once proved, the lemma becomes a computational engine. It will let us evaluate outright. It will also supply the geometric heart of the proof of reciprocity itself. This article gives the precise statement. It includes a complete proof from first principles, using only elementary facts about residues. It offers two fully computed numerical examples with asymmetric inputs. It discusses exactly which hypotheses are load-bearing. Finally, it looks at where the lemma sits historically and in modern applications.
- Gauss's Lemma expresses as , where counts negative least residues among .
- It requires an odd prime and ; both hypotheses are essential.
- The proof multiplies the least-residues together and compares the result to , using unique reduction mod .
- It gives an independent, purely combinatorial route to Euler's criterion's conclusion, without invoking Fermat's Little Theorem directly on .
- It is the direct ancestor of the geometric lattice-point argument (Eisenstein's proof) for the Law of Quadratic Reciprocity.
- It immediately computes and other small supplementary symbols.
- Key idea: counting sign flips of least residues under multiplication by exactly detects whether is a square mod .
Where this lives today
Gauss's Lemma is the direct technical predecessor of the supplementary laws of quadratic reciprocity: applying it with recovers by counting that every element of the half-system flips sign, and applying it with (via a short lattice-point count of how many multiples exceed ) gives . Both supplementary laws are usually proved as corollaries of exactly this counting method before the full Law of Quadratic Reciprocity is attempted. In modern terms, Gauss's Lemma is one of the earliest instances of a sign character computation via a group action: acting on itself by multiplication, tracked through a fundamental domain , produces a cocycle whose value is exactly the Legendre symbol. This viewpoint generalizes to more elaborate reciprocity laws (cubic and biquadratic reciprocity, and Hilbert reciprocity for local fields), where analogous "sign" or "residue symbol" counting arguments recur. Computationally, algorithms for quadratic residuosity testing — relevant to primality tests and to cryptographic protocols relying on the quadratic residuosity assumption (e.g. Goldwasser–Micali encryption) — ultimately rest on the equivalence between Euler's criterion and this sign-counting description, since both give independently checkable routes to the same bit of information. In computational number theory courses, the lemma is frequently used as a hand-computable cross-check against modular exponentiation when verifying quadratic residue tables by two different methods.
Ask the tutor: How does Gauss's Lemma with get refined into the full geometric lattice-point proof of quadratic reciprocity?
Let be an odd prime and let be any integer with . The least residue of modulo , denoted , is the unique integer in the range
(Since is odd, is never equal to , so this range is unambiguous and whenever .) Now fix an integer with , and consider the half-system
Form the products and let be their least residues mod . Define
the number of these least residues that are negative. Gauss's Lemma computes the Legendre symbol in terms of the parity of .
Intuition
Think of the integers mod arranged symmetrically around , from up to , instead of the usual to . Multiplying by permutes the nonzero residues; the question is how many of the "positive half" get thrown, after reduction, into the "negative half" . If , nothing moves: , even, and indeed is always a square. If , every single element of the positive half maps to its negative, so ; this count is even exactly when , matching the classical fact . The lemma says this parity phenomenon is completely general: whenever is a nonresidue, multiplication by must push an odd number of elements across the sign line, and whenever is a residue, an even number cross. The picture below shows , . We track where each of lands after multiplying by and reducing to .
In this picture, land in the negative zone: that is , an odd count, so the lemma predicts . Indeed is not a square mod (the squares mod are ), confirming the prediction.
Let be an odd prime, and let with . Let be the number of negative least residues among
as in the Definition above. Then
Setup. Write . For , let be the least residue of mod , so and . Since and (as ), we have , so for every . Write and , so that
By definition, is exactly the number of indices with , so
Step 1: the values are a permutation of . Each lies in by construction, and there are of them, so it suffices to show the map is injective on . Suppose for some . Then , i.e. . Since , is invertible mod , so this gives .
- If : since , we get , so forces .
- If : then . But , so , and the only multiple of in this range would have to be , impossible since . So this case cannot occur (unless we also already have from the first case forcing even, but we've shown outright is impossible here).
Hence is the only possibility, forcing . So is injective, and since it maps the -element set into itself injectively, it is a bijection. That is,
Step 2: multiply everything together. From for each , take the product over :
By (2), (the same product, just reordered — multiplication is commutative). So
Since is prime and is a product of integers each strictly between and , we have ; hence is invertible mod and we may cancel it:
Step 3: identify via Euler's Criterion. By Euler's Criterion, since ,
Combining with (3):
Both sides lie in , and since is odd, , so ; congruence mod between two elements of forces actual equality. Hence
By (1), the right side equals . Therefore
which is the assertion of the theorem.
∎Worked examples
Example 1: , (asymmetric, no shortcut). Here is odd prime, , and . We compute for , reduce mod , and take least residues in .
| (in ) | least residue | sign | ||
|---|---|---|---|---|
| 1 | 5 | 5 | 5 | + |
| 2 | 10 | 10 | ||
| 3 | 15 | 15 | ||
| 4 | 20 | 3 | 3 | + |
| 5 | 25 | 8 | 8 | + |
| 6 | 30 | 13 | ||
| 7 | 35 | 1 | 1 | + |
| 8 | 40 | 6 | 6 | + |
Check Step 1's claim: the absolute values of the least residues are — indeed a permutation of , confirming (2). Count negative entries: give negative least residues, so , odd. Gauss's Lemma predicts
Independent check via Euler's criterion. We need . Compute stepwise: ; ; . So , confirming directly, matching the lemma's prediction. (Indeed the squares mod 17 are — the list — and is not among them.)
Example 2: , (a second independent check, larger and asymmetric). Here , , . Compute for and take least residues in .
| mod 19 (in ) | least residue | sign | ||
|---|---|---|---|---|
| 1 | 7 | 7 | 7 | + |
| 2 | 14 | 14 | ||
| 3 | 21 | 2 | 2 | + |
| 4 | 28 | 9 | 9 | + |
| 5 | 35 | 16 | ||
| 6 | 42 | 4 | 4 | + |
| 7 | 49 | 11 | ||
| 8 | 56 | 18 | ||
| 9 | 63 | 6 | 6 | + |
Absolute values: — a permutation of as required. Negative entries occur at : that's , even. Gauss's Lemma predicts
i.e. should be a quadratic residue mod .
Verification: indeed ... let's directly search: squares mod 19 are (from ). Since , we confirm is indeed a square, matching even. Also by Euler: . Compute ; ; ; . So , confirming .
Gauss's Lemma is stated for odd primes ; the entire proof leans on this via three places: the half-system requires odd to be a well-defined integer count, the injectivity argument in Step 1 uses that is prime so that is invertible mod , and the cancellation of in Step 2 uses that is prime so . To see what breaks if we merely drop primality (keep odd, but let be composite), take and , with . Here , and we would attempt least residues of reduced into : these are . So (even), and the "lemma" would predict . But the Legendre symbol is only defined for an odd prime; for composite modulus one must instead use the Jacobi symbol, and the Jacobi symbol does not detect being a quadratic residue mod in general. Indeed is not a square mod (squares mod 9 are ), yet the sign-count procedure above still runs and outputs a definite parity — it simply is not computing a Legendre symbol at all, because none exists for composite . Worse, the key algebraic identity from Step 1, that ranges over a full permutation of , can fail outright for composite : it relied on contradiction using that the only way or forces literal equality — an argument valid for any , actually, but the deeper link to Euler's criterion (Step 3) is where primality is truly indispensable, since Euler's Criterion itself is a theorem about primes. Composite voids the bridge between the sign-count and any multiplicative character, so the "lemma" becomes a numerology exercise with no number-theoretic content.
Scope, edge cases & common traps
| Situation | What happens |
|---|---|
| Excluded: , the half-system is empty, and the Legendre symbol mod is not part of the usual theory. | |
| Excluded: Legendre symbol is defined to be ; the least residues of would include , breaking the sign-count entirely. | |
| negative | Fine — the lemma applies to any integer coprime to , positive or negative; just compute least residues of as stated. |
| composite | Invalid; see counterexample above — no Legendre symbol exists to equate the count to. |
| Confusing with for | itself can differ for and (it depends on the actual representative chosen for the "multiplier," not just the residue class), but the parity is a class invariant, since it must always equal , which only depends on . |
The mathematician behind it
Origins · 1 minCarl Friedrich Gauss and how this was discovered
Gauss developed this lemma as part of his lifelong obsession with the Law of Quadratic Reciprocity, which he called the "golden theorem" (theorema aureum) and proved by essentially this counting technique among his several independent proofs (he eventually gave eight). Gauss's Disquisitiones Arithmeticae (1801) systematized modular arithmetic itself, introducing the congruence notation still used today, and quadratic residues were one of its central topics. The lemma bearing his name appears as a tool refined across his second, third, and later proofs of reciprocity, illustrating his practice of returning to a single theorem repeatedly to extract ever more structural understanding.
What exactly does count, in plain language?
It counts how many of the numbers , after being reduced modulo into the symmetric range , land on the negative side. Concretely: take each multiple, subtract off the nearest multiple of so the result is as small in absolute value as possible, and check its sign. If that "balanced remainder" is negative, it contributes to the count. The parity (even or odd) of this count is what the lemma links directly to whether is a square mod .
Why is this called a "lemma" rather than a theorem, given how much work the proof takes?
Historically it is termed a lemma because in Gauss's own development, and in the standard modern treatment, its main role is as a stepping stone toward the Law of Quadratic Reciprocity, which is regarded as the theorem the whole subject is building toward. In terms of pure logical content, though, Gauss's Lemma is a complete, self-contained, non-trivial result: it fully computes the Legendre symbol via an independent combinatorial method, and could reasonably stand as a theorem in its own right. The naming reflects its historical function more than its logical weight.
Does the value of itself depend on the choice of representative for , or only its parity?
The exact integer can genuinely change if you replace by (a different representative of the same residue class), because the actual least residues computed will differ. What Gauss's Lemma guarantees is that the parity of — whether it's even or odd — depends only on the residue class of mod , because that parity always equals , a quantity that manifestly only depends on . So is representative-dependent but is not.
How does Gauss's Lemma relate to Euler's Criterion — are they saying the same thing?
They characterize the same object, , via two logically different routes. Euler's Criterion identifies it with , an algebraic/exponential description tied to the cyclic structure of . Gauss's Lemma identifies it with , a combinatorial/geometric description tied to counting sign flips. The proof of Gauss's Lemma in fact uses Euler's Criterion as one ingredient (Step 3), so logically Gauss's Lemma is a refinement built on top of Euler's Criterion, translating an exponential fact into a directly countable one.
Can Gauss's Lemma be used to compute directly?
Yes, and this is one of its most quoted applications. Applying the lemma with , one counts how many multiples exceed before reduction (since doubling numbers below never wraps around, only those pushing past need reduction, each contributing exactly one negative least residue). A short case analysis on shows this count's parity matches , yielding the classical supplementary law , i.e. exactly when .
Is there a slicker, geometric way to see why the lemma is true?
Yes — this is essentially Eisenstein's refinement. One shows equals the number of lattice points with integer satisfying that make land in the upper half, translated into a count of lattice points strictly below a certain line segment in a rectangle. This reformulation is what lets Eisenstein push the same idea into a symmetric double-counting argument for two primes simultaneously, which is precisely the mechanism that proves full quadratic reciprocity.
Does Gauss's Lemma generalize beyond quadratic residues, e.g. to cubic residues?
The literal statement is specific to quadratic residues and the Legendre symbol, since it is built on the sign involution , which only has order . However, the underlying strategy — track an action of the multiplicative group on residues through a chosen fundamental domain, and extract a character value from the resulting combinatorics — has analogues in higher reciprocity laws (cubic, biquadratic, and general power residue symbols), though those require replacing "sign" with roots of unity of higher order and a correspondingly more elaborate bookkeeping device.