This may seem like a pretty basic question, but I am struggling to find a nice way of expressing $(1+x+\cdots+x^{n-1})^2$ where $n\in\mathbb{Z}_{\geq 2}$. Plugging in some numbers yields a clear pattern,
$(1+x+\cdots+x^{n-1})^2=1+2x+\cdots+nx^n+\cdots+2x^{2n-3}+x^{2n-2}.$
However, I can't seem to find a formal expression of this, or a proof. Can anyone point me in the right direction?
So you can notice that there is a very nice elementary formula for partial sum of geometric progression, i.e. $$ \sum_{i=0}^{n-1} x^i = \frac{1-x^n}{1-x} $$ It comes from the following argument $$ \sum_{i=0}^{n-1} x^i (1-x) = \sum_{i=0}^{n-1} x^i - \sum_{i=0}^{n-1} x^{i+1} = 1 - x^{n-1+1} = 1-x^n $$ Therefore you can square to obtain $$ \left( \sum_{i=0}^{n-1} x^i \right)^2 = \left( \frac{1-x^n}{1-x} \right)^2 = \frac{1+x^{2n} - 2x^n}{1+x^2-2x} $$