sums of rational squares

In his early days, Fermat realized that a natural number that can be written as a sum of two rational squares actually is a sum of two integral squares, but he did not come back to this claim when eventually he discovered the proof of the Two-Squares Theorem. The result in question can be proved with the methods available to Fermat, as I will show here.

Theorem 1 If $n$ is a sum of two rational squares, then every prime $q = 4n+3$ divides $n$ an even number of times.

Theorem 2 Every prime number $p = 4n+1$ is the sum of two integral squares.

Now we invoke the product formula for sums of two squares $$ (a^2 + b^2)(c^2 + d^2) = (ac-bd)^2 + (ad+bc)^2. $$ It implies that every product of prime numbers $4n+1$ and some power of $2$ can be written as a sum of two integral squares, and multiplying through by squares of primes $q = 4n+3$, the claim follows.

Proof of Theorem 1 We will show that primes $p = 4n+3$ do not divide a sum of two coprime squares.

Assume that $p \mid x^2 + y^2$ with $\gcd(x,y) = 1$. Reducing $x$ and $y$ modulo $p$ we may assume that $-p/2 < x, y < p/2$; cancelling possible common divisors we then have $p \mid x^2 + y^2$ with $\gcd(x,y) = 1$ and $x^2 + y^2 < \frac12 p^2$.

If $x$ and $y$ are both odd, then the identity $$ \Big(\frac{x+y}2\Big)^2 + \Big(\frac{x-y}2\Big)^2 = \frac{x^2+y^2}2 $$ allows us to remove any remaining factor of $2$ from the sum, and we may therefore assume that $a^2 + b^2 = pr$ for some odd number $r < p$. Since $a$ and $b$ then have different parity, $a^2 + b^2$ must have the form $4n+1$, and therefore the number $r$ must have the form $4n+2$. But then $r$ must have at least one prime factor $q \equiv 3 \bmod 4$, and since $a^2 + b^2 < p^2$, we must have $q \le r < p$.

Thus if $p \equiv 3 \bmod 4$ divides a sum of two coprime squares, then there must be some prime $q \equiv 3 \bmod 4$ less than $p$ with the same property. Applying descent we get a contradiction.

Proof of Theorem 2

  1. The prime $p$ divides a sum of two squares.

    For every prime $p = 4n+1$ there is an integer $x$ such that $p$ divides $x^2+1$.

    By Fermat's Theorem, the prime $p$ divides $$ a^{p-1}-1 = a^{4n}-1 = (a^{2n}-1)(a^{2n}+1). $$ If we can show that there is an integer $a$ for which $p$ does not divide the first factor we are done, because then $p \mid (a^n)^2+1$. By Euler's criterion it is sufficient to choose $a$ as a quadratic nonresidue modulo $p$. Equivalently we may observe that the polynomial $x^{2n}-1$ has at most $2n$ roots modulo $p$.

  2. The descent. The basic idea is the following: Assume that the prime number $p = 4n+1$ is not a sum of two squares. Let $x$ be an integer such that $p \mid x^2 + 1$. Reducing $x$ modulo $p$ shows that we may assume that $p \mid x^2+1$ for some even integer $x$ with $0 < x < p$. This implies that $x^2+1 = pm$ for some integer $m < p$. Fermat then shows that there must be som prime divisor $q$ of $m$ such that $q$ is not a sum of two squares; since prime divisors of sums of two coprime squares have the form $4n+1$, Fermat now has found a prime number $q = 4n+1$ strictly less than $p$ that is not a sum of two squares. Repeating this step eventually shows that $p = 5$ is not a sum of two squares, which is nonsense since $5 = 1^2 + 5^2$.

    Assume that $p = 4n+1$ is not a sum of two squares. We know that $pm = x^2 + 1$ is a sum of two squares for some odd integer $m < p$. By Theorem 1, $m$ is only divisible by primes of the form $4k+1$. We now use the following

Lemma Assume that $pm = x^2 + y^2$ for coprime integers $x, y$, and let $q$ be a prime dividing $m$, say $m = qm_1$. If $q = a^2 + b^2$ is a sum of two squares, then $pm_1 = x_1^2 + y_1^2$ is also a sum of two squares.

Applying this lemma repeatedly we find that if every $q \mid m$ is a sum of two squares, then so is $p$ in contradiction to our assumption. Thus there is a prime $q = 4k+1$, strictly smaller than $p$, which is not a sum of two squares, and now descent takes over.

It remains to prove the Lemma. To this end, we have to perform the division $\frac{x^2+y^2}{a^2+b^2}$. By the product formula $$ (a^2+b^2)(c^2+d^2) = (ac-bd)^2 + (bc+ad)^2 $$ we have to find integers $c, d$ such that $x = ac-bd$ and $y = bc+ad$.

Since $q \mid (a^2 + b^2)$ and $q \mid (x^2 + y^2)$ we also have $$ q \mid (a^2+b^2)x^2 - (x^2+y^2)b^2 = a^2x^2 - b^2y^2 = (ax-by)(ax+by). $$ Since $q$ is prime, it must divide one of the factors. Replacing $b$ by $-b$ if necessary we may assume that $q$ divides $ax-by$. We know that $q$ divides $a^2 + b^2$ as well as $pm = x^2 + y^2$, hence $q^2$ divides $(ax - by)^2 + (ay+bx)^2 $ by the product formula. Since $q$ divides the first summand, it must divide the second as well, and we have $pm_1 = (\frac{ax-by}q)^2 + (\frac{ay+bx}q)^2$.


This result is pretty shy of needing the full Hasse-Minkowski Theorem. Indeed, since Fermat already knew which integers were a sum of two integer squares, it would suffice for him to show that those that weren't (i.e., those with an odd power of some prime congruent to 3 mod 4 showing up in its prime factorization) could also not be written as a sum of two rational squares. But this is the easy direction of Hasse-Minkowski: To show that (let's say) a prime $p\equiv 3\pmod{4}$ can't be written as a sum of two rational squares, it suffices to check that it can't be a sum of two $\ell$-adic rational squares for some $\ell$. Of course, Fermat did not have the language of the $\ell$-adics, so this would have had been replaced with mod-$q^k$ conditions for various $k$.

Specifically, the modern Hasse-Minkowski proof boils down to the statement that a prime which is 3 mod 4 can't be written as a sum of two rational squares because it can't be done so 2-adically. Indeed, one can just compute the single Hilbert symbol $$ p\equiv 3\pmod{4}\Rightarrow (p,-1)_2=(-1)^{(p-1)/2}=-1, $$ showing that $x^2=pz^2-y^2$ has no $2$-adic, and hence no rational, solutions, which afte the substitutions $a=x/z$ and $b=y/z$, implies one cannot write $p=a^2+b^2$ with $a,b\in\mathbb{Q}$. Of course (again), Fermat did not have Hilbert symbols, but this is just a change of language away from Fermat's approach (I imagine). It would not be hard to unwind the above calculation into a single (probably lengthy) mod-8 calculation, since that's all that goes into deciding which elements of $\mathbb{Q}_2$ are squares, which in turn is essentially all that lives behind the Hilbert symbols.


Dear Michael,

concerning your first question, I think that Franz's proof is really in the spirit of Fermat's techniques. Concerning the second question, here is a short, elementary proof, inspired by a theorem of Thue (cf. exercice 1.2 in Franz's book Reciprocity laws). I tried to write it using only notions known to Fermat.

We want to prove that if there exist positive integers $m,n,a$ and $b$ such that $$m^2n=a^2+b^2,$$ then $n$ is itself the sum of two integer squares. It is easily seen that it is sufficient to prove this assertion under the hypothesis that $a$ and $b$ (and therefore $a$ and $n$) are coprime and that $n$ is not a square. Let $t$ be the unique positive integer such that $t^2< n<(t+1)^2$. Since there are $(t+1)^2>n$ integers of the form $au+bv$ with $0\leq u,v\leq t$, it follows that $n$ divides the difference $a(u-u')+b(v-v')$ of two of them. Setting $x=u-u'$ and $y=v-v'$, we have the inequalities $|x|,|y|\leq t$. The integer $n$ then divides $a^2x^2-b^2y^2$; since it also divides $a^2y^2+b^2y^2$, it divides their sum, which is equal to $a^2(x^2+y^2)$. Now, the integers $a$ and $n$ being coprime, it follows that $n$ divides $x^2+y^2$. The inequalities $0< x^2+y^2<2n$ finally imply that $n=x^2+y^2$.