<s>[INST] Generatingfunctionology Chapter 1 Exercise 1.c Regarding the exercises of the Generatingfunctionology book available at (https://www2.math.upenn.edu/~wilf/DownldGF.html).
In particular Chapter 1, Exercise 1.(c), which asks to find the ordinary power series generating function of
$$a_n = n^2.$$
Following the method explained in the book (Page 8 "The Method"), I define $A(x) = \sum_n a_n x^n$ and arrive (by multiplying by $x^n$ and summing over $n$ both sides) at:
$$(LHS) \quad \sum_n a_n x^n = A(x)$$
$$(RHS) \quad \sum_n n^2 x^n $$$$= \sum_n (x^2 \frac{d^2}{dx^2} + x \frac{d}{dx}) x^n $$$$= (x^2 \frac{d^2}{dx^2} + x \frac{d}{dx}) \sum_n x^n $$$$= (x^2 \frac{d^2}{dx^2} + x \frac{d}{dx})  \frac{1}{1-x}$$
The solution in the book (Page 197) states that I should arrive at $(x D)^2 \frac{1}{1-x}$ which I assume means $(x^2 \frac{d^2}{dx^2})\frac{1}{1-x}$. And it appears I have this $x \frac{d}{dx}$ term, which I shouldn't.
However, $(x^2 \frac{d^2}{dx^2}) x^n \neq n^2 x^n$, actually $(x^2 \frac{d^2}{dx^2}) x^n = (n^2 - n) x^n$, which is exactly why I added the term  $x \frac{d}{dx}$ in the first place to remove the $- n x^n$ that shouldn't be there.
Anyway, I'd appreciate any help that you could give me regarding why my solution does not match the book solution.
 [/INST] $\left(x^2 \frac{d^2}{dx^2} + x \frac{d}{dx}\right)\left(\frac{1}{1-x}\right)$
gives
$2x^2\left(\frac{1}{1-x}\right)^3+x\left(\frac{1}{1-x}\right)^2$
$(xD)^2$ differentiates in two stages.
$(xD)(xD)\left(\frac{1}{1-x}\right)$
$=(xD)x\left(\frac{1}{1-x}\right)^2$
$=x\left(2x\left(\frac{1}{1-x}\right)^3+\left(\frac{1}{1-x}\right)^2\right)$
so they are equal. ($D=\frac{d}{dx}$, so $xD(xD)=x(xD'+D)$, as we started with).
</s>