I'm considering the following sum: $$\sum\limits_{k=0}^n (k+1)\epsilon^k,$$ where $\epsilon=e^{\frac{2\pi i}{n}}$. I write the sum as $$\frac{\rm d}{{\rm d}\epsilon}\sum\limits_{k=0}^n \epsilon^{k+1}=\frac{\rm d}{{\rm d}\epsilon}\left(\epsilon+\epsilon^2+\ldots+\epsilon^n+\epsilon^{n+1}\right),$$ then write it as a sum of a geometric sequence: $$\frac{\rm d}{{\rm d}\epsilon}\left(\epsilon\frac{1-\epsilon^{n+1}}{1-\epsilon}\right),$$ which, after differentiation and using $\epsilon^n=1$, I find equal to $$\frac{1-(n+1)\epsilon}{1-\epsilon}.$$
But, as I know also that $\sum\limits_{k=1}^n \epsilon^k=0$, then $$\frac{\rm d}{{\rm d}\epsilon}\left(\epsilon+\epsilon^2+\ldots+\epsilon^n+\epsilon^{n+1}\right)=\frac{\rm d}{{\rm d}\epsilon}\left(0+\epsilon^{n+1}\right)=(n+1)\epsilon^n=n+1,$$ which is different than the previous result. Finally, I can do also $$\frac{\rm d}{{\rm d}\epsilon}\epsilon^{n+1}=\frac{\rm d}{{\rm d}\epsilon}\epsilon=1.$$
I think that the discrepancy between the last two results (i.e., $(n+1)$ and 1) comes from the fact that $\epsilon$'s form a cyclic group, and $\epsilon^{n+1}$ is like "outside" this group, but the derivative does not know that it should stay within the group. Still, why can't I use the fact that $\sum\limits_{k=1}^n \epsilon^k=0$ like I did in the second and third method?
I verified numerically that the first result: $\frac{1-(n+1)\epsilon}{1-\epsilon}$ is the correct one.
When you write the identity $$\sum\limits_{k=0}^n (k+1)\epsilon^k=\frac{\rm d}{{\rm d}\epsilon}\sum\limits_{k=0}^n \epsilon^{k+1}$$ you should make explicit that you only use the value of $\epsilon$ at the very end, i.e.
$$\sum\limits_{k=0}^n (k+1)\epsilon^k=\left[\frac{\rm d}{{\rm d}x}\sum\limits_{k=0}^n x^{k+1}\right]_{x=\epsilon}$$
If $x$ had a fixed value throuhout the calculation, it would make no sense to take derivative with respect to it.