Number TheoryHonors · Lesson 05 / 16← Lesson 04Lesson 06 →
Lesson 05 · Gaussian integers and characters · 50–65 minutes

Sums of Two Squares

13 = 32 + 22, 29 = 52 + 22, 37 = 62 + 12, but 7, 11 and 19 are not sums of two squares. Fermat claimed that an odd prime is a sum of two squares exactly when p ≡ 1 (mod 4). You will prove it twice: once by a pigeonhole argument that turns the square root of −1 into a small solution, and once by the Euclidean algorithm in ℤ[i], which also computes it. Then you will prove the representation is unique.

Where this lesson is headed

p = a2 + b2  ⇔  p = 2 or p ≡ 1 (mod 4),   and then p = (a + bi)(a − bi) in exactly one way

In words: a prime p ≡ 1 (mod 4) is the norm of a Gaussian integer, uniquely up to order and signs. Equivalently p splits in ℤ[i] into two conjugate Gaussian primes, and the circle x2 + y2 = p passes through exactly 8 lattice points.

You will use

A u with u2 ≡ −1 (mod p) exists for p ≡ 1 (mod 4), and x + yi ↦ x + yu respects sums and products (Lesson 04, step 7; Lesson 03). The norm multiplies, and division with remainder works in ℤ[i] (Lesson 04, steps 4 and 6). A prime dividing a product divides a factor.

p: an odd prime

u: a solution of u2 ≡ −1 (mod p)

representation: p = a2 + b2 with integers a, b

Gaussian prime: a non-unit π ∈ ℤ[i] whose only factorizations are π = unit × associate of π

r2(n): #{(x, y) ∈ ℤ2 : x2 + y2 = n}

01. Which primes are sums of two squares?

Start with p = 13. The search table subtracts x2 from p and checks whether what is left is a square. The circle x2 + y2 = p shows every lattice point on it. The grid on the right turns the square root u of −1 into a small solution without any search.

Search: is p − x2 a square?

Lattice points on x2 + y2 = p

Guided experiments

Do these in order. "Set this up" chooses p.

    All primes below 200

    pp mod 4a2 + b2r2(p)

    Every p ≡ 1 (mod 4) has exactly one representation with 0 < b < a, and 8 lattice points; no p ≡ 3 (mod 4) has any.

    Exactly the primes p ≡ 1 (mod 4), always in one way. Stage 02 proves existence, gives an algorithm, and proves uniqueness.