Introduction to Modern Algebra

Contents › Chapter 12. Unique factorization

12.7 Sums of two squares

Which primes are sums of two squares? 5=1+45 = 1 + 4 and 13=4+913 = 4 + 9 are, while 33 and 77 are not. In Z[i]\mathbb{Z}[i] the question becomes one about factors, since a2+b2=(a+bi)(a−bi)a^2 + b^2 = (a + bi)(a - bi): a prime pp is a sum of two squares exactly when it splits in Z[i]\mathbb{Z}[i] into two factors of norm pp. The Gaussian integers form a PID (Theorem 12.3.4), and that settles the question.

Theorem 12.7.1 (Sums of two squares).
  • (i) An odd prime pp is a sum of two squares of integers if and only if p≡1(mod4)p \equiv 1 \pmod 4.
  • (ii) Up to units, the irreducible elements of Z[i]\mathbb{Z}[i] are: 1+i1 + i; the elements a+bia + bi for which a2+b2a^2 + b^2 is a prime congruent to 11 mod 44; and the primes of Z\mathbb{Z} that are congruent to 33 mod 44.
Proof.

Idea. For (i), find an integer nn with p∣n2+1p \mid n^2 + 1. Then pp divides (n+i)(n−i)(n + i)(n - i) but neither factor, so pp is not prime in Z[i]\mathbb{Z}[i]; in a PID that means it is not irreducible, and a factor of pp of norm pp is a sum of two squares.

  1. (i), only if: an odd sum of two squares is 11 mod 44.

    A square is 00 or 11 mod 44, since (2m)2=4m2(2m)^2 = 4m^2 and (2m+1)2=4(m2+m)+1(2m + 1)^2 = 4(m^2 + m) + 1. So a sum of two squares is 00, 11 or 22 mod 44, and an odd one is 11 mod 44.

  2. Wilson’s theorem: (p−1)!≡−1(modp){(p - 1)! \equiv -1 \pmod p}.

    In the field Fp\mathbb{F}_p (Theorem 10.2.6) every non-zero class xx has an inverse. A class is its own inverse exactly when x2=1x^2 = 1, and x2−1x^2 - 1 has at most two roots in Fp\mathbb{F}_p (Theorem 11.2.3), namely 11 and −1-1, which differ because pp is odd. So the other non-zero classes fall into pairs {x,x−1}\{x, x^{-1}\} with product 11, and the product of all non-zero classes, [1][2]⋯[p−1]=[(p−1)!][1][2] \cdots [p - 1] = [(p - 1)!], is 1⋅(−1)=−11 \cdot (-1) = -1.

  3. If p=4k+1p = 4k + 1, then n=(2k)!n = (2k)! has p∣n2+1p \mid n^2 + 1.

    Pair each j≤2kj \le 2k in (p−1)!(p - 1)! with p−j≡−jp - j \equiv -j:

    (p−1)!≡∏j=12kj(−j)=(−1)2k((2k)!)2(modp).\begin{aligned} (p - 1)! &\equiv \prod_{j = 1}^{2k} j(-j) \\ &= (-1)^{2k}\bigl((2k)!\bigr)^2 \pmod p. \end{aligned}

    So by Wilson’s theorem n2≡−1n^2 \equiv -1, that is, p∣n2+1p \mid n^2 + 1.

  4. Such a pp is not irreducible in Z[i]\mathbb{Z}[i].

    In Z[i]\mathbb{Z}[i], n2+1=(n+i)(n−i)n^2 + 1 = (n + i)(n - i). But pp divides neither factor: p(c+di)=n±ip(c + di) = n \pm i would need pd=±1pd = \pm 1. So pp is not a prime element of Z[i]\mathbb{Z}[i], and since Z[i]\mathbb{Z}[i] is a PID (Theorem 12.3.4), pp is not irreducible (Theorem 12.4.1).

  5. (i), if: p=a2+b2p = a^2 + b^2 for some integers a,ba, b.

    Since N(p)=p2N(p) = p^2 is neither 00 nor 11, pp is a non-zero non-unit (Proposition 12.1.3). As it is not irreducible, p=zwp = zw with z,wz, w non-units. Then N(z)N(w)=N(p)=p2N(z)N(w) = N(p) = p^2 with neither factor 11, so N(z)=pN(z) = p, and z=a+biz = a + bi gives a2+b2=pa^2 + b^2 = p.

  6. (ii) The listed elements are irreducible.

    1+i1 + i has norm 22, and a+bia + bi with a2+b2=pa^2 + b^2 = p has norm pp; both norms are prime, so both elements are irreducible by Proposition 12.1.3 (iii). A prime q≡3(mod4)q \equiv 3 \pmod 4 has norm q2q^2, so a factor that is not a unit would have norm qq, making qq a sum of two squares, which the first step rules out.

  7. (ii) An irreducible π\pi of Z[i]\mathbb{Z}[i] divides a prime qq of Z\mathbb{Z}, and N(π)N(\pi) is qq or q2q^2.

    Its norm N(π)=ππˉN(\pi) = \pi\bar\pi is an integer greater than 11, so it is a product of primes of Z\mathbb{Z}, and π\pi divides this product in Z[i]\mathbb{Z}[i]. Since π\pi is prime (Theorem 12.4.1), it divides one of these primes, qq. From q=πγq = \pi\gamma, N(π)N(γ)=q2N(\pi)N(\gamma) = q^2, so N(π)N(\pi) is qq or q2q^2.

  8. If N(π)=q2N(\pi) = q^2, then π\pi is an associate of qq, and q≡3(mod4)q \equiv 3 \pmod 4.

    Then N(γ)=1N(\gamma) = 1, γ\gamma is a unit, and qq is an associate of π\pi, so qq is irreducible in Z[i]\mathbb{Z}[i]. Then q≠2q \neq 2, since 2=(1+i)(1−i)2 = (1 + i)(1 - i), and q≢1(mod4)q \not\equiv 1 \pmod 4, since otherwise q=a2+b2=(a+bi)(a−bi)q = a^2 + b^2 = (a + bi)(a - bi) by (i). So q≡3(mod4)q \equiv 3 \pmod 4.

  9. If N(π)=qN(\pi) = q, then π\pi is an associate of 1+i1 + i or one of the listed a+bia + bi. This proves (ii).

    Write π=a+bi\pi = a + bi, so a2+b2=qa^2 + b^2 = q. For q=2q = 2, aa and bb are ±1\pm 1, and the four elements ±1±i\pm 1 \pm i are the associates of 1+i1 + i. For odd qq, q≡1(mod4)q \equiv 1 \pmod 4 by (i), and π\pi is one of the listed elements a+bia + bi.

□

Pierre de Fermat stated (i) in a letter to Marin Mersenne dated 25 December 1640, without proof. Leonhard Euler sent a proof to Christian Goldbach in 1749, and published it in two papers of the St Petersburg Academy, in its volumes for 1752–1755 (printed in 1758 and 1760).