Today, we're going to take it easy  lots of time exploring by hand an interesting question similar to some we've already seen.
Question:
$$\text{Take a positive integer }n\text{ and try to write it as }n=a^2+b^2\text{ for }a,b\in\mathbb{Z}\text{; for which }n\text{ is this possible, for which is it not?}$$
It seems that Albert Girard already knew the answer to this question in the first quarter of the 17th century, and Fermat discovered this a couple years later. Girard is an interesting figure, less wellknown than his contemporaries; he apparently was the first to use our modern notation for trigonometric functions, and spent his adult life in the Netherlands escaping religious persecution as a Protestant in France.
A full proof of the answer to this question did not come until Euler (no surprise here) about six score years later.
Some things to think about while you try this are
A separate question to at least keep track of is how many ways can you write a number as a sum of squares, assuming you can indeed write it in this way?
After we work on this a while, and collate our information, possibly making some guesses, I'll try to show a few different points of view of this problem.



First, let's mention something that you should have noticed, based on our patterns in the past.
Fact: $$\text{If }n\equiv 3\text{ mod }(4)\text{, then }n\text{ is not writeable as a sum of squares.}$$
You should be able to prove this pretty easily based on things you already know about squares modulo 4.
The next thing to note is that Sage has a nice command to tell us an answer.
(2, 5) (2, 5) 
If it doesn't exist, we get an error. Notice that I picked a number $n\equiv 1\text{ mod }(4)$, but it is not writeable  so we can't just say that the 'Fact' above takes care of all cases which can't be written as a sum of squares.
Traceback (click to the left of this block for traceback) ... ValueError: 21 is not a sum of two squares Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_6.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# * coding: utf8 *\\n" + _support_.preparse_worksheet_cell(base64.b64decode("dHdvX3NxdWFyZXMoMjEp"),globals())+"\\n"); execfile(os.path.abspath("___code___.py")) File "", line 1, in <module> File "/private/var/folders/Yy/YytEJm5VEB0+pBRD7JNLe++++TQ/Tmp/tmpv2nuGK/___code___.py", line 3, in <module> exec compile(u'two_squares(_sage_const_21 ) File "", line 1, in <module> File "/Applications/MathApps/sage/local/lib/python2.6/sitepackages/sage/rings/arith.py", line 4350, in two_squares raise ValueError, "%s is not a sum of two squares"%n ValueError: 21 is not a sum of two squares 
You can use this interact to avoid the errors.
Click to the left again to hide and once more to show the dynamic interactive window 
Second, we can interpret this question very differently, relying on our geometric intuition.
Click to the left again to hide and once more to show the dynamic interactive window 
This graphic helps us visualize the problem. If $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:
Question: Which circles around the origin have lattice points, and which ones do not?
Question: If a circle has lattice points, how many does it have?
This is the way I choose to prove the questions, though there are many ways, connecting the problem to geometry. We will also see (later this semester) how this function of how many ways there are to write a number as a sum of two squares leads us to calculus ideas in number theory.
Connection to some very old mathematics
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. $$\left(a^2+b^2\right)\left(c^2+d^2\right)=\left(acbd\right)^2+\left(ad+bc\right)^2$$ This 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 means:
Fact: Products of numbers writeable as sums of squares may also be written as sums of squares!
Jones and Jones use the notation $S_2$ to denote the set of numbers which can be written as a sum of squares, so another way to say this is $$\text{If }a,b\in S_2\text{, then }ab\in S_2\; .$$
Click to the left again to hide and once more to show the dynamic interactive window 
So we really can reduce questions back to primes, just like we want to.
Connection to pretty new mathematics
There is one final way to interpret all of this. Suppose that $$n=a^2+b^2\; .$$ Then, if we let the symbol $i$ stand for a (putative) square root of negative one, so that $1=i^2$, we could legitimately factor this: $$n=a^2(i^2b^2)=(a+bi)(abi)$$ For instance, we could factor the prime number thirteen!!!
13 13 13 13 
It turns out that there is a beautiful connection between the theory of numbers in $S_2$ and the Gaussian integers (named after C.F. Gauss, who explored them a great deal, though others were at least incipiently aware of them), which we may define as the set $$\mathbb{Z}[i]=\{a+bi\mid a,b\in\mathbb{Z}\}$$ again, all the while assuming that we can have such a symbol $i$ with $i^2=1$.
Indeed, if we bring back our lattice of integer points, we can think of such numbers as being points on the lattice, where the coordinate point $(3,2)$ corresponds to $3+2i$, one of the 'factors' of 13. I'll plot both 'factors' below.

Though we won't have time to explore it fully, there is a fantastically deep connection between these Gaussian integers and ways to write numbers as a sum of squares.
Indeed, it turns out that the word 'factor' becomes the legitimate word factor, and prime numbers can be defined in this new number system. They turn out to be precisely the 'normal' primes of the form $4n+1$ and the 'factors' of the primes of the form $4n+3$ and $2$.
The basic reason is that we can use the Euclidean algorithm here; the 'size' of $3+2i$ is smaller than the 'size' of 13, and so we can use wellordering on the 'size' of the numbers. We'll define this 'size' next time when we prove exactly which integers are a sum of two squares. See Section 10.2, or the internet, for more details about the connection to complex numbers.
There are many amazing questions to ask about this, and wonderful connections to abstract algebra. Here is a picture to get you thinking.
Click to the left again to hide and once more to show the dynamic interactive window 

Homework:
