 Welcome back to the first of two screencasts where we're going to look at some applications of modular arithmetic. The first is to put a proof on an old divisibility trick that you might have learned when you're in elementary or middle school. Let me phrase what that divisibility trick actually says. It says that if n is an integer such that the sum of its digits is divisible by 3, then the number n itself is divisible by 3. If you've never heard this trick before, it's pretty cool. Let me show you how it works here. So for example, look at the number 387, and we might be interested in knowing whether or not that number is divisible by 3 without using a calculator. Well, if I look at the digits of 387, that's the 3, the 8, and the 7, and add them up. I get 3 plus 8 plus 7, that equals 18. And since 3 divides 18, 3 divides 18, it will imply if this trick works that 3 divides 387. And indeed, you can check that 387 divided by 3 is 129. On the other hand, look at 5,221, and let's add up its digits. That would be 5 plus 2 plus 2 plus 1, and that comes out to equal 10. And 3 does not divide 10. And you can check too that 3 does not divide 5,221. It goes in 1740 times, but has a remainder of 1. So this is actually really an if and only if theorem here. We're going to treat it only in one direction. So if a number's digit sum is divisible by 3, then the number itself is divisible by 3. It's kind of a cool trick, but I bet you've never seen why it actually works. And that's what we're going to do in this video here is prove it. We're going to prove this as a theorem. And modular arithmetic, the O plus and O times operations that we defined in the last video, played the central role in this. Before we jump into a proof, we need to be clear about what exactly do we mean by what is a digit? Well, you can point to a number and tell me what its digits are. If you look at 1,982, the digits are 1,982. The way we're going to have to think about this in our proof here is to think of 1,982 in its base 10 decimal expansion. Now, what I mean by that is every integer that you see can be written as a sum of powers of 10 multiplied by numbers between 0 and 9. For example, 1,982 is 1 times 1,000 plus 9 times 100. This is 1,000, that's 900. 8 plus 8 times 10 that picks up the 80 and then the 2. You have the 1's digit, the 10's digit, the 100's digits, and the 1,000's digit. And we all know what those digits are. You learn that in the second or third grade, how to identify the 1's, 10's, 100's, and so on digit. But you might not realize that every integer can be expanded in this sort of way here. And just as an additional example, if I look at the number 25,173, that can be written as 2 times 10,000 plus 5 times 1,000 plus 1 times 100 plus 7 times 10 plus 3. So every number can be sort of stretched apart into digits, numbers between 0 and 9 times powers of 10. And that's going to be an essential portion of the proof that we're going to look at here in just a moment. Well, actually we're going to look at it right now. Let's just jump right into it. We're going to simplify the proof of this theorem, this divisibility trick, by only looking at four-digit numbers here. It's going to be very easy if you understand this proof to give a generic proof for any number of digits that you want. I think it's going to simplify things a little if we just restrict into four digits. Okay, so here's the proof. So we're going to let n be a four-digit integer, and we're going to assume that the sum of its digits is divisible by 3. So just as we saw with 1982 on the previous line, if n has four digits, I can write it as some number between 0 and 9 times 1,000. And that d3 is the thousandth place digit in the number, like the 1 was in 1982, plus d2 times 100. The d2 would be the 100's digit, that would be the 9 and 982, plus d1 times 10, that's the 10's place, that was the 8 in 1982, plus d0, the 1's digit, that was the 2 in 1982. We're going to label those digits d0, d1, d2, d3. So when we say that the number n has a digit sum that's divisible by 3, well its digit sum is just d3 plus d2 plus d1 plus d0. So what we're doing is we're assuming that this sum here is divisible by 3. So that sets up the assumptions here. Now what we want to prove, of course, is that 3 divides the big number itself. Now we're going to do this in kind of a special way here. We're going to do this by showing that n is congruent to 0 mod 3. Okay? Now that is equivalent to saying that 3 divides n. To say that n is congruent to 0 mod 3 means that 3 divides n minus 0, that is 3 divides n. But we're actually going to do something related but a little bit different. If n is congruent to 0 mod 3, then nz3, the set of congruence classes 0, 1, and 2 under the relation of congruence mod 3, I would like to show that nz3, the class of n equals the class of 0. Now remember, based on our theorems we've seen so far, that if tilde is congruence mod 3, okay, then these two classes will be equal if and only if n is congruent to 0 under this relation, which means these two are equal if and only if n is congruent to 0 mod 3, which is true if and only if 3 divides n. So we're using kind of a strange, somewhat convoluted way of saying 3 divides n by just noting that it's the same thing, logically equivalent, as saying that their equivalence classes in z3 are equal to each other. This is a kind of a, seems like a long way around, but it actually makes the proof really, really simple. So what we're going to do here is prove that the class of n and the class of 0 in the set z mod 3, the integers mod 3, are equal classes, and that will imply that 3 divides n. So the reason this is going to work is because we know that n can be written in a nice form like this, and switch back to my pen. Okay, so I have two equal integers, okay, I have n on this side and some alternate representation of n on the other side, but the important thing to notice is that they are equal to each other. So if I have two equal things and move to their classes, then the class of n will be equal as a set to the class of all this stuff on the right, the class of d3 times 1000 plus d2 times 100. I'm just putting an equivalence class around both sides of this equation. I can do anything I want to both sides of an equation, I will still get equal things. But now I went from equal integers to equal sets. Okay, well let's just look at the right hand side and see what we can do with it. Let me change colors so we're going to change our perspective here in just a second. Notice I have a lot of additions going on in here. Now remember what we're doing here is we're adding objects inside an equivalence class. Well, this is the same thing as using our O plus operation. This is the same thing as d3 times 1000, O plus the class d2 times 100, O plus the d1 times 10, O plus the class of d0. Remember this O plus operation is defined by when I'm adding O plus adding two classes together, I am regular adding their representatives together. This is exactly what we're doing, just kind of doing it in reverse. If I have the class of a bunch of things regular added together, I can split them up into an O plus sum of the individual classes. And you notice I can do the same thing too for the times here. In this first class here for example, I have the class of one thing times another, but that's the same thing, let me change my color again, to the class of d3, O times the class of 1000. So these two guys right here, this single class of a regular multiplication is equal to this new multiplication of two different classes. And I'm just going to write that through the rest of this expression, or I'll need to change a line here. So that's the first class, O plus, here's the second class, that would be the class of d2, O times the class of 100, O plus the class of d1, O times the class of 10, plus finally I have the class of d0. Okay, so there's using my definitions of O plus addition and O plus multiplication. And I'm going to make one extra step here, I'm actually just going to write on this green line here to show you something very interesting. Let's look at three of these classes here, or just classes of numbers, okay, the class of 1000, the class of 100, the class of 10. And remember the equivalence class here is a mod 3, we're all dealing with z3. So look at the class of 10. Now notice that the class of 10 and z3 is going to be equal to the class of 1 in z3 because 10 and 1 are equivalent, they are congruent to each other mod 3. So this class of 10 is really just the class of 1. Let me just mark that out. But you know what, so is the class of 100 for that matter. That's the class of 1 as well because 100 and 1 are congruent to each other mod 3. 100 minus 1 is 99, and that's divisible by 3. So that class there is 1 as well, and so is the class of 1000, and that's the class of 1 as well. So those three numerical classes I have here are just reduced down to the class of 1. Now I want you to think back to the last video where we were discussing multiplying O plus multiplying, or is there O times multiplying by 1. We said that, I'll just do this up here, anytime I have A0 or O times 1, that's the class of A regular times 1, and that's the class of A. So whenever I'm multiplying in this new sense by the class of 1, I'm just going to get the thing I multiplied back. And so this is going to really reduce very nicely here. D3, the class of D3, O times the class of 1 is just the class of D3. And then I am O plusing that with D2, O times the class of 1, and that's just D2. And I'm O plusing that with the class of D1, O times the class of 1, and that's the class of D1. And then the last thing in the string of sums here was D0. So here's where we are in the proof at this point. I now have the class of n is equal to the O plus sum of four different equivalence classes here. What we're going to do now is just use the definition of O plus to pull these classes together. Look at these two right here, the D3 and D2 classes. D3, the class of D3, O plus the class of D2, well that is simply the class of D3 regular plus D2. And likewise, if I keep adding these things in, that, if I O plus that with D1, that will just be the class of the regular sum with D1 and likewise with D0. So I can use the definition of O plus to pull all four of those classes into one. Now, so I have now that the class of n is equal to the class of this, but what is this? This is the digit sum of n, and what did we assume about the digit sum of n? Is that that's divisible by three, okay? So this thing on the inside of the brackets is divisible by three, okay? So what is this class really? This is an equivalence class under the relation of congruence mod three. So what this ultimately equals here, this class is the same thing as the class of zero, okay? Because two classes are equal if and only if they are equivalent to each other, mod three. And that's the case here. The stuff I just underlined in the blue is divisible by three. So that's like the equivalence class of six. It's the same thing as the class of zero. And I have ultimately now proven what I set out to prove. Remember I said I wanted to show way back that three divides n. I was going to do that by showing that the class of n is equal to zero, and I did. So that's it. Cha-ching, we're done with the proof. So that is the proof that the divisibility trick you learned for three actually works. And it's very simple to extend this again to any number of digits you wish. You're just going to have larger and larger powers of ten. And the thing to notice here that what will make it eventually work, and you can prove this separately, is that ten to the nth power is always congruent to one mod three, and that's what would make the general proof work. So now we have proven that this divisibility trick works. Isn't that cool?