 This lecture is part of an online course on the theory of numbers and will be about congruences. And so, so far we've had a few introductory lectures on primes and we're now going to sort of move on to another chapter on the course and the next few lectures will all be about congruences. So we can start by defining congruences. So we say A is congruent B modulo M if A minus B is divisible by M. So first of all, to illustrate that this notation is really important, we have Gauss's book, Disquisitione's Arithmeticae, and the very first sentence of section one is his definition of two numbers being congruent. So the key point is that this is an equivalence relation. So we should think of if two numbers are congruent, modulo M, you should think of A and B as being in some sense equal. So first of all, we need to check the conditions for an equivalence relation. So what does an equivalence relation mean? Well, we have to check that A is equivalent to itself. So this is, we say this is reflexive. And if A is equivalent to B, this implies B is equivalent to A. So this is symmetric and it should be transitive. If A is equivalent to B and B is equivalent to C, this implies A is equivalent to C. So this is transitivity. I should say by the way that mathematicians are really lazy and will quite often miss out writing modulo M everywhere. So usually what you do is you fix M and omit it from the notation to make it a bit simpler, which is what I've done here. And these are the usual properties of an equivalence relation. But in order to say two equal, we need some other properties. We want to say if A is equivalent to B and C is equivalent to D, then A plus C should be equivalent to B plus D. And A times B should be equivalent to, so A times C should be equivalent to B times D. So we need to check these four properties, but all of these properties are pretty trivial. For instance, this says that if M divides B minus A and it divides C minus B, then it divides A minus C, which is kind of obvious. All these other properties are sort of equally obvious. So what we can do is we can choose a set of integers so that every integer is congruent to exactly one of these. For example, let's take M equals three. Then we could choose the integers zero, one, and two, because every integer is congruent to one of these integers. So we can think of the integers modulo three as being a set with three elements represented by these three numbers here. Of course, we don't have to choose zero, one, and two. If we wanted, we could choose 37 and 23, but that would be kind of stupid. It's much easier to choose zero, one, and two. And then we can do addition on these and multiplication. And this is well defined because of these properties here. And if you want, you can write down an addition table, so zero, one, two plus zero, one, two is going to be zero, one, two, one, two, two, zero, zero, one. And multiplication will look kind of similar, so here we get zero, zero, zero, zero, zero, and one times anything is anything, and two times two is one. So you also notice that addition and multiplication on the integers mod M satisfy the usual rules of arithmetic. Well, what are the usual rules of arithmetic? Well, you have to be a bit careful here, because actually they don't satisfy all the usual rules of arithmetic. So the ones they do satisfy, the first of all, addition is an abelian group, so nought plus a equals a, a plus b equals b plus a, a plus b plus c equals a plus b plus c. And there's an inverse, a plus minus a equals zero, so we implicitly assume there's a negative under zero. And multiplication is similar, so we get one times a equals a, a times b equals b times a, a times b times c equals a times b times c. But then we don't always have inverses, so there's not necessary an inverse for multiplication, and finally these should be distributive, so a times b plus c is equal to ab plus ac. So these are the rules of arithmetic that integers modulo M satisfy. So if you've done abstract algebra courses, you know these are the axioms for a ring, more or less. And there are some rules of arithmetic that the integers modulo M do not necessarily satisfy. For instance, one rule is that if ab equals nought, this implies a equals nought or b equals nought. And this doesn't always hold. For example, two times two is congruent to zero if we're working mod four, but two and two are not zero mod four. So when I say all the usual rules of arithmetic hold, I mean all the usual rules of a ring. So let's see some other examples of this. First of all, time. If you measure time in hours, you usually work modulo 12. So if it's nine o'clock and you add six hours, you don't get to 15 o'clock unless you're in the military. So time nine plus six is three. I think military people use something different because if you're a general and you order an attack at five o'clock at dawn, it's very frustrating to get off your army attacks at five o'clock in the evening. Another example is computer integer arithmetic. So suppose you take some programming language and you define the variable n to be an integer in say programming language C or something like that. Actually, the programming language C does not represent it as an integer. It really represents it as an integer modulo two to the word size, which these days is usually about 64 and probably goes up every few years. Now, writing out all the integers from naught to two to 64 is a bit of a pain. So let's work on a computer with word size three. So what this means is that the integers are really integers modulo eight. And we can choose a set of representatives for the integers modulo eight. So one obvious choice is naught, one, two, three, four, five, six, seven. And this corresponds to the computer type known as unsigned integers. So in this case, you will find that if you say take the unsigned integer six and add it to the unsigned integer five, you don't get 11. You get three because we're working modulo two to the power of three. Do you have extremely small word size? If you want to work with signed integers, you use a set of representatives minus four, minus three, minus two, minus one, zero, one, two, three. So if you take two plus two, for example, turns out to be minus four. So here are two choices of sets of representatives. You could choose the numbers from naught to seven, or you could choose the numbers from minus four to three. If you're doing time, you usually use the set of representatives going from one up to 12 rather than zero up to the 11 for various historical reasons. By the way, in case you're wondering why you use a minus four instead of using minus three, minus two, minus one, zero, one, two, three, four. The reason is if you write these out in binary, you find these numbers here look like a 111, 110, 101, 100. And you notice that these all have a one as they're leading binary digits. So if you're set of representatives include minus four rather than four, it makes it easier to check whether numbers are supposed to be negative or not just by looking at the leading digit. So it's also quite common to represent the integers modulo N as a sort of circle. For example, if we look at the integers modulo seven, we might write them as one, two, three, four, five, six, seven. You sort of write them out in a circle like this. Okay, I can't count up to, oh yes I can, that's okay. And the idea is that every time we add one to an integer you go round one step in this circle. So now we should look at some applications of modulo arithmetic. So we might ask the following problem, which integers are sums of two, three or four or more squares? So this is one of the historical problems that number theory sort of started off with, that Fermat studied the problem of which integers are sums of various numbers of squares. Now it turns out that every integer is a sum of four squares, which we will may cover later. But what I want to do is to discuss which integers are sums of two or three squares, and we can find some obstructions to this. So we're trying to solve the equation x squared plus y squared equals N. And we want to know for which N can we solve this? Well, what we can do is if this is solvable, then we can solve x squared plus y squared is congruent to N modulo M for any M. And what we want to do is to choose a careful choice of M so that we can get some useful information from this. And what we're going to do is we're going to take M equals four. And now we notice that what's x squared mod four? Well, if x is equal to zero, one, two or three, then x squared is equal to zero, one, zero or one mod four. So we see that any square is always zero or one mod four. So x squared plus y squared is congruent to zero or one plus zero or one, which is congruent to zero, one or two modulo four. So any number of the form three modulo four is not a sum of two squares. For example, we see that x squared plus y squared cannot ever be one million and seven, because this is congruent to three modulo four. And you see this is much quicker than checking all the possibilities. The converse isn't true. So there are plenty of numbers that are not congruent to three modulo four that are not a sum of two squares. For example, 21 is congruent to one mod four, but 21 is not equal to x squared plus y squared for any integers x and y. So this is a necessary condition, but it's not sufficient. We will see later that if a prime p is congruent to zero, is congruent to one or two mod four, then a prime p can be written as a sum of two squares. This is a very famous and fundamental theorem proved by Fermat. Well, so that says a little bit about two squares. What about sums of three squares? Well, this time we're going to look mod eight. And now if we look at what x squared is modulo eight, we get zero, one, two, three, four, five, six, or seven. And if we look at it square, we get zero, one, four, one, zero, one, four, one. So this is always zero, one, or four. So x squared plus y squared plus c squared must always be congruent to zero, one, four plus zero, one, four plus zero, one, or four modulo eight. And the possibilities here are zero, one, two, three, four, five, or six. And you notice that the number seven doesn't exist. So anything congruent to seven mod eight, then n is not a sum of three squares. Again, this is a necessary condition, but it's not a sufficient condition. For example, 28 is not congruent to seven mod four, but 24 is not a sum of three squares. Sorry, that should be a 28. And to see this, we just look at this equation modulo four. So this is zero or one modulo four, this is zero or one modulo four, and this is zero or one modulo four. But this is congruent to zero modulo four. So the only way something that is zero mod four can be a sum of three things each of which is zero mod four is these must all be, they must all be zero mod four. So x, y, and z must be even. But then we find, if we divide this by four, we find 28 over four is x over two squared plus y over two squared plus c over two squared. But this number here is seven mod eight, so this is not possible. And you see what this argument shows is that if four n is a sum of three squares, then n is a sum of three squares. So if n is of the form seven to the a, sorry, seven plus eight a times four to the b, then n is not a sum of three squares. The converse to this is also true if n is positive and not of this form then it is actually a sum of three squares. That theorem is much more difficult to prove and we probably won't be covering it this course. Well, that said something about sums of squares. What about sums of cubes? Well, for sums of squares we looked modulo two or four. That doesn't work terribly well for cubes. For cubes it's better to work modulo three, nine or twenty-seven. So you see what the pattern is. So if you're looking at squares then it turns out to be a very nice idea to look modulo four or eight or possibly sixteen. And if you're looking at cubes you look modulo three, nine or twenty-seven. If you're looking at fifth powers then you probably want to work modulo five or modulo twenty-five and so on. By the time you get to fifth powers it's rather hard to get useful information out. Anyway, let's look at what cubes can be modulo nine. So here's x, it can be zero, one, two, three, four, five, six, seven or eight and what's x cubed? Modulo nine, it turns out to be zero, one, minus one, zero, one, minus one, zero, one, minus one which is a rather nice pattern. When you get up to five you don't get anything nearly as nice as that. So this only works nicely for cubes and squares. So x cubed plus y cubed plus z cubed is congruent to minus one, zero, one, plus minus one, zero, one, plus minus one, zero or one, modulo nine. Which is congruent to minus three, minus two, minus one, zero, one, two, three, modulo nine. So we see that if n is congruent to four or five, modulo nine, then n is not sum of three cubes. There's a rather difficult unsolved problem in number three which asks, is every sufficiently large positive integer the sum of four positive cubes? And this is sort of unclear. By the way, I should say if we're asking about sums of cubes that there are actually two possibilities. So if you look at n equals x cubed plus y cubed plus c cubed, we can ask case one, we can insist that x, y and z should be greater than or equal to zero. So we might want three positive cubes. And the second case is we might allow x, y and z to be in any integers. And I was a bit surprised to find the problem of writing a number of the sum of three cubes of any sign appears to be a really popular internet problem. There seem to be several YouTube videos about this. So there's a conjecture, I think it's due to Heath Brown, which says that if n is not congruent to four or five modulo nine, is n sum of three positive or negative or zero, I guess, cubes? And there's been a lot of work on trying to solve this equation for n up to about 100. So if I go to the Wikipedia page on this, you can see there's an expression of 42 as a sum of three cubes. It says it was found by Booker and Sutherland quite recently. And you see the smallest solution we found for x, y and z is absurdly large. So, you know, if you did sort of trial and error, you might search and find that there's no solutions for x, y and z less than a million. But that doesn't actually mean it doesn't have solutions. This is one of the difficulties with number theory. We can sometimes have solutions to equations that are far bigger than you might guess. So I should just end with pointing out that there's an old numerical trick for checking calculations called casting out nines. Where you sort of check to see whether a solution is correct by replacing any decimal number with the sum of its digits. And a simple example of this is asking, does 9 divide, say, 29367? And you could do this by doing division or something, but you don't really need to do that. What you do is you just take the sum of the digits and you see this is equal to 27. And then you take the sum of the digits of this and this is 9, which is divisible by 9. And this means the original number is divisible by 9. And what you're really doing in this calculation is you work modulo 9. So we notice that 10 is congruent to 1 modulo 9. So 10 to the n is congruent to 1 modulo 9 for any n. And from this we see that 29367 which is equal to 2 times 10 to the 4 plus 9 times 10 to the 3 plus 3 times 10 squared plus 6 times 10 plus 7 is congruent to 2 plus 9 plus 3 plus 6 plus 7 modulo 9. So if you want to check whether a number is divisible by 9, all you need to do is just take the sum of its digits and see whether that's divisible by 9. And similarly, if you want to check some calculation like a times b equals c, you can do a quick check by working out whether the sum of the digits of a times the sum of the digits of b is congruent to the sum of the digits of c modulo 9. And in the days before, pocket calculators, when you did arithmetic by hand, this was often a useful check. By the way, there's a similar test for divisibility for 11 that I'll just leave as an exercise. So the idea is if you want to check for divisibility by 11, suppose you want to check 29367 for divisibility by 11, what I'll do is I'll take 2 minus 9 plus 3 minus 6 plus 7. So this would be minus 3. And this is not divisible by 11. So the original number isn't divisible by 11. As I said, I'm just going to leave that as an exercise. I should put in one warning here. We did actually say that 10 to the n is congruent to 1 modulo 9. What you've got to be a little bit careful of is that if m is congruent to n modulo 9, this does not imply that a to the m is congruent to a to the n modulo 9. So congruences, the behavior of exponents under congruences is a little bit tricky and we'll be discussing that quite a bit later on. OK, so that's the end of the introduction to congruences. Next lecture we'll be discussing Fermat's little theorem, which is about the most basic and useful theorem in the theory of congruences.