1

Let's say I have the following list of 9 (including repetitions) single-digit numbers: 7,7,7,5,5,3,2,2,2. I want to know, for an arbitrary list of natural numbers, how many ways I can select one, two,...,all of them without the obvious double counting. For example, for the list above I can select two of them in the following 9 ways:

77 75 55 53 32 22 73 72 52,

and again for the list above I can select three of them in the following 15 ways:

777 775 755 553 532 322 222 773 772 722 552 522 753 752 732

(let me know if I missed some).

I've tried thinking of it as a counting without replacement problem, e.g. thinking of each number as a colored marble in an urn but can't seem to get the proper formula.

bcf
  • 3,120
  • is 775 the same as 757 or 577? – Asinomás Dec 16 '13 at 20:54
  • yes, those would all be equivalent and so I would only want to count one of them. – bcf Dec 16 '13 at 20:58
  • Well, it seems that there are no clean solution. You just have to solve $x+y+z+w=n$ with $x\leq 3,y\leq 2, z\leq 1, w\leq 3$ for $1\leq n\leq 9$ and sum all the answers. – M.Jahan Dec 16 '13 at 21:14

3 Answers3

7

You can make a generating function which will count number of possible combinations for you. This is a standard trick from character theory and it is also related to quantum statistics in physics.

For your example, let us assign formal labels to numbers

$$7\leftrightarrow x\,,\ 5\leftrightarrow y\,,\ 3\leftrightarrow z\,,\ 2\leftrightarrow t$$

Then the function

$$f(\epsilon)=\frac{1-\epsilon^4 x^4}{1-\epsilon x}\frac{1-\epsilon^3 y^3}{1-\epsilon y}\frac{1-\epsilon^2 z^2}{1-\epsilon z}\frac{1-\epsilon^4 t^4}{1-\epsilon t}$$

will generate, upon expansion in $\epsilon$, all possible combinations that you are looking for. Degree of $\epsilon$ corresponds to the number of single-digit numbers that you want, e.g.

$$f=1+\epsilon(x+y+z+t)+\epsilon^2(x^2+y^2+t^2+x\,y+x\,z+x\,t+y\,z+y\,t+z\,t)+\ldots$$

The trick is in observation that e.g. $\frac{1-x^4}{1-x}=1+x+x^2+x^3$, so the generating function knows that you have exactly three "$7$"'s, and in your combinations you can pick 0,1,2, or 3 of them, etc.

If you put $x=y=z=t=1$, you get the function which counts dimensions:

$$f_{\rm dim}(\epsilon)=\frac{(1-\epsilon^4)^2(1-\epsilon^3)(1-\epsilon^2)}{(1-\epsilon)^4}=1+4\epsilon+9\epsilon^2+15\epsilon^3+19\epsilon^4+\ldots$$

So, we got 15 different lists of 3 elements, 19 different lists of 4 elements etc. And we confirmed that you found all lists of 3 elements!

In general, if you have $n$ distinguished letters (single-digit numbers), and the $k$'th letter repeats $N_k$ times, then the generating function for the number of possible combinations reads

$$ f_{\rm dim}(\epsilon)=\prod_{k=1}^n\frac{1-\epsilon^{N_k+1}}{1-\epsilon} $$

Any modern symbolic computer software will perform Taylor expansion of this expression in no time.

Vel
  • 216
  • pretty cool stuff! Would you mind explaining a couple items? When you say "...upon expansion in epsilon", is this a Taylor expansion? I.e. how exactly did you get the expression right before you say "The trick is..."? Secondly, what is this "trick" called? I've seen in before but completely forgotten about it. Do you know where I can look for more into that? – bcf Dec 17 '13 at 03:17
1

Suppose we have $N$ balls colored $n$ different colors. For each color $k$, let $d_k$ be the number of balls of color $k$. Our goal is to find the number $a_r$ of ways to choose $r\leq N$ balls without repetition and ignoring order, where balls of the same color are considered identical. Now, any such choice of $r$ balls is completely determined by how many balls of each color it has. In other words, we're reduced to finding the number of $n$-tuples $(e_1,\ldots,e_n)$ of non-negative integers satisfying

  1. $e_k\leq d_k$ for all $k$, and
  2. $e_1+\cdots+e_k=r$.

Here's where we make use of a really nice algebraic trick: consider the product of polynomials $$f(X)=\prod_{k=1}^n\left(1+X+X^2+\cdots+X^{d_k}\right).$$ Expanding this out, we get $$\begin{align*} f(X) &= \left(\sum_{j_1=0}^{d_1}X^{j_1}\right)\cdots\left(\sum_{j_n=0}^{d_n} X^{j_n}\right)\\ &= \sum_{j_1=0}^{d_1}\cdots\sum_{j_n=0}^{d_n} X^{j_1+\cdots +j_n}, \end{align*}$$ so the coefficient of $X^r$ is $$\sum_{j_1+\cdots+j_n=r}1,$$ where $j_k$ is required to be less than or equal to $d_k$ for all $k$. But this is exactly $a_r$. Thus, all we need to do is find a nice representation of the coefficients of $f(X)$.

To do this, recall that $1+X+X^2+\cdots+X^m=(1-X^{m+1})/(1-X)$ for all $m$, and that $(1-X)^{-n}=\sum_{r=0}^\infty \binom{n+r-1}{n-1}X^r$. Then $$\begin{align*} f(X) &= \frac{(1-X^{d_1+1})\cdots(1-X^{d_n+1})}{(1-X)^n}\\ &= (1-X^{d_1+1})\cdots(1-X^{d_n+1})\left[\binom{n-1}{n-1}+\binom{n+1-1}{n-1}X + \binom{n+2-1}{n-1}X^2+\cdots\right]. \end{align*}$$ Now, $(1-X^{d_1+1})\cdots(1-X^{d_n+1})$ expands to $$ 1- \sum_{k=1}^n X^{d_k+1} + \sum_{k_1,k_2=1}^n X^{d_{k_1}+d_{k_2}+2} - \cdots + (-1)^n\sum_{k_1,\ldots,k_n=1}^n X^{d_{k_1}+\cdots+d_{k_n}+n}, $$ where in each sum, the $k_i$'s are required to be distinct. To multiply this together with the series in brackets, let's figure out what happens when we multiply the series in brackets with a single guy of the form $X^s$, where $s$ is a positive integer. Well, $$\begin{align*} X^s\cdot\frac{1}{(1-X)^n} &= X^s\left[\binom{n-1}{n-1}+\binom{n+1-1}{n-1}X + \binom{n+2-1}{n-1}X^2+\cdots\right]\\ &= \binom{n-1}{n-1}X^s+\binom{n+1-1}{n-1}X^{s+1} + \binom{n+2-1}{n-1}X^{s+2}+\cdots\\ &= \binom{n+s-s-1}{n-1}X^s + \binom{n+s+1-s-1}{n-1}X^{s+1} + \binom{n+s+2-s-1}{n-1}X^{s+2}\cdots\\ &= \sum_{r=s}^\infty \binom{n+r-s-1}{n-1}X^r. \end{align*}$$ But when $\binom{n+r-s-1}{n-1}=0$ whenever $r<s$ (by the definition of the binomial coefficient), so we can tack on all the $r<s$ terms to the above series expression and not change anything: $$X^s\cdot\frac{1}{(1-X)^n} = \sum_{r=0}^\infty \binom{n+r-s-1}{n-1}X^r.$$

Finally, returning to our expansion of $(1-X^{d_1+1})\cdots(1-X^{d_n+1})$ and multiplying by the series, we get that the $r$th coefficient of $f(X)$, i.e. $a_r$, is $$a_r= 1- \sum_{k=1}^n \tbinom{n+r-d_k-2}{n-1} + \sum_{k_1,k_2=1}^n \tbinom{n+r-d_{k_1}-d_{k_2}-3}{n-1} - \cdots + (-1)^n\sum_{k_1,\ldots,k_n=1}^n \tbinom{n+r-d_{k_1}-\cdots-d_{k_n}-n-1}{n-1},$$ where, as before, in each sum, the $k_i$'s are required to be distinct.

Avi Steiner
  • 4,209
0

So lets express your digits along with multiplicity in the following way:$7^3,5^2,3,2^3$

The number of was to pick n assuming there where infinite choices is $\binom{3+n}{3}$ (see stars and bars).

and to these substract the combinations that don't satisfy at least one of the regulations.

And to see which ones don't satisfy at least one of the number limits you need to count the ones that only break limitations on only 1 digit by inclusion-exclusion, then the ones tha break limitations on only 2 limits, 3 limits and finally the ones that break all three limits.

See this question to get an idea: Enumerating number of solutions to an equation

I don't think there is a nicer solution.

Asinomás
  • 105,651