Multisets and multivariate generating functions
Consider a multiset, \(S = \{11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 15, 15, 15\}\). How many combinations of 8 elements can be made from the set so that the sum of those 8 elements is equal to 105, when the numbers are picked without replacement?
Here, if the sum is not asked, the problem can be solved using an ordinary generating function as
and finding \([x^8]G(x)\)
But when the sum is also there as a constraint, we require one more variable to keep track of the sum. So, we may use \(x\) to know the number of elements chosen, and \(y\) for the sum of those numbers. Hence, the required bivariate generating function can be written as
Now, the answer to the question would be \([x^8 y^{105}] G(x,y)\) in the expansion of the product.
If the question was to find the number of combinations with replacement, the generating function can be represented as
Now, let us focus our attention to a related probability problem:
From the multiset S, what is the probability of choosing 8 elements such that the sum of those 8 elements is equal to 105, when the numbers are picked without replacement?
This looks simple and we may be tempted to say that the answer is \([x^8 y^{105}]G(x,y) / [x^8] G(x)\), but note that some combinations of numbers are more probable to be picked since the number of each element are not the same. E.g. If the set contains \(\{11, 11, 12\}\), the probability of choosing \(\{11, 11\}\) will be more than the probability of choosing \(\{11, 12\}\).
Anyway, it can still be solved using a generating function:
and the required probability is
And what is the probability if we do it with replacement? In this case, the probability can be found by using an exponential generating function, which is written as:
and the probability is given by \([x^8 y^{105}]E(x,y)\dfrac{8!}{22^8} = \dfrac{5621995920}{22^8} \approx 0.102449319851133\).
The above probabilities can also be verified by monte-carlo simulations in J, for the without replacement case:
lst=:(4#11,12),(5#13),(6#14),3#15 sim=: 3 : '105=+/(8?#lst){lst' (+/%#)(sim"0)1e5#0 |
and for the with replacement case:
lst=:(4#11,12),(5#13),(6#14),3#15 sim=: 3 : '105=+/(?8##lst){lst' (+/%#)(sim"0)1e5#0 |