<s>[INST] Generating functions - deriving a formula for the sum $1^2 + 2^2 +\cdots+n^2$ I would like some help with deriving a formula for the sum $1^2 + 2^2 +\cdots+n^2$ using generating functions. 
I have managed to do this for $1^2 + 2^2 + 3^2 +\cdots$ by putting
$$f_0(x) = \frac{1}{1-x} = 1 + x + x^2 + x^3 +\cdots$$
$$f_1(x) = x \frac{d}{dx}[f_0(x)] = \frac{1}{(1-x)^2} = 0 + x + 2x^2 + 3x^3 +\cdots$$
$$f_2(x) = x \frac{d}{dx}[f_1(x)] = \frac{x^2+x}{(1-x)^3} = 0^2 + 1^2x + 2^2x^3 + 3^2x^3+\cdots,$$
and I assume I'm supposed to be able to do something similar in this case, but things get trickier when it's bounded by n and I keep getting stuck.
 [/INST] Given a generating function $f(x)$ for $a_n$, the generating function for $\sum_{i=0}^n a_i$ is $\sum_{n\geq 0} (\sum_{i=0}^n a_i)x^n = (\sum_{n\geq 0} x^n)(\sum_{n\geq 0} a_nx^n) = \frac{1}{1-x} f(x)$.
In this case, we have $f(x) = \frac{x(1+x)}{(1-x)^3}$ as you mention, so the desired generating function is $\frac{x(1+x)}{(1-x)^4}$.  This has a partial fraction expansion:
$$\frac{x(1+x)}{(1-x)^4} = \frac{1}{(1-x)^2} - \frac{3}{(1-x)^3} + \frac{2}{(1-x)^4}$$
Since $1/(1-x)^{k+1}$ is the generating function for ${n+k}\choose{k}$ (we can see this by repeatedly differentiating $\frac{1}{1-x}$), this gives us:
$$1^2+2^2+\cdots+n^2 = {{n+1}\choose 1} - 3{{n+2}\choose 2} + 2{{n+3}\choose 3} = \frac{n(n+1)(2n+1)}{6}$$

By the way, we can avoid all this work with a good choice of basis.  Since $n^2 = {n \choose 0} - 3{{n+1}\choose 1} + 2{{n+2}\choose 2}$, we have:
$$\sum_{i=0}^n i^2 = \sum_{i=0}^n \left({i \choose 0} - 3{{i+1}\choose 1} + 2{{i+2}\choose 2}\right) = {{n+1}\choose 1} - 3{{n+2}\choose 2} + 2{{n+3}\choose 3}$$
All we need here is the sum $\sum_{i=0}^n {{i+k}\choose k} = {{n+k+1}\choose {k+1}}$, which follows from the simple generating functions identity $\frac{1}{(1-x)^k}\cdot \frac{1}{1-x} = \frac{1}{(1-x)^{k+1}}$.
</s>