# Exponential generating function and number of balls

Use exponential generating functions to determine the number $a_n$ of ordered choices of $n$ balls such that there are $2$ or $4$ red balls, an even number of green balls, and an arbitrary number of blue balls.

If we denote red with $r$, green with $g$, and blue with $b$. I guess we will have $r^2 + r^4$ for red balls, $1 + b + b^2 + \ldots = \frac{b}{1-b}$ for blue balls. But how can I express the green balls, and how can I then solve the problem using exponential generating functions?

Exponential generating functions are useful for this sort of problem because we can find the answer by multiplying the EGF for each of the types of balls: $$\color{red}{\left(\frac{x^2}{2!}+\frac{x^4}{4!}\right)}\color{green}{\frac12\left(e^x+e^{-x}\right)}\color{blue}{e^x}.$$ This expands to $$\frac12\cdot\frac{x^2}{2!} + \frac12\cdot\frac{x^4}{4!} + \sum_{n=2}^\infty \frac1{16}2^nn(n-1)\frac{x^n}{n!} + \sum_{n=4}^\infty\frac1{768}2^nn(n-1)(n-2)(n-3)\frac{x^n}{n!}.$$ Simplification yields $$\frac{x^2}{2!}+3\frac{x^3}{3!}+13\frac{x^4}{4!} + \sum_{n=5}^\infty \frac1{768} 2^nn(n-1)(n^2-5n+54)\frac{x^n}{n!}.$$ Hence $$a_n =\begin{cases} 1,& n=2\\ 3,& n=2\\ 13,& n=4\\ \frac1{768} 2^nn(n-1)(n^2-5n+54),& n\geqslant 5. \end{cases}$$