# Why and How do certain manipulations in indefinite integrals “just work”?

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.

1. 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?

2. 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 ?

Many otherwise-mysterious tricks in integrals involving trigonometric functions can be explained by expressing the trig functions in terms of exponentials, as in $$\cos(x)=(e^{ix}+e^{-ix})/2$$. The resulting rational expressions in exponentials can always be integrated…
EDIT: to explain why/how rational expressions on $$e^{ix}$$ can always be integrated: for example,
$$\int {1\over 1+e^{ix}} \, dx \;=\; -i \int {1\over e^{ix}(1+e^{ix})}\;d(e^{ix}) \;=\; -i \int {1\over t(1+t)}\;dt$$
with $$t=e^{ix}$$. Then use partial fractions to break this up into easily-computable pieces.