Combinatorics – How to Use Generating Functions to Find Letter Permutations

combinatoricsgenerating-functionspermutations

I have been going through this example to understand how to use generating functions.

Here is the question:

How many 6-letter permutations can be formed using only the letters of the word, MISSISSIPPI?

And here is the answer:

$\begin{equation}
6!\left(1 + \frac{x}{1!}\right)\left(1 + \frac{x}{1!} + \frac{x^2}{2!}\right)\left(1 + \frac{x}{1!} + \frac{x^2}{2!} + \frac{x^3}{3!} + \frac{x^4}{4!}\right)^2
\end{equation}$

Now, we wrote the term (1+x) because we only have 1 M. Again, we wrote the 2nd term because we have 2 P's, and so on. I understand why the exponential terms are written this way. However, I don't really understand how the exponential terms we wrote are derived from the generating functions.

For a sequence $a_n$, we can define an exponential generating function

$F(x)=\sum_{}a_n\frac{x^n}{n!}$.

If I tried to solve this problem, I would try to find an equation for $F(x)$, then find the coefficient of $\frac{x^n}{n!}$ so that I could find a value for $a_n$ (like when we want to find explicit formulas using a recursive formula). But that is not what we did in the previous solution, isn't it? We expanded each exponential summation until the number of occurrence of each letter and we multiplied them. I don't get the logic/intuition of this process.

Best Answer

Here we extract the coefficient of the product of four generating functions in order to obtain the wanted number of $6$-letter words. Let's take a closer look at this problem. We can explicitly label the terms with the corresponding letters.

  • We are looking for $6$-letter words which contains at most one $M$. This can be represented as \begin{align*} F_M(x)=\sum_{i=0}^1 M^i\frac{x^i}{i!}=1+Mx \end{align*} where we label the number of occurrences of the letter $M$ explicitly by a corresponding power of $M$.

  • Since the $6$-letter word can have zero, one or two $P$, we can write this as \begin{align*} F_P(x)=\sum_{j=0}^2 P^j\frac{x^j}{j!}=1+Px+P^2\frac{x^2}{2!} \end{align*} where we label the number of occurrences of the letter $P$ by a power of $P$.

  • Since the $6$-letter word can have up to $4$ $S$, we can write this as \begin{align*} F_S(x)=\sum_{l=0}^4 S^l\frac{x^l}{l!}=1+Sx+S^2\frac{x^2}{2!}+S^3\frac{x^3}{3!}+S^4\frac{x^2}{4!} \end{align*}

  • Finally, since the $6$-letter word can have up to $4$ $I$, we can write this as \begin{align*} F_I(x)=\sum_{k=0}^4 I^k\frac{x^k}{k!}=1+Ix+I^2\frac{x^2}{2!}+I^3\frac{x^3}{3!}+I^4\frac{x^2}{4!} \end{align*}

Denoting the coefficient of $x^n$ of a power series with $[x^n]$ we are looking for \begin{align*} \color{blue}{6!}&\color{blue}{[x^6]\left(F_M(x)F_P(x)F_I(x)F_S(x)\right)}\\ &=6![x^6](1+Mx)\left(1+Px+P^2\frac{x^2}{2!}\right)\left(1+Sx+S^2\frac{x^2}{2!}+S^3\frac{x^3}{3!}+S^4\frac{x^4}{4!}\right)\\ &\qquad\qquad\cdot\left(1+Ix+I^2\frac{x^2}{2!}+I^3\frac{x^3}{3!}+I^4\frac{x^4}{4!}\right)\\ &=\frac{6!}{0!0!3!3!}S^3I^3+\frac{6!}{0!1!2!3!}PS^2I^3+\frac{6!}{1!0!2!3!}MS^2I^3\\ &\qquad\qquad+\cdots+\frac{6}{1!2!3!0!}MP^2S^3\tag{1} \end{align*}

In (1) we see how many different $6$-letter words with a specific number of occurrences of each of the letterr $M,P,I,S$ can occur. We observe we have the product of $four$ generating functions of the form $\sum_{n=0}^{\infty}a_n\frac{x^n}{n!}$ to consider. Since the number of occurrences of each letter is small, we do not have an upper limit $\infty$ but a small number instead, resulting in polynomials.

But, in fact we do not need to differentiate between different representatives as in (1), since we are only interested by the total number of admissible $6$-letter words. We can therefore consider the simpler generating functions by setting the coefficients $M=P=S=I=1$ and we get \begin{align*} G_M(x)&=1+x,\quad G_P(x)=1+x+\frac{x^2}{2!},\\ G_S(x)&=G_I(x)=1+x+\frac{x^2}{2!}+\frac{x^3}{3!}+\frac{x^4}{4!} \end{align*} We therefore calculate \begin{align*} \color{blue}{6![x^6]}&\color{blue}{\left(G_M(x)G_P(x)G_S(x)G_I(x)\right)}\\ &=6![x^6]\left((1+x)\left(1+x+\frac{x^2}{2!}\right)\left(1+x+\frac{x^2}{2!}+\frac{x^3}{3!}+\frac{x^4}{4!}\right)^2\right)\\ &=\cdots\\ &\,\,\color{blue}{=1\,610} \end{align*}