16

How can I find the number of $k$-permutations of $n$ objects, where there are $x$ types of objects, and $r_1, r_2, r_3, \cdots , r_x$ give the number of each type of object?

I'm still looking for the solution to this more general problem out of interest.

Here is an example with $n = 20, k = 15, x = 4,$ $ r_1 = 4 \quad r_2 = 5 \quad r_3 = 8 \quad r_4 = 3$.

I have 20 letters from the alphabet. There are some duplicates - 4 of them are a, 5 of them are b, 8 of them are c, and 3 are d. How many unique 15-letter permutations can I make?

Edits:

I've done some more work on this problem but haven't really come up with anything useful. Intuition tells me that as Douglas suggests below there will probably not be an easy solution. However, I haven't been able to prove that for sure - does anyone else have any ideas?

I've now re-asked this question on MO.

Cam
  • 1,328

4 Answers4

5

There's probably not going to be an easy way to do this... Consider two different examples of 15-letter "permutations". Then the number of permutations with that multiset of digits depends on the proportions of the chosen digits.

If you really want to do this, you can sum $k!/(s(1)! s(2)! \cdots s(x)!)$ (called the mulitnomial coefficient) over all partitions of $s(1)+s(2)+ \cdots +s(x)=k$ [in this partition s(i) is allowed to be zero and order is important] such that $s(i) \leq r(i)$ for all i. The part s(i) says you have s(i) copies of the i-th letter. The number of permutations with s(i) i-th letters is given as above, by the Orbit Stabiliser Theorem.

Although, this is only one step better than the caveman's counting formula: sum_P 1 where P is the set of permutations you want to count. I.e. just count them one-by-one.

EDIT: While I'm making a few touch-ups, here's GAP code that implements the above formula.

NrPermIdent:=function(k,T)
  local PSet,x;
  x:=Size(T);
  PSet:=Filtered(OrderedPartitions(k+x,x)-1,p->ForAll([1..x],i->p[i]<=T[i]));
  return Sum(PSet,p->Factorial(k)/Product(p,i->Factorial(i)));
end;;

where T is a list of bounds and k is the number of terms in the partition.

For example:

gap> NrPermIdent(15,[4,5,8,3]);
187957770

As another indication that finding a simple formula for these numbers is not going to be easy, observe that NrPermIdent(n,[n,k]) is equal to $\sum_{0 \leq i \leq k} {n \choose k}$ (which is considered a difficult sum to find -- see: https://mathoverflow.net/questions/17202/). I remember reading somewhere (most likely in A=B) that you can prove there is no "closed-form" solution for this.

4

Consider the sum defined by $$ \begin{align} &\sum_{k=0}^\infty s_k\frac{x^k}{k!}\\ &=\textstyle\underbrace{\left(1{+}x{+}\dots{+}\frac{x^8}{8!}\right)}_{\substack{\text{the exponent of $x$}\\\text{is the number of c's}}}\underbrace{\left(1{+}x{+}\dots{+}\frac{x^5}{5!}\right)}_{\substack{\text{the exponent of $x$}\\\text{is the number of b's}}}\underbrace{\left(1{+}x{+}\dots{+}\frac{x^4}{4!}\right)}_{\substack{\text{the exponent of $x$}\\\text{is the number of a's}}}\underbrace{\left(1{+}x{+}\dots{+}\frac{x^3}{3!}\right)}_{\substack{\text{the exponent of $x$}\\\text{is the number of d's}}}\tag1 \end{align} $$ A typical term in the product that contributes to $s_{15}\frac{x^{15}}{15!}$ is $\frac{x^7}{7!}\cdot\frac{x^2}{2!}\cdot\frac{x^3}{3!}\cdot\frac{x^3}{3!}$ which adds $\frac{15!}{7!\,2!\,3!\,3!}$ to $s_{15}$. This accounts for all permutations with $7$ c's and $2$ b's and $3$ a's and $3$ d's. Adding up over all the collections of exponents that sum to $15$, we get that $s_{15}$ accounts for all the permutations of $15$ of the $20$ letters.

That is, define the exponential generating function of the indicator function for the set $\{i\in\mathbb{Z}:0\le i\le j\}$: $$ P_j(x)=\sum_{i=0}^j\frac{x^i}{i!}\tag2 $$ then the number you are looking for is $$ \underbrace{15!\left[x^{15}\right]}_\text{extract $s_{15}$}\underbrace{P_8(x)P_5(x)P_4(x)P_3(x)\vphantom{\left[x^{15}\right]}}_\text{product from $(1)$}=187957770\tag3 $$


Mathematica code

Define

f = Sum[x^k/k!,{k,0,#}]&

f[j] gives $P_j(x)$ from $(2)$. Then f/@{8,5,4,3} gives the list of $P_j(x)$'s from $(1)$. Times@@f/@{8,5,4,3} computes their product. Thus,

15! Coefficient[Times@@f/@{8,5,4,3},x,15]

gives the result from $(3)$.

robjohn
  • 345,667
  • I've read for extremely large polynomials, FFT polynomial multiplication can be used to bring the time complexity down. Does that sound plausible? – qwr Feb 12 '24 at 04:21
1

There are 20!/4!5!8!3! arrangements of the 20 alphabets. Consider the action of $S_5$ on the arrangements by permuting the last 5 digits. You want to compute the number of orbits. You can then try to do it by Burnside's formula. It is not difficult to do it at least for this case, since if a permutation of $S_5$ fixes an arrangement, it means that each cycle of the permutation corresponds to a color.

For the general case, I suspect that Polya's enumeration theorem can do it, though I'm not certain.

  • This seems to be a just a change of variables: you can instead sum over t(1)+t(2)+...+t(x)=n-k where t(i)=r(i)-s(i). [in this partition t(i) is allowed to be zero] Actually, as it stands, it's even more complicated than that, since you're summing over partitions of {16..20} corresponding to the cycles of permutations, then assigning letters a..d to the parts in such a way as to not create too many copies of a single letter. – Douglas S. Stones Aug 31 '10 at 05:49
0

The answer by robjohn gives a method to compute the answer to this question using Mathematica, or any computer algebra system that can multiply polynomials. Here is a different algorithmic approach, which is slower than robjohn's approach, but conceptually more simple and possibly easier to implement.

For each $i\in \{1,2,\dots,x\}$, and each $j\in \{0,1,\dots,k\}$, let $$ A(i,j)= \begin{matrix} \text{number of arrangements of $j$ items from an urn with $i$ colors of tokens,}\\\text{with $r_1$ tokens of the first color, $r_2$ of the second color, ... , $r_i$ of the $i^\text{th}$ color} \end{matrix} $$ The answer to your problem is $A(x,k)$, while $A(i,j)$ is a simpler problem when $i<x$ and $j<k$. These subproblems satisfy the following recursive equation: $$ A(i,j) = \sum_{s=0}^{\min(j,a_i)} \binom{j}{s}A(i-1,j-s)\\ A(1,j)=\begin{cases}1 & 0\le j\le r_1 \\ 0 & r_1< j\end{cases} $$ The idea is that in order to count the number of arrangements of $j$ items using the first $i$ colors, you consider all the possibilities for the number of times color $i$ is chosen. If color $i$ appears $s$ times, then you can place those $s$ tokens in the sample in $\binom js$ ways, and then fill in the remaining $j-s$ spots with the first $i-1$ colors in $A(i-1,j-s)$ ways.

This recursive equation lets you compute $A(n,m)$ by filling out a $x\times (k+1)$ dynamic programming table, whose entry in the $i^{th}$ row and $j^{th}$ column is $A(i,j)$. Since there are $O(kx)$ entries, and each entry is a summation of $O(k)$ terms, the time this takes is $O(k^2x)$. The time this takes gets unwieldly pretty quickly.

Mike Earnest
  • 75,930