Skip to main content
Logo image

Section 13.5 All the Squares Fit to be Summed

There is one loose end. What are all the numbers we can represent as a sum of squares?
For instance, why are some composite numbers of the form 4k+1 not writeable as the sum of two squares? Also, many even numbers are representable – how do we tell which even numbers are writeable? We conclude our discussion by proving the full statement, after a couple of preliminary lemmas.

Proof.

Each of those primes is representable, so we can use Fact 13.1.9 to write all intermediate products as a sum of squares. Hence all such products are representable.

Example 13.5.2.

Consider this:
442=21317=(12+12)(32+22)17
=[(1312)2+(12+13)2](42+12)
=(12+52)(42+12)=(1451)2+(11+54)2=12+212.

Proof.

First, p2 (even if p is not prime) is trivially always representable, since p2=p2+02. Now, rather than using Fact 13.1.9, let P be the product of all prime factors of the form 4k+3, which is necessarily a perfect square P=Q2, given that all the powers are even. We can simply multiply this by N/Q2=a2+b2, which is possible by Lemma 13.5.1 since Q2 removes all primes of the form 4k+3 in the prime factorization. This yields (aQ)2+(bQ)2.

Example 13.5.4.

Consider this:
35802=44234=(12+212)3232
=123232+2123232=92+1892

Proof.

From 13.5.1 and 13.5.3, the only case left to consider if N has a prime of the form p=4k+3, but to an odd power. This seemed to be the bottleneck in our exploration.
By way of contradiction, suppose that it is possible to write
N=a2+b2.
First, divide this equation by any factors of p common to N, a, and b to get
M=c2+d2
The power of p we divided by (so that N=Mp) must be an even power, since each term on the right-hand side is a perfect square and can only contribute even powers of primes by the Fundamental Theorem of Arithmetic.
Since N had an odd power of p, we know M still has an odd power of p dividing it, yet pc,d.
Take everything modulo p to get the congruence
0c2+d2 (mod p).
Since pc, we can multiply this congruence by (c1)2 to get
01+(c1)2d21(c1d)2 (mod p)
This is a contradiction, as by Fact 13.3.2 there is no square root of 1 modulo p for p=4k+3, finishing the proof!

Example 13.5.6.

This theorem fully explains why 21=73 and the others mentioned in Fact 13.1.2 cannot be written as a sum of squares.
If the whole theorem still seems too neat and dried, it can be instructive to get insight by plugging in different n below. When do you get an error, when not?
(As a bonus, can you turn this into an interactive cell? See Sage note 12.6.8.)