<s>[INST] Exponential generating functions balls problem I had a question about an exercise that I couldn't solve on my exam.
It was the following:

You have 3 boxes. 1 with an unlimited amount of identical red balls, 1 with an unlimited amount of identical green balls and 1 with an unlimited amount of identical blue balls. We now draw n balls in order out of these boxes and make an ordered list of the drawn balls. 
Call:
  
  
*
  
*$A_n$ the number of possible lists of length n that contains at least 1 green ball
  
*$B_n$ the number of possible lists of length n that contains at least 2 blue balls
  
*$C_n$ the number of possible lists of length n that contains at least 1 green ball and at least 2 blue balls
  
*$D_n$ the number of possible lists of length n that contains at least 1 green ball or at least 2 blue balls
  
  
  1) Find the exponential generating function of those situations with a simple expression
2) Find $A_n$, $B_n$, $C_n$ and $D_n$. The sum taht you find has to be 196.

How could I solve this problem? 
Thanks in advance!
 [/INST] To start off, we can find the exponential generating function where the coefficient of $\frac{x^r y^g z^b}{n!}$ is the number of lists containing $r$ red balls, $g$ green balls, and $b$ blue balls, where $r + g + b = n$. This is given by
$$
\left(1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} + \cdots \right)
\left(1 + y + \frac{y^2}{2!} + \frac{y^3}{3!} + \cdots \right)
\left(1 + z + \frac{z^2}{2!} + \frac{z^3}{3!} + \cdots \right)
$$
which is just
$$
e^x e^y e^z = e^{x + y + z}.
$$
Plugging in $x = y = z$ (effectively, adding up the total number of balls in the exponent) gives the generating function for the total number of lists of size $n$, $e^{3x}$.
Then we modify the construction to get the answers to each part.


*

*For $A_n$,  we want $y^1$ to be the smallest allowed factor of $y$, so we instead multiply
$$
\left(1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} + \cdots \right)
\left(y + \frac{y^2}{2!} + \frac{y^3}{3!} + \cdots \right)
\left(1 + z + \frac{z^2}{2!} + \frac{z^3}{3!} + \cdots \right)
$$
to get $e^x (e^y - 1) e^z$. Plugging in $x = y = z$,
$$
\sum_{n \ge 0} A_n \frac{x^n}{n!} = e^{2x}(e^x - 1).
$$

*For $B_n$,  we want $z^2$ to be the smallest allowed factor of $z$, so we instead multiply
$$
\left(1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} + \cdots \right)
\left(y + \frac{y^2}{2!} + \frac{y^3}{3!} + \cdots \right)
\left(\frac{z^2}{2!} + \frac{z^3}{3!} + \cdots \right)
$$
to get $e^x e^y (e^z - z - 1)$. Plugging in $x = y = z$,
$$
\sum_{n \ge 0} B_n \frac{x^n}{n!} = e^{2x} (e^x - x - 1).
$$

*To get $C_n$, we use the power series in $y$ from $A_n$ and the power series in $z$ from $B_n$, to get $e^x (e^y - 1)(e^z - z - 1)$. Plugging in $x = y = z$,
$$
\sum_{n \ge 0} C_n \frac{x^n}{n!} = e^{x} (e^x - 1) (e^x - x - 1).
$$

*The easiest way to find $D_n$ is to notice that $D_n = A_n + B_n - C_n$. Hence, we have that
\begin{align*}
\sum_{n \ge 0} D_n \frac{x^n}{n!}
&= e^{2x}(e^x - 1) + e^{2x} (e^x - x - 1) - e^{x} (e^x - 1) (e^x - x - 1) \\
&= e^x\left(e^{2x} - x - 1 \right)
\end{align*}

All of the generating functions above can be found by a more direct method, if we notice that a list of $n$ balls is effectively the same as all the balls being labeled distinctly (say, by index in the list). Then $e^x$ is the generating function for 0 or more labeled balls of a specific color, $e^x - 1$ for one or more labeled balls of a color, and $e^x - x - 1$ for two or more labeled balls of a color. The generating functions for $A_n, B_n,$ and $C_n$ immediately follow.
For $D_n$, note that $e^{2x}$ counts collections of labeled balls of two colors, and we only want to exclude the case with exactly one blue and no greens and the case of none of each, so $e^{2x} - x - 1$ is the number of valid collections of blue and green balls, and then multiply by $e^x$ for red balls, to get $e^x(e^{2x} - x - 1)$.
</s>