Fact13.1.1
If \(n\equiv 3\text{ (mod }4)\), then \(n\) is not writeable as a sum of squares.
Let's assume you've done some exploration on your own. Here's a first pattern that you may have noticed, similarly to patterns in the past.
If \(n\equiv 3\text{ (mod }4)\), then \(n\) is not writeable as a sum of squares.
The next thing to note is that Sage has a nice command to tell us an answer.
If a representation doesn't exist, we get an error. If it does, Sage returns two numbers \((a,b)\) such that \(a^2+b^2=\) your number.
In the next cell, I pick a number for which \(n\equiv 1\text{ (mod }4)\), but this number is not writeable. Thus Fact 13.1.1 doesn't just take care of all cases.
There are \(n\equiv 0,1,3\text{ (mod }4)\) which are not representable as a sum of two squares.
You can use this interact to avoid the errors.
Most computer languages have a way to “handle” errors if we don't want to think of them as errors. In Python, this is the try/except syntax you see above. Basically, we are trying to use the two squares command, but if it hiccups, we instead just print a nice message.
We have already addressed a very special case of writing numbers as a sum of squares. In fact, in Theorem 3.4.5 we saw a precise characterization of when a perfect square is a sum of two squares. We will mention this again briefly in Subsection 14.2.2.
Next, we can interpret this question very differently, relying on our geometric intuition. This graphic helps us visualize the problem.
In this graph, \(n=a^2+b^2\), then \(n\) is the square of the radius of a circle which has \((a,b)\) as the coordinates of a point. So the sum of squares problem is actually a geometric one!
That is, we can rewrite our questions like this.
Which circles around the origin have lattice points, and which ones do not?
If a circle has lattice points, how many does it have?
We will choose to address these questions by connecting to geometry. There are many ways; for instance, in Section 20.1 we will connect to calculus ideas in number theory.
The following identity was, separately, already known to Diophantus (remember Diophantine equations?) around 250, to Brahmagupta (about whom more later) around 600, and to Leonardo of Pisa (known also as Fibonacci) around 1250.
\begin{equation*}\left(a^2+b^2\right)\left(c^2+d^2\right)=\left(ac-bd\right)^2+\left(ad+bc\right)^2\end{equation*}
This sort of identity may seem amazing to us, but to people used to needing lots of symbolic manipulation, it was just part of a toolkit by the time number theory began ascending with Fermat or Euler.
What is useful about this identity is that it implies the following.
Products of numbers writeable as sums of squares may also be written as sums of squares!
A final question for the reader is to ponder why this means that we can really reduce the question to whether primes are writeable as a sum of squares.