 This video is part of Berkeley Math 115, an introductory undergraduate course on number theory, and will be mostly about the Gaussian integers and their relation to binary quadratic forms. So from the last few lectures, we've been looking at binary quadratic forms ax squared plus bxy plus cy squared, and considering which numbers n can be represented by them. And we were mostly taking n to be prime. For example, we can show that a number of prime can be written in the form x squared plus y squared if and only if p is equal to two or p is congruent to one modulo four. And what I want to do in this lecture is to consider more generally the case of what happens if n is not prime, which is a little bit more complicated. And for simplicity, I'm not going to talk about an arbitrary form. I'm just going to talk about the form x squared plus y squared. So we want to study which integers n can be represented as x squared plus y squared. And in how many ways can they be represented like this? Obviously, we're going to take n to be greater than or equal to zero. Otherwise, the question is kind of trivial. So this form has discriminant D, which is b squared minus four ac equal to minus four. So we know that n is represented primitively by some form of discriminant minus four. And all forms of discriminant minus four are equivalent to x squared plus y squared. So that's n is represented primitively by x squared plus y squared if and only if the discriminant D, which is minus four, is a square modulo four n. You remember there was this condition we had earlier about when is the number primitively represented by some form of discriminant D? Just remind you that primitive means x and y have to be co-prime. Well, in order to check this condition that D equals minus four is a square mod four n by the Chinese remainder thing, we just need to check the case n is some power of a prime because if something is a square modulo or prime powers dividing four n, then that would be okay. So we look at several cases. If p is congruent to three mod four, then there are no solutions because minus four or minus one is not a square modulo p for p three mod four. If p is congruent to one mod four, we are okay, we get some solutions. And if p is equal to two, it becomes a little bit more complicated because minus four is a square mod eight but not mod 16. So we can have n equal to two but not four because four times four is 16 and minus four is then not a square modulo four n. So we get the following condition for n to be primitively represented. So n is primitively represented by x squared plus y squared if and only if all primes dividing n are one or two modulo four and furthermore two squared does not divide the number n. What about non-primitive representations? Notice that there are plenty of numbers which have non-primitive representations but don't have primitive representations. For example, eight is equal to two squared plus two squared is a non-primitive representation of eight but you can't write n eight as a sum of two co-primes squares. So for non-primitive representations, x and y might have a common factor g. So we might have g times big x is equal to little x and g times big y is equal to little y and then we see that our form is going to look like g squared times a times big x squared plus big y squared. So this occurs if n is a square times something with primitive representation. So this is equivalent to saying that all primes dividing n that are pre-mod for divide n to an even power. So to illustrate this, suppose I want to check whether say 3060 is divisible is a sum of two squares. You look at its prime factorization so it's two squared times three squared times five times 17 and now you pick out all the primes that are three mod four dividing it and you see there's only one prime that's three mod four and then you see it divides it to an even power. So this exponent is even and that means we are okay. So 3060 can be written as a sum of two squares although this will obviously be non-primitive because both of these squares will necessarily be divisible by this number three. So if we want to write a number as a sum of two squares how do we do it? Well we can observe that if m and m are both sums of two squares then so is m times n and there's a direct proof of this is short but somewhat mysterious. Suppose that m is equal to x1 squared plus y1 squared and suppose n is equal to x2 squared plus y2 squared then m times n is x1 squared plus y1 squared times x2 squared plus y2 squared which is equal to x1 x2 minus y1 y2 all squared plus x1 y2 plus x2 y1 all squared which you can check with a little bit of algebra and this certainly proves that the product of m and n is the sum of two squares but there's a big problem where does this funny-looking identity come from? I mean I just seem to have pulled it out of midair like a magician pulling a rabbit out of a hat or something. Well there's a good explanation for this identity as follows. It comes from Gaussian integers so what's a Gaussian integer? Well the Gaussian integer is something of the form m plus n i where m and n are integers and i squared is equal to minus one so these are complex numbers and we can draw a picture of the Gaussian integers so you know the complex numbers can be identified with the plane by mapping the complex number x plus i y to the point x y in the plane so the complex integers just form the so the Gaussian integers just form the lattice of all points in the plane with integer coordinates so that might be zero might be one two and the number i is here i plus one is there and so on so so this gives a very good picture of the Gaussian integers they look like the corners of a chess board and now we can explain this funny identity so m squared plus n squared if you've got a sum of two squares this means that m squared plus n squared actually factorizes in the Gaussian integers as n plus n i times m minus n i so sums of two squares mean that something in the Gaussian integers factorizes now suppose that m is equal to x one squared plus y one squared which is equal to x one plus i y one times x two plus times x one minus i y one and n is equal to x two squared plus y two squared which is x two plus i y two times x two minus i y two now we just multiply them together m times n is equal to x one plus i y one times and i'm going to take x two plus i y two and then i'm going to have x one minus i y one and x two minus i y two and now you notice that the product of the first two terms x one plus i y one times x two plus i y two is x one x two minus y one y two plus i times x one y two plus x two y one and this thing is the same except we change i to minus i and I'm not going to bother writing it all out and now we notice that if we take the square of this term here and add the square of this term here then we just get m times n because you know that we're just getting this number times its complex conjugate so if you look we've now reproduced this funny identity the mysterious term x one x two minus y one y two and so on come as the real and imaginary part of of this number here so calcium integers explain this strange identity and now we can use this to write numbers as a sum of two squares for example suppose I want to write seven six five zero zero um as a sum of two squares well I factorize it it's two squared times five cubed times three squared times 17 and now I write each of these primes dividing it as a sum of two squares and then since there are some of two squares I can write them as a product of Gaussian integers so two becomes one plus i squared times one minus i squared and five cubed becomes two plus i times two minus i or cubed because five is two squared plus one squared and three we can't write as um a sum of two squares so I just leave it as three squared and 17 we get um four plus i times four minus i and now what I want to do is I want to write this as m plus n i times m minus n i for some m and n and to do that I just pick out a sort of half of all these factors so I could take m to be say um um one plus i squared and then I have to pick out three of these well let's take three of the two plus i's so three times take two plus i cubed then I've got to pick out half of these three so I just get one three and then I pick out half of these and I could take the four plus i but let's take the four minus i just for a change and if I want I can put a unit in front of this like a power of i so m plus n i is going to be equal to this and if I multiply this out it turns out to be minus 114 minus 252 i so we get 76500 is equal to 114 squared plus 252 squared um so uh there's a similar thing you can do for sums of four squares that I just briefly mentioned so this is not about binary quadratic forms it's about quadratic forms and four variables and I'll just sketch it because it's a little bit off topic so I suppose I've got two integers that are sums of four squares um then their product is also a sum of four squares and I'm going to write this out because it's actually a bit messy and what I'll do is I'll just show you how you can find this expression for yourself so if I've got a sum of two squares I can write this as a plus bi times a minus bi if I've got a sum of four squares I can write this as a plus bi plus cj plus dk times a minus bi minus cj minus dk provided i, j and k satisfy the following relations first of all they must all have square equal to minus one and secondly they must actually anti-commute this means that i, j is minus j, i which is k, j, k is minus k, j which is i and k, i is minus i, k which is j and these are the famous Hamiltonian quaternions and if you write a, b, c, a squared plus c, b squared plus c squared plus d squared in this form and do the same for e squared plus f squared plus g squared plus h squared and then multiply a plus bi plus cj plus dk by e plus fi plus g, j plus h, k then you find a way of writing this product of two sums of four squares as another sum of four squares well if we can do that for two squares and for four squares you can ask can we do it for sums of three squares suppose I've got an integer which is the sum of three squares and another integer which is the sum of three squares is there some clever way of writing it as the sum of three squares and the answer is no we can write three is equal to one squared plus one squared plus one squared and five is equal to two squared plus one squared plus zero squared but three times five is fifteen and you can easily check this cannot be written as the sum of a square plus a square plus a square so so this is something funny that happens for sums of two squares and sums of four squares but there's no direct analog for sums of three squares and next we come to the following question suppose we have a prime which is common to one mod four and we want to find x and y such that p is equal to x squared plus y squared and we maybe we want to do this explicitly well there's a slow way we can just use trial and error so for example if we want to write 61 as a sum of two squares what we do is we pick the biggest square less than 61 and subtract it so we take 61 minus seven squared which is 12 and that's not a square well that's no good then we try the next biggest square 61 minus six squared and this is equal to 25 and that's really nice that's five squared so we've written 61 is equal to six squared plus five squared and this works just fine for small numbers up to a hundred or so um incidentally um the um um there's a uh people used to do mental calculation as a sort of way of um making money and one of the things mental calculators used to do as a trick was to write numbers as sums of four squares so here I've got a book on the mental calculators and one of the chapters is explicitly about writing numbers as sums of four squares and let me just magnify it so you can see it a bit better and you see there was some psychologist who was asked testing these calculator calculators and asking them to write say 15633 as a sum of four squares and it says you know Ruckel found the solution 125 squared plus six squared plus one squared plus one squared and eight seconds it sounds impressive um actually finding that in eight seconds was pretty easy for a competent calculator that the point is that 15663 is actually very slightly larger than five to the power of six which is 15625 and every mental calculator knows all the small powers of integers so we instantly noticed this was just equal to five to the power of six plus 38 so there you've got five to the power of six is 125 squared and then you've just got to write 38 as a sum of three squares and you know that that's not exactly difficult because notice it's 36 plus one plus one so you notice Ruckel was actually using this algorithm that I suggested that you subtract off the biggest square less than the number and then and then take a look at what's left um anyway um so that does actually give um a way of writing small primes as a sum of two squares but obviously it's not terribly good if you're trying to write a really big primes as sum of two squares you know imagine p has you know 50 or 100 digits so what we would like is a fast method for writing p as a sum of two squares well what we do is we first solve um x squared is congruent to minus one modulo p and you remember we had a fast probabilistic method of doing this what you do is you pick a random number g and you raise g to the power of p minus one over four and there's about a 50 chance that this will have square equal to minus one um so you just keep going until you find one that works okay so we have x squared plus one is equal to p times n for some integer n now we're going to factor this over the Gaussian so we've x plus i times x minus i is equal to p times n and p is going to have some factor y plus i z times y minus i z and how can we find y plus i z well um we can try finding it as the greatest common divisor of x plus i and p so we take the greatest common divisor of x plus i and our prime p in the Gaussian integers and uh with a very small amount of luck this greatest common divisor will be y plus i z for some y and z and then we will find p is equal to y plus i z times y minus i z so this will give us p is equal to y squared plus c squared so let's just see an example of how this works so um let's take p to be 13 and try and write it as a sum of two squares well I mean yeah this is kind of trivial it's three squared plus two squared but let's pretend we haven't noticed that so we first solve x squared is congruent to minus one mod 13 and the simplest solution to that is x equals five so we've got five squared plus one is 26 so we've got five squared plus one is equal to 13 times something 13 times two so five plus i times five minus i is equal to 13 times something so now what we do is we take the highest common divisor greatest common divisor five plus i and 13 well how do we do that well we just use Euclid's algorithm of course so we take 13 and divide it by five plus i and it's two times five plus i and we've got a remainder of three minus two i and then we take five plus i and we divide it by three minus two i and it's three minus two i times one plus i plus the remainder is now zero so Euclid's algorithm is finished and the greatest common divisor is three minus two i so um we find three squared plus two squared is indeed equal to 13 well there's one thing you may be a little bit suspicious of i said we were using Euclid's algorithm for Gaussian integers well how do we know we can do that so let's discuss Euclid for m plus ni we want Gaussian integers now for Euclid's algorithm to work we need division by remainder so given numbers a and b so a and b are now going to be Gaussian integers we want to write um um a is equal to b times q plus a remainder r with b where b is not equal to zero of course and we want r to be smaller than than b well what does smaller mean well we need to actually decide what it means for one Gaussian integer to be smaller than another and what we're going to say is is that the and we're going to measure the size of the Gaussian integer to be distance to the origin so if we've got a Gaussian integer r equals s plus i t the distance to the origin from point st to zero is just the square root of s squared plus t squared and instead of using the square root of s squared plus t squared let's use s squared plus t squared so let's use the square of the distance because that saves having to take square roots so what we want to do is we need to show we can divide one Gaussian integer by another and find a remainder that's smaller in the following sense so what we need to do is given a divided by b we need to write this as q plus r over b and now we want r over b to be of absolute distance the origin should be less than or equal to one so this is just the usual complex absolute value so we notice that this is some complex number and this is some Gaussian integer and this is some complex number of absolute value at most one so what we've got to do is to show given any complex number we can write it as a Gaussian integer plus something of absolute value at most one and if we can do that we will have a nice Euclidean algorithm and that's quite easy to see let's see it by drawing a picture of the Gaussian integers so here we have the Gaussian integer zero one one plus i i and so on remember they form a nice square lattice and now we're going to draw all complex numbers that are within distance one of a Gaussian integer so to do that we just draw a disc of radius one around every Gaussian integer and what we've got to do is to show that every complex number is inside one of these discs and that's kind of obvious um i mean um you know you can just see that these discs of radius one are obviously covering the complex plane so um you know if you've got some number q it's going to be inside one of these discs it may be inside more than one of these discs so the when we write a over b equals q plus um some remainder r over b this number q isn't necessarily unique if for instance if if sorry if if a over b was here for example we would take q to be this number one or we could take it as one minus i and r over b is going to be the distance from this is going to be the vector from this this Gaussian integer q to our number a over b so we do in fact have a nice Euclidean algorithm for Gaussian integers and can copy the usual algorithm for finding greatest common divisors there's another nice property Euclide algorithm actually implies the Gaussian integers have unique factorization so we can define what a Gaussian prime is it's one that you can't um write as a product of Gaussian numbers that aren't units for example five is not a prime in the Gaussian integers because we can write as two plus i times two minus i but anyway since we've got Euclide algorithm we can we can just copy the usual proof that the integers have unique factorization and we find the Gaussian integers have unique factorization um so i'm going to give another application of the Gaussian integers um so we've discussed whether or not we can write n as a sum of two squares but now let's ask how many solutions to the equation x squared plus y squared equals n are there and you notice there can be several solutions for example we can write 65 is equal to 8 squared plus 1 squared well it's also 7 squared plus 4 squared so it's two quite different solutions so what does this mean well um he would try to write n is equal to x squared plus y squared so we're trying to write n is equal to x plus i y times x minus i y so this says we're trying to write n as a complex number times its complex conjugate complex conjugate just means you change i to minus i so let's write n is equal to 2 to the something 2 to the a times 3 to the b times 5 to the c times 7 to the d and so on so we're going to write its prime factorization and we want to write each of these as something plus i y times something minus i y now we notice 2 to the a can be written as 1 plus i to the a times 1 minus i to the a so we can pick out we need to pick out a of these factors 3 to the b well well all we can do is write that as 3 to the b 5 to the c we can write as 2 plus i to the c times 2 minus i to the c and 7 to the d we can just write as 7 to the d and so on so um now what we we have to do is we have to pick out half these factors so for 3 the only thing we can pick out is 3 to the b over 2 um here we can pick out 2 plus i to the something and we can also pick out 2 minus i to the c minus something so we notice there are c ways to do this and 7 of course all we can do is take 7 to the d over 2 2 you've got to be a little bit careful about you might think we can take 1 plus i to the something times 1 minus i to the a minus something and you might think there are a different ways of doing that the trouble is that 1 plus i and 1 minus i differ from each other by units um you you notice that 1 minus i times i is actually equal to 1 plus i so um there's really only one way up to units of um picking out factors from this we can just pick out 1 plus i to the a and we might get a unit so the units are 1 i minus 1 minus i so let's see how many different ways of doing this there are first of all for every prime that's 3 mod 4 there's only one way to write n like this for the prime 2 we always get a factor of 4 because we can pick one of these four units in front of it to mess around with and for every prime of the form 1 mod 4 so i should have put c plus 1 there we get um the exponent of the prime plus 1 ways of doing it so um so this tells us um how many solutions there are for writing n as x squared plus y squared what we do is we write n as a product of primes we check that all primes that are 3 mod 4 have an even exponent otherwise there are no solutions and then we take 4 times the product of 1 plus the exponent of the primes that are 1 mod 4 so let's do an example or two just to see um so let's for example do 65 which is 5 times 13 and just check this so this is 5 power of 1 times 13 to the power of 1 so we have predicted the number of solutions should be 4 times 1 plus 1 that's this exponent plus 1 times 1 plus 1 that's the other exponent plus 1 okay so let's try and find these 16 solutions well we've got 65 is equal to 8 squared plus 1 squared is equal to 7 squared plus 4 squared and you know there are no other ways of writing 65 as a sum of two squares um so we seem to have a contradiction we said there are 16 solutions and here there are definitely only two solutions what's gone wrong well it turns out that each of these is really eight different solutions because we can also write this as plus or minus eight squared plus plus or minus one squared so um that's really four solutions because there are two signs there and two signs there and we can also write them in the other order it's plus or minus one squared plus plus or minus eight squared so so this really corresponds to eight slightly different solutions you know that these are actually different complex numbers we have eight plus i eight minus i minus eight plus i and so on and similarly there's another eight there so we really do have 16 different ways of writing 65 as a sum of two squares um well that's um where the exponent is one let's just have a look at one where the exponent is larger so let's just look at the number of ways of writing five to the n as a sum of two squares so five to the one well five is equal to two plus i times two minus i um so we can write as two squared plus one squared and by twiddling around with signs and changing the order we see there are eight solutions which is four times one plus one as predicted now five squared we're predicting there should be four times two plus one which is 12 solutions and five squared is two plus i squared times two minus i squared and now we can pick out a factor of i so some power of i so there are four possibilities times well we can get two plus i squared or two plus i times two minus i two minus i squared and this is going to give us the following solutions we can write five squared is equal to three squared plus four squared or um um zero squared plus five squared and this gives us eight solutions if we twiddle around with signs and so on and this gives us four solutions notice that we get four rather than eight because if you change the sign of zero that doesn't actually make a whole lot of difference so again we get 12 solutions but what about five cubed well here we can have two plus i cubed two plus i squared times two minus i two minus plus i times two minus i squared or two minus i cubed and this is going to give us two plus 11 i 10 plus five i 10 minus five i and two minus 11 i so you notice we're getting the solutions that 125 which is five cubed can be two squared plus 11 squared or it can be 10 squared plus five squared or it can be 10 squared plus minus five squared or it can be 10 squared uh sorry um or it can be two squared plus minus 11 squared so again we get um 16 solutions um as as as predicted and five to the four is similar here um we can get two plus i to the four giving which is equal to minus seven plus 24 i or we can get two plus i cubed which gives us um um well it's going to be two plus i cubed times two minus i and that's just going to be two plus i squared times five and that that's going to give us um 15 squared plus 20 squared you notice that's really three squared plus four squared except we've multiplied it by five squared and and similarly we can get two plus i squared times two minus i squared which is going to give us um it's going to give us naught squared plus 25 squared and so on so you can check we get the right number of solutions um okay well you notice from this um that we're getting a lot of solutions of Pythagoras's equation z squared is x squared plus y squared so there we have five squared is three squared plus four squared which is the one everyone knows and here we have um 25 squared is equal to seven squared plus 24 squared um so what i'm going to do next lecture is to look in more detail at Pythagoras's equation x squared plus y squared equals z squared and um look at several um different methods of solving that