TITLE: $\int\frac{\sin\left(x\right)}{\cos\left(x\right)}\,\mathrm{d}x$ by substitution
QUESTION [8 upvotes]: I'm trying to solve the following integral:
$$\int\frac{\sin\left(x\right)}{\cos\left(x\right)}\,\mathrm{d}x$$
Using the substitution method with the substitution $u = \sin\left(x\right)$.
The exercise has two parts: the first one is using the substitution $u = \cos\left(x\right)$. No problem.
I'm having difficulties with the second part, which is using the substitution $u = \sin\left(x\right)$.
I spent a couple of hours with the exercise before asking here, and after some trials I got this:
$$\int f\left(g\left(x\right)\right)g'\left(x\right)\,\mathrm{d}x = \int f\left(u\right)\,\mathrm{d}u$$
$$g\left(x\right) = \sin\left(x\right)$$
$$g'\left(x\right) = \cos\left(x\right)$$
$$f\left(x\right) = \frac{x}{\cos^2\left(\arcsin(x)\right)} = \frac{x}{1 - x^2}$$
$$\int f\left(u\right)\,\mathrm{d}u = -\frac{1}{2}\log|1 - u^2| + C = -\frac{1}{2}\log|1 - \sin^2\left(x\right)| + C$$
$$1 - \sin^2\left(x\right) = \cos^2\left(x\right)$$
$$\int\frac{\sin\left(x\right)}{\cos\left(x\right)}\,\mathrm{d}x = -\frac{1}{2}\log|\cos^2\left(x\right)| + C = -\log|\cos\left(x\right)| + C$$
But it feels too complicated, $f\left(x\right)$ was really hard for me to discover. What am I missing?

REPLY [3 votes]: What you did is fine. One can view it as carrying out the standard strategy when we have a product of integer powers of sines and cosines, with at least one of the powers odd.  In this case, both powers are odd. 
Note that
$$\frac{\sin x}{\cos x}=\frac{\sin x\cos x}{\cos^2 x}=\frac{\sin x\cos x}{1-\sin^2 x}.$$
Then the substitution $u=\sin x$ transforms our integral to
$$\int \frac{u}{1-u^2}\,du.$$
Remark: If we had instead something like $\int\frac{\sin^4 x}{\cos x}\,dx$, then the same strategy of substituting for $\sin x$ would work. The substitution $u=\cos x$ would be less attractive.