Key idea of this section
n = x² + y² is solvable ⟺ every prime q ≡ 3 (mod 4) divides n to an even power.
Fermat's two-square theorem
Fermat announced in a letter of 1640 that every prime p ≡ 1 (mod 4) is a sum of two squares; Euler published the first proof in 1752. Since squares are ≡ 0 or 1 (mod 4), no prime ≡ 3 (mod 4) has this property, and 2 = 1² + 1².
Lemma 11.1 (Thue, 1902). Let p be a prime and a an integer with p ∤ a. There exist integers x, y, not both zero, with |x|, |y| < √p and x ≡ ay (mod p).
Proof. Let m = ⌊√p⌋, so (m + 1)² > p. The (m + 1)² numbers u − av with 0 ≤ u, v ≤ m cannot all be distinct modulo p, so u₁ − av₁ ≡ u₂ − av₂ for two different pairs. Put x = u₁ − u₂ and y = v₁ − v₂. These are not both zero, |x|, |y| ≤ m, and m < √p because a prime is not a perfect square. ∎
Theorem 11.2 (Fermat–Euler). Every prime p ≡ 1 (mod 4) is a sum of two squares, and the representation p = x² + y² with x > y > 0 is unique.
Proof. By Corollary 4.4 there is a with a² ≡ −1 (mod p). Take x, y from Thue's lemma. Then x² + y² ≡ a²y² + y² ≡ 0 (mod p), and 0 < x² + y² < 2p, so x² + y² = p. For uniqueness, suppose p = a² + b² = c² + d² with a, b, c, d > 0. Then a²d² − b²c² = a²(p − c²) − (p − a²)c² = p(a² − c²), so p divides (ad − bc)(ad + bc). Also p² = (a² + b²)(c² + d²) = (ac + bd)² + (ad − bc)² = (ac − bd)² + (ad + bc)². If p | ad − bc, then since 0 < ad, bc < p we get ad = bc; as gcd(a, b) = gcd(c, d) = 1 this forces a | c and c | a, so (a, b) = (c, d). If p | ad + bc, then 0 < ad + bc ≤ p forces ad + bc = p, hence ac = bd, and similarly (a, b) = (d, c). So the representation is unique up to order. ∎
Worked example: p = 13, a = 5 (since 5² = 25 ≡ −1). With |x|, |y| ≤ 3 we need x ≡ 5y (mod 13): y = 2 gives x ≡ 10 ≡ −3. Indeed (−3)² + 2² = 13. Don Zagier (1990) gave a famous "one-sentence proof" of Theorem 11.2: the involution on the finite set {(x, y, z) ∈ ℕ³ : x² + 4yz = p} defined by three cases has exactly one fixed point, so the set has odd size, and hence so does the fixed-point set of the obvious involution (x, y, z) ↦ (x, z, y), which therefore is non-empty; a fixed point (x, y, y) gives p = x² + (2y)².
The general case
The Brahmagupta–Fibonacci identity,
(a² + b²)(c² + d²) = (ac − bd)² + (ad + bc)²
is the multiplicativity of the norm N(a + bi) = a² + b² in ℤ[i]. It shows that products of sums of two squares are sums of two squares.
Theorem 11.3. A positive integer n is a sum of two squares if and only if the exponent of q in n is even for every prime q ≡ 3 (mod 4).
Proof. Sufficiency: write n = m²k with k squarefree. Every prime factor of k is 2 or ≡ 1 (mod 4), so k is a product of sums of two squares, hence one itself, and n = m²(x² + y²) = (mx)² + (my)². Necessity: suppose q ≡ 3 (mod 4) and q | x² + y². If q ∤ y then (xy⁻¹)² ≡ −1 (mod q), contradicting (−1/q) = −1. So q | y and then q | x, and q² | x² + y², with (x/q)² + (y/q)² = n/q². Induction on the exponent of q in n completes the proof. ∎
The Gaussian integers
The ring ℤ[i] is Euclidean with respect to the norm (divide in ℚ(i) and round each coordinate to the nearest integer; the error has norm ≤ 1/2), hence a principal ideal domain and a unique factorisation domain. Its units are ±1, ±i, and its primes are, up to units: 1 + i (with norm 2); the rational primes q ≡ 3 (mod 4), which stay prime; and, for each p ≡ 1 (mod 4), the two conjugate primes x ± yi with x² + y² = p. This is the simplest instance of the splitting of primes in a number field, and the rule "p splits iff p ≡ 1 (mod 4)" is reciprocity in disguise.
Counting the representations through this factorisation gives Jacobi's formula: the number r₂(n) of pairs (x, y) ∈ ℤ² with x² + y² = n is
r₂(n) = 4(d₁(n) − d₃(n)),
where dᵢ(n) is the number of divisors of n that are ≡ i (mod 4). For n = 65 the divisors 1, 5, 13, 65 are all ≡ 1 (mod 4), so r₂(65) = 16, matching the representations (±1, ±8), (±8, ±1), (±4, ±7), (±7, ±4). For n = 2026 = 2 · 1013, the odd divisors 1 and 1013 are ≡ 1 (mod 4), so r₂(2026) = 8: the only representation up to order and sign is 2026 = 45² + 1², obtained from 1013 = 23² + 22² by (1 + i)(23 + 22i) = 1 + 45i.
Pythagorean triples
Theorem 11.4. The solutions of x² + y² = z² in positive integers with gcd(x, y) = 1 and y even are exactly
x = m² − n², y = 2mn, z = m² + n²,
with m > n > 0, gcd(m, n) = 1 and m, n of opposite parity.
Proof. Since gcd(x, y) = 1 and y is even, x and z are odd and coprime. Then (y/2)² = ((z + x)/2)((z − x)/2), where the two factors are coprime positive integers (a common divisor divides their sum z and difference x). By unique factorisation each is a square: (z + x)/2 = m², (z − x)/2 = n². The stated conditions on m, n are forced by the coprimality and the parity of x. Conversely these formulas always give primitive triples. ∎
A geometric view: rational points on the circle X² + Y² = 1 correspond, via lines of rational slope t through (−1, 0), to the parametrisation (X, Y) = ((1 − t²)/(1 + t²), 2t/(1 + t²)). This is the prototype of the arithmetic of curves of genus 0.
Infinite descent
Theorem 11.5 (Fermat). The equation x⁴ + y⁴ = z² has no solutions in positive integers. In particular Fermat's Last Theorem holds for exponent 4.
Proof. Suppose a solution exists and take one with z minimal; then gcd(x, y) = 1 and (x², y², z) is a primitive triple. Say y is even: x² = m² − n², y² = 2mn, z = m² + n² as in Theorem 11.4. From x² + n² = m² with x odd, n must be even (otherwise x² + n² ≡ 2 (mod 4) would be a square), so (x, n, m) is again a primitive triple: x = r² − s², n = 2rs, m = r² + s² with gcd(r, s) = 1. Now (y/2)² = m · (n/2) = m · r · s, and m, r, s are pairwise coprime, so each is a square: r = u², s = v², m = w². Then u⁴ + v⁴ = r² + s² = m = w², a new solution with 0 < w ≤ w² = m < m² + n² = z, contradicting minimality. ∎
Fermat's Last Theorem in general (xⁿ + yⁿ = zⁿ has no positive solutions for n ≥ 3) was proved by Wiles in 1995, by establishing enough of the modularity conjecture for elliptic curves; by the earlier work of Frey, Serre and Ribet, a counterexample would give an elliptic curve that cannot be modular.
Three and four squares
Lagrange proved in 1770 that every positive integer is a sum of four squares; Euler's four-square identity (the multiplicativity of the quaternion norm) reduces this to primes. Legendre and Gauss showed that n is a sum of three squares if and only if n is not of the form 4ᵃ(8b + 7). Jacobi's formula r₄(n) = 8 ∑ d, summed over the divisors d of n with 4 ∤ d, comes from the theory of modular forms, which is the natural home of all such representation numbers.
Exercise
- (a)Find the representation of 1013 as a sum of two squares and use it to write 2026 as a sum of two squares.
- (b)Which of 245, 246 and 250 are sums of two squares? Give representations.
- (c)Find all primitive Pythagorean triples with hypotenuse 65.
Show solution
Answers: (a) Trying squares: 1013 − 23² = 1013 − 529 = 484 = 22², so 1013 = 23² + 22², and 2026 = 2 · 1013 = (23 + 22)² + (23 − 22)² = 45² + 1², using (a² + b²)(1² + 1²) = (a + b)² + (a − b)². (b) 245 = 5 · 7² is a sum of two squares: 14² + 7² = 196 + 49. 246 = 2 · 3 · 41 is not (3 appears to the first power). 250 = 2 · 5³ is: 15² + 5² = 225 + 25 and 13² + 9² = 169 + 81. (c) m² + n² = 65 with m > n > 0 coprime of opposite parity: (m, n) = (8, 1) and (7, 4). These give (63, 16, 65) and (33, 56, 65).