Legendre's Three-Square Theorem
Statement
Legendre's three-square theorem (1798): a positive integer is representable as a sum of three perfect squares,
if and only if is not of the form for non-negative integers and .
The excluded residues mod that cannot be sums of three squares are . Multiplying by propagates the obstruction: if is excluded, so is .
Visualization
Status for through . Excluded numbers () are marked with :
| Form? | Status | Representation | |
|---|---|---|---|
| 7 | no three-square rep | ||
| 14 | OK | ||
| 15 | no three-square rep | ||
| 21 | OK | ||
| 23 | no three-square rep | ||
| 28 | no three-square rep | ||
| 30 | OK |
Complete list of excluded : .
All other admit a representation. For instance:
- :
- :
- :
Proof Sketch
- Necessity (excluded form cannot be represented). Any square is or , so the sum of three squares is but never . Hence is excluded. The factor-of- obstruction follows: if , then are all even (check mod 4), so .
- Sufficiency (all other are representable). The proof uses Dirichlet's theorem on primes in arithmetic progressions to find a prime that divides a suitable form, then reduces to showing primes not of the excluded form are representable.
- Reduction to primes. For each prime one constructs a direct representation; the general case uses composition identities.
Connections
This is the three-square analogue of Lagrange's Four-Square TheoremLagrange's Four-Square TheoremEvery natural number is the sum of four perfect squaresRead more →, which has no exceptions. The excluded residue condition is a local obstruction at the prime , similar in spirit to the local-global principle underlying Sum of Two SquaresSum of Two SquaresA prime is a sum of two perfect squares if and only if it equals 2 or is congruent to 1 mod 4Read more → (Fermat's characterisation via primes ).
Lean4 Proof
import Mathlib.NumberTheory.SumFourSquares
/-- Explicit three-square witness: 30 = 1² + 2² + 5². -/
theorem three_sq_30 : ∃ a b c : ℕ, a ^ 2 + b ^ 2 + c ^ 2 = 30 :=
⟨1, 2, 5, by norm_num⟩
/-- Explicit three-square witness: 14 = 1² + 2² + 3². -/
theorem three_sq_14 : ∃ a b c : ℕ, a ^ 2 + b ^ 2 + c ^ 2 = 14 :=
⟨1, 2, 3, by norm_num⟩
/-- The excluded form 4^0*(8*0+7) = 7 is indeed 7 mod 8. -/
theorem seven_mod_eight : 7 % 8 = 7 := by decide
/-- The mod-8 residues of squares: decide on all residue classes 0..7. -/
theorem sq_mod_eight_set : ∀ r : Fin 8, (r.val ^ 2) % 8 = 0 ∨
(r.val ^ 2) % 8 = 1 ∨ (r.val ^ 2) % 8 = 4 := by decideReferenced by
- Lagrange's Four-Square TheoremNumber Theory