 This lecture is part of an online undergraduate course in The Theory of Numbers and will be about the Jacobi symbol. I'd better stop by apologising to anybody who speaks German because I'm mispronouncing Jacobi, the proper German pronunciation is something closer to Jacobi, but if I call it that then nobody in England or America will understand me, so I will use the English pronunciation. So the Jacobi symbol is an extension of the Legendre symbol. So you remember we have the Legendre quadratic residue symbol defined for p, an odd prime, and this is equal to plus one if a is a square, not congruent to zero, and minus one if a is not square and not congruent to zero. And we saw last lecture that you can work this out using the quadratic reciprocity law, but it is very annoying that the denominator has to be a prime because that means you need to keep factorising the numerator when you're working it out and factorisation can be really hard in general. Anyway, Jacobi found this really nice generalisation of the Jacobi symbol to sort of the Legendre symbol where the denominator is now allowed to be any number, so any odd number. So the Jacobi symbol is defined when b is odd and greater than zero, and a is any integer. And it's defined very easily. You just factor b into a product of prime, so you write p1, p2, up to pn, and you just make it multiplicative. Notice by the way that if b is one, we've got an empty set here, so we find that a1 is just equal to plus one. It's a special case of the usual convention on products of empty sets. This definition seems a little bit silly or bizarre, but we'll justify it fairly soon. I should put in one warning here. So a b equals plus one does not imply a is a square. To see an example of this, let's just take b equals 15, which is 3 times 5, and let's suppose that a3 and a5 are both minus one. For example, we could just take a equals 2. And then you notice that a15 is equal to minus one times minus one, which is plus one, but a is certainly not a square mod 15. In fact, it's not even a square modulo 3. So the interpretation of the Jacobi symbol is a little bit trickier than for the Legendre symbol. So let's write down some properties of the Jacobi symbol. So first of all, it has many of the properties of the Legendre symbol. So a1b equals a2b. If a1 is congruent to a2 modulo b, that follows almost immediately from the definition. Minus one b is equal to minus one to the b minus one over two. And again, that follows easily from the definition and from the fact this is true when b is a prime. 2b is again minus one to the b squared minus one over eight, which is equal to one if b is congruent to plus or minus one modulo eight and minus one otherwise. So these rules all go through just before. Slightly more subtle is the quadratic reciprocity law also works. So a b is equal to minus one to the a minus one over two, b minus one over two times b a. Here a and b are both odd and both greater than zero. And this follows from the quadratic reciprocity rule for primes if you do a little bit of work. So I'm feeling too lazy to do this. So I'll just leave this as an exercise. And then we've got multiplicativity. So a1 a2 b is equal to a1 b a2 b and the same thing works for denominators. So a b1 b2 is equal to a b1 times a b2. This follows almost instantly from the definition. This follows easily from the property for a genre symbols. We've got a sort of periodicity on the bottom, but you have to be a little bit careful. So a b1 equals a b2. If b1 is congruent to b2 modulo 4a, not a. So the numerators only depend on a modulo b, but the denominators are a little bit funny. For example, you can see this, if a is equal to minus 1, for example, then if you take b1 equals 3 and b2 equals 5, this fails modulo a. It works modulo a if a is congruent to 1 modulo 4. It's very common in quadratic reciprocity for the things that are 1 modulo 4 to behave a little bit better than the things that are 3 modulo 4. And now the really big advantage of the Jacobi symbol is you can work out the quadratic reciprocity symbol fast even if a and b are large. So we've actually had at least three ways of working it out. First of all, you can work it out a really stupid way just by checking all numbers to see if they're squares. Secondly, we could work it out reasonably fast using Euler's identity, which says that it's equal to a to the b minus 1 over 2 mod b, at least at b as prime. And thirdly, we saw that we could work it out using the reciprocity law for the genre symbol except that involved factorizing a. And the Jacobi symbol means we can sort of do the same thing except we don't need to factorize a. So just as an example, let's work out minus 200299991, which is almost the same example we've had last time except I've added a factor of minus 2 there. So what you have to do is you must first take out all the factors of minus 1 and 2 in order to make the numerator odd. So this is minus 199991 times 299991 times 100199991. And now this one is equal to minus 1 because that's 3 mod 4 and this one is equal to plus 1 because this is 7 modulo 8. So we get factors of minus 1 and plus 1. And now we have to work out this term, which is the one we did last time. So last time we had to start by factorizing 1001 because we weren't allowed to put primes on the bottom. But with the Jacobi symbol, we don't need to factorize it. We can just use the quadratic reciprocity law and say this is equal to minus 999991 1001. So we get a minus sign from coming from there. And now we can just reduce the numerator modulo the denominator. And if I work this out right, this comes to 892 modulo over 1001. Then we take out the factors of 2 squared and we find this is minus 223 1001. And now we use quadratic reciprocity again to invert this. So we get this is now minus 1001 223 because 1001 is 1 mod 4. And then we divide and take a remainder again, which is minus 109 223. And then we use quadratic reciprocity again and we find this is minus 223 109. And then we divide again and we find that this is minus 5109. And then this is equal to minus 1095 using quadratic reciprocity yet again. And now this is equal to minus 45 and we can take out factors of 2 and this gives us minus 15, which is equal to minus 1 because 1 is a quadratic residue of 5. Now, if you look at this, you'll notice that it's very, very similar to Euler's algorithm for finding the greatest common divisor of two numbers. We're constantly switching the numbers and dividing one by the other. The only slight difference is we have to take out factors of 2 because we're only allowed to switch the numbers when both are odd. Actually, remember I gave an algorithm for greatest common divisor which was even faster than Euler's algorithm because instead of dividing the numerator by the denominator, you could just make the numerator and denominator both odd and then just subtract the denominator from the numerator or vice versa. And you can do exactly the same thing for the Jacobi symbol. In fact, it's even better designed for the Jacobi symbol because you have to take out factors of 2 anyway. So the fastest algorithm for this, you shouldn't really do long division because long division is really tiresome. What you should do is really just subtract 2, 2, 3 from the 1,001 and then take out factors of 2 and continue. That takes a slightly more steps but, as I said, the steps don't involve doing long division which is a real headache. So we can work out Legendre and Jacobi symbols really fast. And because they're so easy to work out, they're a sort of fundamental part of computational number theory. I mean, if A and B have a million digits, it's still no big problem to work out the Jacobi symbol. So one thing we can do is we can improve our prime tests. So you remember one way of testing to see if N is prime is to look at A to the N and see if A to the N is congruent to A modulo N for various values of A. And if this fails, then N is definitely not prime. And if it's true, well, N is probably prime but you remember for N equals 561, A to the N is congruent to A mod N for all A. So 561 is not prime. It's divisible by 3 for a start and by 11 and so on. So the simple-minded application of Fermat's theorem doesn't really work for a few numbers. I mean, it works nearly all the time but there are these occasional exceptions. And what we can do is we can improve this using the Jacobi symbol. So here we have a sort of Jacobi test. If N is prime, this implies A to the N minus 1 over 2 is congruent to A N modulo N. So we can test to see if this is true. For example, let's take N to be this troublesome number 561 and let's take A to be 5. Then we've got to work out 5 to the 280 and compare it with 5561 and see if they're the same. And if they're not the same, then this number 561 is definitely not prime. Well, we can work out this using quadratic reciprocity. So this is equal to 5615, which is equal to 15, which is equal to plus 1. And we can work out this number here by using the usual algorithm for working out something to the power of something modulo something else. And it turns out to be 67. And you see 67 is not equal to plus 1, so 561 is not prime. Actually, notice we didn't really need to work out the Jacobi symbol here because we could have just worked. All we need to notice is that Jacobi symbol has to be either plus or minus 1 and 67 is not only plus 1, but it's not minus 1 either. So in this particular example, we didn't really need to work out the Jacobi symbol. But in general, the Jacobi symbol will sometimes help you to eliminate more numbers. So we can get an improved primality test, which is much more like, well, slightly more like to work than the Fermat test. Well, you know that the definition of the Jacobi symbol saying AP1, P2 and so on is equal to AP1, AP2 and so on looks really artificial. There's a sort of neater description of it found by Zolotarov. He showed that the Jacobi symbol AB is equal to the sign of the permutation X goes to X times A on Z modulo BZ. That works. Here we're taking A and B both to be odd and greater than zero. So let me explain what the sign of the permutation is. So multiplying by A is a bijection on this set Z modulo BZ. And you call these a permutation. So permutation is just a map from a set say one up to B to itself. And a permutation has a sign and the sign is given as follows. So what we do is we take variables X1, X2 up to XB and we multiply X1 minus X2, X1 minus X3, X2 minus X3 and so on. So this is just equal to the product of I less than J of XI minus XJ. And if we call this number delta, well, if we apply the permutation to all the XIs, it permutes the XIs. And you can see that delta is going to get changed to either plus delta or minus delta if we if we renumber all the variables. So X2 minus X3 might get changed to X3 minus X2 and it might not be and we'd pick up a sign and similarly we might get lots of signs. And Zolliter found that AB is just the sign of the permutation of given by A, given by multiplication by A, given by X goes to AX. And let's see why this is true. So I'll just quickly sketch why this is true. Well, first of all, if you've got a permutation on various numbers, one, two, three, four, five, let's do six say. So you might have a permutation which is multiplication by two and multiplication by two modulo seven will sort of do this. It will take three to six, six to five and five to three. So you see the permutation to be written as a union of cycles and the rule for the sign of a cycle is very easy. So an odd cycle is an even permutation and an even cycle is an odd permutation. So an even permutation is one that gives you a sign plus one when you apply it to delta and an odd permutation is one that takes delta to minus delta. So as usually in mathematics, the terminology is a bit of a mess. And this is quite easy to check. For example, if you've got a cycle of length two, that's just taking one to two and two to one, you can see that takes X1, exchanges X1 and X2. So delta in this case would be X1 minus X2 and changes sign. If you've got a cycle of length three, it looks like this. And here we would have X1 minus X2, X2 minus X3, X1 minus X3. And you can check this goes to X2 minus X3, X3 minus X1 times X3 minus, wait a moment, X3 minus X1. Hang on, that doesn't look right. That should be an X1. So that would be X2 minus X1. And you can check that this is equal to plus one times that. And you can check other cycles similarly. Now we want to see that if something is a quadratic residue, then it gives you an even cycle. And if it's a quadratic non-residue, then it gives you an odd cycle. Well, let's take G to be a primitive root. Then we get one goes to G, goes to G squared, goes to G to the B minus one. And this is a cycle of length B, which is even. And you remember even cycles give you odd permutations. So X goes to X times G is an odd permutation. And now we know that A is a quadratic residue is equivalent to saying A is equal to G to the N with N even. And a quadratic non-residue is equivalent to A equals G to the N with N odd. And these are even permutations. And these are odd permutations because multiplication by G is an odd permutation. So the Nth power of G is either even or odd depending. So this shows that A P for P prime is plus or minus one depending on the permutation X goes to A X being even or odd. So that proves the result for P prime. For B composite, the same is true for A B. Here you have to use the fact that A B is equal to A P1 times A P2 and so on. And I'm just going to leave this bit as a little exercise because I'm feeling too late to do it. So Zolotarov gave a very neat interpretation of the Jacobi symbol for all odd A and B. In fact, he was able to prove a quadratic reciprocity law giving a proof depending on this interpretation in terms of odd and even permutations. Okay, I just finished by saying a little bit about the Kronika symbol. So the Kronika symbol is also written A B and this is now defined for all integers A and B. So you remember the Jacobi symbol had this slightly annoying feature that B had to be odd and positive. And the Kronika symbol eliminates this by defining it for all B but I should warn you the definition is a little bit funny. So we define A2 to be 1 if A is congruent to plus or minus 1 mod 8 and minus 1 if A is congruent to plus or minus 3 mod 8. I should have said that this is going to be plus or minus 1 if A and B are co-prime and not if A and B are not co-prime. So if A is even this is automatically 0 and we define A minus 1 to be 1 if A is greater than or equal to 0 and minus 1 if A is less than 0. And then as before we define A plus or minus P1 Pn to be A plus or minus 1 Ap1 up to Apn. And the problem is that the Kronika symbol behaves a little bit oddly. For example, A, B, A1, B and A2, B may be different if A1 is congruent to A2 mod B. So they're sometimes not equal. So periodicity breaks down. And we also want to define A0, we define that to be plus 1 and the problem is this makes multiplicativity break down a little bit. For example, minus 1, 0 is not equal to 1, 0 times minus 1, 3 because that's 1 and that's minus 1 and that's 1. And you might think well we could fix that by changing minus 1, 0 to be minus 1 but that doesn't work either because you would then find out that minus 1, 0 was not equal to 1, 0 times minus 1, 1. So you can't quite get multiplicativity if you insist on defining this for all A and B. It still satisfies the multiplicativity condition as long as A and B are both non-zero. So the Kronika symbol definitely has a few kind of glitches in it. You should also notice that this is not the Legendre symbol for A for P equals 2. For the Legendre symbol if you define it for the prime 2 it would have to be plus 1 whenever A is odd. And this is one of the reasons why it's actually a bad idea to define the Legendre symbol when the denominator is 2 because it then conflicts with the Kronika symbol. And you might ask why did Kronika have this rather funny definition of the Kronika symbol? Well, the reason for this definition is we will see later that the Kronika symbol AB for primes P gives you the decomposition of a prime P and a quadratic extension of discriminant A which we might cover later when we discuss quadratic fields. So there is actually a really good reason for defining A2 in this slightly bizarre looking way. Okay, next lectures might be on binary quadratic forms.