Prove that $\int_{0}^{\pi}\frac{r}{1-2r\cos x+r^2}dx=\int_{0}^{\pi}\frac{\cos x}{1-2r\cos x+r^2}dx$ Prove for every $r\in(-1,1)$: $$\int_{0}^{\pi}\frac{r}{1-2r\cos x+r^2}\,dx=\int_{0}^{\pi}\frac{\cos x}{1-2r\cos x+r^2}\,dx$$
I tried proving that $$\int_{0}^{\pi}\frac{\cos x-r}{1-2r\cos x+r^2}dx=0$$ using variable substitution with $t=\tan(x/2)$ but it didn't get me anywhere.
 A: We may notice that:
$$ 1-2r\cos x+r^2 = (r-e^{ix})(r-e^{-ix}) \tag{1}$$
hence:
$$ J(r)=\int_{0}^{\pi}\frac{r-e^{ix}}{1-2r\cos x+r^2}\,dx = \int_{0}^{\pi}\frac{dx}{r-e^{-ix}} \tag{2}$$
but for every $n\in\mathbb{N}\setminus\{0\}$ we have:
$$ \int_{0}^{\pi}e^{-nix}\,dx = \left\{\begin{array}{rcl}-\frac{2i}{n}&\text{if}&n\equiv 1\pmod{2}\\ 0 &\text{if}& n\equiv 0\pmod{2}\end{array}\right. \tag{3}$$
hence by expanding the integrand function in the RHS of $(2)$ as a geometric series we have that, given $r\in(-1,1)$,
$$ 0 = \text{Re } J(r) = \int_{0}^{\pi}\frac{r-\cos x}{1-2r\cos x+r^2}\,dx\tag{4} $$
as wanted.
A: By symmetry this is the same as proving that
$$\int_0^{2\pi} \frac{r}{1-2r \cos x + r^2} \; dx
= \int_0^{2\pi} \frac{\cos x}{1-2r \cos x + r^2} \; dx$$
for $r\in (-1,1).$

Put  $z   =  \exp(ix)$  so  that   $dz  =  i\exp(ix) \;  dx$  and  hence
$\frac{dz}{iz} = dx$ to obtain for the first integral
$$\int_{|z|=1}
\frac{r}{1-r(z+1/z) + r^2} \; \frac{dz}{iz}
\\ = \frac{1}{i}
\int_{|z|=1}
\frac{r}{z-r(z^2+1) + zr^2} \; dz
\\ = \frac{1}{i}
\int_{|z|=1}
\frac{r}{-rz^2 + z(r^2+1) -r} \; dz.$$
This has poles  at $z=r$ and $z=1/r$ and  with $r\in(-1,1)$ only $z=r$
is inside the contour. We thus get for the first integral
$$2\pi i \times \frac{1}{i} \times
\left.\frac{r}{-2rz + r^2+1}\right|_{z=r}
= \frac{2\pi r}{1-r^2}.$$
We get for the second integral
$$\frac{1}{i}
\int_{|z|=1}
\frac{1/2(z+1/z)}{-rz^2 + z(r^2+1) -r} \; dz.$$
We thus obtain from the pole at $z=r$ the residue
$$\left.\frac{1/2(r+1/r)}{-2rz + r^2+1}\right|_{z=r}
= \frac{1}{2}(r+1/r) \times \frac{1}{1-r^2}.$$
and from the pole at $z=0$
$$-\frac{1}{2r}
= -\frac{1-r^2}{2r} \frac{1}{1-r^2} .$$
This yields for the second integral
$$2\pi i \times \frac{1}{i} \times
\left(\frac{1}{2}(r+1/r) - \frac{1}{2}(1/r-r)\right)
\frac{1}{1-r^2}
\\ = 2\pi \times
\left(\frac{1}{2}\times 2r\right)
\frac{1}{1-r^2}
= \frac{2\pi r}{1-r^2}.$$
We have equality of the two integrals as claimed.
A: From here we have 
$$\sum_{n=1}^\infty r^{n-1} \cos(nx)=\frac{\cos(x)-r}{1-2r\cos(x)+r^2}$$
$$\Longrightarrow \int_0^\pi\frac{\cos(x)-r}{1-2r\cos(x)+r^2}\ dx=\sum_{n=1}^\infty r^{n-1} \underbrace{\int_0^\pi\cos(nx)\ dx}_{0}=0$$
