Evaluate $\int_0^{\pi} \frac{\cos m\theta-\cos m \phi}{\cos \theta - \cos \phi} \text{d}\theta$ In the Hardy's book Divergent series is proved the equality
$$\frac{\cos m\theta-\cos m \phi}{\cos \theta - \cos \phi} \text{d}\theta=2\sum_{n=1}^{\infty} \frac{\sin n\phi}{\sin \phi} \cos n\theta(\cos m\theta-\cos m \phi)$$
With $m\in\mathbb{N}$. Then integrating that equality $0<\theta<\pi$ (he says "ignoring any difficulties about the range of $\theta$ over which it may be expected to be valid) we obtain
$$\int_0^{\pi} \frac{\cos m\theta-\cos m \phi}{\cos \theta - \cos \phi} \text{d}\theta=\pi \frac{\sin m\phi}{\sin \phi}$$
How that result is reached? I've tried, in a sloppy way (because I didn't proved the possibility to exchange series and integral), this approach with Werner identities
$$\int_0^\pi 2\sum_{n=1}^{\infty} \frac{\sin n\phi}{\sin \phi} \cos n\theta(\cos m\theta-\cos m \phi) \text{d}\theta=$$
$$2\sum_{n=1}^{\infty} \frac{\sin n\phi}{\sin \phi} \int_0^\pi (\cos n\theta \cos m\theta-\cos n\theta\cos m \phi) \text{d}\theta=$$
$$\sum_{n=1}^{\infty} \frac{\sin n\phi}{\sin \phi} \int_0^\pi (\cos (n\theta+m\theta)+\cos (n\theta-m\theta) -\cos (n\theta+m\phi) -\cos (n\theta-m\phi)) \text{d}\theta=$$
$$\sum_{n=1}^{\infty} \frac{\sin n\phi}{\sin \phi} \left[\frac{\sin (n\theta+m\theta)}{n+m}+\frac{\sin(n\theta-m\theta)}{n-m} -\frac{\sin(n\theta+m\phi)}{n} -\frac{\sin(n\theta-m\phi)}{n}\right]_{\theta=0}^{\theta=\pi}=$$
$$\sum_{n=1}^{\infty} \frac{\sin n\phi}{\sin \phi} \left[\frac{\sin (n\pi+m\pi)}{n+m}+\frac{\sin(n\pi-m\pi)}{n-m} -\frac{\sin(n\pi+m\phi)}{n} -\frac{\sin(n\pi-m\phi)}{n}\right]$$
And here I'm stuck. Any help is appreciated.
 A: Here is my approach to the problem. It is natural to think of complex analysis. Let $\sqrt{-1}=i$. Now we will prove that:
$$I_m:=\int_{0}^{\pi} \frac{\cos mx}{\cos x - \cos \phi}\mathrm{d}x = \pi\cdot \frac{\sin m\phi}{\sin \phi}=\frac{1}{2}\int_{-\pi}^{\pi} \frac{\cos mx}{\cos x - \cos \phi}\mathrm{d}x$$$$=\frac{1}{2}\int_{-\pi}^{\pi} \frac{e^{imx}+e^{-imx}}{\left(e^{ix}-e^{i\phi}\right)\left(e^{ix}-e^{-i\phi}\right)}\mathrm{d}x$$
Let $z=e^{ix}$, $\mathrm{d}z = ie^{ix}\mathrm{d}x$. Hence:
$$I_m = \frac{-1}{4\sin\phi}\left(\int_{\vert z\vert=1}\frac{z^m}{\left(z-e^{i\phi}\right)\left(z-e^{-i\phi}\right)}\mathrm{d}z-\int_{\vert z\vert=1}\frac{z^{-m}}{\left(z-e^{i\phi}\right)\left(z-e^{i\phi}\right)}\mathrm{d}z\right)=A_m-B_m$$
Where:
$$A_m:=\frac{-1}{4\sin\phi}\int_{\vert z\vert=1}\frac{z^m}{\left(z-e^{i\phi}\right)\left(z-e^{-i\phi}\right)}\mathrm{d}z$$
$$B_m:=\frac{-1}{4\sin\phi}\int_{\vert z\vert=1}\frac{z^{-m}}{\left(z-e^{i\phi}\right)\left(z-e^{-i\phi}\right)}\mathrm{d}z$$
We need to show that $B_m = 0, \forall m \in \mathbb{N}$.It is obvious for $n=1$ We only need to show that:
$$J_m:=\int_{\vert z \vert = 1} \frac{1}{z^m (z-z_1)}\mathrm{d}z = 0, \forall m\in \mathbb{N}, z_1 = e^{i\phi}. $$
By induction, it is obvious that for $m=1$, we have $J_1= 0$. Assume that $J_m =0$ for $m=n-1$. We need to show that $J_n =0$.Since $\frac{1}{z^m}, m>1$ is a meromorphic function, by partial fraction decomposition:
$$J_n=z_1^{-1}\int_{\vert z \vert = 1}\frac{1}{z^{n}} - \frac{1}{z^{n-1}(z-z_1)}\mathrm{d}z=0 - J_{n-1}=0.$$
By obtaining this result, it follows directly that $B_m=0$.Finally, for $A_m$ by Residue theorem, leads us:
$$I_m:=A_m=\frac{-2\pi i}{4\sin\phi}\left(e^{im\phi}-e^{-im\phi}\right)=\pi \frac{\sin m\phi}{\sin \phi}$$
Then your result follows easily since:
$$\int_0^{\pi} \frac{\cos m\theta-\cos m \phi}{\cos \theta - \cos \phi} \text{d}\theta=I_m - I_0 =\pi \frac{\sin m\phi}{\sin \phi}$$
