Why is this Definite Integral wrong? This is the main problem
$$\int_{0}^{\pi} \frac{\sin{x}}{1+\cos^{2}{x}}\,dx$$
and if I let $u=\cos{x}$ then
$$-\int_{1}^{-1}\frac{du}{1+u^{2}}$$
which equals $-\tan^{-1}{u}$ from $1$ to $-1$
and where I make the mistake that I don't understand is
$$-\tan^{-1}(-1) = -\frac{3\pi}{4}$$
but this gives me the wrong answer, In order to get the correct one I'm supposed to get that
$$-\tan^{-1}(-1) = \frac{\pi}{4}$$
This has been bugging me for quite some time. is there some weird rule that says I have to use $-\frac{\pi}{4}$ instead of $\frac{3\pi}{4}$
 A: There are multiple branches for $\tan^{-1}(x)$ each differing from another by an integer multiple of $\pi$.
The principal branch, which is continuous on the interval from $-1$ to $1$,
gives $\tan^{-1}(-1)=-\frac\pi4$ and $\tan^{-1}(1)=\frac\pi4$. Thus, the integral should be
$$
\tan^{-1}(1)-\tan^{-1}(-1)=\frac\pi2
$$
The problem with using $\tan^{-1}(-1)=\frac{3\pi}4$ is that that is from a different branch than the one for which $\tan^{-1}(1)=\frac\pi4$.  If you want to use $\tan^{-1}(-1)=\frac{3\pi}4$, you would need to use $\tan^{-1}(1)=\frac{5\pi}4$
A: With tangent we have to restrict its domain so as to be sure it is injective, and  it is usually chosen the domain $\;\left(-\frac\pi2,\,\frac\pi2\right)\;$, which is then the codomain of its inverse function $\;\arctan\;$ . 
As for the integral: observe that $\;\sin x=-(\cos x)'\;$ , so
$$\int_0^\pi\frac{\sin x\;dx}{1+\cos^2x}=\left.-\int_0^\pi\frac{d(\cos x)}{1+\cos^2x}=-\arctan\cos x\right|_0^\pi=$$
$$=-\arctan\cos\pi+\arctan\cos0=-\arctan(-1)+\arctan1=-\left(-\frac\pi4\right)+\frac\pi4=\frac\pi2$$
A: To supplement RobJon's answer, the multiple branches for the arctangent function have integral representation 
$$\arctan(x;n)=n\pi+\int_0^x \frac{1}{1+u^2}\,du \tag 1$$
for integer $n$.  On the principal branch for the arctangent, $n=0$. 
Using $(1)$, we can write the integral of interest as 
$$\int_{-1}^1\frac{1}{1+u^2}\,du=\arctan(1;n)-\arctan(-1;n) \tag 2$$
The choice of branch for the arctangent does not impact the value of the integral in $(2)$, provided one uses only one branch for both $\arctan(1;n)$ and $\arctan(-1;n)$.  

An as aside, we can evaluate the integral in $(2)$ without appealing to the arctangent function.  For $|x|\le 1$, the integral in $(1)$ can be transformed into the series
$$\int_0^x \frac{1}{1+u^2}\,du=\sum_{n=0}^\infty \frac{(-1)^n\,x^{2n+1}}{2n+1}$$ 
For $x= 1$, Leibniz used a purely geometric proof to show 
$$\sum_{n=0}^\infty \frac{(-1)^n}{2n+1}=\frac{\pi}{4} $$
from which it trivially follows that
$$\int_{-1}^{1}\frac{1}{1+u^2}\,du=\frac{\pi}{2}$$ 

Using Leibniz's result, we can also evaluate the integral $\int_0^\infty \frac{1}{1+u^2}\,du$ by writing
$$\begin{align}
\int_0^\infty \frac{1}{1+u^2}\,du&=\int_0^1\frac{1}{1+u^2}\,du+\int_1^\infty \frac{1}{1+u^2}\,du \tag 3\\\\
&=2\int_0^1 \frac{1}{1+u^2}\,du \tag 4\\\\
&=\frac{\pi}{2}
\end{align}$$
where in going from $(3)$ to $(4)$ we enforced the substitution $u\to 1/u$ in the second integral.  Therefore, we find that 
$$\lim_{x\to \infty}\arctan(x;n)=n\pi+\pi/2$$
as expected!
