 Welcome back to another screencast that has to do with the integers mod n. In this video, we're going to do something a little unusual to this set we defined in the last video. So first, let's review. So we defined the integers mod n to be the set defined as follows. Take a natural number n bigger than one and look at the equivalence relation on the set of all integers given by congruence mod n. We saw last time that this creates n distinct equivalence classes, namely the classes of 0, 1, 2, and so on up to the class of n minus 1. The class of n is the same set as the class of 0 because n is congruent to 0 mod n. The class of n plus 1 is the same as the class of 1 and so forth. So there are only n classes in z mod n. I want to point out one thing that's important but subtle. We call this set the integers mod n, but that's really kind of a misnomer because this set does not contain integers. The square bracket things here inside z mod n are not integers but sets. These integers mod n sets consist of equivalence classes which are sets. So that's important to point out because what we're going to do now is invent something. We're going to invent a brand new kind of addition and multiplication that works on these equivalence classes. We're going to define a way of adding and multiplying two equivalence classes together in a way that lends itself to some interesting applications. Before we do this, I just want to assure you that it is totally normal to use the words addition and multiplication for things that are not just regular numbers. We've been doing this since middle school with two different kinds of objects, polynomials and matrices. Polynomials are in numbers but we have no problem adding them or multiplying them. We just have to define what we mean back in middle school. You may not remember doing that but somewhere in the past you had to define addition and multiplication on polynomials. And in high school algebra 2 or in linear algebra when you looked at matrices, these aren't numbers either although they have numbers inside them. But we can certainly add them and we can define a special kind of multiplication that works on them. So to repeat, it's totally normal to adapt the basic concepts of number addition and number multiplication to define new kinds of addition and multiplication on objects that aren't numbers. And that's what we're going to do now using the equivalence classes in the integers mod n. Actually, we're going to restrict our attention to z3 only at first and then we'll generalize to any z mod n. So here's z3 which consists of these three equivalence classes, the class of 0, the class of 1, and the class of 2. Let's first think about how we'll add two elements of z mod n together. We are creating a new kind of addition here because we've never added sets before. We've talked about unions and intersections and Sotheborth but never adding two sets together. So we can define this however we want but here's one approach that makes sense. Let's look at the three elements of z3 and define a new kind of addition which we're going to denote with an O plus here to distinguish it from regular number addition like this. Let's define the class of A plus or O plus, the class of B to be equal to another equivalence class and that equivalence class is the class of A plus B where the plus here is regular integer addition. So in other words, let's define the sum of two equivalence classes to be the equivalence class of the regular sum of the representatives. So for example, 0, O plus 1, I'm adding the class of 0 together to the class of 1. That would be the class of 0, regular plus 1 and that would be the class of 1. The class of 1, O plus the class of 1 would be the class of 1, regular plus 1, that's the class of 2. So I'm adding two equivalence classes together and getting another equivalence class and that's good. Notice this here, the class of 1, O plus the class of 2 would be the class of 1 plus 2 and that's the class of 3. But since we're dealing with congruence mod 3, this is the same class as the class of 0 as we've discussed earlier. So notice in this operation we have two kinds of addition going on here. The O plus addition is addition of equivalence classes and the regular plus addition is addition of integers. So here's a little practice for you, not exactly a concept check, but here are some remaining O plus addition problems to work out. Work these out as you pause the video, write down your answers, and then we'll debrief. So let's work through the answers here. The first sum is the class of 0 plus 0, where 0 is regular addition. So we end with a class of 0. The second sum is the class of 1 regular plus 0 and that gives the class of 1. Watch these next two though. 2 O plus 1 is technically the class of 2 regular plus 1 and that's the class of 3. This is correct, but it's not complete because the class of 3 equals the class of 0. So let's reduce this down to one of the classes that's actually in Z3. Finally, the class of 2 O plus the class of 2 is the class of 2 regular plus 2. That would be the class of 4. But this is the same class as the class of 1 because 1 is congruent to 4 under the relation here. It's congruent to 4 mod 3. So notice something super important here. The O plus sum of any two of these classes in Z3 can be expressed as another element of Z3. That means that Z3, the set of equivalence classes under congruence mod 3 is closed under this operation. Just like the regular integers are closed under regular addition. In fact, since there are only three elements in Z3, it actually wouldn't be much work to do all possible addition problems. And here they are arranged in a table form. The way to read this table, for example, is say in the entry in the third row, second column, that is what you would get when you compute 2 O plus 1. Notice that since regular plus addition is commutative, that is we can add integers in any order we want, it follows that O plus addition is commutative 2. And so 2 O plus 1 equals 1 O plus 2. This system of addition works for any Zn, for any natural number n, not just Z3. For example, we can define O plus addition and Z4 the same way. The class of A plus the class of B will be the class of A plus B. And here the relation is congruence mod 4 since we're working with Z4. And let's fill in the addition table for Z4, which I have here just as a blank table. Notice that 0 O plus A is the class of 0 plus A, where the addition here is regular integer addition. And that's going to equal the class of A for every A in the set. So the first row and column are really easy to fill in. Let me do that very quickly here. As for the class of 1, let's do the second row. The class of 1 O plus the class of 1 is the class of 1 regular plus 1, and that's equal to the class of 2. 1 O plus 2 is 3. And 1 O plus 3 should be equal to the class of 4, and that's correct. But that class is equal to the class of 0, because 0 and 4 are equivalent or congruent mod 4. We argued earlier that this operation is commutative, so I can fill in the column for 1 with the same results as the row for 1. As a concept check, pause the video right here and fill in the remaining cells and come back when you're done. And here they are. Remember, we are just adding the interiors of the square brackets using regular integer addition, and then reducing to the equivalence class that actually belongs to Z4. So we can also do this with multiplication. Let's go back to Z3 again and define multiplication on these equivalence classes by defining the product, which will designate with an O dot of two classes to be the class of the regular product of the insides. So for example, the class of 1 O dot to the class of 2 is the class of 1 times 2, and that would of course be the class of 2. The class of 2 O dot to the class of 2 would be the class of 2 regular times 2, which is the class of 4. But that reduces to the class of 1 because now we're back to congruence mod 3 as my equivalence relation. We can make a multiplication table for Z3 in this way, and it looks like this. Multiplication of classes will be commutative, just like addition of classes was commutative, and for the same reason, the O dot product is defined in terms of regular integer multiplication, which is commutative. The system of addition and multiplication of equivalence classes mod n is referred to as modular arithmetic. It's different than regular arithmetic, although it's based on regular arithmetic, and it is hugely important and useful as a variation of regular integer arithmetic. It has lots of applications, some of which we'll see in a few videos. So let's make a multiplication for Z4, 2. About half of this table is trivial to make. The row and column for 0 will be entirely filled with the class of 0, because for example, 0 O dot 2 would be the class of 0 regular times 2, which is the class of 0. So we can fill these in quickly. The row and column for the class of 1 are easy too, because for example, 1 O dot 2 would be the class of 1 times 2, and that is the class of 2. So the class of 1 acts in much the same way in modular arithmetic as the integer 1 does under regular integer arithmetic. When you multiply something by the class of 1, you get that something back, just like when you multiply an integer times 1. As for the rest, let's have you fill this in as a concept check and come back when you're ready. So now let's complete the table. 2 O dot 2 is the class of 2 times 2, which is the class of 4. But under congruence mod 4, this is the same thing as the class of 0. Now this is kind of interesting here. We have two non-zero elements in Z4, and we multiply them together to get 0. Now this is a lot different from the way regular multiplication works in integers or real numbers. In regular multiplication, if you have a product of two things, and that product equals 0, then one of the two terms in the product must equal 0. But in modular arithmetic, this is obviously, apparently not necessarily true. Two things can sometimes multiply together to be 0, but neither of the terms is equal to 0. So this is quite a different algebraic world that we're creating here. Now to fill in the rest of the table here, just notice that 2 O dot 3 is the class of 2 times 3, which is the class of 6, and that equals the class of 2 because we're dealing with congruence mod 4. And 3 O dot 3 is the class of 9, which equals the class of 1, because 9 and 1 are congruent to each other mod 4, so they have the same equivalence class. And we can see that Z4, with this addition of multiplication operations, is also closed under those operations. So what we're going to do now in the next two videos is show how modular arithmetic can be used. The next video proves an old divisibility trick that you might have learned in elementary school, and the one after that shows how modular arithmetic can be used to encrypt a message you want to send. So stay tuned.