Prove $$\csc(x)=\sum_{k=-\infty}^{\infty}\frac{(-1)^k}{x+k\pi}$$
Hardy uses this fact without proof in a monograph on different ways to evaluate $\int_0^{\infty}\frac{\sin(x)}{x} dx$.
Prove $$\csc(x)=\sum_{k=-\infty}^{\infty}\frac{(-1)^k}{x+k\pi}$$
Hardy uses this fact without proof in a monograph on different ways to evaluate $\int_0^{\infty}\frac{\sin(x)}{x} dx$.
We can use also this well known summation formula (a consequence of the residue theorem): $$\sum_{k\in\mathbb{Z}}\left(-1\right)^{k}f\left(k\right)=-\sum\left\{ \textrm{residues of }\pi\csc\left(\pi z\right)f\left(z\right)\textrm{ at }f\left(z\right)\textrm{'s poles}\right\} $$ so if we take $f\left(z\right)=\frac{1}{x+z\pi} $ we get $$\sum_{k\in\mathbb{Z}}\frac{\left(-1\right)^{k}}{x+k\pi}=-\underset{z=-x/\pi}{\textrm{Res}}\left(\frac{\pi\csc\left(\pi z\right)}{x+z\pi}\right)=\csc\left(x\right)$$ as wanted.
Presumably the principal value of the two-sided infinite sum is what was intended in the question.
We'll solve this just using Euler's product formula for the sine function:
\begin{align} \sin x=x\prod_{n=1}^\infty \left(1-\frac{x^2}{n^2 \pi^2}\right). \end{align}
Compute the logarithmic derivative:
\begin{align} \cot x &= \frac1{x}+\sum_{n=1}^\infty \frac{-2x/n^2\pi^2}{1-\frac{x^2}{n^2 \pi^2}} \\&=\frac1{x}+\sum_{n=1}^\infty \frac{2x}{x^2-n^2\pi^2} \\&=\frac1{x}+\sum_{n=1}^\infty\big(\frac{1}{x+n\pi}+\frac{1}{x-n\pi}\big), \end{align}
so
$$ \cot x-\frac1{x}=\sum_{n=1}^\infty\big(\frac{1}{x+n\pi}+\frac{1}{x-n\pi}\big).$$
It follows that
\begin{align} \cot\big(\frac{x}{2}\big)-\frac2{x}&=\sum_{n=1}^\infty\big(\frac{1}{x/2+n\pi}+\frac{1}{x/2-n\pi}\big) \\&=2\sum_{n=1}^\infty\big(\frac{1}{x+2n\pi}+\frac{1}{x-2n\pi}\big) \\&=2\sum_{\substack{n\ge 1\\n\text{ even}}}\big(\frac{1}{x+n\pi}+\frac{1}{x-n\pi}\big). \end{align}
Subtracting now, we obtain
\begin{align} \cot\big(\frac{x}{2}\big)-\cot(x)-\frac1{x}&=2\cdot\!\!\!\sum_{\substack{n\ge 1\\n\text{ even}}}\big(\frac{1}{x+n\pi}+\frac{1}{x-n\pi}\big)-\sum_{n=1}^\infty\big(\frac{1}{x+n\pi}+\frac{1}{x-n\pi}\big) \\&=\sum_{\substack{n\ge 1\\n\text{ even}}}\big(\frac{1}{x+n\pi}+\frac{1}{x-n\pi}\big)-\sum_{\substack{n\ge 1\\n\text{ odd}}}\big(\frac{1}{x+n\pi}+\frac{1}{x-n\pi}\big) \\&=\sum_{n=1}^\infty (-1)^n \big(\frac{1}{x+n\pi}+\frac{1}{x-n\pi}\big). \end{align}
But
\begin{align} \cot\big(\frac{x}{2}\big)-\cot(x)&=\frac{\cos(x/2)}{\sin(x/2)}-\frac{\cos x}{\sin x} \\&=\frac{\cos(x/2)}{\sin(x/2)}\cdot\frac{2\sin(x/2)\cos(x/2)}{\sin x}-\frac{\cos x}{\sin x} \\&=\frac{2\cos^2(x/2)-\cos x}{\sin x} \\&=\frac1{\sin x} \\&= \csc x. \end{align}
So we've shown that
\begin{align} \csc x &= \frac1{x}+\sum_{n=1}^\infty (-1)^n \big(\frac{1}{x+n\pi}+\frac{1}{x-n\pi}\big), \end{align}
which is the principal value of $$\sum_{n=-\infty}^\infty (-1)^n \frac{1}{x+n\pi},$$
as desired.
In this answer (using complex methods) and in this answer (using real methods), it is shown in detail that $$ \sum_{k=-\infty}^\infty\frac{1}{z+k}=\pi\cot(\pi z)\tag{1} $$ $(1)$ is the sum for even and odd $k$. The sum for even $k$ would be $$ \sum_{k=-\infty}^\infty\frac{1}{z+2k}=\frac\pi2\cot\left(\frac{\pi z}2\right)\tag{2} $$ The sum for even minus the sum for odd would be twice $(2)$ minus $(1)$ $$ \begin{align} \sum_{k=-\infty}^\infty\frac{(-1)^k}{z+k} &=\pi\cot\left(\frac{\pi z}2\right)-\pi\cot(\pi z)\\ &=\pi\frac{1+\cos(\pi z)}{\sin(\pi z)}-\pi\frac{\cos(\pi z)}{\sin(\pi z)}\\[9pt] &=\pi\csc(\pi z)\tag{3} \end{align} $$ Therefore, $$ \sum_{k=-\infty}^\infty\frac{(-1)^k}{z+k\pi}=\csc(z)\tag{4} $$
We begin by expanding the function $\cos(xy)$ in a Fourier series,
$$\cos(xy)=a_0/2+\sum_{k=1}^\infty a_k\cos(ky) \tag1$$
for $x\in [-\pi/\pi]$. The Fourier coefficients $(1)$ are given by
$$\begin{align} a_k&=\frac{2}{\pi}\int_0^\pi \cos(xy)\cos(ky)\,dy\\\\ &=\frac1\pi (-1)^k \sin(\pi x)\left(\frac{1}{x +k}+\frac{1}{x -k}\right)\tag2 \end{align}$$
Substituting $(2)$ into $(1)$, setting $y=0$, and dividing by $\sin(\pi x)$ reveals
$$\begin{align} \pi \csc(\pi x)&=\frac1y +\sum_{n=1}^\infty (-1)^k\left(\frac{1}{x -k}+\frac{1}{x +k}\right)\\\\ &=\sum_{k=-\infty}^\infty \frac{(-1)^k}{x-k}\\\\ &=\sum_{k=-\infty}^\infty \frac{(-1)^k}{x+k}\tag3 \end{align}$$
Finally, enforcing the substitution $x\to x/\pi$ and dividing by $\pi$ in $(3)$ yields the coveted result
$$\csc(x)=\sum_{k=-\infty}^\infty \frac{(-1)^k}{x+k\pi}$$