Evaluate the following trignometric sum I am interested in the following sum
$$\sum_{\text{even } n=-\infty}^{\infty}\left(-\cos^2x\delta_{n,0}+\cos x\left(\frac{1-\cos x}{\sin x}\right)^{|n|}\right).$$
Wolfram alpha returns answer $\sin^2x$ which does not make any sense to me as the function clearly goes to 0 at $x=\pi/2$. Am I missing something?
Here is what I did:
$$\sum_{n=0}^\infty\cos x\left(\frac{1-\cos x}{\sin x}\right)^{2n}=\sum_{n=0}^\infty\cos x\left[\tan^2\left(\frac{x}{2}\right)\right]^n=\cos x\frac{1}{1-\tan^2\left(\frac{x}{2}\right)}=\cos^2\left(\frac{x}{2}\right).$$
The problem is that the above is legal only for $\tan^2\left(\frac{x}{2}\right)<1$ which necessarily means for $x<\pi/2$. The question is then how do you then reconcile that the series sums to 0 at $x=\pi/2$ while it sums to $1$ at $x=\pi/2^{-}$?
 A: Let a sequence of continuous functions, $f_n(x)$, be defined by
$$f_n(x)=\begin{cases}\cos(x) \left(\frac{1-\cos(x)}{\sin(x)}\right)^{2n}&,0\le|x|<\pi/2\\\\0&,x=\pi/2\end{cases}$$
Then, the sum $\sum_{n=0}^Nf_n(x)$ can be written
$$\begin{align}
\sum_{n=0}^N f_n(x)&=\sum_{n=0}^N \cos(x) \tan^{2n}(x/2)\,\,\,\,\,\,\,,0\le |x|\le\pi/2\\\\
&=\begin{cases}
\cos(x)\frac{1-\tan^{2N+2}(x/2)}{1-\tan^2(x/2)}&,0\le |x|<\pi/2 \tag 1\\\\
0&,x=\pi/2
\end{cases}
\end{align}$$
Using $\frac{\cos(x)}{1-\tan^2(x/2)}=\cos^2(x/2)$ for $0\le |x|<\pi/2$ and taking the limit of $(1)$ as $N\to \infty$ yields
$$\sum_{n=0}^\infty f_n(x)=\begin{cases}\cos^2(x/2)&,0\le |x|<\pi/2 \\\\
0&,x=\pi/2\end{cases} $$
which is discontinuous at $x=\pi/2$.  

This result is not particularly surprising since the limit of a sequence of continuous functions need not be continuous.  A simple example of this is the sequence of functions $g_n(x)=x^n$ for $x\in [0,1]$.  Obviously, $g_n(x)$ is continuous on $[0,1]$ for all $n$.  However, the limit function is the discontinuous function $$g(x)=\begin{cases}0&,x\ne 1\\\\1&,x=1\end{cases}$$

A: It should be $\cos^2(x/2) $ by analytical continuation. 
