I have been looking at This Problem and Answer about generating functions. The problem asked for the generating function of: $$a_n=4a_{n-1}-4a_{n-2}+{n\choose 2}2^n+1$$ I understand how Ron Gordon simplified it to: $$\sum_{n=2}^{\infty} (a_n-4 a_{n-1}+4 a_{n-2}) x^n = \sum_{n=2}^{\infty} n(n-1)2^{n-1} x^n + \sum_{n=2}^{\infty} x^n$$ and where he defined the generating function as: $$g(x) = \sum_{n=0}^{\infty} a_n x^n$$but then he broke the summation into $3$ seperate summations and this is where I start to get messed up. I do understand in the first summation how we can get: $$\sum_{n=2}^\infty a_nx^n=\sum_{n=0}^\infty a_nx^n-(a_0+a_1x)$$I don't understand the next two summations though.
Question:
1) In the second and third summation where did the $x$ and $x^2$ come from?
2) Do you always multiply by $x^n$ in generating functions? or does it change?
3) I believe I remember my professor saying that every generating function would always be $f(x)=\sum_{n=0}^na_nx^n$ but why is that the case?
4) I guess my overall trouble is understanding what the goal of a generating function is.
Any help would be much appreciated!
(I have looked at other questions, but I can't find a clear answer. So if there is one out there that I missed that answers this I'd be happy to delete my question. Thanks.)
First, we want to manipulate things so that the subscript of the coefficients matches the exponents: \begin{align*} \textsf{LHS} &= \sum_{n=2}^{\infty}a_nx^n - 4\sum_{n=2}^{\infty}a_{n-1}x^n + 4 \sum_{n=2}^{\infty}a_{n-2}x^n \\ &= \sum_{n=2}^{\infty}a_nx^n - 4x\sum_{n=2}^{\infty}a_{n-1}x^{n-1} + 4x^2 \sum_{n=2}^{\infty}a_{n-2}x^{n-2} \\ \end{align*} Next, we want to make a change of variables so that each summation involves $a_nx^n$. Let $s := n - 1$ for the second summation and let $t := n - 2$ for the third summation. Then $s$ ranges from $1$ to $\infty$ and $t$ ranges from $0$ to $\infty$. After making this substitution, we can switch back to $n$ by letting $n := s$ for the second summation and $n := t$ for the third summation. This part might seem weird, but just remember that the the indexing variable is just a dummy variable that can be replaced however we like (provided that the new variables are still nonnegative integers): \begin{align*} \textsf{LHS} &= \sum_{n=2}^{\infty}a_nx^n - 4x\sum_{s=1}^{\infty}a_{s}x^{s} + 4x^2 \sum_{t=0}^{\infty}a_{t}x^{t} \\ &= \sum_{n=2}^{\infty}a_nx^n - 4x\sum_{n=1}^{\infty}a_{n}x^{n} + 4x^2 \sum_{n=0}^{\infty}a_{n}x^{n} \\ \end{align*} Next, we want to make all the summation indices start from $0$: \begin{align*} \textsf{LHS} &= \left[\sum_{n=0}^{\infty}a_nx^n - a_0 - a_1x \right] - 4x \left[\sum_{n=0}^{\infty}a_{n}x^{n} - a_0 \right] + 4x^2 \left[\sum_{n=0}^{\infty}a_{n}x^{n} \right] \\ &= (1 - 4x + 4x^2)\sum_{n=0}^{\infty}a_{n}x^{n} + (4a_0 - a_1)x - a_0 \\ &= (1 - 4x + 4x^2)g(x) + 3x - 1 \\ \end{align*}
Thus, provided that we can also simplify the right hand side, it follows that: $$ g(x) = \frac{\textsf{RHS} - (3x - 1)}{1 - 4x + 4x^2} $$ which can hopefully be expressed in the form $\sum a_n x^n$ to get our desired coefficients $a_n$.