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$
 A: Time for the dog-bone contour (dumbbell contour), which  works perfectly.
Indeed, consider the contour $\mathcal{C}$ given as follows:
$\hspace{12em}$
With the principal branch cut, as the radius/band-width of $\mathcal{C}$ goes to zero,
\begin{align*}
\oint_{\mathcal{C}} \frac{i\sqrt{z-1}\sqrt{z+1}}{i(z^2+1)} \, dz
&\longrightarrow
\int_{-1-0^+i}^{1-0^+i} \frac{i\sqrt{z-1}\sqrt{z+1}}{z^2+1} \, dz
- \int_{-1+0^+i}^{1+0^+i} \frac{i\sqrt{z-1}\sqrt{z+1}}{z^2+1} \, dz \\\\
&\quad = 2\int_{-1}^{1} \frac{\sqrt{1-x^2}}{x^2+1} \, dx.
\end{align*}
On the other hand, Residue Theorem tells that
\begin{align*}
\oint_{\mathcal{C}} \frac{i\sqrt{z-1}\sqrt{z+1}}{z^4+1} \, dz
&= - 2\pi i \sum_{z_k \ : \ z_k^2 + 1 = 0} \underset{z=z_k}{\mathrm{Res}} \, \frac{i\sqrt{z-1}\sqrt{z+1}}{z^2+1} \\\\
&= 2\pi (\sqrt{2}-1)
\end{align*}
(In order to use Residue Theorem, consider a large circle, apply Residue Theorem to the region enclosed by this circle and $\mathcal{C}$, and then let the radius of the circle go to $\infty$.) Therefore
$$ \int_{-1}^{1} \frac{\sqrt{1-x^2}}{x^2+1} \, dx = \pi (\sqrt{2}-1) $$
A: 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!
