 This lecture is part of Berkeley Math 115, an introductory undergraduate course on number theory, and this lecture will be about calculation of the Legendre symbol. So I'll just start by quickly recalling what the Legendre symbol is. You remember the Legendre symbol is written as a sort of funny fraction with parentheses around it, and it's equal to plus 1 if a is a quadratic residue mod p, that means a is congruent to x squared for some x, a is not 0, and it's minus 1 if a is a quadratic non-residue, that means a is not congruent to x squared for any x, a is not congruent to 0, and it's 0 if a is congruent to 0. And last lecture we calculated whether or not 2 was a quadratic residue, so we recall that this was equal to plus 1 if a is congruent to 1 or 7, sorry p is congruent to 1 or 7 mod 8, and minus 1 if p is congruent to 3 or 5 modulo 8. And now we're going to calculate this for some, if we change 2 to some other values. So one easy case to do is to work out whether or not minus 2 is a quadratic residue of p, and this is very easy because we remember the Legendre symbol is multiplicative in the top, so minus 2 is minus 1 times 2, so we get this relation here. And now we know what both of these are, so we can calculate this as follows. Suppose p is congruent to 1, 3, 5 or 7 mod 8, then minus 1 p is equal to plus 1, minus 1, plus 1, minus 1 respectively, and 2p is equal to plus 1, minus 1, minus 1, and plus 1 by last lecture, so we just multiply these together and we find that minus 2p is equal to plus 1, here we get plus 1, here we get minus 1, and here we get minus 1. So minus 2 is a quadratic residue exactly when p is congruent to 1 or 3 modulo 8. Now we'll have an application of this, so you remember we showed that there are infinitely many primes of the form 8n plus 1 by looking at primes factoring x to the 4 plus 1, and using the fact that if p is an odd prime dividing x to the 4 plus 1, then it must be of the form 8n plus 1. What we want to do now is to show there are infinitely many primes of the form 8n plus 3, 8n plus 5, or 8n plus 7, so these are all special cases Dirichlet's theorem. And to do this we're going to use the quadratic residue symbol, so we recall that if p divides x squared minus 2, here we're going to take p odd, then p is congruent to 1 or 7 modulo 8, and that's because if p divides x squared minus 2, this implies 2 is congruent to x squared mod p, so 2 is a quadratic residue of p, and we've seen that occurs exactly when p is 1 or 7 mod 8. So that means we can find primes that are 1 or 7 mod 8 by factoring x squared minus 2, and the question is how do we get rid of the ones that are 1 mod 8? Well that's not very difficult. Suppose we take all the primes p1 up to pn, suppose they're all congruent to 7 mod 8, and we think of all the primes 7 mod 8 that we thought of, and we want to find a new one. What we do is we multiply them together, and then we square it, and we notice that this is now 1 modulo 8 because it's the square of an odd number, and then we're going to subtract 2 from it, and we notice that this is now 7 mod 8, because it's 1 mod 8 minus 2, and so now we take a prime p dividing this expression, and we see that any such prime p must be congruent to 1 or 7 mod 8, but not all primes dividing it can be 1 mod 8, because if all primes dividing this will 1 mod 8, their product will also be 1 mod 8, and this would have to be 1 mod 8, which it isn't. So there's at least one prime that 7 mod 8 dividing this number here, and it can't be p1 up to pn because then it would divide 2, which is just silly. So we can find infinitely many primes that are 7 mod 8 by just multiplying together all the ones we found squaring it, subtracting 2, and we've shown that at least one of the primes dividing this must be a new prime that's 7 mod 8. So let's actually try a few examples of x squared minus 2. So we have 3 squared minus 2 is 7, that's 7 mod 8, 5 squared minus 2 is 23, that's 7 mod 8, 7 squared minus 2 is 47, that's 7 mod 8, 9 squared minus 2 is 79, that's 7 mod 8. In fact, it seems to be a rather good way of producing, I mean, x squared minus 2 rather often seems to be prime, but when we get to 11 squared minus 2, this is equal to 7 times 17, and now we see that 17 is 1 mod 8, and 7 is 2 is 7 mod 8. So this isn't always prime, and some of its factors are not 7 mod, are not 1 mod 8, but at least one of them must be 7 mod 8. Of course, this isn't a new one, but that's because we didn't take 11 to be the product of all the prime 7 mod 8 that we thought of so far. So next we would take, you know, 7 times 23 and square it and subtract 2, and that would have a new prime factor that's 7 mod 8 and so on. So, well that does primes that are 7 mod 8. Now let's try and show that infinitely many primes that are 3 mod 8. Well, this is quite similar. All we do is we look at prime factors of x squared plus 2, and we notice that if we take x to be p1 up to pn, where all the p i's are congruent to 3 mod 8, then x squared is going to be congruent to 1 mod 8. So this thing will be congruent to 3 mod 8, and we also notice that if p divides x squared plus 2, then minus 2 is a quadratic residue. So p must be congruent to 1 or 3 mod 8, and just as when we look at primes that are 7 mod 8, they can't all be, so not all factors of x squared plus 2 are 1 mod 8, because then x squared plus 2 would be 1 mod 8, which it isn't, it's 3 mod 8. So we can get infinitely many primes that are 3 mod 8 by multiplying together all the ones we found, squaring it, adding 2, and looking for a suitable prime factor of that, that's 3 mod 8. So that leaves 5 mod 8. I'm not going to do p equals 5 mod 8 in detail. I'm just going to leave as an exercise. I'll just say you use 4x squared plus 1, where x is a product of a lot of primes, and this is always 5 mod 8, and all its factors must be 1 or 5 mod 8, and now you can sort of copy the proof we gave before. So that's given some applications of when 2 is a quadratic residue of p. The next case to do is to look at when 3 is a quadratic residue of p, so we want to calculate this Legendre symbol. And now let's recall Gauss's lemma. So Gauss's lemma says that if we take the numbers 3, 6, 9, up to p minus 1 over 2 times 3, then 3p is equal to minus 1 to the n, where n is the number of these, so it's the number of these things here, between p over 2 and p when reduced mod p. So what we have to do, we have to write these numbers down, and we get nought, and then we get p over 2, and then we get p, and we get 3p over 2, and if you write them out, they'll get 3, 6, 9 and so on, and they'll get all the way up here to p minus 1 over 2 times 3, which is slightly less than this. So what we want to do is to know how many of these numbers are in this region here. And that's easy to work out, because the number in this region here is the integer part of p over 3. Sorry, the number all the way up to here is the integer part of p over 3, and the number here is the integer part of p minus p over 2 over 3. So the number in this region here is p over 3 minus p over 2 over 3, where we take the integer parts of these, and we want to know is this even or odd, because this is the number n, and we want to know minus 1 to the power of n. Now in order to work out whether that's even or odd, what we need to do is to work out what p is modulo, well here we're dividing p by 6, so to work out whether the remainder is even or odd, we need to know what p is modulo 12. So let's just work it all out. We can have p is equal to 12n plus 1, 12n plus 5, 12n plus 7, or 12n plus 11, because any prime that's not 2 or 3 must be of one of these forms, and let's work out the integer part of p over 3, well here we get 4n, 4n plus 1, 4n plus 2, and 4n plus 3. So we're just dividing this by 3 and throwing away the remainder, and then we get p over 2 divided by 3, take the integer part of that, and there we're going to get 2n, and here we get 2n, and here we get 2n plus 1, and here we get 2n plus 1, and the difference is, well here it's even, here it's odd, here it's odd, and here it's even. So 3p is plus 1, minus 1, minus 1, plus 1. So this calculates the Legendre symbol 3p, it's equal to plus 1 if p is congruent to 1 or 11, mod 12, or you can write that as plus or minus 1, mod 12 if you want, and it's minus 1 if p is congruent to 5 or 7 modulo 12. Well, now working out whether or not minus 3 is a quadratic residue of p is of course rather easy because this is just minus 1p times 3p, and we've worked out both of these, so we just write it down, p can be congruent to 1, 5, 7 or 11 modulo 12, now minus 1p, the Legendre symbol is equal to plus 1, plus 1, minus 1, minus 1, and 3p is equal to plus 1, minus 1, minus 1, plus 1, so we just multiply these together and we find minus 3p for the residues 1, 5, 7 and 11 is plus 1, minus 1, plus 1, or minus 1. So we say that minus 3 is a quadratic residue, if and only if p is congruent to 1 or 7 modulo 12. Well, in fact, that's a bit of a clumsy way of stating it because you may notice this is actually equivalent to saying that p is congruent to 1 modulo 3, so whether or not minus 3 is a quadratic residue is actually easier than whether 3 is a quadratic residue because whether minus 3 is a quadratic residue only depends on what p is mod 3. As an application, what you can do is you can find that show their infinite number of primes congruent to say 11 modulo 12, and in order to do this you can look at prime factors of x squared minus 3, so any prime fact, any odd prime dividing this will have 3 as a quadratic residue if it's not 3, and therefore must be 1 or 11 mod 12, and now you can sort of copy the proof I gave for numbers mod 8, so I believe that is an exercise. It details because it's really very similar to the case we did for before, so the next application will be a test for where the firman numbers are primes, so you remember we have these firman numbers which are 2 to the 2 to the n plus 1, and we can ask is this prime? Remember the exponent here has to be a power of 2, otherwise this number definitely isn't prime, and it was prime if n is equal to 0, 1, 2, 3, or 4, and as far as nobody knows of any larger values of n for which this is prime, and what I'm going to do is I'm going to give a test that you can use for reasonably large values of n, maybe around 20 or so, where it becomes rather difficult to test this because that would be around 2 to the million or something, so you certainly can't just test all prime factors of this, and the criterion is that p which is 2 to the 2 to the n plus 1 is prime, if and only if 3 to the p minus 1 over 2 is equivalent to minus 1 modulo p, and that's very nice because we can work out this fast using the Russian peasant method of exponentiating, especially because this is a power of 2, so we just need to keep squaring it a few times, so we've got to show two implications, first of all let's assume p is prime, and we want to show this, well if p is prime we notice that p is equivalent to 5 modulo 12 because p is equivalent to 1 modulo 4 because that's divisible by 4 unless n is 0 or something, so we're going to ignore the first two or three small values, and we also notice that p is congruent to 2 modulo 3 because this bit is going to be congruent to 1 modulo 3 and so is that, and the Chinese remainder theorem shows that if p is 1 mod 4 and 2 mod 3 it must be 5 mod 12, well this implies that 3 is not a quadratic residue of p, and by Euler's criterion this is equivalent to saying that 3 to the p minus 1 over 2 is equivalent to minus 1 mod p, so that's just Euler's criterion for when something is a quadratic residue, so that shows that if p is prime then then 3 to the p minus 1 over 2 is congruent to minus 1, on the other hand if 3 to the p minus 1 over 2 is congruent to minus 1, so let's suppose 3 to the p minus 1 over 2 is congruent to minus 1 mod p, we notice that p minus 1 over 2 is a power of 2, and we also notice that 3 to the p minus 1 is congruent to 1, so the order of 3 divides p minus 1 but not p minus 1 over 2 which is 2 to the something, this is 2 to the something minus 1, well that means the order of 3 is exactly p minus 1 because the only factor of 2 to the something that doesn't divide 2 to the something minus 1 is 2 to the something, and so this means that z modulo pz star has order divisible by p minus 1, so since it obviously is order at most p minus 1 it has order exactly p minus 1, so p is prime because if p wasn't prime the order of this would be would be less than p minus 1, so this gives us a necessary and sufficient condition for a firm and number to be prime which is reasonably fast, it means you know that you kind of firm out primes with millions of did sorry firm and numbers with millions of digits and you can test them reasonably fast on a computer to see if they're prime or not. By the way we will just notice that if we compare 3p with p3 we see that this is congruent to 1 if p is congruent to 1 or 11 mod 12 and this is equal to 1 if p is congruent to 1 mod 3, so we see that these two things are actually the same if p is congruent to 1 mod 4 and different if p is congruent to 3 mod 4, this will actually be a special case of the law of quadratic reciprocity that we're going to discuss next lecture, we also notice by the way that minus 3p is actually equal to p3, so this is sort of hinting that there's some sort of relation between the Legendre symbol and the Legendre symbol turned upside down except it's the relation is a bit mysterious, we'll be seeing more about that next lecture. Now let's see what happens if we try a equals 5, so what does, when is 5 a quadratic residue of a prime p? Well what we need to do is to look at the multiples 5, 10, 15 and so on and we want to see that we want to work out the number n that are between p over 2 and p when reduced mod p, so here we have numbers going up from 0 to p over 2 to p to 3 p over 2 up to 2p up to 5p over 2 and here the numbers are going to go 5, 10, so all the way up to p minus 1 over 2 times 5 and we want to know the number in this interval plus the number in this interval, so n is going to be the sum of these two numbers and how are we going to work this out? Well you see the number in here that are here is is going to be 4p over 10 or the integer part of this and the number here is going to be the integer part of 3p over 10 and the number here is going to be the integer part of 2p over 10 and the number here is going to be the integer part of p over 10. So n will be equal to 4p over 10 minus 3p over 10 plus 2p over 10 minus p over 10. And what we want to do is to work out what this is and if you think about it a bit we only need to know whether this number is even or odd and all of these bits the even or oddness will only depend on what p is modulo 20. So what we do is we have this big table p can be 20n plus 1 or plus 3 or plus 7 or plus 9 or plus 11 or plus 13 or plus 17 or plus 19. Now we work out these four terms here. So 4p over 10 will go 0, 1, 2, 3. So we get 3 here because you know we 9 4s are 36 and when we divide that by 10 it's we get 3 plus a remainder. And I'm missing out the 20n divided by 10 because that's just that's always going to be 2n which is even and then we get 4, 5, 6 and 7. And if we subtract 3p over 10 we get 0, 0, 2, 2, 3, 3, 5, 5 and 2p over 10 we get 0, 0, 1, 1, 2, 2, 3, 3 and for this one we get 0, 0, 0, 0, 1, 1, 1, 1. And now we want to add or subtract all these numbers and work out whether the result is even or odd and it doesn't really matter whether you add or subtract them because that doesn't affect the even or oddness of them. So here we here the sum is even, odd, this is odd, even, even, odd, odd, even. So the 5, the quadratic where I'm not 5 is a quadratic where it goes plus 1, minus 1, minus 1, plus 1, plus 1, minus 1, minus 1, plus 1. So we see that 5p is equal to 1 if and only if p is congruent to what we've got, we've got 1 or 9 or 11 or 19 modulo 20. Well you see we don't actually need to work modulo 20 because this is just equivalent to p being congruent to 1 or 4 modulo 5. And in fact this is also the condition for p5 to be 1. So the squares modulo 5 are exactly the numbers that are 1 or 4 mod 5. So in fact we see that 5p is equal to p5. So it's another case of the quadratic reciprocity law which allows you to turn the Legendre symbol upside down sometimes. Well we could do this for 7 rather than 5 but already for 5 it's getting to be a little bit tedious and we really need a better method for working out where the numbers are quadratic residues and this will be the, we want to generalize this rule here into the law of quadratic reciprocity which will be coming up next lecture. Just to finish off this lecture I'll do one case that's reasonably easy which is when is 6 a quadratic residue of p? So we've done 1, 2, 3 and 5 and 4 is trivial because 4 is always a square. So 6 is the next one. Well that we can work out by saying 6p is 2p times 3p and now we know both of these and this depends on what p is mod 8 and this depends on what p is mod 12. So this should depend on what p is mod 24. So let's just work this out. Suppose p is congruent to 1, 5, 7, 11, 13, 17, 19 or 23 mod 24 then we just work out what is 2p. Well 2p goes plus 1, minus 1, plus 1, minus 1, minus 1, plus 1, minus 1, plus 1 because that's 1 for things that are 1 or 7 mod 8 and 3p we've worked out it goes plus 1, minus 1, minus 1, plus 1, plus 1, minus 1, minus 1, plus 1. So if you multiply these together we find 6p is congruent to plus 1, plus 1, minus 1, minus 1, minus 1, plus 1, plus 1. So 6 is a quadratic residue of the prime p where p is not 2 or 3 otherwise these cases are it's not for p equals 3 and not defined for p equals 2 so this is equal to plus 1 if and only if p is congruent to 1, 5, 19 or 23 mod 24. Okay so next lecture as I've said will be on the law of quadratic reciprocity which will make this process a lot more systematic.