Fermat’s Two Squares Theorem (Gaussian Integers approach)

Today we will discuss Fermat’s Two Squares Theorem using the approach of Gaussian Integers, the set of numbers of the form a+bi, where a, b are integers. This theorem is also called Fermat’s Christmas Theorem, presumably because it is proven during Christmas.

Have you ever wondered why $5=1^2+2^2$, $13=2^2+3^2$ can be expressed as a sum of two squares, while not every prime can be? This is no coincidence, as we will learn from the theorem below.

Theorem: An odd prime p is the sum of two squares, i.e. $p=a^2+b^2$ where a, b are integers if and only if $p\equiv 1 \pmod 4$.

(=>) The forward direction is the easier one. Note that $a^2\equiv 0\pmod 4$ if a is even, and $a^2\equiv 1\pmod 4$ if a is odd. Similar for b. Hence $p=a^2+b^2$ can only be congruent to 0, 1 or 2 (mod 4). Since p is odd, this means $p\equiv 1\pmod 4$.

(<=) Conversely, assume $p\equiv 1\pmod 4$, where p is a prime. p=4k+1 for some integer k.

First we prove a lemma called Lagrange’s Lemma: If $p\equiv 1\pmod 4$ is prime, then $p\mid (n^2+1)$ for some integer n.

Proof: By Wilson’s Theorem, $(p-1)!=(4k)!\equiv -1\pmod p$. $(4k)!\equiv [(2k)!]^2\equiv -1\pmod p$. We may see this by observing that $4k\equiv p-1\equiv -1\pmod p$, $4k-1\equiv -2\pmod p$, …, $4k-(2k-1)=2k+1\equiv -2k\pmod p$. Thus $[(2k)!]^2+1\equiv 0\pmod p$ and hence $p\mid n^2+1$, where $n=(2k)!$.

Then $p\mid (n+i)(n-i)$. However $p\nmid (n+i)$ since $p\nmid n=(2k)!$. Similarly, $p\nmid (n-i)$. Therefore $p$ is not a Gaussian prime, and it is thus not irreducible.

$p=\alpha\beta$ with $N(\alpha)>1$ and $N(\beta)>1$. $N(p)=N(\alpha)N(\beta)$, which means $p^2=N(\alpha)N(\beta)$. Thus we may conclude $N(\alpha)=p$, $N(\beta)=p$.

Let $\alpha=a+bi$. Then $p=a^2+b^2$ and we are done.

This proof is pretty amazing, and shows the connection between number theory and ring theory.