Why are these $\sum \cos$ and $\csc$ equivalent? Mathematica 'simplifies' this formula
$$\sum_{k=1}^R \cos \frac{2k \pi x}{R}$$
to this
$$\frac{1}{2} \biggl(\csc \frac{\pi x}{R} \sin \frac{(2R+1) \pi x}{R}-1\biggr)$$
A graphical plot of the two formulae generates two identical continuous curves - but why?
Surely $\csc \frac{\pi x}{R}$ is discontinuous, with poles at $x={0,R,2R,3R...}$? So, how can $\frac{1}{2} \bigl(\csc \frac{\pi x}{R} \sin \frac{(2R+1) \pi x}{R}-1\bigr)$ produce a continuous curve?
I'd be grateful for:


*

*A proof of this equivalence

*An explanation for why the resulting curve is continuous despite $\csc \frac{\pi x}{R}$ being discontinuous.


Assuming you're a bit familiar with complex numbers:
$$e^{ix}=\cos(x)+i\sin(x)\tag{1}$$ Let $a=\frac{2\pi}{R}$, then you want to find the sum $$\sum_{k=1}^{R}\cos(akx)\tag{2}$$
 Notice that it is way easier to first compute (which we later can relate to $\cos(akx)$) $$\sum_{k=1}^{R}e^{akix}=\sum_{k=1}^{R}\left (e^{aix}\right )^k\tag{3}$$ which is a geometric series. This evaluates to $$\sum_{k=0}^R \left (e^{aix}\right )^k=\frac{e^{aix(R+1)}-1}{e^{aix}-1}\tag{4}$$
But since your series starts at $k=1$ we have to subtract the first term, so that $$\sum_{k=1}^R\left (e^{aix}\right )^k=\frac{e^{aix(R+1)}-1}{e^{aix}-1}-1\tag{5}$$
Now substitute eq. $(1)$ back into $(5)$ to get $$\sum_{k=1}^R\cos(akx)+i\sum_{k=1}^R\sin(akx)=\dots$$ Can you take it from here?
