 This lecture is part of an online undergraduate course on the theory of numbers and will be about Gauss's lemma. And before describing it, I'll just point out how to spell Gauss's. There should be an apostrophe S at the end. A lot of people get really nervous about having three S's in a row and miss out the final S, but you should put it in. So in order to motivate this, we start by recalling that we've shown that minus 1 is a square modulo p, where p is prime. And the prime p equals 2 always causes problems, so we're going to assume that p is not equal to 2. So minus 1 is a square modulo p if and only if p is congruent to 1 modulo 4. And this suggests the problem. Can we find a similar criterion to tell whether other numbers are squares modulo p? So when is say 2 or minus 3 a square modulo p? And Gauss and Euler and Fermat in the early days of starting up the theory of numbers did lots and lots of calculations to try and figure this out. So for example, here is Gauss's table of whether certain numbers are quadratic residues of prime. So if I magnify it a bit so you can see it a bit better. So what he's got along the top of these numbers minus 1, 2, 3, 5 and so on. And on the left hand edge he's got odd primes and there's a sort of horizontal line whenever the number on the top is a square modulo the left hand edge. So for example 2 is a square modulo 7 and modulo 17 and modulo 23 and modulo 31. I have to say Gauss's table is not actually terribly easy to read. I mean he was good at many things but presenting data was possibly not one of them. So let's look at the following problem. When is 5 square modulo p? And I keep forgetting to do that. And what I will do instead of using Gauss's table I'll write out the primes in a form that's a little bit easier to read. So let's write out the primes from up to 100. And what I'm going to do is mark the ones for which 2 is a quadratic residue and then I'm going to give a slight puzzle for you to guess the rule and what you should do is pause the video at that point if you want to actually try and figure it out. So I'll tell you when you should pause the video and you can sort of get ready for it. So these ones are the ones that are quadratic residues and the ones that are quadratic none residues are all the other ones left over. So what you want to do is to find a rule that allows you to separate out the green ones from the red ones and you can pause now if you want. I'll just give you a hint. The rule is actually very simple. You could explain it to a first grader. So I'll just wait a couple of seconds. So the rule is very simple. It's red and none residue if and only if the last digit is 3 or 7. In other words, the residues are the ones with P is congruent to 1 or 4 mod 5 and none residues the ones with P congruent to 2 or 3 mod 5 except for P equals 2 which always goes wrong and P equals 5 which is obviously going to go wrong because 5 is the number you're actually looking at. So we've got this rather nice result that whether or not 5 is a square modulo p this seems to depend only on P modulo 5 and minus 1 is a square modulo p if and only if p is something or other modulo 4. So this suggests the following problem or conjecture that the quadratic residue symbol for fixed A depends only on P modulo something. In fact possibly 4A we will see that 4A is in fact correct. Here as usual P is an odd prime. Things always go wrong for 2. And so we're going to show this using Gauss's lemma. So what's Gauss's lemma? Well we start off with Euler's result which says that the Legendre symbol AP is equal to A to the P minus 1 over 2 modulo p. By the way I ought to warn you I've got a bad habit of accidentally calling this the binomial coefficient but it's not it's the Legendre symbol. Unfortunately it looks very much like a binomial coefficient. And what Gauss did he said here this really clever idea what you do is you write out the numbers 1, 2, 3 up to P minus 1 over 2 and you multiply them together to get P minus 1 over 2 factorial. Well this isn't his clever idea yet. His clever idea is you now multiply all these by this number A so you get A2A3A up to P minus 1 over 2A. And you notice that the residues of these mod P are plus or minus 1 plus or minus 2 up to plus or minus P minus 1 over 2. So the point is these numbers if x and y are any two of these numbers then x is not equivalent to plus or minus y modulo p because that's true for these numbers and so it's also true if you multiply them by A. That means that every number from 1 to P minus 1 over 2 has to be equal to exactly one of these numbers up to sign because there are P minus 1 over 2 of them and so they must fill all these numbers here. So the product of all these, well the product of them is obviously P minus 1 over 2 factorial times A to the P minus 1 over 2. And this is rather nice because this A to the P minus 1 over 2 is exactly what you get up there. On the other hand you can work out this product because it's equal to plus or minus 1 times plus or minus 2 times plus or minus 3 and so on. So A to the P minus 1 over 2 is equal to minus 1 to the number of signs. And what's the number of signs? Well the number of signs is equal to the number of elements A to A up to P minus 1 over 2 A congruent to something in the interval P over 2 to P. So let's see an example of how this works. So just to recall the Legendre symbol is now the parity of, sorry it's minus 1 to the power of the number of elements A up to 2 A up to P minus 1 over 2 A in P over 2 to P mod P. So let's do 3, it's not 3 choose 11, it's the Legendre symbol 311 as an example. So we write out the numbers 0, 11 over 2, 11, 3 times 11 over 2 and so on. So this is now the real axis and I'm going to mark the multiples of 3 on it. So we get 3 is somewhere here, 6 is somewhere here, 9 is about there, 12 is there and 15 is there. Now I'm going to colour these intervals green and red. So the green intervals are the good intervals and the red ones are the bad ones where you have to change signs. So 3 is congruent to 3, 6 is congruent to minus 5, 9 is congruent to minus 2, 12 is congruent to 1 and 15 is congruent to 4 modulo 11. And so what you see is these are the numbers 1, 2, 3, 4 and 5 up to sign. And now how many signs are there? Well the number of signs is the number of multiples of 3 that lie in this red interval here because this is where you're between 11 over 2 and 11. So 3, the Legendre symbol 3, 11 is just the number of signs. So it is minus 1 to the power of the number of signs which is equal to minus 1 squared which is equal to 1. So we see that 3 is a quadratic residue of 11. Of course this is very easy to check directly because 3 is just congruent to 5 squared modulo 11. So in a small case like that we don't really gain very much. Now let's just do this, check this for whether minus 1 is a residue. So let's check minus 1 to see whether it's a quadratic residue of p. Well here we take all the numbers from 1 to p minus 1 over 2 and we multiply them by minus 1. And these are the same as 1 up to p minus 1 over 2 with p minus 1 over 2 signs. So minus 1 p is equal to minus 1 to the p minus 1 over 2 as usual p is odd of course. And this is equal to 1 if p is congruent to 1 mod 4 and minus 1 if p is congruent to 3 mod 4 which is the result we found earlier. So this works for minus 1. Now let's try it for 2 and try and figure out for which primes is 2 a quadratic residue. So we write out the real lines and we mark the points 0 and p over 2 and p on it. And now we have to arrange that all the multiples 2 times 1, 2 times 2 up to 2 times p minus 1 over 2 on it. And these are just the numbers 2, 4, 6 up to p minus 1. And we need to work out how many of them are in this red region. Well that's easy enough to work out because the number in this region here is the number of even numbers less than p over 2 which is the integer part of p over 4. Here this is a square bracket and nothing to do with the round brackets that occur in the Legendre symbol. And the square bracket is the integer part of x. So the integer part of x is the largest integer that's less than or equal to x. For example the integer part of pi is equal to 3. And what you've got to be a bit careful of is the integer part of minus 1.5 is equal to minus 2 not minus 1. So a lot of computer languages and pocket calculators have an integer part function but it sort of gives you the wrong answer. It will tell you the integer part of minus 1.5 is minus 1. So you have to be a little bit careful when taking integer parts and negative numbers. Anyway we've got the integer part of p over 4 here and similarly the number here is the integer part of p over 2 which is of course just p minus 1 over 2. So the number in this region here is going to be p over 2 the integer part of minus p over 4. And we want to work out whether this is even or odd. And this is a little bit tricky to work out because the integer part function kind of jumps a bit unexpectedly. So what we're going to do is we're going to divide into four cases. We're going to look at the cases p is equal to 1, 3, 5 or 7 plus 8n. And then the integer part of p over 2 is 4n, 4n plus 1, 4n plus 2 and 4n plus 3. And the integer part of p over 4 is 2n, 2n, 2n plus 1, 2n plus 1. And now we need to figure out what the difference is. Well all we care about the difference is whether it's odd or even. So here it's even, odd, odd, even. So the Legendre symbol 2p is now equal to minus 1 to this number here. So it's plus 1, minus 1, minus 1, plus 1. And we see that 2 is a quadratic residue of the odd prime p. If and only if p is congruent to 1 or 7 modulo 8. So we'll now give an application of this. So let's prove Dirichlet's theorem, or Dirichlet's theorem, for primes of the form 8n plus 1, 8n plus 3, 8n plus 5 and 8n plus 7. Well 8n plus 1 we sort of already done. So we know any factor of x to the 4 plus 1, sorry any odd factor, is of the form 8n plus 1. And from that it's easy to find infinitely many primes of the form 8n plus 1 just by arranging for this to be even and co-prime to all the numbers we've already found. So we sort of already did that. Now let's look at 8n plus 5. Well that's actually fairly easy because some factor of 4x squared plus 1 with x odd is of the form 8n plus 5. That's some prime factor. The reason for this is that this number here is congruent to 5 modulo 8. And if p divides 4x squared plus 1 this implies p equals 2 or p is congruent to 1 modulo 4. Now that means all factors of this if you choose x to be odd are going to be 1 or 5 mod 8 and they can't all be 1 mod 8. So 1 factor must be 5 mod 8. So that allows you to generate lots of primes that are 5 mod 8. And so far we haven't been using the quadratic residue symbol very much. Well that turns out when we do 8n plus 7. So for 8n plus 7 we know that if p divides x squared minus 2 this implies p is congruent to 1 or 7 mod 8 at least if x is odd. And now if we choose x odd then x squared minus 2 is congruent to 7 mod 8. So the factors are not all 1 mod 8 because if they were then their product would be 1 mod 8. So x squared minus 2 must have at least one prime factor of the form 7 mod 8. So by choosing x to be the product of all the prime factors we've already thought of that is 7 mod 8 we can find a new one. 8n plus 3 is kind of similar. This time we use the fact that if p divides x squared plus 2 this implies p is congruent to 1 or 3 mod 8. Well why is that? Well this says that minus 2 is a quadratic residue of p. Well how do we work out minus 2p? Well that's easy because minus 2p we saw earlier is minus 1p times 2p. And we know what this is it depends on p mod 8 and we know what this is it depends on p mod 4. And if we put them together we find that this is 1 exactly when p is 1 or 3 mod 8. And now you can copy the argument for 8n plus 7 and find there are infinitely many primes of this form. Okay for the next example let's work out when 3 is a quadratic residue of a prime. So as before we first will draw a real line and we mark on nought and p over 2 and p and 3p over 2. And now we write out all multiples of 3, 3, 6, 9, up to 3 times p minus 1 over 2. And we want to know how many of them are in this red region here. So we've just got one red region so far. So for 2 and 3 we only get one red region. If we took 3 to be say 5 we would then discover there was a second red region and so on so it gets more complicated. And now we need to know how many of these numbers are there in each of these regions. So here there are p over 2 divided by 3 and then we take the integer part of them. In this region here there are p divided by 3 and then we take the integer part. And this region here we don't really care very much about. We would take 3p over 2 and then divide it by 3 and then take the integer part. So we want the number in this red region and this number is the integer part of p over 3 minus the integer part of p over 6. And we want to know whether this is odd or even. And just as before this is a little bit tricky because it jumps in funny places depending what p is. So what we're going to do is to consider the different possibilities for p modulo 12. So we're going to write p as 1, 5, 7, 11 plus 12n. And of course we're missing out p being 2 or 3 because 2 always goes wrong and 3 is the number we're testing. So we expect something to go wrong for p equals 3 as well. And now the integer part of p over 6 is now 2n, 2n, 2n plus 1, 2n plus 1. And the integer part of p over 3 is 4n, 4n plus 1, 4n plus 2 and 4n plus 3. And now we look at the difference and see whether it's even or odd. Well, here it's even, odd, odd, even. So 3p, the Legendre symbol, is 1 if this is even and minus 1 otherwise. So we see that 3 is a quadratic residue of p, not equal to 2 or 3, is equivalent to saying p is congruent to 1 or 11 modulo 12. Well, now let's work out roughly what happens in general. So in general you're going to get something rather similar. Suppose we try and work out whether or not a is a quadratic residue of p. What you do is you write out a long line. So we get 0p over 2p, 3p over 2. That's right, that's 2p over 2 just to be consistent. 4p over 2 and we go all the way up to ap over 2. And now we colour these intervals green, green, red, red and so on. And then we write down the numbers a, 2a and so on up to p minus 1 over 2a. And we want to know how many of them are in red intervals. And the number in this interval is going to be the integer part of p over 2a. And the number in this interval is going to be the integer part of 2p over 2a. And we go all the way up to the number in this interval here is going to be the integer part of ap over 2a. And we've got to be a little bit careful because we're not quite sure whether it ends with something that's red or something that's green. It depends a bit on whether a is even or odd. So let's take a to be odd just to be definite. Then if a is odd it's going to end in a green interval so we have to sort of stop here and what we would get is well we have the number in this red interval which is going to be p over 2a or minus p over 2a plus 2p over 2a. So these two terms here are just giving the number in this interval and then we get minus 3p over 2a. I've got to take the integer part of it plus 4p over 2a and these two terms are the number in this interval and we go all the way up to a minus 1p over 2a and then we get minus something or other. And again if a was even we would have to change this a little bit so that there is a slight fiddle you have to do depending whether a is even or odd. Well this sum looks like a bit of a mess. However it has the following very nice property the parity of all terms depends only on p modulo 4a. You see if you add 4a to this number p then all these numbers here are only going to vary by an even amount. So what we see is that the quadratic residue symbol given a number a depends only on p modulo 4a. So in particular if a is 3 then whether or not 3 is a quadratic residue p depends only on p modulo 12 which is the result we saw before. For example let's work out whether or not 5 is a quadratic residue of 1,000,000 and 3 so we need to work out this number here. Well this is equal to 5,3 that's because 1,000,000 and 3 is congruent to 3 modulo 4 times 5 and this is easy to evaluate because this is just 2 choose not choose 3 the Legendre symbol 2,3 which is equal to minus 1. So 5 is not a quadratic residue of 1,000,000 and 3. So you see this is we said there was a reasonably fast way of doing this using Euler's criterion but Euler's criterion involves working out 5 to the 1,000,000 and 3 minus 1 over 2 modulo 1,000,000 and 3 and you see this calculation here is very, very much easier than this calculation here. Incidentally when I said that this is true because these are equivalent modulo 4 times 5 in fact this is not best possible. So I'm going to leave this as a sort of exercise show that 5p depends only on p modulo 5 which is the example we had at the beginning of this lecture and using Gauss's lemma you should now be able to prove this. Okay so next lecture we're going to extend this and over the next few lectures we're going to introduce the law of quadratic reciprocity which makes working out the Legendre symbol for any a and p really, really fast.