I would like to find the generating function solution for the following combinatorics/probability problem. I have a combinatorial solution and the generating function deduced thereof. But I can not fathom the direct interpretation of it. I would like to reverse the current solving process and directly deduce the following or some other generating function, then get the relevant coefficient as the solution.
In a stack of $W$ white cards, $G$ green cards and $R$ red cards, what is the number of arrangement for no green card is next to a red card?
One solution is to view the $W$ white cards as dividers and leaving $W+1$ slots in between them together with both ends. For each $r\in \{1,2,\dots,R\}$ and $g\in\{1,2,\dots, G\}$, designate non-overlappingly $r$ slots for inserting the red cards and $g$ slots for the green cards. There are ${W+1\choose r,g}$ combinations. For each of these combinations, we insert $R$ red cards into the previously designated $r$ red slots, and there are ${R-1\choose r-1}$ ways of insertion. Do the same for the $g$ green cards and there are ${G-1\choose g-1}$ ways of insertion. Multiplying them and summing over $r$ and $g$, we arrive at the desired total number of arrangements:
$$\sum_{r=1}^R\sum_{g=1}^G{W+1\choose r,g}{R-1\choose R-r}{G-1\choose G-g}.$$
But this is the coefficient of $x^Ry^G$ in $(1+x+y)^{W+1}(1+x)^{R-1}(1+y)^{G-1}$.
Now how do I deduce this generating function directly from the problem?
(The notations are slightly changed here)
We may use a directed graph for such pattern avoiding problems.
Write the matrix as
\begin{align*} A = \left(\begin{array}{r|rrr} & W & G & R \\ \hline W & w & g & r \\ G & w & g & 0 \\ R & w & 0 & r \\ \end{array}\right) \end{align*}
$W,G,R$ are the states to indicate the three colors and $w,g,r$ are the formal variables to indicate the colors.
To obtain the recurrence formula, find the characteristic polynomial,
$$x^{3} - \left(g + r + w\right) x^{2} + g r x + g r w = 0$$
If we indicate $F(a,b,c)$ as the number of ways to arrange the cards, where a,b,c are the number of white, green and red cards respectively, then $$F(a,b,c) = F(a-1,b,c)+F(a,b-1,c)+F(a,b,c-1)-F(a,b-1,c-1)-F(a-1,b-1,c-1)$$ and set the necessary boundary conditions
To obtain the generating function, find $$\left(I-x\, A\right)^{-1}$$ Each entry will have a g.f. for that entry, and we require the sum of the first row, which is
$$G(x) =\frac{1-g\, r\, x^{2}}{1\, -\, {\left(g\, +\, r\, +\, w\right)+\, g\, r\, x^{2}+g\, r\, w\, x^{3}}}$$
If there are $n=a+b+c$ cards in total, find $[x^n]$ and find the required $[w^a\, g^b\, r^c]$
Richard Stanley's "Enumerative combinatorics" discusses such methods (transfer matrices)