<s>[INST] Sum of Cosine/Exponential I try to simplify to get rid of sum
$$ \sum_{k=0}^{n-1}\cos(2 \pi fk)$$
I discover I shall use euler equation to form:
$$ \sum_{k=0}^{n-1}\frac{1}{2}(e^{2 \pi fki}+e^{-2 \pi fki})$$
but how to sum exponentials?
 [/INST] You could proceed using the fact that $\cos(k \theta) = \dfrac{\exp(i k \theta) + \exp(-i k \theta)}{2}$, where $\theta = 2 \pi f$, as others have suggested.
Here is another method. Let $I_n = \displaystyle \sum_{k=0}^{n-1} \cos(k \theta)$. Now multiply by $\sin \left( \dfrac{\theta}{2}\right)$. Hence,
\begin{align}
\sin \left( \dfrac{\theta}{2}\right) I_n & = \sin \left( \dfrac{\theta}{2}\right) \displaystyle \sum_{k=0}^{n-1} \cos(k \theta) = \displaystyle \sum_{k=0}^{n-1} \cos(k \theta) \sin \left( \dfrac{\theta}{2}\right)\\
& = \dfrac12 \left(\displaystyle \sum_{k=0}^{n-1} \left( \sin \left( \left(k+\dfrac12 \right) \theta \right) - \sin \left( \left(k- \dfrac12 \right) \theta \right) \right) \right)
\end{align}
Now telescopic cancellation gives us
$$\sin \left( \dfrac{\theta}{2}\right) I_n = \dfrac12 \left( \sin \left( \left( n - \dfrac12\right) \theta \right)  + \sin \left( \dfrac{\theta}{2}\right)\right) = \sin \left( \left(\dfrac{n}{2} \right) \theta \right) \cos \left( \left(\dfrac{n-1}{2}  \right)\theta\right)$$
Hence, $$I_n = \dfrac{\sin \left( \left(\dfrac{n}{2} \right) \theta \right) \cos \left( \left(\dfrac{n-1}{2}  \right)\theta\right)}{\sin \left( \dfrac{\theta}{2}\right)}$$
The same idea works for $J_n = \displaystyle \sum_{k=0}^{n-1} \sin(k \theta)$ as well. Multiply by $\sin \left( \dfrac{\theta}{2}\right)$ and write each term as a difference of cosines to get
$$J_n = \dfrac{\sin \left( \left(\dfrac{n}{2} \right) \theta \right) \sin \left( \left(\dfrac{n-1}{2}  \right)\theta\right)}{\sin \left( \dfrac{\theta}{2}\right)}$$
</s>