<s>[INST] Computing a residue To find the value of $\int_0^\pi \frac{\sin^2 \theta}{a + \cos \theta} \, d\theta$ with $a > 1$ using residue theory, I am trying to compute the residue at the simple pole $z=-a+\sqrt{a^2-1}$ inside the unit disc. I tried both ways:
\begin{align}
\operatorname{Res}\left(\frac{z^4-2z^2+1}{z^4+2az^3+z^2},-a+\sqrt{a^2-1}\right) &= \frac{z^4-2z^2+1}{\frac d{dz}(z^4+2az^3+z^2)}\Bigg\vert_{z=-a+\sqrt{a^2-1}} \\
&= \frac{z^4-2z^2+1}{4z^3+6az+2z}\Bigg\vert_{z=-a+\sqrt{a^2-1}}
\end{align}
and
\begin{align}
\operatorname{Res}\left(\frac{z^4-2z^2+1}{z^4+2az^3+z^2},-a+\sqrt{a^2-1}\right) &= \lim_{z \to -a+\sqrt{a^2-1}} (z-(-a+\sqrt{a^2-1}))\frac{z^4-2z^2+1}{z^4+2az^3+z^2} \\
&= \lim_{z \to -a+\sqrt{a^2-1}} \frac{z^4-2z^2+1}{z^2(z-(-a-\sqrt{a^2-1}))}.
\end{align}
Is there a clean way to finding this particular residue? Because the methods I tried above require chugging through long arithmetic calculations.
 [/INST] Note that we can simplify your analysis by writing 
$$\begin{align}
\frac{\sin^2(\theta)}{a+\cos(\theta)}=\frac{1-a^2}{a+\cos(\theta)}+a-\cos(\theta)
\end{align}$$
The integral of the term $a-\cos(\theta)$ is trivial.  If we wish to use contour integration for the term $\displaystyle \frac{1-a^2}{a+\cos(\theta)}$, we can proceed to write for $a>1$
$$\begin{align}
\int_0^\pi \frac{1-a^2}{a+\cos(\theta)}\,d\theta&=i(a^2-1) \oint_{|z|=1} \frac{1}{z^2+2az+1}\,dz\\\\
&=2\pi (1-a^2)\text{Res}\left(\frac{1}{z^2+2az+1}, z=-a+\sqrt{a^2-1}\right)\\\\
&=-\pi\sqrt{a^2-1}
\end{align}$$
Hence, we find that 
$$\int_0^\pi \frac{\sin^2(\theta)}{a+\cos(\theta)}\,d\theta=\pi(a-\sqrt{a^2-1})$$
</s>