Sum of Two Squares
Statement
A prime can be written as a sum of two integer squares,
if and only if or .
Equivalently, the only primes that are not sums of two squares are the primes .
Visualization
Which primes up to 50 split as ?
p p mod 4 Decomposition Verdict
---+---------+--------------------+--------
2 2 1² + 1² YES
3 3 — NO
5 1 1² + 2² YES
7 3 — NO
11 3 — NO
13 1 2² + 3² YES
17 1 1² + 4² YES
19 3 — NO
23 3 — NO
29 1 2² + 5² YES
31 3 — NO
37 1 1² + 6² YES
41 1 4² + 5² YES
43 3 — NO
47 3 — NO
The pattern is sharp: every prime splits; none of the primes does.
Proof Sketch
-
Necessity ( no split): Squares are or , so or . A sum of two squares is never .
-
: . Done.
-
split (Fermat–Euler):
- By Quadratic ReciprocityQuadratic ReciprocityRelationship between solvability of quadratic congruences for two odd primesRead more → (specifically the first supplement), is a quadratic residue mod whenever , so there exists with .
- Apply Fermat's descent (or the Gaussian integer argument): the ideal in factors as where , giving .
-
Gaussian integer proof: is irreducible in but not a Gaussian prime when . The factorization in yields the decomposition directly.
Connections
This theorem is intimately connected to Quadratic ReciprocityQuadratic ReciprocityRelationship between solvability of quadratic congruences for two odd primesRead more → (which characterises when is a square mod ), Fermat's Little TheoremFermat's Little TheoremFor prime p, a^p is congruent to a mod pRead more → (used in Euler's criterion), and Fundamental Theorem of ArithmeticFundamental Theorem of ArithmeticEvery integer greater than 1 has a unique prime factorizationRead more → (which guarantees unique factorization in ). The analogous question for four squares is answered by Lagrange's Four-Square TheoremLagrange's Four-Square TheoremEvery natural number is the sum of four perfect squaresRead more →. The structure of representations also links to Multiplicative FunctionsMultiplicative FunctionsArithmetic functions that split over coprime inputs: f(mn) = f(m)f(n) when gcd(m,n) = 1Read more → and Euler's Totient, since the number of representations is multiplicative.
Lean4 Proof
/-- Fermat's theorem on sums of two squares: a prime `p` with `p % 4 ≠ 3`
can be written as `a^2 + b^2`. Mathlib's `Nat.Prime.sq_add_sq` covers
both `p = 2` (which satisfies `2 % 4 = 2 ≠ 3`) and `p ≡ 1 mod 4`. -/
theorem prime_sum_two_squares (p : ℕ) [hp : Fact p.Prime] (h : p % 4 ≠ 3) :
∃ a b : ℕ, a ^ 2 + b ^ 2 = p :=
hp.out.sq_add_sq h
/-- Primes that are ≡ 3 mod 4 cannot be a sum of two squares.
We verify this for `p = 3` by a norm_num check. -/
theorem three_not_sum_two_squares (a b : ℕ) : a ^ 2 + b ^ 2 ≠ 3 := by
omegaReferenced by
- Pythagorean TriplesNumber Theory
- Legendre's Three-Square TheoremNumber Theory
- Lagrange's Four-Square TheoremNumber Theory