1 00:00:00,710 --> 00:00:03,440 PROFESSOR: So now we're ready to put together the facts 2 00:00:03,440 --> 00:00:05,980 that the gcd is a linear combination 3 00:00:05,980 --> 00:00:08,930 to prove two cool results-- one fun, 4 00:00:08,930 --> 00:00:13,240 and the other important and serious. 5 00:00:13,240 --> 00:00:15,940 Let's begin with the Die Hard example. 6 00:00:15,940 --> 00:00:18,270 So we looked at the Die Hard state machine, 7 00:00:18,270 --> 00:00:21,280 and we figured out the behavior of it 8 00:00:21,280 --> 00:00:25,530 with jugs of size 3 and 5 gallons, 9 00:00:25,530 --> 00:00:28,632 and also with jugs of size 3 and 6 gallons. 10 00:00:28,632 --> 00:00:30,090 Let's look at the general case now. 11 00:00:30,090 --> 00:00:34,710 Suppose that I have jugs of a gallons 12 00:00:34,710 --> 00:00:38,755 and b gallons, where a and b are positive integers. 13 00:00:41,460 --> 00:00:43,400 Now, when we looked at the state machine, 14 00:00:43,400 --> 00:00:46,290 we figured out that under the Die Hard rules, 15 00:00:46,290 --> 00:00:50,080 the number of gallons in each bucket at any stage 16 00:00:50,080 --> 00:00:54,170 is a linear combination of the bucket sizes. 17 00:00:54,170 --> 00:00:58,920 So at any point after any sequence of moves of Die Hard 18 00:00:58,920 --> 00:01:03,635 moves, in each bucket there will be a linear combination of a 19 00:01:03,635 --> 00:01:05,570 and b. 20 00:01:05,570 --> 00:01:08,920 Now, the point is that linear combinations of a and b 21 00:01:08,920 --> 00:01:12,690 are the same as multiples of the gcd. 22 00:01:12,690 --> 00:01:22,160 The reason is that the gcd is a divisor of a and b, of course. 23 00:01:22,160 --> 00:01:23,870 It's a common divisor, and therefore it 24 00:01:23,870 --> 00:01:26,650 divides any linear combination of a and b. 25 00:01:26,650 --> 00:01:31,150 So any linear combination of a and b is a multiple of the gcd, 26 00:01:31,150 --> 00:01:33,540 and the gcd is itself a linear combination. 27 00:01:33,540 --> 00:01:35,670 So linear combinations of a and b 28 00:01:35,670 --> 00:01:38,277 are the same as multiples of gcd. 29 00:01:38,277 --> 00:01:40,110 So that gives us a pretty good understanding 30 00:01:40,110 --> 00:01:44,260 of what the amounts that we can get in the various buckets are. 31 00:01:44,260 --> 00:01:47,430 We can only get multiples of gcd's, but in fact, you 32 00:01:47,430 --> 00:01:52,320 can get any multiple of the gcd of a and b into a bucket, 33 00:01:52,320 --> 00:01:55,534 providing it will fit in the bucket. 34 00:01:55,534 --> 00:01:56,950 That's the same as saying that you 35 00:01:56,950 --> 00:02:02,100 can get any linear combination amount of a and b into a bucket 36 00:02:02,100 --> 00:02:05,140 if there is room for it in the bucket. 37 00:02:05,140 --> 00:02:07,467 So let's see how to do that. 38 00:02:07,467 --> 00:02:09,550 So suppose I have a linear combination of a and b, 39 00:02:09,550 --> 00:02:12,800 sa plus tb, that will fit in bucket 40 00:02:12,800 --> 00:02:15,540 b, meaning it's greater than or equal to 0, 41 00:02:15,540 --> 00:02:17,540 and it's less than b. 42 00:02:17,540 --> 00:02:21,760 So it's a number of gallons that could fit into bucket b. 43 00:02:21,760 --> 00:02:25,150 How do I get that amount into bucket b? 44 00:02:25,150 --> 00:02:28,480 And here's how. 45 00:02:28,480 --> 00:02:30,790 We can assume that s is positive. 46 00:02:30,790 --> 00:02:35,370 We've already seen that we can arrange that to be the case. 47 00:02:35,370 --> 00:02:38,900 And so what we're going to do is repeat the following procedure 48 00:02:38,900 --> 00:02:40,550 s times. 49 00:02:40,550 --> 00:02:45,860 I'm going to fill up bucket a and pour it into bucket b. 50 00:02:45,860 --> 00:02:48,400 Whenever b gets filled up, I'll just 51 00:02:48,400 --> 00:02:53,962 dump it so that it's empty, and I can keep filling up bucket a 52 00:02:53,962 --> 00:02:56,410 and pouring it into bucket b. 53 00:02:56,410 --> 00:02:59,160 And I repeat that s times. 54 00:02:59,160 --> 00:03:01,560 Now, when I do that, the total number 55 00:03:01,560 --> 00:03:06,020 of times that I've filled bucket a is s times. 56 00:03:06,020 --> 00:03:08,150 So the total amount of water that I 57 00:03:08,150 --> 00:03:11,780 have taken from the faucet, or from the fountain, 58 00:03:11,780 --> 00:03:13,880 is s times a. 59 00:03:13,880 --> 00:03:19,910 And I've poured it into b and then dumped 60 00:03:19,910 --> 00:03:23,895 it, leaving only some amount that's in b that's less than b. 61 00:03:23,895 --> 00:03:29,260 So the amount that's left after pouring in sa gallons 62 00:03:29,260 --> 00:03:31,960 and dumping out what won't fit, I'm 63 00:03:31,960 --> 00:03:36,250 left with some amount that's non-negative and less than b 64 00:03:36,250 --> 00:03:38,320 in bucket b. 65 00:03:38,320 --> 00:03:39,400 OK. 66 00:03:39,400 --> 00:03:43,950 Now, the point is that the number of emptyings of bucket b 67 00:03:43,950 --> 00:03:51,610 must be exactly t, which is why the amount of water that's left 68 00:03:51,610 --> 00:03:53,855 in bucket b is sa minus tb. 69 00:03:53,855 --> 00:03:55,480 And the reason why it has to be minus t 70 00:03:55,480 --> 00:04:04,510 is that if I've got sa there, if I had more than t emptyings, 71 00:04:04,510 --> 00:04:06,230 I would have had bucket b go negative. 72 00:04:06,230 --> 00:04:08,140 There just isn't enough room for it. 73 00:04:08,140 --> 00:04:11,920 And if I had fewer than t emptyings, 74 00:04:11,920 --> 00:04:14,560 then the bucket would have an amount larger than b in it. 75 00:04:14,560 --> 00:04:21,930 So the only possible number of emptyings of b is minus t. 76 00:04:21,930 --> 00:04:24,950 Remember, t is negative, so minus t is a positive number. 77 00:04:24,950 --> 00:04:30,310 And that means that I've put in sa and taken out tb, 78 00:04:30,310 --> 00:04:34,540 and I'm left with exactly the linear combination sa minus tb. 79 00:04:38,680 --> 00:04:41,730 So in fact, there's no need to count, 80 00:04:41,730 --> 00:04:48,790 because you don't need to know what s and t are. 81 00:04:48,790 --> 00:04:53,990 Because knowing that you can get any desired amount that's 82 00:04:53,990 --> 00:04:56,800 a multiple of the gcd into bucket b, 83 00:04:56,800 --> 00:04:59,580 you just keep doing this process until you 84 00:04:59,580 --> 00:05:01,470 get the amount that you want. 85 00:05:01,470 --> 00:05:03,090 So you fill bucket a. 86 00:05:03,090 --> 00:05:05,140 You pour it into b. 87 00:05:05,140 --> 00:05:06,330 When b fills, you empty it. 88 00:05:06,330 --> 00:05:11,340 You just keep track of how many gallons there are in bucket b, 89 00:05:11,340 --> 00:05:13,940 and you keep going until you get the amount that you want. 90 00:05:13,940 --> 00:05:16,590 And then you're done.