# Proof of the generating function of $1 -2x +3x^2 -4x^3+5x^4-6x^5+\cdots$

The ordinary generating function for the sequence $\{a_n\}_{n\geq0}$ where $a_n = (-1)^n\,n$ is

$$1 -2x +3x^2 -4x^3+5x^4-6x^5+\cdots = \frac{1}{(x+1)^2}$$

I can see from the geometric formula, and even from long division that

$$1 -x +x^2 -x^3+x^4-x^5+\cdots = \frac{1}{1+x}$$

but I'm not seeing the coefficients to explain $\frac{1}{(x+1)^2}.$

$$S_n = 1 -2x +3x^2 -4x^3+5x^4-6x^5+\cdots$$ $$\implies xS_n = x - 2x^2 + 3x^3 -\cdots$$ $$(1+x)S_n=1-x+x^2-x^3\cdots=\frac{1}{1+x}$$
$$S=1 -x +x^2 -x^3+x^4-x^5+\cdots = \frac{1}{1+x}$$ Take the derivative $$S'=0 -1 +2x -3x^2+4x^3-5x^4+\cdots = \frac{-1}{(1+x)^2}$$ Multiply by $-1$ $$-S'=1 -2x +3x^2-4x^3+5x^4+\cdots = \frac{1}{(1+x)^2}$$ $$\sum_{k=0}(-1)^k(k+1)x^k = \frac{1}{(1+x)^2}$$
$\dfrac1{1-x} =\sum_{n=0}^{\infty} x^n$.
$\begin{array}\\ \dfrac1{(1-x)^2} &=\sum_{n=0}^{\infty} x^n\sum_{m=0}^{\infty} x^m\\ &=\sum_{n=0}^{\infty}\sum_{m=0}^{\infty} x^{m+n}\\ &=\sum_{k=0}^{\infty}\sum_{m=0}^{k} x^{k}\\ &=\sum_{k=0}^{\infty} x^{k}\sum_{m=0}^{k}1\\ &=\sum_{k=0}^{\infty}(k+1) x^{k}\\ \text{so}\\ \dfrac1{(1+x)^2} &=\sum_{k=0}^{\infty}(k+1)(-1)^k x^{k}\\ \end{array}$