1 00:00:00,699 --> 00:00:02,490 PROFESSOR: The final general counting rules 2 00:00:02,490 --> 00:00:04,960 that we'll examine is called inclusion-exclusion, 3 00:00:04,960 --> 00:00:09,870 and it is a straightforward generalization of the sum 4 00:00:09,870 --> 00:00:12,660 rule-- at least in the simple case of two sets 5 00:00:12,660 --> 00:00:14,310 that we'll look at first. 6 00:00:14,310 --> 00:00:18,290 So we're going to look at 6042 example of applying 7 00:00:18,290 --> 00:00:21,830 inclusion-exclusion, but let's begin by stating what it is. 8 00:00:21,830 --> 00:00:24,060 So the sum of the rule says that if you have two 9 00:00:24,060 --> 00:00:28,840 sets A and B that are disjoint-- no overlap between A and B-- 10 00:00:28,840 --> 00:00:32,420 then the size of A union B is equal to the size of A 11 00:00:32,420 --> 00:00:34,670 plus the size of the B. Well that's obvious. 12 00:00:34,670 --> 00:00:37,690 We took that as kind of basic axiom. 13 00:00:37,690 --> 00:00:39,710 But what if they're not disjoint? 14 00:00:39,710 --> 00:00:42,020 Suppose that A and B overlap, and there's 15 00:00:42,020 --> 00:00:45,960 some stuff in here that's the intersection of A and B 16 00:00:45,960 --> 00:00:48,810 where there are points in common, what then 17 00:00:48,810 --> 00:00:53,040 is the size of A union B in terms of simpler things 18 00:00:53,040 --> 00:00:55,960 that we can count? 19 00:00:55,960 --> 00:01:01,470 And the answer is that the size of A union B is the size of A 20 00:01:01,470 --> 00:01:07,520 plus the size of B minus the size of A intersection B. 21 00:01:07,520 --> 00:01:10,260 Now, the intuitive reason for that-- and it's not really 22 00:01:10,260 --> 00:01:12,690 very hard to make a precise argument-- 23 00:01:12,690 --> 00:01:16,530 is that when you're adding up the elements in A, 24 00:01:16,530 --> 00:01:19,960 you're counting all the elements of the intersection once. 25 00:01:19,960 --> 00:01:24,390 And then when you add in the elements in B here-- A plus B-- 26 00:01:24,390 --> 00:01:26,990 you're counting all the elements in the intersection 27 00:01:26,990 --> 00:01:27,930 a second time. 28 00:01:27,930 --> 00:01:30,260 The ones that are in A minus B get counted once. 29 00:01:30,260 --> 00:01:32,820 The ones that are in B minus A get counted once, 30 00:01:32,820 --> 00:01:34,930 but the ones that are in A intersection B 31 00:01:34,930 --> 00:01:36,950 get counted twice. 32 00:01:36,950 --> 00:01:38,910 So to get the right count, I have 33 00:01:38,910 --> 00:01:42,300 to subtract the size of A minus B 34 00:01:42,300 --> 00:01:47,350 so it's only counted once in the total formula, 35 00:01:47,350 --> 00:01:50,320 and that's an intuitive explanation of why 36 00:01:50,320 --> 00:01:54,880 inclusion-exclusion formula holds for two sets. 37 00:01:54,880 --> 00:01:56,880 Let's apply it. 38 00:01:56,880 --> 00:01:59,770 And I'm going to look at an example 39 00:01:59,770 --> 00:02:01,802 where we're looking at digit permutations, 40 00:02:01,802 --> 00:02:03,760 and I'm going to look at permutations of the 10 41 00:02:03,760 --> 00:02:06,180 digits, 0 through 9 inclusive. 42 00:02:06,180 --> 00:02:08,639 There's a standard one where they're listed in order, 43 00:02:08,639 --> 00:02:12,550 and there is just a random seeming permutation 44 00:02:12,550 --> 00:02:15,670 of the digits 0 through 9. 45 00:02:15,670 --> 00:02:19,800 Notice that the 1 and 3-- the 2 is sort of out of order. 46 00:02:19,800 --> 00:02:21,940 The rest are in order. 47 00:02:21,940 --> 00:02:23,610 Now, what I'm going to be interested in 48 00:02:23,610 --> 00:02:28,464 is those permutations where certain patterns appear. 49 00:02:28,464 --> 00:02:30,380 So first of all, let's note it that the number 50 00:02:30,380 --> 00:02:33,360 of permutations we know how to count-- it's 10 factorial. 51 00:02:33,360 --> 00:02:35,790 I'm interested in how many permutations 52 00:02:35,790 --> 00:02:41,080 have a consecutive 6 and 0, a consecutive 0 and 4, 53 00:02:41,080 --> 00:02:43,210 or a consecutive 4 and 2. 54 00:02:43,210 --> 00:02:46,220 In other words, two of the consecutive numbers 55 00:02:46,220 --> 00:02:49,560 that appear in 6042. 56 00:02:49,560 --> 00:02:52,230 Well, the first one does not. 57 00:02:52,230 --> 00:02:57,320 There's no 60, 04, or 42 in this list. 58 00:02:57,320 --> 00:02:58,640 This one has a 42. 59 00:02:58,640 --> 00:03:02,870 So it would count as one of those permutations that has 60 00:03:02,870 --> 00:03:07,660 either a 60, a 04, or 42 because it's got the 42. 61 00:03:07,660 --> 00:03:11,580 Here's one where you've got a 2 and a 4, 62 00:03:11,580 --> 00:03:13,840 but that's not a 4 and a 2. 63 00:03:13,840 --> 00:03:17,970 And in fact, there is no pattern here of 60, 04, 42. 64 00:03:17,970 --> 00:03:20,220 So it's not one of the permutations 65 00:03:20,220 --> 00:03:21,630 that I'm interested in. 66 00:03:21,630 --> 00:03:24,850 On the other hand, here's one that's doubly good. 67 00:03:24,850 --> 00:03:30,270 This is a permutation that has both a 04 in it and a 42 in it. 68 00:03:30,270 --> 00:03:34,240 So it would be one of these permutations of the kind that 69 00:03:34,240 --> 00:03:37,210 I'm looking for that has at least one of the pattern 60, 70 00:03:37,210 --> 00:03:40,450 04, or 42. 71 00:03:40,450 --> 00:03:43,680 Well, if I let P sub x be the permutations 72 00:03:43,680 --> 00:03:47,110 with the sub-sequence x, then what I'm really saying 73 00:03:47,110 --> 00:03:51,150 is that this one with a 42 in it is in P 42 74 00:03:51,150 --> 00:03:53,460 because it's got the 42 pattern. 75 00:03:53,460 --> 00:03:59,290 This one with the 04 and a 42 in it is in the P 04 set 76 00:03:59,290 --> 00:04:04,270 of permutations with the pattern 04 intersected with the set 77 00:04:04,270 --> 00:04:06,710 of patterns that have a 42. 78 00:04:06,710 --> 00:04:10,680 So that's what that one illustrates. 79 00:04:10,680 --> 00:04:14,180 So what we're really asking for then is the union of three 80 00:04:14,180 --> 00:04:19,480 things-- the union of P 60, P 04, and P 42. 81 00:04:19,480 --> 00:04:23,520 How big is the set of sequences that have a 60 union, 82 00:04:23,520 --> 00:04:26,380 the set of things that have a 04 union, 83 00:04:26,380 --> 00:04:28,230 the set of things that have a 42? 84 00:04:28,230 --> 00:04:31,760 And as we saw illustrated in the previous slide, 85 00:04:31,760 --> 00:04:33,545 these are not disjoint. 86 00:04:33,545 --> 00:04:34,920 We'll I've been cheating a little 87 00:04:34,920 --> 00:04:37,280 because in order to figure out this one, 88 00:04:37,280 --> 00:04:39,370 I'm going to need inclusion-exclusion 89 00:04:39,370 --> 00:04:42,730 for three sets instead of two, which is slightly more 90 00:04:42,730 --> 00:04:45,150 complicated because I have a union of three things that 91 00:04:45,150 --> 00:04:47,020 overlap. 92 00:04:47,020 --> 00:04:48,150 And let's look at that. 93 00:04:48,150 --> 00:04:51,010 So what does inclusion-exclusion look like for three sets? 94 00:04:51,010 --> 00:04:54,880 If I want to know what's the size of A union B union C, 95 00:04:54,880 --> 00:04:57,590 here's a Venn diagram that shows a picture 96 00:04:57,590 --> 00:05:01,580 of A union B union C with all possible overlaps 97 00:05:01,580 --> 00:05:03,040 illustrated there. 98 00:05:03,040 --> 00:05:09,090 And the formula turns out to be-- you add up A, B, and C. 99 00:05:09,090 --> 00:05:13,170 You add up the size of A, the size of B, and the size of C. 100 00:05:13,170 --> 00:05:16,820 Now that has a consequence that just that sum of A, B, and C 101 00:05:16,820 --> 00:05:21,210 is counting this lens shaped region 102 00:05:21,210 --> 00:05:23,630 that is the intersection of A and C. 103 00:05:23,630 --> 00:05:26,810 It's counting it twice in the A plus C term. 104 00:05:26,810 --> 00:05:29,550 It's counting A intersection B twice, 105 00:05:29,550 --> 00:05:32,340 and it's counting this lens shape, which 106 00:05:32,340 --> 00:05:34,580 is C intersection B twice. 107 00:05:34,580 --> 00:05:38,140 So in order to get the sum right, 108 00:05:38,140 --> 00:05:42,010 I'm going to have to subtract one occurrence 109 00:05:42,010 --> 00:05:45,020 of A intersection B, one A intersection C, one B 110 00:05:45,020 --> 00:05:48,610 intersection C so that those items are only counted once 111 00:05:48,610 --> 00:05:50,070 in this sum. 112 00:05:50,070 --> 00:05:52,490 And then in fact, if you look at this region 113 00:05:52,490 --> 00:05:55,410 here, of the sort of rounded triangle region-- which 114 00:05:55,410 --> 00:05:59,070 is the intersection of A with B and C-- 115 00:05:59,070 --> 00:06:02,140 that one is actually getting counted three times. 116 00:06:02,140 --> 00:06:04,580 All three circles overlap it. 117 00:06:04,580 --> 00:06:08,910 So when I add in A and I add in B and I add in C, 118 00:06:08,910 --> 00:06:14,130 every one of those points there is being added three times. 119 00:06:14,130 --> 00:06:20,650 On the other hand, this rounded triangle shape, 120 00:06:20,650 --> 00:06:24,330 which is count of three times in the sum A plus B plus C, 121 00:06:24,330 --> 00:06:26,920 is being subtracted three times. 122 00:06:26,920 --> 00:06:32,580 Because when I look at A intersection B-- this region-- 123 00:06:32,580 --> 00:06:36,030 and I subtract it, I'm taking one away from the count 124 00:06:36,030 --> 00:06:37,390 on each point there. 125 00:06:37,390 --> 00:06:40,230 And likewise with A intersection C, takes one away. 126 00:06:40,230 --> 00:06:42,540 And B intersection C takes one away. 127 00:06:42,540 --> 00:06:46,290 Leaving the points in the rounded triangle in A intersect 128 00:06:46,290 --> 00:06:49,020 B intersection C not counted at all. 129 00:06:49,020 --> 00:06:51,900 So if I'm going to get the total count right so that every point 130 00:06:51,900 --> 00:06:54,980 discounted exactly once, I have to add back 131 00:06:54,980 --> 00:06:59,270 in the intersection of A and B and C. 132 00:06:59,270 --> 00:07:01,870 So that's an informal explanation 133 00:07:01,870 --> 00:07:07,430 of how the inclusion-exclusion formula works for three sets. 134 00:07:07,430 --> 00:07:11,110 We'll look at ways to rigorously prove inclusion-exclusion 135 00:07:11,110 --> 00:07:14,440 for an arbitrary number of sets shortly but not 136 00:07:14,440 --> 00:07:15,430 in this segment. 137 00:07:15,430 --> 00:07:18,910 Let's go on and apply the inclusion-exclusion rule 138 00:07:18,910 --> 00:07:25,810 for three sets to the example of digit permutations with 139 00:07:25,810 --> 00:07:30,160 the patterns 60, 04, and 42. 140 00:07:30,160 --> 00:07:36,650 And the way to remember this is that the intersections 141 00:07:36,650 --> 00:07:39,660 of an even number of sets occur negatively, 142 00:07:39,660 --> 00:07:41,770 the intersection of an odd number of sets 143 00:07:41,770 --> 00:07:44,910 occur positively, and of course, a single set can 144 00:07:44,910 --> 00:07:46,860 be thought of just am intersection of one 145 00:07:46,860 --> 00:07:48,370 set with itself. 146 00:07:48,370 --> 00:07:52,080 So it's also odd and occurs positively. 147 00:07:52,080 --> 00:07:53,670 All right. 148 00:07:53,670 --> 00:07:58,690 Well, now we can apply the formula and say that the set 149 00:07:58,690 --> 00:08:01,270 of permutations that have a 60, a 04, 150 00:08:01,270 --> 00:08:06,070 and a 42 is equal to the sum of the number that have a 60, 151 00:08:06,070 --> 00:08:10,720 the number that have a 04, and the number that have a 42 minus 152 00:08:10,720 --> 00:08:17,040 the numbers that have two of the patterns minus those that have 153 00:08:17,040 --> 00:08:18,500 all three patterns. 154 00:08:18,500 --> 00:08:24,350 At let's count these individual intersections and sets of 155 00:08:24,350 --> 00:08:25,560 permutations separately. 156 00:08:25,560 --> 00:08:28,000 It turns out that each one is easy to count, which 157 00:08:28,000 --> 00:08:32,590 is a typical situation which is why inclusion-exclusion 158 00:08:32,590 --> 00:08:36,590 is a valuable principle because this thing that is harder 159 00:08:36,590 --> 00:08:38,559 to count can be broken up into counting 160 00:08:38,559 --> 00:08:40,500 a bunch of other things-- intersections-- 161 00:08:40,500 --> 00:08:42,360 that are often easier to count. 162 00:08:42,360 --> 00:08:43,890 And they will be here. 163 00:08:43,890 --> 00:08:46,120 So let's begin by looking at P 60. 164 00:08:46,120 --> 00:08:52,340 P 60 is the set of permutations which have a 60 in them. 165 00:08:52,340 --> 00:08:54,960 Well, to count them, we can think about it this way. 166 00:08:54,960 --> 00:08:58,000 Think of the patterns with a 60 in them 167 00:08:58,000 --> 00:09:02,790 as a permutation of nine items-- the digits 1 through 5 and 7 168 00:09:02,790 --> 00:09:09,400 through 9 and the object 60 that you can place anywhere, but it 169 00:09:09,400 --> 00:09:10,920 it's got to be lumped together. 170 00:09:10,920 --> 00:09:14,130 So there are really nine possible permutations 171 00:09:14,130 --> 00:09:17,680 of these things-- eight of them digits, and one of them 172 00:09:17,680 --> 00:09:20,050 is this pair of digits, 60. 173 00:09:20,050 --> 00:09:22,270 And the number of those permutations 174 00:09:22,270 --> 00:09:24,590 is equal to the number of permutations with the pattern 175 00:09:24,590 --> 00:09:25,120 60. 176 00:09:25,120 --> 00:09:28,760 So the answer is there are 9 factorial permutations 177 00:09:28,760 --> 00:09:30,460 with the pattern 60. 178 00:09:30,460 --> 00:09:36,480 Same of course, applies to P 04, and P 42. 179 00:09:36,480 --> 00:09:39,020 The number of permutations with a given two digit pattern 180 00:09:39,020 --> 00:09:40,250 is 9 factorial. 181 00:09:40,250 --> 00:09:40,910 OK. 182 00:09:40,910 --> 00:09:44,330 What about P 60 intersection P 42? 183 00:09:44,330 --> 00:09:46,540 Well, you can think of this as the same way. 184 00:09:46,540 --> 00:09:48,130 You can think of this as saying, OK. 185 00:09:48,130 --> 00:09:52,150 I've got an object 60, I've got an object 42, 186 00:09:52,150 --> 00:09:55,980 and I've got the remaining digits 1, 3, 7, 8, 9 187 00:09:55,980 --> 00:09:56,730 to permute. 188 00:09:56,730 --> 00:10:05,380 And the sequences of 10 digits that contain both a 60 and a 42 189 00:10:05,380 --> 00:10:07,720 correspond exactly to permutations 190 00:10:07,720 --> 00:10:12,940 of the digits 1, 3, 5, 7, 8, 9, and the object 42, 191 00:10:12,940 --> 00:10:14,510 and the object 60. 192 00:10:14,510 --> 00:10:16,150 Now, there's eight of things. 193 00:10:16,150 --> 00:10:19,110 And so the number of permutations of these eight 194 00:10:19,110 --> 00:10:22,690 things is 8 factorial, which means the size of P 60 195 00:10:22,690 --> 00:10:24,400 intersection P 42. 196 00:10:24,400 --> 00:10:27,140 The number of permutations of 10 digits that 197 00:10:27,140 --> 00:10:31,365 have both a 60 and a 42 pattern is 8 factorial. 198 00:10:31,365 --> 00:10:34,240 Now, that's the case of an intersection where 199 00:10:34,240 --> 00:10:35,790 these two things don't overlap. 200 00:10:35,790 --> 00:10:40,920 Let's look at the case of P 60 intersection P 04. 201 00:10:40,920 --> 00:10:43,670 Well, if it's got both a 60 and a 04, 202 00:10:43,670 --> 00:10:47,100 it actually is the same as having a 604. 203 00:10:47,100 --> 00:10:52,720 So the intersection of P 60 and P 04 is the set of sequences 204 00:10:52,720 --> 00:10:55,070 that have the pattern 604. 205 00:10:55,070 --> 00:10:56,720 And I count those in the same way. 206 00:10:56,720 --> 00:10:58,380 I say, OK. 207 00:10:58,380 --> 00:11:02,626 I've got an object 604 plus the remaining digits-- 1, 2, 3, 5, 208 00:11:02,626 --> 00:11:06,360 7, 8, 9 for a total of eight objects, 209 00:11:06,360 --> 00:11:10,460 and the number of permutations of the 10 digits 210 00:11:10,460 --> 00:11:13,060 that half the pattern 604 corresponds 211 00:11:13,060 --> 00:11:15,820 to the number of permutations of these eight things. 212 00:11:15,820 --> 00:11:18,500 Again, 8 factorial. 213 00:11:18,500 --> 00:11:19,300 OK. 214 00:11:19,300 --> 00:11:23,940 Finally, how many permutations are there that have all three 215 00:11:23,940 --> 00:11:26,390 patterns-- 60, 04, and 42? 216 00:11:26,390 --> 00:11:28,090 That of course, is exactly the same 217 00:11:28,090 --> 00:11:32,350 as the set of sequences with the single pattern 6042, the four 218 00:11:32,350 --> 00:11:33,360 digit pattern. 219 00:11:33,360 --> 00:11:35,500 And again, we count that by saying 220 00:11:35,500 --> 00:11:37,170 that it's the number of permutations 221 00:11:37,170 --> 00:11:39,850 of the digits other than 6042-- six of them 222 00:11:39,850 --> 00:11:41,920 plus the 6042 object. 223 00:11:41,920 --> 00:11:45,280 There are seven of these , and so there are 7 factorial 224 00:11:45,280 --> 00:11:48,330 permutations that have all three patterns. 225 00:11:48,330 --> 00:11:51,440 So that means that I can go back to my inclusion-exclusion 226 00:11:51,440 --> 00:11:56,990 formula for the sequences that have one of the three 227 00:11:56,990 --> 00:12:00,790 patterns-- 60, 04, and 42-- and plug them in. 228 00:12:00,790 --> 00:12:06,420 So I get 3 9 factorials for the first sum of three terms. 229 00:12:06,420 --> 00:12:08,780 The intersections-- we all figured out each of them 230 00:12:08,780 --> 00:12:10,490 were-- I'm sorry it's 8 factorial. 231 00:12:10,490 --> 00:12:13,020 So I'm going to subtract 3 times 8 factorial. 232 00:12:13,020 --> 00:12:17,230 And this last term we figured out was 7 factorial. 233 00:12:17,230 --> 00:12:22,410 Well, I can think of 3 times 9 factorial as 9 times 8 times 234 00:12:22,410 --> 00:12:27,150 3 times 7 factorial, and this is 3 times 8 times 7 factorial. 235 00:12:27,150 --> 00:12:27,860 And I wind up 236 00:12:27,860 --> 00:12:30,794 [NO AUDIO] 237 00:12:38,720 --> 00:12:41,040 PROFESSOR: 72,720. 238 00:12:41,040 --> 00:12:45,760 That's how many permutations of the digits 0 through 9 239 00:12:45,760 --> 00:12:49,030 there are that have one or another of these three 240 00:12:49,030 --> 00:12:49,790 patterns. 241 00:12:49,790 --> 00:12:54,670 Turns out that's about 27% of the 10 factorial permutations 242 00:12:54,670 --> 00:12:56,590 of 0 through 9. 243 00:12:56,590 --> 00:13:02,130 So that's the significance of applying the disjunction 244 00:13:02,130 --> 00:13:07,240 of constraints, this union of having either 60, 04, or 42.