 In this video, we're going to introduce now one last type of field, which in fact is a finite field, the rash numbers, the complex numbers, the real numbers. These are all infinite fields. There's no limit to the number of numbers we have. But could we construct a field which has a limit to the number of numbers, right? There's only five numbers. There's only seven numbers in the entire field. This will be called finite field. And we can accomplish that using a new type of arithmetic, which we call modular arithmetic, which turns out that we actually do modular arithmetic on a daily basis. We just don't necessarily realize it. So we're going to let N be some positive integer. And we're going to let A, so we're going to take N, N and A, these are going to be two integers. And we're going to require that N be a positive integer for this discussion here. Now consider the operation of A divided by N, right? Now, the division algorithm, which we know from primary school, guarantees that there exist unique numbers, Q and R. So there's going to be some numbers Q, which we call the quotient. And there's going to be a number R, which we call the remainder. The division algorithm we know guarantees this quotient or remainder such that A is equal to Q in plus R. So A, it's a multiple of N, but there might be some term left over this remainder. So when I talk about your division algorithm saying, like, if you take A and you divide it by the number N, you're like, okay, I'm going to get the number Q, right? There's all this business going on and then you get this remainder R. This is what I'm talking about. This can be done for any two integers. And we also know that our remainder R, it's going to be less than N, because if it was bigger than N, you could keep on going. And itself will be a positive number. It could be zero if it divides in there evenly. And so a very quick example of such a thing is, what if we take the numbers N equals 5 and A equals, say, 13? If we were to go through the details of this, we take 13 divided by 5. We're like, okay, what's the biggest multiple of 5 that goes into 13? I can do that two times because 10 is 2 times 5. And when you subtract these things, 13 take away 10, you get 3. This is your remainder term. Your quotient was 2. And so this tells us that 13 is 2 times 5 plus 3. So given these two integers, we can always do this type of construction, right? So generally we interpret this statement as 5 divides into 13 two times with remainder 3, right? So for example, if we had 13 vectors that we want to share amongst our five friends, each friend would get two vectors. And then we have three vectors left over that we have to figure out how to distribute amongst our friends right there. And so typically with the division problem, one is interested in finding the quotient. How do we distribute these vectors amongst all my friends? But modular arithmetic is not interested in the quotient. It's interested in the remainder. The remainder is the term that we love when one does something called modular arithmetic. All right, so we're now ready to find what we mean by modular arithmetic. We're going to take the set ZN. So without the N, this would just be the set of integers. When you add a subscript of N to Z here, this will give you a finite set. You start with 0, you go to 0, 1, 2, 3, you can go all the way up to N minus 1. Now notice this will be a list of N integers. And this should be viewed as the set of all possible remainders when you divide by N. If you divide by N, your remainder could be 0, 1, 2, 3, 4, up to N minus 1. Your remainder couldn't be N, it couldn't be bigger than N, because otherwise you did your division process incorrectly. So we're going to define a function now. That function, it has the name mod N. And it's a function from the set of integers to the set of ZN. And what it does is it takes the number A mod N. So A mod N, what does that mean? This is going to equal the remainder R. That is when A equals Q in plus R. That same R is what we're going to define right here. So taking A mod N means give me the remainder, give me the remainder when you divide by N. So an example of this, let's take for example 14, when we haven't done yet, 14 mod 5. What that means is we want to find the number, the remainder we get when we divide 14 by 5. Well, let's see if I were to do that, 14 divided by 5, 5 goes into there. Again, 2 times take away 10, you're left with a remainder of 4. And so 14 mod 5 is equal to 4. That's what we mean right here. This operation would return 4 back. The remainder of 14 divided by 5 gives us a 4. Or if we did something like what's 8 mod 3? 8 mod 3, well, 3 goes into 8. 2 times at 6, you get a remainder of 2. So 8 mod 3 is equal to 2. These are the type of operations we have in mind when we talk about modular arithmetic. So the response you get when you do these modular calculations will always be a number between 0 and 1 less than the modulus. So when we work to mod 5, your answer has to be 0, 1, 2, 3, or 4. When you work mod 3, your answer has to be 0, 1, or 2. Those are the only possibilities you can get when you think about all the possible remainders. Alright, let's see. Another example here is that you could also do this with negative values as well. A doesn't have to be positive. The modulus has to be positive. That's what mod is short for. It's short for modulus. The modulus has to be positive, but the number that you're modding out doesn't have to be. So we could do something like, say, negative 11 mod 6. Now this one might have to be a little bit more careful about what you're doing here. In this situation, we have negative 11, we have Q6 plus R. We're trying to figure out which quotient can we choose in order to get this remainder between 0 and 5. Now, if we were to do this, it's like, let's see, if I take 2 times 6, that's equal to 12, and 12 plus, I'm sorry, I need to take negative 2, negative 2 times 6 would give us negative 12. And then if you add 1 to that, that gives you negative 11. So negative 11 mod 6 gives you, excuse me, positive 1 as your modulus right there. And so we can do this operation with negative numbers as well. It can get a little bit more confusing if we have negatives. And I honestly like to think of it in the following way. What we're going to do is we're going to find a relationship between integers based upon a modulus. And we want to think of it in the following way. That we have, when you're working mod 6, we're going to have these 6 numbers. You think of it as like these pearls on a diamond, on a pearl necklace here. They're all stringed together like this. So when you're working with Z6, these are the 6 numbers that you can possibly have. You have the numbers 0, 0, 1, 2, 3, 4, and 5. And so if we were to take this, if we take this circle and we were to just spin it around, we spin it around, let's go clockwise this time. If we spin it around once, what I mean by that is we're going to add 6 to all of these numbers. And what you're going to then get is that 0 plus 6 is equal to 6. 6 plus 1 is 7. 2 plus 6 is 8. 3 plus 6 is 9. 4 plus 6 is 10. And 6 plus 5 is 11. And so when you spin this diamond necklace, or this pearl necklace around once, you end up with these 6 new numbers. So what we're going to say is we're going to say the number 11 is congruent to the number 5 mod 6. Because when you add 6 to all these numbers, you get the same thing again. Likewise, 10 is congruent to 4 mod 6. We say 9 is congruent to 3 mod 6 because they're in the same positions here. And so if we play this game again, play this game again, let me erase these numbers. If we add 6 to all the numbers one more time, 6 plus 6 is 12. Then we get 13, 14, 15, 16, and 17. And so what we also see is that 17 is likewise congruent to 5. 16 is congruent to 10, which is congruent to 4. 15 is congruent to 9, which is congruent to 3. Again, as we spin this thing around and around and around, we see all these numbers are congruent to each other. Another example, 13 is congruent to 7, which is congruent to 1 mod 6. All of these numbers are the same. And that's because they all have the same remainder when you divide by 6. 1 divided by 6 gives you a remainder of 1. 7 divided by 6 gives you a remainder of 1. 13 divided by 6 is its remainder will again be 1. And so when 1 works with modular arithmetic, it can interchange these numbers. We're considering these numbers now the same number. 1, 7, 13 are all considered the same number. And like I said, this object is not exactly foreign to us, right? Because when we look at our clocks, we often think of in the following manner, mod 12, right? If it's presently 3 p.m. And it's like, hmm, what's going to happen 11 hours from now? 3 plus 11 is equal to 14. Oh, if it's 3 p.m., then 11 hours from now, it's going to be 14 p.m. No, we don't ever say that. We're like, oh, okay, I really need to kind of replace 14 with 2. In which case we're like, oh, if I take 3 p.m. and I add 11 hours to it, that's going to be 2 a.m. in the morning. So maybe I'm downloading something online. It's like it's going to take 11 hours to download. It's going to stop at 2 a.m. So when we work with hours in the day, we're working mod 12, and that's what we're doing just maybe now with different moduli as we start doing these things. So coming back to this negative expression right here, negative 11, if we want to find the remainder, what we can do is we can just keep on adding 6 to it. We could take negative 11 plus 6. That's going to give us that negative 11 is congruent to negative 5. If we add 6 to it again, that'll give us 1. And so that's now a number between 0 and 5. So that's the remainder we want. So any number we have, we can just add or subtract multiples of our modulus until we get the remainder we're looking for. And that's how we do these calculations, mod, such and such. And this right here also suggests that we can do things like addition, subtraction, multiplication, and division with various moduli. So I want to show you some examples of how we do this. We can talk about modular addition, modular multiplication, by just adding together the integers and then reducing to the remainder. So when you want to do something like 6 plus 11 mod 5, what that means is just take 6 plus 11, which is 17 in the usual integer number system, but then we're going to reduce that down because 17 mod 5 is the same thing as 17 minus 5, which, of course, is 12. 12. Sorry, my pen's acting weird. 12, which you could also subtract 5 from that, and that would reduce it down to be 7, which you could subtract 5 again, that would reduce it down just to be 2. And so that is the remainder we're looking for. 6 plus 11, which is 17, would reduce to 2 mod 5. And modular arithmetic is just integer arithmetic with this additional reduction. We could have actually done it a lot quicker by recognizing that 17 minus 15, 15 is the multiple of 5, is equal to 2. And so that would be our answer right there. 7 plus 13 mod 5, 7 plus 13 is equal to 20. 20 is actually a multiple of 5, and so we see that in this case the remainder would be 0, because we divide by 5, you get just remainder 0. 2 times 5, or 2 times 4 mod 7, multiplication doesn't work out any differently here. 2 times 4 is equal to 8, and now we're trying to subtract multiples of 7 to get a number between 0 and 6. So if you subtract 7, in fact, you're going to get 8 minus 7 is 1. So what we're saying here is that 2 times 4 is the same thing as 1 when you work mod 7. So 2 times 4 is the same as 1 mod 7. We can combine addition and multiplication here. If we were to do the arithmetic here, 4 plus 6, sorry, 5 plus 6 is equal to 11. 2 times 6 is equal to 22. Now we want to start reducing this mod 13. Let's see, it's bigger than 13, 22 is, but it's less than 26, which is 2 times 13. So I'm just going to take 22 minus 13 here, and that's going to end up with just a 9, which will be our result there. So 2 times 5 plus 6 mod 13 is the same thing as 9. And as another example here, if we take 3 times 5, that's going to give us 15 plus 8. Now what we could do is we could add 8 to that and then reduce that by mod 11. But if ever you get a number that's bigger than the modulus in the intermediate calculations, you can reduce that right away. 15 take away 11 would give us 4, 4 plus 8. It's always nicer to use smaller numbers if possible. So 15 plus 8 is the same thing as 4 plus 8 when we work mod 11. 4 plus 8 is 12, which is congruent also to 1 mod 11. And so this gives you some ideas of how we do these calculations with addition and multiplication, right? We can talk about subtraction, right? What does it mean to subtract these things? If you take something like, if you take negative 2 minus 4, be aware that in just usual arithmetic, let's say we're working mod 5 here. In usual arithmetic, 2 minus 4 would be the same thing as negative 2. But how do we get something that's between 0 and 4? We'll just add to it, just add to it a multiple of 5, 5 will be enough here, and then we end up with 3. So 3 is the difference of 2 and 4 when we work mod 5. And division can get a little bit tricky. It really can. When it comes to division, let's say you want to do something like 5 divided by 4 and let's work mod 7. There's kind of two ways you could handle this. One, when you look at 5 divided by 4, that means 5 times the multiplicative inverse of 4, right? So we're looking for a number which when you times by 4 is congruent to 1 mod 7. What's a number which times by 4 to give us a remainder, we want to times 4 by something to get a number 1 bigger than a multiple of 7, right? And you can actually see that 4 inverse here is going to equal 2. The reason for that is that if you take 4 times 2, that's equal to 8 and 8 is congruent to 1. 8 is of course just 7 plus 1. It's bigger than, it's 1 bigger than that. And so when you take something like 5 divided by 4, that just means 5 times 2, which is 10, which would of course reduce down to 3 if you subtract 7 from that. You'll notice that instead of equal signs, I'm typically using like this triple equal sign there. And that's because we're not saying the numbers are equal as integers. We're saying they're congruent as in modular arithmetic here. Now this process of finding the multiplicative identity can be a little bit confusing. There is an algorithm we can use to actually compute the multiplicative reciprocal here, but I don't really want to go down that path right now. And so to kind of avoid some needless guessing and checking, I did want to present another way we could do this modular arithmetic as an alternative approach. What we can do is we can replace the numerator 5 with some number congruent to it, mod 7, until we can divide out the 4. So for example, 5 divided by 4 is the same thing as 5 plus 7 divided by 4, which you'll notice here that 5 plus 7 is equal to 12. Now as an integer 12 is genuinely divisible by 4. In this case, we end up with 4 goes into 12 three times, which would be the answer working mod 7 right here. One more example, because that might have been too quick for us, right? Let's try this again, where we're going to take 17 divided by 3 and we're going to work mod 5. So we could look for the multiplicative inverse of 3, but in this case, we're just going to take 17. And you'll notice 17, we actually could reduce it mod 5, right? 17, because it's not divisible by 3, you could add 5 to it or you could start subtracting 5, right? If you take 17 minus 5, notice what happens there, you end up getting 12, which 12 divided by 3 is equal to 4, which would be the answer. But that's if we went down, right? We could also have gone up. So that's 17 plus 5. In that situation, you're going to end up with 22. 22 is not divisible by 3. But what we could do is we could just add another multiple of 5 to the numerator. That gives you 27 over 3, which 3 does go into 27. That would happen 9 times, which is the answer. But wait, we want a number between 0 and 5. Oh, 9 take away 5 is equal to 4, which gave us the answer before. It doesn't matter which path you take. If we replace numbers with something congruent to it, we will ultimately find the correct answer we want. And so this shows us how we can do arithmetic with modular addition, subtraction, multiplication, division. And it turns out that with these new arithmetic operations, modular arithmetic, we can start solving linear equations and we're going to do that in the next video.