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.


Hint:
Evaluate $$\Re\left(\sum_{k=0}^Re^{i2\pi kx/R}\right)=\Re\left(\sum_{k=0}^R\left(e^{i2\pi x/R}\right)^k\right),$$ which involves a geometric sum.
