How do I evaluate $\int \cot^2x$? I have an integral with $\frac{1}{\tan^2x}$ needed to be evaluated. But instead of searching online for the antiderivative of $\cot^2x$, how would i find it from first principles? 
 A: 
The first thing I would suggest to learn is the Weierstrass substitution. It is a way to reduce all integrals of rational functions of $\sin(x)$ and $\cos(x)$ to the integral of a rational function, which we always know how solve using partial fraction decomposition.

For a shorter, although less powerful approach you can write it as:
$$\frac{\cos^2(x)}{\sin^2(x)}=\cos(x)\frac{\cos(x)}{\sin^2(x)}$$
Notice that the $\cos(x)$ is easy to differentiate, while the $\frac{\cos(x)}{\sin^2(x)}$ is easy to integrate. This suggests integration by parts.
$$\int\frac{\color{red}{\cos(x)}}{\sin^2(x)}=\frac{-1}{\sin(x)}$$

Here we have used that $$\int f(g(x))\color{red}{g'(x)}dx=\int f(y)dy$$ for $y=g(x)$. In our case $g(x)=\sin(x)$, $g'(x)=\cos(x)$, and $f(y)=\frac{1}{y^2}$.

while $$(\cos(x))'=-\sin(x)$$
So, we get 
$$\int\frac{\cos^2(x)}{\sin^2(x)}=\cos(x)\frac{-1}{\sin(x)}-\int(-\sin(x))\frac{-1}{\sin(x)}$$
There you can finish it.

Idea: The integrals of the form $\int \sin^a(x)\cos^b(x)$ can be solved by combining this form of integration by parts combined with using $\sin^2(x)+\cos^2(x)=1$. This last we didn't have to use in this particular problem, but in others it is useful to turn even powers of a $\sin$ into cosines.

A: \begin{align}
\int \cot^2 x \, dx &= \int\csc^2x-1 \, dx = \boxed{- \cot x - x + C}
\end{align}
