<s>[INST] Solve $I^{\prime}(a)=\int_{0}^{\pi} \frac{2 a-2 \cos x}{1-2 a \cos x+a^{2}} d x$ I tried to compute  $I^{\prime}(a)=\int_{0}^{\pi} \frac{2 a-2 \cos x}{1-2 a \cos x+a^{2}} d x$
\begin{equation}\begin{aligned}
&\int_{0}^{\pi} \frac{2 a-2 \cos x}{1-2 a \cos x+a^{2}} d x&\\
&=\int_{0}^{\pi} \frac{2(a-1)+4 \sin ^{2} \frac{x}{2}}{(a-1)^{2}+4 a \cdot \sin ^{2} \frac{x}{2}} d x\\
&=2 \int_{0}^{\frac{\pi}{2}} \frac{2(a-1)+4 \sin ^{2} x}{(a-1)^{2}+4 \operatorname{asin}^{2} x} d x\\
&=\frac{2}{a} \int_{0}^{\frac{\pi}{2}}\left(1+\frac{2 a(a-1)-(a-1)^{2}}{(a-1)^{2}+4 a \sin ^{2} x}\right) d x\\
&=\frac{\pi}{a}+\frac{2}{a} \int_{0}^{\frac{\pi}{2}} \frac{a^{2}-1}{(a-1)^{2}+4 a \sin ^{2} x} d x\\
&=\frac{\pi}{a}+\frac{2}{a} \int_{0}^{\frac{\pi}{2}} \frac{\frac{a+1}{a-1} \sec ^{2} x}{1+\left(\frac{a+1}{a-1}\right)^{2} \tan ^{2} x} d x\\
&=\frac{\pi}{a}+\frac{2}{a} \int_{0}^{\infty}  \frac{1}{1+u^{2}}d u\\
&=\frac{2 \pi}{a}
\end{aligned}\end{equation}
But I can't find my mistake.
 [/INST] This result $I=2\pi/a$ is true only if $a>1$, for a<1 $I=0$.
When $a<1$, $t=\frac{a+1}{a-1} \tan x \implies t=0 (x=0) ~\text{but}~ t=-\infty (x=\pi/2)$. Then
$$I=\left(1+\frac{|a-1|}{a-1}\right)\frac{\pi}{a}$$
When $a=1$ the orininal integral is $\pi$.
</s>