<s>[INST] A weird contour integral calculation I have function $\int_{-1}^{1}\frac{\sqrt{1-x^2}}{1+x^2}dx$.
Here to use residue thm, I rewrite the integral as  $\int_{-1}^{1}\frac{\sqrt{1-z^2}}{1+z^2}dz$ with the poles $z=i$ and $-i$. However there is a given condition $-1<x<1$, so it means $z^2<1$. This is the problem because when the poles are at $|z|=1$. It's outside the boundary. So I have no idea about how I can calculate this integral
Here's my Residues
$\operatorname{Res}_{z=i}[f(z)]=\lim_{z\to i}\frac{\sqrt{1-z^2}}{i(1-zi)}dz=\frac{\sqrt{2}}{2i}$
$\operatorname{Res}_{z=-i}[f(z)]=\lim_{z\to -i}\frac{\sqrt{1-z^2}}{i(1+zi)}dz=\frac{\sqrt{2}}{2i}$
But I guess these are wrong
Edit: since I need a closed contour i replaced $x=cos\theta$ and $dx=-sin\theta d\theta$
And my integral is now $-\frac{1}{2}\oint \frac{\sqrt{1-cos^2\theta}}{cos^20+cos^2\theta}(-sin\theta) d\theta$=
$-\frac{1}{2}\oint \frac{-sin^2\theta}{cos^20+cos^2\theta}d\theta$
 [/INST] By your comments in my previous question, we can also deal in another way (but I am about to tell you that is more tedious, even if apparently at the beginning it looks easier).
With $x = \cos\theta$ we get
$$-\int_{\pi}^0 \frac{\sin^2(\theta)}{1 + \cos^2(\theta)}\ \text{d}\theta$$
We can close the contour by doubling the integration range:
$$\frac{1}{2}\int_0^{2\pi} \frac{\sin^2(\theta)}{1 + \cos^2(\theta)}\ \text{d}\theta$$
From here we are ready to Complex again:
$$\sin(\theta) = \frac{1}{2i}\left(z - \frac{1}{z}\right) ~~~~~~~ \cos(\theta) = \frac{1}{2}\left(z + \frac{1}{z}\right) ~~~~~~~ \text{d}\theta = \frac{\text{d}z}{iz}$$
Whence
$$\frac{1}{2}\oint_{|z| = 1} \frac{\left(\frac{1}{2i}\left(z - \frac{1}{z}\right)\right)^2}{\left(1 + \frac{1}{4}\left(z + \frac{1}{z}\right)^2\right)}\frac{\text{d}z}{iz} \longrightarrow \frac{1}{2}\oint_{|z| = 1} \frac{i \left(z^2-1\right)^2}{z^5+6 z^3+z}$$
Here there are five poles:
$$\left\{\{z\to 0\},\left\{z\to -i \sqrt{3-2 \sqrt{2}}\right\},\left\{z\to i \sqrt{3-2 \sqrt{2}}\right\},\left\{z\to -i \sqrt{2 \sqrt{2}+3}\right\},\left\{z\to i \sqrt{2 \sqrt{2}+3}\right\}\right\}$$
But only three of them lie inside the unit circle:
$$\{z\to 0\},\left\{z\to -i \sqrt{3-2 \sqrt{2}}\right\},\left\{z\to i \sqrt{3-2 \sqrt{2}}\right\}$$
Now it's about Residues time again.
Whereas the residue at $z = 0$ is rather easy, not easy (just tedious) are the calculations of the two others. But eventually, by doing that calculation, you will get the identical final result!
</s>