Generating function with quadratic coefficients. $h_k=2k^2+2k+1$. I need the generating function $$G(x)=h_0+h_1x+\dots+h_kx^k+\dots$$ I do not have to simplify this, yet I'd really like to know how Wolfram computed this sum as $$\frac{x(2x^2-2x+5}{(1-x)^3}$$ when $|x|<1$. Rewrite Wolfram's answer as $$x(2x^2-2x+5)(1+x+x^2+\dots)^3=x(2x^2-5x+2)(1+2x+3x^2+\dots)(1+x+x^2+\dots),$$ but how would this give $G$?
 A: I don't know for sure how W|A did it specifically, but here's a hint for how I'd do it:
$$\left(x\frac{d}{dx}\right)^nx^k=k^nx^k\quad\implies\quad\left(x\frac{d}{dx}\right)^n\sum_{k\ge0}a_kx^k=\sum_{k\ge0}a_kk^nx^k$$
Specifically for $k=0,1,2$ and the generating function $(1-x)^{-1}$. This should allow you to obtain the desired generating function simply by applying algebraic manipulations and differentiation to rational functions. More generally for any polynomial $P$ we have
$$f(x)=\sum_{k\ge0}a_kx^k\implies P\left(x\frac{d}{dx}\right)f(x)=\sum_{k\ge0}a_kP(k)x^k.$$
Note that by $\left(x\frac{d}{dx}\right)^n$ I mean the differential operator $x\frac{d}{dx}$ applied $n$ times, so e.g.
$$\left(x\frac{d}{dx}\right)^2f(x)=x\frac{d}{dx}\left[x\frac{d}{dx}f(x)\right]=xf'(x)+x^2f''(x).$$
A: One way to do it is to start with the fact that, by the binomial theorem, for all $j\ge 0$,
$$
\sum_{k\ge 0} \binom{k+j}{j} x^k=(1-x)^{-(j+1)}. \qquad (*)
$$
Then, rewrite $h_k$ as a sum of binomial coefficients:
$$
h_k = 4 \binom{k+2}{2}-4\binom{k+1}{1}+\binom{k}{0}.
$$
Adding up appropriate multiples of $(*)$ gives you the generating function
$$
\sum_{k\ge 0} h_k x^k=4 (1-x)^{-3}-4(1-x)^{-2}+(1-x)^{-1}=\frac{(x+1)^2}{(1-x)^3}.
$$
A: $$\sum_{k=0}^{\infty} x^k = \frac{1}{1-x}$$
$$\sum_{k=0}^{\infty}k x^k = \frac{x}{(1-x)^2}$$
$$\sum_{k=0}^{\infty}k^2 x^k = \frac{x(1+x)}{(1-x)^3}$$
$$G(x) = \sum_{k=0}^{\infty} (2 k^2+2 k+1) x^k$$
Combine the above expressions as defined by $G(x)$ and you should reproduce Wolfram.
