TITLE: Odd Mathematica series result
QUESTION [6 upvotes]: I asked Mathematica to evaluate
$$\sum_{i=1}^{\infty} \cos(i a)\cos(i b)$$
where $a$ and $b$ are unspecified real numbers, and it told me the answer was simply $-\frac{1}{2}$. This is clearly wrong, as I expect the series to fail to converge for almost any choice of $a,b$ -- but is there some formal sense in which Mathematica's answer makes sense?

REPLY [15 votes]: Let's get reckless:
$$\begin{align}
\sum_{k=1}^\infty \cos (kx) &= \frac{1}{2}\left(\sum_{k=1}^\infty e^{ikx} + \sum_{k=1}^\infty e^{-ikx}\right)\\
&= \frac{1}{2} \left(\frac{e^{ix}}{1-e^{ix}} + \frac{e^{-ix}}{1-e^{-ix}} \right)\\
&= \frac{1}{2}\left(\frac{e^{ix}}{1-e^{ix}} + \frac{1}{e^{ix}-1}\right)\\
&= -\frac{1}{2}.
\end{align}$$
Then use
$$\cos (ka) \cos (kb) = \frac{1}{2}\left(\cos \left(k(a+b)\right) + \cos \left(k(a-b)\right)\right)$$
to transform
$$\sum_{k=1}^\infty \cos (ka)\cos (kb)$$
into sums of the above form.
Suffice it to say, the series does actually converge in the sense of distributions.