Finding result of composing operations many times

Solution 1:

The coefficients are Stirling numbers of the second kind.

We can write $$P^n=\sum_{k=1}^n a_{n,k}x^k D^k$$ where $D=\frac d{dx}$. Then $$P^{n+1}=\sum_{k=1}^n a_{n,k}(xD)(x^k D^k) =\sum_{k=1}^n a_{n,k}(kx^k D^k+ x^{k+1} D^{k+1})$$ so that $$a_{n+1,1}=a_{n,1},$$ $$a_{n+1,n+1}=a_{n,n}$$ and $$a_{n+1,k}=a_{n,k-1}+ka_{n,k}$$ These recurrences are the same as for the Stirling numbers, so $$a_{n,k}=S(n,k).$$