<s>[INST] Calculating $\int_0^\pi \frac{1}{a+b\sin^2(x)} dx $ How do I calculate this integral? $a \gt b$ is given.
$$\int_0^\pi \frac{1}{a+b\sin^2(x)} dx $$
I am confused since WolframAlpha says one the one hand, that $F(\pi) = F(0) = 0 $ , but with some random values  it isn't 0. 
What am I missing?
Note that I am not really interested in a complete antiderivative, I am more interested in a $G(a,b) = F(\pi) - F(0) = \, ... $
 [/INST] Suppose we seek to evaluate
$$\frac{1}{2} \int_0^{2\pi} \frac{1}{a+b\sin^2 x} dx.$$
Put  $z   =  \exp(ix)$  so  that   $dz  =  i\exp(ix) \;  dx$  and  hence
$\frac{dz}{iz} = dx$ to obtain
$$\frac{1}{2} \int_{|z|=1}
\frac{1}{a+b(z-1/z)^2/4/(-1)}\frac{dz}{iz}
\\ = \frac{1}{2} \int_{|z|=1}
\frac{4}{4a-b(z-1/z)^2}\frac{dz}{iz}
\\ = \frac{2}{i} \int_{|z|=1}
\frac{z}{4a-b(z-1/z)^2}\frac{dz}{z^2}
\\ = \frac{2}{i} \int_{|z|=1}
\frac{z}{4az^2-b(z^2-1)^2} dz
\\ = \frac{2}{i} \int_{|z|=1}
\frac{z}{-bz^4+(2b+4a)z^2-b} dz.$$
The poles here are all simple and located at
$$\rho_{1,2,3,4}
= \pm\sqrt{\frac{2a+b}{b} \pm 
\frac{2\sqrt{a^2+ab}}{b}}.$$
Re-write this as
$$\rho_{1,2,3,4}
= \pm\sqrt{1+\frac{2a}{b} \pm 
\frac{2\sqrt{a^2+ab}}{b}}.$$
With $a$ and  $b$ positive the first two poles  are clearly not inside
the contour (modulus larger than one). That leaves
$$\rho_{3,4}
= \pm\sqrt{1+\frac{2a}{b}
- \frac{2\sqrt{a^2+ab}}{b}}.$$
Now we have
$$1+\frac{2a}{b} 
- \frac{2\sqrt{a^2+ab}}{b} < 1$$
and also
$$1+\frac{2a}{b} 
- \frac{2\sqrt{a^2+ab}}{b} > 0$$
since
$$(b+2a)^2 = b^2+4ab+4a^2 > 4(a^2+ab)$$
and therefore these poles are indeed inside the contour.

The residues are given by
$$\left. \frac{z}{-4bz^3+2(2b+4a)z}
\right|_{z=\rho_{3,4}}
= \left. \frac{1}{-4bz^2+2(2b+4a)}
\right|_{z=\rho_{3,4}}.$$
This is
$$\frac{1}{-4b-8a+8\sqrt{a^2+ab}
+2(2b+4a)}
= \frac{1}{8\sqrt{a^2+ab}}.$$
It follows that the desired value is
$$\frac{2}{i}\times 2\pi i
\times \frac{2}{8\sqrt{a^2+ab}}
= \frac{\pi}{\sqrt{a}\sqrt{a+b}}.$$
</s>