3

Let's say I have a multiset of integers a with a size n (here n = 10)

$$a = \{1, 1, 2, 2, 3, 4, 5, 6, 6, 10\}$$

I'd like to know the count of k-combinations I can obtain with a provided k value and excluding the duplicate combinations

From the dedicated article I know the formula to count those including duplicates is $\frac{n!}{k! (n - k)!}$, but I found no mention of a possible way to get a count while excluding them anywhere. Is there only a mathematical formula allowing to calculate it, or is the only solution to rely on some algorithm?

1 Answers1

2

Possible strategies

As discussed in Number of k-combinations of a multiset, your problem of counting $k$-combinations $\mathcal C_k$ of some multiset $\{a_1^{(r_i)},a_2^{(r_i)},\dots,a_n^{(r_i)}\}$ where $(r_i)$ counts how many elements of kind $a_i$ are in there, is equivalent to counting the number of integer solutions to the equation

$$ x_1+x_2+x_3+\dots+x_n=k, 0\le x_i\le r_i, $$

where $x_i$ represents the number of times the element of $a_i$ kind was used in a combination.

Note that if $k=0,1$ then the answer is simply $1,n$. Otherwise, this problem does not have a closed form solution, but there are still different ways to solve it.

See answers given to extended stars-and-bars problem(where the upper limit of the variable is bounded). As demonstrated there, you can use for example the Inclusion–exclusion principle or look at coefficients of corresponding polynomial.



Applying possible strategies to your example

In the case of your example: $$\{1^{(2)},2^{(2)},3^{(1)},4^{(1)},5^{(1)},6^{(2)},10^{(1)}\}\implies n=7,$$ I will try out both mentioned answers to the previously linked question.


$$\text{I}.$$ We can for example use the Inclusion–exclusion principle: (see an answer from the linked post)

$$\begin{align} \mathcal C_k = \sum_{S\subseteq \{1,2,\dots,n\}}(-1)^{|S|}\binom{k+n-1-\sum_{i\in S}(r_i+1)}{n-1} \end{align}$$

Which is for corresponding $k$ expanded and simplified as:

$$\begin{align} \cal C_{2} = C_{8} &= \binom{8}{6} - 4\cdot\binom{6}{6} &= 24 \\ \cal C_{3} = C_{7} &= \binom{9}{6} - \left(3\cdot\binom{6}{6}+4\cdot\binom{7}{6}\right) &= 53 \\ \cal C_{4} = C_{6} &= \binom{10}{6} - \left(3\cdot\binom{7}{6}+4\cdot\binom{8}{6}\right) + 6\cdot\binom{6}{6} &= 83 \\ \cal C_{5} = C_{5} &= \binom{11}{6} - \left(3\cdot\binom{8}{6}+4\cdot\binom{9}{6}\right) + \left(12\cdot\binom{6}{6}+6\cdot\binom{7}{6}\right) &= 96 \\ \end{align}$$

Note that if total number of elements is $m$, then $\cal C_i = C_{m-i}$, which is $m=10$ in your example.


$$\text{II}.$$Alternatively, if you don't want to use Inclusion–exclusion principle, you can look at the coefficients of (see the other answer from the linked post):

$$ P(x) = \prod_{i=1}^n (1-x^{(r_i+1)}) = \sum_ic_ix^{e_i} $$

Then your answer becomes:

$$ {\cal{C}}_k = \sum_{i=0}^kc_i\binom{k-e_i+n-1}{n-1} $$

In the case of your example, the polynomial I got is:

$$P(x) = -x^{17}+\dots+18 x^{10}+11 x^9-11 x^8-18 x^7-x^6+12 x^5+6 x^4-3 x^3-4 x^2+1 $$

And when I substitute in the coefficients, I get the exact same equations as in previous method.


$$\text{III}.$$ Sometimes if your multiset is simple enough, you can use tricks or counting principles to get a result without needing to rely on things like previous two methods. Or if your multiset is of special kind, then there are nicer formulas. For example, if all $r_i$ are equal or if all $r_i$ are $\infty$.

If you want to explore such examples, you can search questions tagged [multisets] [combinations].

For example, the accepted answer to Unable to think about 10-combinations of a multiset is able to reduce the problem to a "Stars and bars" problem which does have a closed formula. The other answer there is also nice because it solves it graphically.



Remark

In case you wanted, you can easily print out every of those combinations for every $k$ with python.

from sympy.utilities.iterables import multiset_combinations

M = {1:2, 2:2, 3:1, 4:1, 5:1, 6:2, 10:1}

for k in range(sum(M.values())+1):
print(k) for i,m in enumerate(multiset_combinations(M,k)): print(i+1,m)

The code gives the expected results for your example:

0
1 []
1
1 [1]
2 [2]
3 [3]
4 [4]
5 [5]
6 [6]
7 [10]
2
1 [1, 1]
2 [1, 2]
3 [1, 3]
4 [1, 4]
5 [1, 5]
6 [1, 6]
7 [1, 10]
8 [2, 2]
9 [2, 3]
10 [2, 4]
11 [2, 5]
12 [2, 6]
13 [2, 10]
14 [3, 4]
15 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4, 5, 6, 6, 10]
18 [1, 2, 2, 3, 4, 5, 6, 6]
19 [1, 2, 2, 3, 4, 5, 6, 10]
20 [1, 2, 2, 3, 4, 6, 6, 10]
21 [1, 2, 2, 3, 5, 6, 6, 10]
22 [1, 2, 2, 4, 5, 6, 6, 10]
23 [1, 2, 3, 4, 5, 6, 6, 10]
24 [2, 2, 3, 4, 5, 6, 6, 10]
9
1 [1, 1, 2, 2, 3, 4, 5, 6, 6]
2 [1, 1, 2, 2, 3, 4, 5, 6, 10]
3 [1, 1, 2, 2, 3, 4, 6, 6, 10]
4 [1, 1, 2, 2, 3, 5, 6, 6, 10]
5 [1, 1, 2, 2, 4, 5, 6, 6, 10]
6 [1, 1, 2, 3, 4, 5, 6, 6, 10]
7 [1, 2, 2, 3, 4, 5, 6, 6, 10]
10
1 [1, 1, 2, 2, 3, 4, 5, 6, 6, 10]
Vepir
  • 12,516
  • Could you please add the expansion and simplification process for one $C$ of the first strategy? That would help me understand. As my maths background is narrow I'm having trouble calculating from the base formula to the final forms you provided as examples – CodeTalker Aug 30 '20 at 13:11
  • @CodeTalker If you're talking about The Inclusion-Exclusion Principle, don't focus on the formula, but try to understand the principle. This might help: combinations-of-elements-in-multisets-with-finite-repetition – Vepir Aug 30 '20 at 13:26
  • Thank you for the resource, however it's very general and I'm having trouble linking it to my problem. The provided formula results are good and in my case it's a better understanding of it that would help me – CodeTalker Aug 30 '20 at 14:37
  • @CodeTalker There is an example at the bottom of the linked resource (in my previous comment) that counts $6$-combinations of $${2\cdot x, 3\cdot y, 4\cdot z}={x,x,y,y,y,z,z,z,z}={1,1,2,2,2,3,3,3,3}$$ where note that it is irrelevant if we label the elements with letters or numbers or etc., it just matters how much of each kind of element there is. Your example is similar: $${1,1,2,2,3,4,5,6,6,10}={2\cdot a,2\cdot b,2\cdot c,1\cdot d,1\cdot e,1\cdot f, 1\cdot h}$$ Are you able to solve your example like they solved theirs? – Vepir Aug 30 '20 at 14:49
  • @CodeTalker To better understand how to apply the first method to your problem (or the link in my other comment), you need to first make sure you understand these two concepts because the method combines them together: "The Inclusion-Exclusion Principle" and the "Combinations of Elements in Multisets with Infinite Repetition Numbers" (which is also called "Stars and bars – Vepir Aug 30 '20 at 15:05
  • So, no general solution is mentioned ? – Eric Apr 19 '23 at 20:58