# Lecture 17: Counting Rules II

Flash and JavaScript are required for this feature.

Download the video from iTunes U or the Internet Archive.

Description: Covers computing cardinality of sets with inclusion–exclusion, the bookkeeper rule, the subset rule, and poker hands with applications to probability and counting.

Speaker: Marten van Dijk

The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high quality educational resources for free. To make a donation or view additional materials from hundreds of MIT courses, visit MIT OpenCourseWare at ocw.mit.edu.

PROFESSOR: We're going to talk about inclusion-exclusion which is a generalization of what we did at the end of last lecture, which was about the sum rule. Everybody's still talking I hear. Anyway, the inclusion-exclusion principle is very important. And the best way to explain this is by using Venn diagrams. So let's do this.

So what did we do before? When we worked on a sum rule, we saw that if we count the union of a whole collection of sets that are all disjoints, then we can just some all the cardinalities of each of the members. So in the case where we have intersections-- so sets are not disjoint-- well, if you just count all the cardinalities-- all of the sizes of the sets together-- you'll start to do some double counting.

So with the inclusion-exclusion principle, we can actually exactly compute the cardinality of the union of sets. And you will see that this principle can be used in plenty of examples, including some of them that are on the problem set. So how does it work?

So let's set take an example where we just have two sets and they have an intersection. So say this is one set which we call M, and say here is another set which we call E. Well, they have an intersection-- there's some overlap over here. So if you would like to write out the different areas over here, what they were equal to, well, this is everything that is in M, but we exclude what is in E. So you write it M backslash E.

This part over here is the intersection of-- this maybe is a little bit too small-- so this is the intersection of both sets. And over here we have everything that's in E but excluding what is in M. So if you just write out the cardinalities of the different sets that we're interested in-- so we would like to compute the cardinality of the union of M and E.

So let's have a look how the cardinality of M itself can be computed. Well, if you use the sum rule which says that we can simply add the two disjoint sets that make up set M-- we can count each of those cardinality-- so we have M consisting of this part, which is M excluding E, plus the part that is right here which is the intersection. So we use the sum rule and conclude that we have the sum of everything that's in M excluding E plus the cardinality of the intersection.

Now, for set E we can do something completely similar. So we will have everything that's in E excluding what is in M. And then we still have the intersection. Now we are interested in the union of the sent M and E. And now we need to add this one this one and this once together. So what do we see? We see that this is actually equal to everything that is in M but not in E, everything that is in their intersection, plus everything that's in E but not in M.

So we have these equations that we can directly derived from the sum rule. And, well, now we can see here that if we are going to simply add-- that's what the sum rule would say-- simply add the cardinality of M and of E, well, if we add those two together, we will count the intersection double. So we'll need to cancel that because it's only counted once in the union.

So if we combine those three over here-- those three equations-- then we can conclude that this counts the set M intersecting with E twice. So we have that the union is really equal to the cardinality of M plus that of E minus their intersection. Now we can generalize this. And we will give one more example where we have three sets and it will give the general equation.

So suppose you have three sets now. Like one, another one, and another one over here. So we have M, E, and, say, the set S. Well, let's have a look how many times these different areas-- they're all disjoint-- how many times they are counted when me add the three cardinalities together.

So we have M plus the cardinality of E plus the cardinality of S. Well, if you do that then we count this area exactly once because it's in M, this area we count once because it's in M and another time because it's in E-- so it's twice-- this particular area is only counted once in this sum over here. And similarly, we have two times over here, two times here, and one times over here. And this intersection of all of the three, well, it's counted when we count elements in M but also when we count elements in E and also when we count elements in S. So this is counted three times.

So let's have a look. It seems like we want to do exactly the same as what we did before. We like to subtract an intersection of M and S. That's this part. It cancels the double counting in this area, right? We can subtract this intersection such that this part is cancelled. The double counting here is canceled. And similarly, we want to subtract the intersection between E and S which would eliminate this double counting.

But now we can see that we start to subtract too much because this central area here will be-- well, it's part of each of those intersections so it's actually eliminated. All of it is subtracted.

So let's create the same diagram. But now when we count the sum of all those intersections-- so we have the intersection of M intersect with E, the intersection of M with S, and we also want to figure out how many times elements are counted in the set E intersects with S. So let's have a look.

Well, this area here is counted zero times. It's not part of any of these intersections because it-- this part is only in M and not in S or E. So this is counted zero times. And here we have the same. Well, this part over here is exactly once in this intersection between those two sets. It's not in this one so this is counted once. So we have by symmetry that for all the others.

This area, however, is in both this intersection as well as this one and also this one. So it's counted three times. So now we can easily start to combine all these together. And you can see, if we take this sum and we subtract this, then the middle area is cancelled. So we have to still add the intersection of the three sets. The intersection of M, E and S together.

So in a formula that would look like this. So we are interested in the union. And this can now be written as, well, the sum of the cardinalities of the individual sets. And we subtract the intersections that we have up there. So M intersect E minus M intersect with S and minus E intersect with S.

Now we have eliminated-- if you look at this Venn diagram over here-- this diagram over here-- we've eliminated everything that's in the middle area. So we still need to add intersection-- everything that is counted in the intersection of M, E, as well as S. So we have this equation. And now you can see why we call this the inclusion-exclusion principle.

Here we include all the elements in M, E and S. Now we have to exclude what we counted too much. So we have exclusion over here. And now we, again, have to include some stuff because we excluded too much. And then we keep on going like this.

So, in general, we get the following theorem that says that, if you look at the cardinalities-- of the cardinality of the union of a whole bunch of sets-- say we have n sets-- then this is actually equal to-- well, we first include the sums of all the individual cardinalities. Which is from I equals 1 to n cardinality of Ai minus-- now we have to, again, we have to eliminate all the double counting-- so we look at every pair of sets indexed by i1 and i2. And we look at their intersection and we take that out using this minus sign. We exclude this.

And we continue like this. So we add now-- because we have excluded too much, we have to include some more-- we look at all triples of sets indexed by i1, i2-- oops-- and i3. And now we look at the intersection of those sets. And we continue like this all the way until we look at the very last intersection that you can have, which is intersection of all the sets. And it depends on whether n is even or add whether we have to include or exclude it.

So we have a minus 1 to the power n plus 1. And then we have the intersection of all of these. Now, we can write this out in a more elegant formula where we just put all this what I wrote here in a sum. And then it looks like this. It's the sum over k equals 1 to n minus 1 to the power k plus 1. So depends whether k is even or odd whether we do an inclusion or an exclusion in this sum.

And we look at all the subsets that our subsets of the index set 1 up to n such that the cardinality of the set S is equal to k. And now we need to look at the cardinality of all-- of the intersection of all the sets that are indexed by S. So that's-- so I run-- I put i-- so do the intersection of all i in S of the sets Ai.

So this general formula is the inclusion-exclusion principle. And this is the way how we can think about it how to derive it. Of course, this is not a proof. But you could do this yourself by using induction. And you can use induction on n. So that's a pretty straightforward exercise.

OK. So let's give an example. Let's do that over here. You will have a problem that's similar on the problem set. And it's goes like this. You would like to know how many permutations are there with a special property. So how many permutations do I have of the set 0, 1 all the way up to 9. So all the digits. And that have consecutive-- so I put this in brackets just to clarify-- so consecutive either a 4 and a 2 right next to one another. So remember, a permutation is a sequence that has each of those digits exactly once.

And I like to count those permutations that have a 4 and a 2 next to one another in this way. So we have 4, 2. Or the permutation may have a 0, 4 or a 6, 0. So I'm very curious, how many permutations do I have? And I'm going to use this principle that I just described.

So how do we need to go ahead with this? Well, this-- so I'm interested in the permutations that have a 4 and 2 next to one another. So that could be my first set, say, M. And then I have a set that I want to count that has the 0 and the 4 next to one another. That could be my E. And the S could be those permutations that have the 6 and a 0 next to one another. So then I would like to use that rule over here.

So I would also need to count all the intersections and so on. So let's do this. Let me first give an example of such a permutation. So for example, I could have the permutation that is the sequence 7, 2, 5, 6, 0, and the 4, for example, 3, 5, 1 and 9. So I have all the digits that are in the-- contained in the set. And I see that, actually, this particular permutation has a 6 and a 0 next to one another. So it's in this particular-- the set of permutations that have a 6 and a 0. I can also see it has a 0 and a 4. So it's also in the set of permutations that have a 0 and a 4 next to one another.

OK. So now I'm going to define these different sets and then we're going to start counting these. And this is the type of counting that you're doing in this problem set. And the intuition that you create by doing that you can use later on when we study probability theory.

OK. So let's define the set P4, 2 as all the permutations that have-- so it's the set of permutations with 4, 2. And similarly, we have P0, 4 which is the same thing but now with 0, 4. P6, 0, the set of full permutations with 6, 0.

So let's have a look at what the sizes of an individual set of permutations. How can we do this? So let's have a look at the size of, say, this one, P60. Well, what kind of trick can I do in order to count this?

So we have learned a few rules last time. And what I would like to do is, well, this is a slightly more complex structure, so I would like to map this to a set by means of a bijection That will be great. Then to do some kind of other sets that is easy to count for me. So then, by the bijection rule, I will be able to figure out what the cardinalities of this set.

So the trick here is to find such a bijection. And the idea is that you could actually treat the 6 and the 0 as one unique symbol. So let's see how it works. So what I could do is I can have, from the set of-- from P60-- so all the permutations that have 6 and a 0 next to one another-- I can find a bijection to the permutations of the set that have 6, 0 as a single symbol. And then I have all the other symbols, all the other digits. So 1, 2, 3, 4, 5, 7, 8, and 0.

So let's have an example of-- we have one up here, actually. So how would I map this? This would be mapped according to that definition. To 7, 2, 5. And now I combine 6 and 0 into one symbol in my sequence. And then I have the rest. 4, 3, 5, 1, and 9.

Now this is easy for me to count, right? So this is a bijection. And by the bijection rule, the cardinality of this set is equal to the total number of permutations on this set. Now, this set has exactly eight elements so I know how many there are. So I know that the cardinality is equal to 8 factorial. Because there are 8 factorial permutations on sets of size 8. We saw that last time. So that's the trick or--

AUDIENCE: Nine.

PROFESSOR: Oh, is it nine? Oh, yeah, you're right. Great. So this is 9. And similarly, in the same way, we can also count these, right? We can treat 0, 4 as one symbol or 4, 2 as one symbol. So I also know that the cardinalities of these are also equal to 9 factorial.

Now, when I use the inclusion-exclusion principle-- so now I've computed those three, essentially-- I need to subtract their intersections. So let's compute the intersections. And if you do that, we're going to use the exact same trick. So we're going to find the bijection to permutations of a set of symbols. And we just have to specify those.

So let's do this together and take, for example, the intersection of P42 with P60. So what kind of a bijection could I have? So it will be all-- to all the permutations on what kind of a set? So I use the exact same trick here. So I'm going to treat 4 and 2 as one symbol and 6, 0 as one symbol.

So I have 4, 2, 6, 0 and then all the other digits. So it's the 1, 3, 5, 7, 8, and 9. You can count that this number is 8. So by the bijection rule, we have that the cardinality of this intersection is equal to 8 factorial.

And we continue like this to compute all the other intersections. And they do look a little bit different sometimes. So for example, if I have 6, 0 and P 0, 4-- so let me define the permutation first-- or the bijection first. So how do we do this one? Any suggestions?

So what kind of a set can I find a permutation to? If I look-- so over here I have a permutation in which 6 and 0 are next to one another. But this is also a permutation in which 0 and 4 are next to one another.

AUDIENCE: [INAUDIBLE].

PROFESSOR: Yeah, exactly. So 3, 6, 0 and 4 is one symbol because permutation is right in here has a 6 and 0 next to one another. And the 0 should also be next to the 4 because it's in this set as well. So we know that every permutation in here has a sub sequence of 6, 0, 4 next to one another. So we can treat this as one symbol. And then we have all the other ones.

And again, this is-- these are 8 elements. So we have that also, for this intersection, the cardinality is equal, by the bijection rule, as the total number of permutations on a set of eight elements, which is 8 factorial.

So for the last one, we also have similar-- so let me see which one I need to do. So I have 4, 2 and 0, 4. Well, again, I do the same trick. Now I have a symbol that has-- well, the permutation here has a 0 and a 4 next to one another, and the 4 is next to a 2. So I treat this as one symbol.

So if the permutations on the set 0, 4, 2, and then 1, 3, 5, 7-- oh, and 6 as well-- 8 and nine. So the cardinality of this set is also equal to 8 factorial. So now we still have to look at the intersection of all of those three in order to use the inclusion-exclusion principle. And, well, the same trick can be used over here.

So we look at the intersection of P60 with P04 and the permutations that have 4 and 2 next to one another. So what does that mean? It means that the permutation that's in here has a 6, 0 and then a 4 and then a 2. So these are all the permutations with a 6, 0, 4, 2 next to one another.

And this can map easily to the sets where we treat this as one symbol-- 6042-- and then we have 1, 3, 5, 7, 8, and 9. This set has seven elements, so the intersection of these three is equal to 7 factorial. And now we can use the inclusion-exclusion principle using this over here.

And when we plug everything in here, we can see that the intersection-- that the union-- when we count the union of P60 which P04 and P42 is actually equal to 9 factorial for these, 8 factorials for those, and a 7 factorial for these. So it's 3 times 9 factorial minus 3 times 8 factorial plus 1 times a 7 factorial. So this is how we can use inclusion-exclusion principle.

So this generalized the sum rule. And now we have a whole set of rules already discussed since last time. We continue with the bookkeeper rule. You have already seen it during recitation so I will only write it out once more. And all these rules together we will then use in a set of examples.

So what was the bookkeeper rule? We have that-- so the bookkeeper rule is, if I have distinct copies of letters-- so distinct copies of letters l1, l2, l3 and lk, well, then the number of sequences that have exactly n1 letters of the type l1 and n2 letters of the type l2 and so on, well, we can count those. So sequences with n1 copies of l1 and n2 copies of l2, and then we continue like this until we have nk copies of lk.

Well, we can count this. So these copies can be in an arbitrary order in the sequence. And we saw in recitation that this can be written as n plus 1 plus n2 all the way up to nk factorial. And we divide out the product that starts with n1 factorial times n2 factorial up to nk factorial. And this we also can write as what-- well, this is actually the definition of what we call the multinomial coefficient.

So you've already seen the binomial coefficients, which is a special case of this one. So we write this as n1 plus up to nk. And then we have n1, n2, and we just repeat all of those in here. If we have k equals 2, then we get the binomial coefficient. And if k equals this 2, we also often just forget about the last term. So we would get expressions that look like this, which is really equal to nk comma n minus k.

OK. So this is some-- these are some definitions. And we can apply this bookkeeper rule. For example, last time in the lecture we were talking about the number of bit sequences of length 16 with four 1's. We wanted to count this because we found out that if you want to select 12 donuts of five varieties, we can find a mapping of bijection towards this set of bit sequences with 12 0's and four 1's.

So the bookkeeper rule will tell us exactly how many there are. And that's the most basic example, essentially, of this way of counting. So what do we have? So the number of bit sequences of length 16 and with four 1's-- well, is exactly equal to, according to this rule, as length 16 and we need to choose four 1's out of these 16. And it's the binomial coefficients where we choose four out of the 16 symbols. And this is equal to 16 factorial divided by 4 factorial times 12 factorial.

Now we often also denote the following rule-- we sort of identify as a special case. We say that the number of k elements-- of k element subsets-- of an n element set is actually equal to n choose k. So this is an important rule to remember which will occur many times.

OK. A theorem that we can have derived from all this stuff is what we call the binomial theorem. So we'll quickly go over that. The binomial theorem says that, for all integers n-- positive integers n-- we have a plus b to the power n equals to the sum where we take k from 0 to n and then we have the binomial where we have this expression over here. We choose k out of n and we choose, say, k times b in this expression. I will explain in a moment by an example. And n minus k ace.

And this is the theorem. And I will just give an example just to show how we can think about this. So let me do that over here. So if you take n equals to 2, then we can see that we get all the combinations, essentially, of a and b of length 2. So you have a times a, a times b, b times a, and b times b.

So what do we see? We see a squared plus ab plus ba plus b squared. Now we see that these have 1 times an a and 1 times a b. This one has 2 times an a and this one has 2 times a b. And this combines together as a squared plus 2 times ab plus b squared.

Now, if you have n equals 3-- so we have a plus b to the power 3-- you will get all the different products, all the different terms, that add up to this, are all the kinds of combinations of a's and b's. So for example, we have three a's-- so 3 times a-- but it can also have a squared times b plus aba plus b a squared. And those have exactly two times an a and one times a b.

I can now look at all the others-- so I may have two times the b and one times the a. So what our those? We have a times b squared plus bab plus b squared a. So I count these as the same, right? They each have the same number of b's. Two times the b and one times the a. And then, finally, I have b to the power 3 which counts three times the b.

So these are all the possible terms that I have. There are eight in total. One, two, three, four, five, up to eight. And that fits, right? Because I can have a choice of an a and a b. And I do that three times. So 2 times 2 times 2 is equal to 8. So I have eight terms.

And I can group them together by taking a to the power 3 plus 3 times a squared b plus 3 times-- and now I have b squared a-- and finally, b to the power 3. So what do we see here? How many terms are their that have exactly two times an a and one times a b? Well, it's like we have a set of three elements, right? Or three positions. And I like two of them to be an a. So I choose two out of those three to be an a. So I use this subset rule to count how many times I see the same term back.

So let's write this out so that is-- so the number of terms that have k times an a, and we have, say, n minus k times a b. So how many terms do I have? Well, that is the length of-- so the number of-- oops. Change that. So it's the number of length n sequences that have the following property. That these have k a's and n minus k b's.

And that's easy to count. Which is equal to what we have done here before. We have the binomial n choose k. And that, if you plug that in over here, then we get this particular sum. So it is-- this is the binomial theorem. Very famous.

And now we're going to use all this stuff to count some poker hands. So we have come to this part of the lecture. So we're going to do a bunch of examples that are similar to some of those that you will see in the problem set. And then at the end we go and continue with some-- with a different proof technique.

So let's first define a deck of cards because that's what we are going to use now. So for this type of problems, we will use a deck which is actually a set of 52 cards. And a card itself actually has a suit. And the suit can be something that looks like this, which is called spades. S of spades. We have another symbol which is this, hearts. And we will have clubs and we have diamonds.

And besides a suit, a card also has a value. And the values are arranged from 2, 3, 4, all the way up to 10. Then we have a special symbol-- special value-- which is called the Jack. We've got a Queen and a King and finally the Ace. And in total, we have 13 possible values. So you can see that we have four times, because of four different suits, 4 times 13 is 52 different cards and that makes up a deck.

So we're going to look at hands. And a hand is actually a collection-- a set of five cards. So it's a subset of the deck of five cards. And we do not worry about the order of the cards in your hand. They can be permuted, if you want. So the order's not important. So it's a subset of five cards.

So how many hands do I have? Well, how many ways are there to choose a subset of five cards out of a deck of 52 cards? Well, we can use a subset through and we get the binomial 52 choose 5. Which is, by the way, a lot so let me write it out as well. It's about 2 and 1/2 million.

So we are interested in, when we play poker-- if you do that-- in really good hands. So we like four of a kind, which means that we have four cards that actually have the same value. Or we have cards that-- hands that have what we call a full house. We will count those in a moment. Or other kinds of combinations.

And the rarer the combination is in your hand, the higher or the better your hand is, and the more likely it is that you win the poker game. If you do not get left out. All right.

So let's give an example of a four of a kind. So we're going to compute those and we will see that we need to do-- to use all the-- a combination for all these rules. OK. So four of a kind is the special hand where we have four of one kind of value.

Notice, by the way, that the fifth card, because of this, must have a different value, right? Because there are only four cards that have, say, the value eight. Because there are only four different suits. So the fifth card will ultimately have a different value.

So as an example, we will have the 8 of spades and then the 9 of diamonds and all the other 8's-- the 8 of diamonds and the 8 of hearts and, say, the 8 of clubs. And how do we count these types of hands? We're going to look for a representation of how can you represent such hands, such objects? So we have to count a special type of object, a special kind of poker hand. And in order to do that, we're going to look for a way to represent these objects and in such a way that we can count them very easily.

And that's really the trick in order to solve these kinds of counting problems. So the representation that we have here is-- well, we can choose-- first of all, we can choose the value of the four kinds-- of the four cards. So how many choices do I have? Well, I got any choice. There are 13 different values so I have 13 choices. So that's easy.

Secondly, I can choose the value of the extra card. So how many choices do I have here? Well, the four of a kind already eliminates one kind of value completely. Right? So I have any of the other values is possible. Is equally likely, even. So I have 12 choices.

And, lastly, I can represent-- I need to still represent the suit of the extra card. So I also want to know the suit of the extra card. And how many choices do I have? Well, I can choose any of those four. So that's four.

So, essentially, what we constructed here is a mapping by using this representation. And the mapping tells us-- is as follows. Let's keep this up. So the mapping goes from poker hands-- from card-- from hands to-- from hands with four of a kind to this representation. So let's write it out.

So we have four of a kind. And then we have a function-- a mapping f-- that goes to this representation. We will have the first entry-- the value 1 and the value 2 and then a value 3. So for example, if you take this hands of cards, well, the first one, we see that the four of a kind has value 8. The value of the second card is the 9 of the 9 diamonds cards. So we have 9. And finally, the suit that I need to select for, the extra card is diamonds. So this is an example.

And now we know, because this is a bijection, we know that the number of hands with four of a kind is equal to all these types of sequences, all these types of sequences that can-- that are chosen according to this representation. Well, we have 13 choices for the first value. And given this first value, we have 12 choices for the second value. And given those two, I have four choices for the very last entry in this sequence.

So this is the generalized product rule that I'm using. So we see that the number of sequences is equal to 13 times 12 times 4. Turns out this is equal to 624. Well, if you divide it over total number of cards.

So how did we do this? This is the generalized product rule. If you divide this number of the total number of cards we could get the fraction of one over about 4,000. So it's really rare that you get four of a kind. So it's a really good hand.

OK. Let's do a few more of these. We also like to know how many full houses there are. A full house is a special hand. It has three cards of one value and two cards of another value.

So how many are there? So again, we are going to use the exact same principle. We're going to find a representation of this type of hand. So we have three cards of one value and two cards of another.

So for example, we may have the hands that contain, say, three cards with value 2. A 2 clubs, a 2 spades, and also a 2 diamonds. And, say, a Jack club and a Jack of diamonds. And another example could be, say, a 5 of diamonds and a 5 of hearts, 5 of clubs, 7 of hearts, and also a 7 of club.

So now you can see that it's very easy to represent this. Right? We can start grouping things together. We can say, represent this by first taking the value of the three cards that I have here. So it's 2. Then I want to indicate in a second term in my sequence-- in my representation-- which suits did I use over here? Well, I used clubs, spades and diamonds. So it's a set club, spades and diamonds.

And now I also have a pair. Like, two cards with the same value. What's the value? It's Jack. And what are the suits associated to these? Well, clubs and the diamonds. So I have not yet for-- given you the formal definition of the representation, but you can see that you could do something like this. So this is often how we start out on a piece of paper. You try to do something and hopefully it works.

So we have-- here we have diamonds, hearts, and clubs. And then we have-- finally we have two cards with the same value 7. And they have the hearts and clubs as suits. OK.

So the representation is defined as follows. It just started out with a first entry in my representation. And this is going to be the value of the triple. So how many choices do we have for this value? Well, I can choose any of the 13 possible values. So I have 13 choices.

And the second part is the suits of the triple. Well, I have to choose a subset of the four possible suits of size three. So I need to have a subset of size three out of the four possible suits. And that will give me the proper representation.

So how many choices do I have for such a subset? Well, there's three elements out of four. So we can use the subset rule and see that this has 4 choose 3 equals four choices. Then the last part is to value of the pair that I have of the two cards that are having the same value.

Now, how many choices do I have here? Well, I have to be a little bit careful, though. I just want to make sure that I do the right reasoning here. I know that there's still-- because I chose a triple of cards of the same value-- for example, over here I chose all these 2's-- but I still have one card in my deck which has a 2. Actually, here I've chosen clubs, spades and diamonds. So the one that is missing is the 2 of hearts. So I could possibly choose the 2 of hearts.

But wait a minute. If I choose the 2 of hearts, how can I make a pair? That's not possible, right? Because I've already chosen all the other 2's so there's no other 2 to match to find a pair. So I actually cannot choose this particular value of this triple for the pair. But all the other values are possible. So I have 12 choices. One less than the one that I've already chosen for the triple.

Now, and then similarly, I can choose suits of the pair. And how many choices do I have? Well, look at every possible subset that I can have of size two out of the four suits. So I use the subset rule and find that this is 4 choose 2 which is equal to 6.

So now we're going to multiply all of these together. We use the generalized product rule again. So we have found a mapping from hands with a full house to these types of representations-- to this representation. And this mapping is bijective. So the number of full house is exactly equal to the number of these representations. And by the generalized product rule, I can choose the first entry of such a sequence in 13 ways. The second one, given the first one, in four ways. This one I can choose in 12 ways given I've already chosen my triple. And so on.

So by the generalized product rule, I know now that the product of those four is equal to the total number of full house hands. So how much is that? It's 13 times 4 choose 3 times 12 times 4 choose 2. And this turns out to be equal to 3,744. Which is a factor six bigger than a four of a kind. So it's much more likely that you get one of those. And that's the reason why four of a kind has more worth-- is worth much more than a full house.

So let's do another example, a hand with two pairs, and see whether we can continue this type of reasoning. It's going pretty well. And maybe we can do the same thing. We'll see that, in counting, you really have to take a lot of care. So maybe you can already see what's happening when I start reasoning in the exact same way as before.

So let me first define what I want to count. It's a hand that have exactly two pairs. So what does that mean? It means that there is-- that we have two cards of one value and another two cards of another value.

So let's start out as before. We're going to write out a representation and see whether we can do this properly. So we're going to use the exact same technique. So first of all, we're going to choose the value of the first pair.

Now, how many ways can I do this? Well, I can do this in 13 ways. Any possible value is possible. I need to choose the suits of the first pair.

And how many ways can I do this? Well, I use the same techniques as over here, so it's any possible way to choose two elements out of a set of four which represent all the suits. So that's 4 choose 2.

Then, three, we're going to choose the value of the second pair. Well, that's easy because the second pair, by definition, must have a different value than the one in the first pair. Well, I've already chosen one value so I have 12 choices left. So that's no problem.

And now we can continue and do the same thing. So we're going to count the number of suites that are possible for the second pair. And it's the same number as we have for the first pair. So we have a number of suits of the second pair. Again, we need to choose two suits out of the complete set of suits, which has four possibilities. So it's 4 choose 2.

And now we can have still a choice for the last cards. We have now two pairs. We still have a fifth card. The fifth card also has a value. Actually, I did not write it down, but if we talk about a hand with two pairs, we mean two cards of one value, two cards of another value, and the fifth card-- the extra card-- has yet another value. Because otherwise you would have a full house and we have already counted those.

OK. So value of the extra card. Well, I've chosen already two values. The one for the first pair, the one of the second pair, so there are 11 choices left. And finally, I can choose a suit of the extra card. Well, I have one out of four choices for my suit.

So again we can use the generalized product rule and we can say that we have 30 choices for my first entry in my presentation. Right? For the first choice. Then given the first choice, I have 4 choose 2 choices for the second. And then 12 choices for the third if I've already chosen the first two. And so on.

So I can use the generalized product rule and count these representations. So the number of representations is actually equal to 13 times 4 choose 2 times 12 times 4 choose 2 again times 11 times 4 choose 1.

So is this a number of the hands with two pairs? So this seems to be pretty reasonable. But can you see something that has happened here that we also saw actually last lecture? Like, do I know for sure that the hands with two pairs is-- well, that are this number of hands with two pairs. What do I need to check in order to make sure that that is true?

Well, I need to make-- I need to prove, essentially, that this representation is actually bijection from the hands with two pairs to this types of sequences. So is that true? Or does this mapping have a different property? Any ideas? Yeah? Over there.

AUDIENCE: No.

PROFESSOR: No? You don't want to answer? OK. Well, let me-- when we talked about the chess game last time, or with the rooks, we could essentially had two rooks that we could choose and put them on different positions with no shared rows or shared columns. And here we have two pairs with no shared suit-- with no shared values.

But what can we do? We can actually interchange the first and the second pair. So as an example, we can have two representations that map to the same hand. So let me give an example.

So for example, suppose you choose the value 3 for the first pair and then I'm choosing the set diamonds and clubs for the suits of those. And say the second pair is a queen of diamonds and hearts. And finally, I have an ace of clubs. Well, this would be a proper sequence according to this representation.

But this maps to a hand that does also map to if we interchange the first and the second pair. We can also start off with the queen for the first pair and we have diamonds and hearts. And we have three for the second pair with diamonds and clubs. And then we finally have the fifth card which is the same, the ace of clubs.

Now these map to exactly the same hand. We just need to change the first and the second pair. Now this is a kind of problem or a mental sort of confusion that very easily happened. This is a rather easy example where you can see it. But if you do counting, we really have to take care that we make sure that each of the sequences in this representation are really represented by, say, one hand, in this case, with two pairs.

But how can we remedy this? It turns that we can-- by interchanging these two pairs, these two sequences are the only two sequences that map to the same hand. So we know that this is not a bijection but it is a 2-to-1 mapping. So now we can choose-- we can use the division rule.

And by the division rule we now know that the number of hands with two pairs is actually equal to this whole thing over here divided by 2 because we have a 2-to-1 function. Now, this is really something that is pretty disturbing because we have a near miss in our reasoning. And therefore, it is important to keep in mind the following guidelines when we do counting.

It's very important to, first of all, check whether it's truly a bijection. And you need to know how many sequences or maps to the same-- to the same hand. So the guidelines are as follows. They're pretty straightforward actually.

First of all, if we have a function f that maps from A to B, then we would really like to check very carefully whether the number-- what is the number of elements of A that are mapped to each element of B? So we check how many to one of a mapping this really is. And after this we will then apply the division rule.

It's very important to check this. But very often, we're making mistakes. For example, right now I'm doing some research and I've been counting something. Turns out it-- if I use a different method to count the same thing I get a different answer. So I made a mistake somewhere.

So that's the second guideline. So what you want to do is you want to try and solving a problem in multiple ways. So try solving a problem in a different way. And especially with counting this is very helpful. So this will lead to an extra check. So we will do that for this particular example. And it generally would always like to find multiple ways to prove things, I would say, because at least you want to have multiple-- maybe not a complete proof but subparts of proofs-- you may want to find different ways why that is true.

So that's how I usually do my proofing of things. So let's find a second way to count this over here, to do the double check. So we're going to create a different representation that should actually lead to a bijection. So I want to find a representation that's a bijection, a 1-to-1 mapping.

So how do we do this? I can-- let me see where I am. OK. So what I could do is, first of all, I can choose the values of the two pairs. So in this case, I have the values 3 and the queen. So how many choices do I have? Well, I can choose two out of 13 choices.

Secondly, I'm going to describe the suit of the smaller pair which is uniquely defined because they have two values. One is smaller and the suit of the smaller pair I can choose by taking one out the four-- two out of four choices because I need to choose two suits for the smaller pair.

For the larger pair, I do the same. And I get 4 choose 2. Now, again, I have the value of the extra card. And I have 11 choices. I have already chosen two so there are 11 choices left. And finally, the suit for the extra card can be done in 4 choose 1 ways.

So if you multiply those together, we get 13 times 12 divided by 2. And then we get times 4 choose 2 times 4 choose 2 times 11 times 4 choose 1. And we can see that that's exactly the same as this whole product divided by 2. We actually have a bijection. This particular representation is a 1-to-1 mapping. So it's always good to find a second way to prove the same result.

OK. Let me do one more. Let's do that over here. Just to make sure that you really understand this stuff, I'm going to count hands that have each suit in it. So I want to count the hands with every suit.

So as an example, I can have, say, the 7 of diamonds, the King of clubs, the 3 of diamonds, the Ace of hearts, and the 2 of spades. Why is this a proper hand? Because I can see the diamonds, the clubs, the hearts, and the spades. So I have a hand in which every suit is represented.

So what do I do for my representation? Well, I can have the values of each suit and I assign a specific order to those. So I want to represent for the diamonds and the clubs and the heart and the spade. I want to find out what values do I really have. So values of each suit in the order D, C, hearts and spades.

And how many ways do I have? Well, I have 13 values for the 7, I have 13 values for the King-- for this one, for this value, 13 values for that one and 13 values for this one. So that is pretty straightforward.

Now, we still have the extra card. And the extra card has a suit which I can do in four ways because of four choices. And finally, it also has a value. And the value is-- it's actually-- so how much is this? Can this be 13? Are there 13 values? No, not really, right? Because for each possible given suit that I've chosen, I already chose a value before when I chose a value for the suit that I did over here.

So for example, this one cannot be the 7, it has to be something else. There are 12 choices. If I would have chose a different suit, for example hearts, then I would not be able to choose the Ace because I already have chosen the Ace in the first step. So I have 12 possibilities here. So this is not 13. You may want to check that again.

So now let's give the representation for this one. So I can have diamonds, clubs-- so let's see, in the order of diamonds, clubs. So I have the 7, I have a King, I have for hearts I have an Ace, for spades I have a 2. Then I have the suit for the extra card which is a diamonds. And then a value which is a 3.

Now we are going to check according to our guidelines over here. We're going to check the number of elements that are-- the number of sequences that map to the same hand over here. So is this a bijection? It's not, right?

So why is this not a bijection? Well, we can also have the following situation where we swap the 3 diamonds and the 7 diamonds around. So we choose the 3 for the diamonds and then we have the King, the Ace and the 2. then we have the fifth card which is also diamonds, but now it's the 7.

Well, this one also maps to this particular hand. So we have a 2-to-1 mapping. And we conclude that the total number of hands, where every suit is represented, is 13 to the power 4 times 4 times 12 by the generalized product rule. And now by the division rule, we have to still divide by 2. So that's the total number.

OK. So now we come to combinatorial proofs. So this is a new proof technique. And what we're going to do is we're going to count a set in two different ways. And that will lead to a combinatorial equation.

So the whole idea is as follows. So let me give an example first. So for a combinatorial proof, for example, suppose I have n shirts and I want to choose-- I want to keep k and I want to trash n minus k.

So how do I count the number of choices that I have? Well, I can choose, out of n, I can choose the k keepers. But I also can count it in a different way. I can also count this as how many ways I can select the trashers. So there are n minus k out of n shirts that I will trash.

So there are two different ways to count the same choices that I have. So we have an equation over here. And you already know this one because by the definition of the binomial coefficient, we have that this is equal to this. And so it's pretty straightforward. It's equal to this one over here.

But the idea is that we're going to count a set in two different ways. So another example is where we have the following. We choose a team of k elements. Of k elements out of-- oh, actually, I'm talking about a team. I was talking about students here. Of k students.

Out of n students. Now, how many ways can I do this? Well, n choose k, right? Well, there is a way to count this differently. I could also say, well, let's first count the total number of ways in which I choose k students that includes Bob. So let's do that.

So Bob is one of the students, and if I count the number of teams with Bob, how many choices do I have? I choose Bob. I still need to choose k minus 1 students out of the remaining n minus 1 students. So I have taken out Bob. So there are n minus 1 students left and I still need to choose k minus 1 students.

The other possibility is that we have teams that-- in which Bob is not represented. So now we need to choose k students out off all the students minus Bob. So we have n minus 1 choose k. So by the sum rule, we can just add those two together and that should be equal to all the possibilities to choose team of k students.

So what do I see? I see that n minus 1 choose k minus 1 plus n minus 1 choose k should be equal to-- well, before I counted it as this-- so it should be equal to n choose k. And this is called Pascal's Identity. And the general idea is is that we do the following. So we are actually counting a set in two different ways. That's what we did so far.

And when you solve these types of problems, the difficulty is that you will need to define the set S. So usually you get a problem, you need to prove some equation like this. So you define a set S. That's the hard part of it.

Then we are going to show that the cardinality of S is some number n, say, in one way. So we have one method to do this. By counting. And we will show that S is also equal to some other number-- like, in this case, we had one number and this was my second one-- also by counting. And then we can conclude that n-- so we conclude that n equals m.

So we're almost done because I'm going to prove to you a very simple equation using this technique. But it is not as trivial as the one that we saw just now. What we do now is the following. We want to prove a theorem that says that if a sum r is 0 all the way up to n, then, if you take the product of the following binomial coefficients n choose r times 2n choose n minus r, this is equal to 3n choose n. We need to prove this.

So we need to find the proper set. So how can we think about it? Well, the idea is that we're probably going to choose n elements out of 3n elements. We're going to do it in a special way. And so the proof will be as follows.

We take S to be all the subsets of n balls chosen from a basket of n red balls and 2n green balls. And this will do the trick. So how do we do this?

We're going to first choose the red balls and then the green balls. So let's first count S in the very easy way. Well, I just choose n balls out of a basket of 3n balls. I don't care how many green or red balls I have. So I have really 3n choose n choices. This is the number of n element subsets from a 3n element set. So that's easy.

Now, we can also count it in a different way. We first of all wonder about the number of subsets with exactly r red balls. So how many are there? Well, we choose r red balls so we have n red balls. So we need to choose r out of those. Now, in total, I need to choose n balls. So I still need to choose n minus r balls out of the set of green balls.

I have 2n green balls. I'm going to choose n minus r green balls over here. So these are the red balls that I select and here are the green balls. Now we'll use the sum rule. And I add all the different possible subsets with 0 red balls, with 1 red ball, 2 red balls, all the way up to n red balls. So essentially, I get the sum by the sum rule of r 0 all the way up to n where I count the number of subsets with exactly r red balls. So that means I can choose r out of the n red balls and another n minus r out of the 2n balls-- 2n green balls.

So now we equate those two together and that proves the theorem. So the really hard part in this type of proofs is that you need some creativity to find and define that set S and see how that would work. And the way to do that usually is to look at this equation and then say, oh, wait a minute, I'm going to talk about sets because I choose n out of 3n over here. So out of 3n elements. And maybe I can divide up the sets in some kind of specific choice. So tomorrow during recitation you will also see combinatorial proof. Thank you.