<s>[INST] What is this sum $\sum_{i=0}^{n-1}\sum_{j=0}^{i}x^i$? How to find this sum ?
$$\sum_{i=0}^{n-1}\sum_{j=0}^{i}x^i$$
without knowing this sum:
$$\sum_{i=1}^{n}ix^{i-1} = \frac{nx^{n+1}-(n+1)x^n+1}{(x-1)^2}$$
 [/INST] You have $$\sum_{i=1}^{n}ix^{i+1}=\sum_{i=0}^{n-1}(i+1)x^i$$
$$=\sum_{i=1}^{n-1} \underbrace{(1+1+...+1)}_{i+1\text{ times}}x^{i}$$
$$=\sum_{i=1}^{n-1}\sum_{j=0}^{i}x^i.$$
It is a geometric series so we have $$\sum_{i=0}^{n}x^{i}=\frac{1-x^{n+1}}{1-x}$$
Thus $\sum_{i=1}^{n}ix^{i-1}=\frac{d}{dx}\big(\frac{x^{n+1}-1}{x-1}\big)=\frac{nx^{n+1}-(n+1)x^n+1}{(x-1)^2}$ which is valid for $x\neq 1$.
If you didn't have this sum then  $$S=\sum_{i=1}^{n}ix^{i-1}=1+2x+3x^2+4x^3+...+(n-1)x^{n-2}+nx^{n-1}$$
$$x^2S=x^2+2x^3+3x^4+4x^5+...+(n-2)x^{n-1}+(n-1)x^{n}+nx^{n+1}$$
$$-2xS=-2x-4x^2-6x^3-8x^4-...-2(n-1)x^{n-1}-2nx^{n}$$
Now adding the above you have $$S(x^2-2x+1)=1+nx^{n+1}+(n-1)x^n-2nx^n=nx^{n+1}-(n+1)x^n+1$$
Thus $$S=\frac{nx^{n+1}-(n+1)x^n+1}{(x-1)^2}$$
</s>