1 00:00:00,435 --> 00:00:01,810 PROFESSOR: The idea of congruence 2 00:00:01,810 --> 00:00:04,312 was introduced to the world by Gauss 3 00:00:04,312 --> 00:00:07,680 in the early 18th century. 4 00:00:07,680 --> 00:00:10,070 You've heard of him before, I think. 5 00:00:10,070 --> 00:00:14,150 He's responsible for some work on magnetism also. 6 00:00:14,150 --> 00:00:17,180 And it turns out that this idea, after several centuries, 7 00:00:17,180 --> 00:00:21,210 remains an active field of application and research. 8 00:00:21,210 --> 00:00:24,110 And in particular, in computer science 9 00:00:24,110 --> 00:00:27,530 it's used significantly in crypto, 10 00:00:27,530 --> 00:00:32,680 which is what we're going to be leading up to now in this unit. 11 00:00:32,680 --> 00:00:35,410 It's plays a role in hashing, which 12 00:00:35,410 --> 00:00:41,700 is a key method for managing data in memory. 13 00:00:41,700 --> 00:00:44,910 But we are not going to go into that application. 14 00:00:44,910 --> 00:00:47,500 Anyway, the definition of congruence is real simple. 15 00:00:47,500 --> 00:00:52,210 Congruence is a relation between two numbers, a and b. 16 00:00:52,210 --> 00:00:54,700 It's determined by another parameter 17 00:00:54,700 --> 00:00:57,070 n, where n is considered to be greater than one. 18 00:00:57,070 --> 00:00:59,010 All of these, as usual, are integers. 19 00:00:59,010 --> 00:01:00,690 And the definition is simply that a 20 00:01:00,690 --> 00:01:06,220 is congruent to b mod n if n divides a minus b or a minus 21 00:01:06,220 --> 00:01:09,900 b is a multiple of n. 22 00:01:09,900 --> 00:01:12,147 So that's a key definition to remember. 23 00:01:12,147 --> 00:01:13,480 There's other ways to define it. 24 00:01:13,480 --> 00:01:15,879 We'll see very shortly an equivalent formulation 25 00:01:15,879 --> 00:01:18,170 that could equally well have been used as a definition. 26 00:01:18,170 --> 00:01:20,830 But this is a standard one. 27 00:01:20,830 --> 00:01:25,750 A is equivalent to b means that a minus b is a multiple of n. 28 00:01:25,750 --> 00:01:27,420 Well let's just practice. 29 00:01:27,420 --> 00:01:35,320 30 is equivalent to 12 mod 9 because 30 minus 12 is 18, 30 00:01:35,320 --> 00:01:37,750 and 9 divides 18. 31 00:01:37,750 --> 00:01:38,500 OK. 32 00:01:38,500 --> 00:01:40,450 An immediate application is that does 33 00:01:40,450 --> 00:01:43,350 this number with a lot of 6's is ending in a 3 34 00:01:43,350 --> 00:01:49,410 is equivalent to 788253 modulo 10. 35 00:01:49,410 --> 00:01:50,412 Now why is that? 36 00:01:50,412 --> 00:01:51,870 Well, there's a very simple reason. 37 00:01:51,870 --> 00:01:55,260 If you think about subtracting the 6 number ending 38 00:01:55,260 --> 00:01:58,870 in 3 from the 7 number ending in 3, what you can immediately 39 00:01:58,870 --> 00:02:01,370 see without doing much of any of the subtraction-- 40 00:02:01,370 --> 00:02:05,440 just do the low order digits-- when you subtract these, 41 00:02:05,440 --> 00:02:08,100 you're going to get a number that ends in 0. 42 00:02:08,100 --> 00:02:11,260 Which means that it's divisible by 10. 43 00:02:11,260 --> 00:02:15,310 And therefore those two numbers are congruent. 44 00:02:15,310 --> 00:02:17,550 It's very easy to tell when two numbers are congruent 45 00:02:17,550 --> 00:02:21,210 mod 10 because they just have the same lower digit. 46 00:02:21,210 --> 00:02:23,830 OK. 47 00:02:23,830 --> 00:02:26,770 Another way to understand congruency and what it's really 48 00:02:26,770 --> 00:02:29,080 all about is the so-called remainder lemma, 49 00:02:29,080 --> 00:02:32,470 which sets that a is congruent to b mod n, if 50 00:02:32,470 --> 00:02:36,680 and only if a and b have the same remainder on division 51 00:02:36,680 --> 00:02:37,870 by n. 52 00:02:37,870 --> 00:02:39,750 So let's work with that definition. 53 00:02:39,750 --> 00:02:42,530 We can conclude using this formulation, equivalent 54 00:02:42,530 --> 00:02:45,560 formulation, that 30 is equivalent to 12 55 00:02:45,560 --> 00:02:50,640 mod 9 because the remainder of 30 divided by 9, 56 00:02:50,640 --> 00:02:54,490 well it's 3 times 9 is 27, remainder 3. 57 00:02:54,490 --> 00:02:57,330 And the remainder of 12 by 9 is 3. 58 00:02:57,330 --> 00:03:00,010 So they do indeed have the same remainder 3. 59 00:03:00,010 --> 00:03:02,060 And they're congruent. 60 00:03:02,060 --> 00:03:06,770 By the way, this equivalent sign with the three horizontal bars 61 00:03:06,770 --> 00:03:10,070 is read as both equivalent and congruent. 62 00:03:10,070 --> 00:03:13,747 And I will be bouncing back between the two pronunciations 63 00:03:13,747 --> 00:03:14,455 indiscriminately. 64 00:03:14,455 --> 00:03:16,240 They are synonyms. 65 00:03:16,240 --> 00:03:19,820 OK, let's think about proving this remainder lemma just 66 00:03:19,820 --> 00:03:21,380 for practice. 67 00:03:21,380 --> 00:03:23,170 And in order to fit on the slide, 68 00:03:23,170 --> 00:03:27,080 I'm going to have to abbreviate this idea of the remainder of b 69 00:03:27,080 --> 00:03:30,150 divided by n with a shorter notation r sub b n. 70 00:03:30,150 --> 00:03:31,190 Just to fit. 71 00:03:31,190 --> 00:03:32,200 OK. 72 00:03:32,200 --> 00:03:35,290 So the if direction of proving the remainder 73 00:03:35,290 --> 00:03:37,290 limit that they're congruent if and only if they 74 00:03:37,290 --> 00:03:38,440 have the same remainder. 75 00:03:38,440 --> 00:03:41,080 The if direction here in an if and only if 76 00:03:41,080 --> 00:03:44,540 is from right to left. 77 00:03:44,540 --> 00:03:48,051 I've got to prove that if they have the same remainder, then 78 00:03:48,051 --> 00:03:48,800 they're congruent. 79 00:03:48,800 --> 00:03:50,690 So there are the two numbers, a and b. 80 00:03:50,690 --> 00:03:54,270 By the division theorem, or division algorithm, 81 00:03:54,270 --> 00:03:59,010 they can each be expressed as a quotient of a divided by n 82 00:03:59,010 --> 00:04:03,060 times the quotient sub a plus the remainder of a divided 83 00:04:03,060 --> 00:04:03,560 by n. 84 00:04:03,560 --> 00:04:05,780 And likewise, b can be expressed in terms 85 00:04:05,780 --> 00:04:07,750 of quotient and remainder. 86 00:04:07,750 --> 00:04:11,620 And what we're given here is that the remainders are equal. 87 00:04:11,620 --> 00:04:13,660 But if the remainders are equal, then clearly 88 00:04:13,660 --> 00:04:18,950 when I subtract a minus b, I get qa minus qb times n. 89 00:04:18,950 --> 00:04:21,510 Sure enough, a minus b is a multiple of n. 90 00:04:21,510 --> 00:04:23,540 And that takes care of that one. 91 00:04:23,540 --> 00:04:26,560 The only if direction now goes from left to right. 92 00:04:26,560 --> 00:04:29,060 So in the converse, I'm going to assume 93 00:04:29,060 --> 00:04:32,420 that n divides a minus b, where a and b are expressed 94 00:04:32,420 --> 00:04:38,570 in this form by the division algorithm or division theorem. 95 00:04:38,570 --> 00:04:41,630 So if n divides a minus b, looking at a minus b 96 00:04:41,630 --> 00:04:44,510 in that form what we're seeing is that n divides 97 00:04:44,510 --> 00:04:49,590 this qa minus qb times n, plus the difference 98 00:04:49,590 --> 00:04:50,460 of the remainders. 99 00:04:50,460 --> 00:04:53,660 That's what I get just by subtracting a and b. 100 00:04:53,660 --> 00:04:57,640 But if you look at this n divides that term, 101 00:04:57,640 --> 00:05:01,110 the quotient times n. 102 00:05:01,110 --> 00:05:06,240 And it therefore has to divide the other term as well. 103 00:05:06,240 --> 00:05:07,920 Because the only way that n can divide 104 00:05:07,920 --> 00:05:10,280 a sum, when it divides one of the sum ands, 105 00:05:10,280 --> 00:05:12,360 is if it divides the other sum and. 106 00:05:12,360 --> 00:05:17,880 So n divides ra minus the remainder of 8 divided by n 107 00:05:17,880 --> 00:05:19,010 from b divided by n. 108 00:05:19,010 --> 00:05:20,840 But remember, these are remainders. 109 00:05:20,840 --> 00:05:24,200 So that means that they're both in the interval from 0 110 00:05:24,200 --> 00:05:26,150 to n minus 1 inclusive. 111 00:05:26,150 --> 00:05:29,820 And the distance between them has got to be less than 1. 112 00:05:29,820 --> 00:05:36,760 So if n divides a number that's between 0 and n minus 1, 113 00:05:36,760 --> 00:05:38,272 that number has to be 0. 114 00:05:38,272 --> 00:05:40,480 Because it's the only number that n divides in there. 115 00:05:40,480 --> 00:05:44,160 So in fact, the difference of the remainders is 0. 116 00:05:44,160 --> 00:05:46,330 And therefore, the remainders are equal. 117 00:05:46,330 --> 00:05:49,680 And we've knocked that one off. 118 00:05:49,680 --> 00:05:52,180 So there it is restated. 119 00:05:52,180 --> 00:05:56,090 The remainder lemma says that they're congruent if 120 00:05:56,090 --> 00:05:58,200 and only if they have the same remainders. 121 00:05:58,200 --> 00:06:00,900 And that's worth putting a box around 122 00:06:00,900 --> 00:06:03,140 to highlight this crucial fact, which 123 00:06:03,140 --> 00:06:06,560 could equally well have used as the definition of congruence. 124 00:06:06,560 --> 00:06:08,560 And then you'd prove the division definition 125 00:06:08,560 --> 00:06:10,560 that we began with. 126 00:06:10,560 --> 00:06:14,920 Now some immediate consequences of this remainder lemma 127 00:06:14,920 --> 00:06:19,770 are that a congruence inherits a lot of properties of equality. 128 00:06:19,770 --> 00:06:21,520 Because it means nothing more than that 129 00:06:21,520 --> 00:06:22,970 the remainders are equal. 130 00:06:22,970 --> 00:06:26,650 So for example, we can say the congruence is symmetric, 131 00:06:26,650 --> 00:06:30,110 meaning that if a is congruent to b, then b is congruent to a. 132 00:06:30,110 --> 00:06:31,870 And that's obvious cause a congruent to b 133 00:06:31,870 --> 00:06:33,940 means that a and b have the same remainder. 134 00:06:33,940 --> 00:06:37,590 So b and a have the same remainder. 135 00:06:37,590 --> 00:06:39,710 One that would actually take a little bit of work 136 00:06:39,710 --> 00:06:41,350 to prove from the division definition-- 137 00:06:41,350 --> 00:06:43,340 not a lot, but a little bit-- would 138 00:06:43,340 --> 00:06:47,300 be that if a is congruent to b, and b is congruent to c, then a 139 00:06:47,300 --> 00:06:48,820 is congruent to c. 140 00:06:48,820 --> 00:06:52,339 But we can read it is saying the first says that a and b have 141 00:06:52,339 --> 00:06:53,130 the same remainder. 142 00:06:53,130 --> 00:06:55,338 The second says that b and c have the same remainder. 143 00:06:55,338 --> 00:06:57,940 So obviously a and c have the same remainder. 144 00:06:57,940 --> 00:07:00,010 And we've prove this property that's known 145 00:07:00,010 --> 00:07:02,420 as transitivity of congruence. 146 00:07:05,090 --> 00:07:07,890 Another simple consequence of the remainder theorem 147 00:07:07,890 --> 00:07:09,940 is a little technical result that's 148 00:07:09,940 --> 00:07:12,580 enormously useful called remainder lemma, which 149 00:07:12,580 --> 00:07:16,580 says simply that a number is congruent to its own remainder, 150 00:07:16,580 --> 00:07:19,070 modulo n. 151 00:07:19,070 --> 00:07:22,150 The proof is easy. 152 00:07:22,150 --> 00:07:25,040 Let's prove it by showing that a and the remainder of a 153 00:07:25,040 --> 00:07:26,930 have the same remainder. 154 00:07:26,930 --> 00:07:29,780 Well, what if I take remainders of both sides, 155 00:07:29,780 --> 00:07:32,830 the left hand side becomes the remainder of a divided by n. 156 00:07:32,830 --> 00:07:35,870 The right hand side is the remainder of the remainder. 157 00:07:35,870 --> 00:07:37,670 But the point is that the remainder 158 00:07:37,670 --> 00:07:40,760 is in the interval from 0 to n. 159 00:07:40,760 --> 00:07:44,510 And that means when you take its remainder mod and its itself. 160 00:07:44,510 --> 00:07:47,830 And therefore the left hand side is the remainder 161 00:07:47,830 --> 00:07:49,580 of a divided by n, and the right hand side 162 00:07:49,580 --> 00:07:51,950 is also the remainder of the a divided by n. 163 00:07:51,950 --> 00:07:56,550 And we have proved this corollary 164 00:07:56,550 --> 00:07:58,750 that's the basis of remainder arithmetic. 165 00:07:58,750 --> 00:08:00,430 Which will basically allow us whenever 166 00:08:00,430 --> 00:08:03,880 we feel like it to replace numbers by their remainders, 167 00:08:03,880 --> 00:08:05,420 and that way keep the numbers small. 168 00:08:07,990 --> 00:08:11,230 And that also merits a highlight. 169 00:08:11,230 --> 00:08:11,780 OK. 170 00:08:11,780 --> 00:08:16,450 Now, in addition to these properties like equality 171 00:08:16,450 --> 00:08:19,640 that congruence has, it also interacts very well 172 00:08:19,640 --> 00:08:20,770 the operations. 173 00:08:20,770 --> 00:08:22,570 Which is why it's called a congruence. 174 00:08:22,570 --> 00:08:25,960 A congruence is an equality-like relation 175 00:08:25,960 --> 00:08:28,350 that respects the operations that 176 00:08:28,350 --> 00:08:29,929 are relevant to the discussion. 177 00:08:29,929 --> 00:08:32,470 In this case, we're going to be talking about plus and times. 178 00:08:32,470 --> 00:08:34,929 And the first fact about congruent 179 00:08:34,929 --> 00:08:37,460 says that if a and b are congruent, 180 00:08:37,460 --> 00:08:41,230 then a plus c and b plus c are congruent. 181 00:08:41,230 --> 00:08:44,070 The proof of that follows trivially from the definition. 182 00:08:44,070 --> 00:08:46,390 Because the a congruent to b mod, 183 00:08:46,390 --> 00:08:48,360 n says that n divides a minus b. 184 00:08:48,360 --> 00:08:51,790 And if n divides a minus b, obviously n divides a plus 185 00:08:51,790 --> 00:08:53,170 c minus b plus c. 186 00:08:53,170 --> 00:08:56,870 Because a plus c minus b plus c is equal to a minus b. 187 00:08:56,870 --> 00:08:58,760 That one is deceptively trivial. 188 00:09:02,370 --> 00:09:05,710 It's also the case that if a is congruent to b, then a times 189 00:09:05,710 --> 00:09:08,480 c is congruent to b times c. 190 00:09:08,480 --> 00:09:11,730 This one takes a one line proof. 191 00:09:11,730 --> 00:09:15,180 We're given that n divides a minus b. 192 00:09:15,180 --> 00:09:18,030 That certainly implies that n divides 193 00:09:18,030 --> 00:09:19,910 any multiple of a minus b. 194 00:09:19,910 --> 00:09:22,700 So multiply it by c and then apply distributivity, 195 00:09:22,700 --> 00:09:26,100 and you discover that n divides ac 196 00:09:26,100 --> 00:09:32,980 minus bc, which means ac is congruent to bc modulo n. 197 00:09:32,980 --> 00:09:35,060 It's a small step that I'm going to omit 198 00:09:35,060 --> 00:09:36,830 to go from adding the same constant 199 00:09:36,830 --> 00:09:38,960 to both sides to adding any two congruent 200 00:09:38,960 --> 00:09:40,580 numbers to the same sides. 201 00:09:40,580 --> 00:09:44,200 So if a is congruent to b and c is congruent to d, then 202 00:09:44,200 --> 00:09:48,350 in fact, a plus c is congruent to b plus d. 203 00:09:48,350 --> 00:09:52,050 So again, congruence is acting a lot like ordinary equality. 204 00:09:52,050 --> 00:09:55,560 If you add equals to equals, you get equals. 205 00:09:55,560 --> 00:09:58,940 And of course the same fact applies to multiplication. 206 00:09:58,940 --> 00:10:04,270 If you multiply equals by equals, you get equals. 207 00:10:04,270 --> 00:10:08,660 A corollary of this is that if I have two numbers that 208 00:10:08,660 --> 00:10:12,540 are congruent modulo n, then if I have any kind of arithmetic 209 00:10:12,540 --> 00:10:15,690 formula involving plus and times and minus-- 210 00:10:15,690 --> 00:10:19,130 and what I want to know is what it's equivalent to modulo n-- 211 00:10:19,130 --> 00:10:22,390 I can figure that out freely substituting 212 00:10:22,390 --> 00:10:24,490 a by a prime or a prime by a. 213 00:10:24,490 --> 00:10:27,650 I can replace any number by a number that it's congruent to, 214 00:10:27,650 --> 00:10:32,660 and the final congruence result of the formula 215 00:10:32,660 --> 00:10:35,130 is going to remain unchanged. 216 00:10:35,130 --> 00:10:39,950 So overall what this shows is that arithmetic modulo n is 217 00:10:39,950 --> 00:10:43,080 a lot like ordinary arithmetic. 218 00:10:43,080 --> 00:10:45,170 And the other crucial point thought 219 00:10:45,170 --> 00:10:47,780 that follows from this fact about remainders 220 00:10:47,780 --> 00:10:54,340 is that because a is congruent to the remainder of a divided 221 00:10:54,340 --> 00:10:59,040 by n, then when I'm doing arithmetic on congruences, 222 00:10:59,040 --> 00:11:02,970 I can always keep the numbers involved in the remainder 223 00:11:02,970 --> 00:11:03,490 interval. 224 00:11:03,490 --> 00:11:07,590 That is, in the remainder range from 0 to n minus 1. 225 00:11:07,590 --> 00:11:13,930 And we use this standard closed open interval notation to mean 226 00:11:13,930 --> 00:11:15,380 the interval from 0 to n. 227 00:11:15,380 --> 00:11:18,830 So it's sometimes used in analysis 228 00:11:18,830 --> 00:11:20,404 to mean the real interval of reals. 229 00:11:20,404 --> 00:11:22,070 But we're always talking about integers. 230 00:11:22,070 --> 00:11:24,500 So this means-- the integers that square bracket 231 00:11:24,500 --> 00:11:25,940 means 0 is included. 232 00:11:25,940 --> 00:11:29,710 And a round parenthesis means that n is excluded. 233 00:11:29,710 --> 00:11:33,840 So that's exactly a description of the integers that 234 00:11:33,840 --> 00:11:38,920 are greater and equal to 0 and less than n. 235 00:11:38,920 --> 00:11:42,950 Let's do an application of this remainder arithmetic idea. 236 00:11:42,950 --> 00:11:48,530 Suppose I want to figure out what's 287 to the ninth power 237 00:11:48,530 --> 00:11:50,780 modulo 4? 238 00:11:50,780 --> 00:11:56,430 Well, for a start but if I take the remainder of 287 239 00:11:56,430 --> 00:12:00,970 divided by 4, it's not very hard to check that that's 3. 240 00:12:00,970 --> 00:12:06,849 And that means that 287 to the ninth is congruent mod 4 to 3 241 00:12:06,849 --> 00:12:07,390 to the ninth. 242 00:12:07,390 --> 00:12:09,380 So already I got rid of the three digit number, 243 00:12:09,380 --> 00:12:11,550 the base of the exponent, and replaced it 244 00:12:11,550 --> 00:12:13,920 just by a one digit number, 3. 245 00:12:13,920 --> 00:12:15,310 That's progress. 246 00:12:15,310 --> 00:12:17,660 Well, we can make more progress because 3 to the ninth 247 00:12:17,660 --> 00:12:21,861 can be expressed as 3 squared, squared, squared times 3, 248 00:12:21,861 --> 00:12:22,360 right? 249 00:12:22,360 --> 00:12:25,870 Because when you iterate taking powers, 250 00:12:25,870 --> 00:12:27,490 it means that the exponents multiply. 251 00:12:27,490 --> 00:12:31,280 So this is 3 to the 2 times 2 times 2, or 8, times 3-- 252 00:12:31,280 --> 00:12:33,580 which adds 1 to the exponent-- or 9. 253 00:12:33,580 --> 00:12:36,630 So that's simple exponent arithmetic. 254 00:12:36,630 --> 00:12:43,310 But notice that 3 squared is 9. 255 00:12:43,310 --> 00:12:46,090 And 9 is congruent to 1 mod 4. 256 00:12:46,090 --> 00:12:50,400 So that means I can replace 3 squared by 1, 257 00:12:50,400 --> 00:12:53,510 and the outer 2 squared stays. 258 00:12:53,510 --> 00:12:57,740 It becomes 1 squared squared, but that's 1 times 3. 259 00:12:57,740 --> 00:13:03,300 And the punchline is that 287 to the ninth is congruent to 3 mod 260 00:13:03,300 --> 00:13:09,880 4 by a really easy calculation that did not involve taking 261 00:13:09,880 --> 00:13:12,460 anything to the ninth power.