TITLE: Why and How do certain manipulations in indefinite integrals "just work"?
QUESTION [55 upvotes]: I am going to take a very simple example to elaborate my question.
When we integrate $\sec (x)\,dx$ we divide and multiply by $\sec (x) + \tan (x)$.
$$\int \sec(x)\,dx = \int \sec (x) \left[{\sec (x) + \tan (x) \over \sec (x) + \tan (x)}\right]\, dx$$
I am just solving from here.
$$\int {\sec^2(x) + \sec(x)\tan(x) \over \sec(x) + \tan(x)} \, dx $$
Then we let $\sec(x) + \tan(x) = u$
$$\implies du = (\sec^2(x) + \sec(x)\tan(x))\,dx$$
$$\implies \int {du \over u}$$
$$= \ln{\left|\sec(x) + \tan(x)\right|} + c$$
Now coming to my questions.

Why do we HAVE to make that manipulation of multiplying $\sec(x) + \tan(x)$. Like I know its to get the answer...but why does it work so well?

How to even think like that? Like "if I multiply $\sec(x) + \tan(x)$ in the numerator and denominator then I'll be able to solve this very easily." What in that integral gives one direction to think of such a manipulation ?

REPLY [5 votes]: There is a more elementary way to see this — to see why one would do this — that I don't think the other answers have really highlighted.
First of all, one must be familiar with logarithms, and the fact that $\frac{f^\prime}{f}$ is the derivative of $\ln\left|f\right|$.
Next you look at your trig derivatives. The functions $\sin$ and $\cos$ are a pair, and their derivatives are just each other, with a minus sign thrown in when appropriate. Couldn't be simpler! (Well, it could be simpler, if the minus sign weren't a thing, but that behavior is reserved for $\sinh$ and $\cosh$.)
Another nice pair of functions is $\sec$ and $\tan$. What makes them a pair? Well, they both have the same domains, because they have $\cos$ in their denominators. They also live together in a version of the Pythagorean identity: $\tan^2x + 1 = \sec^2x$. So let's look at their derivatives.
We have $\frac{d}{dx}\tan x=\sec^2 x$, and $\frac{d}{dx}\sec x=\sec x\tan x$. Their derivatives aren't exactly "each other", but they are each $\sec x$ times the other function. That means that, because addition is commutative, the derivative of their sum has a nice property: $$\frac{d}{dx}(\sec x+\tan x) = \sec x(\sec x+\tan x)$$ Taking $f(x) = \sec x+\tan x$, we have $$f'(x) = \sec x\cdot f(x)$$ or: $$\frac{f'(x)}{f(x)}=\sec x$$
From here, it's just a matter of putting the pieces together.