Recently, a friend of mine asked me for the indefinite integral $$F(x)=\int \sec^3(x)$$ Integrating by parts, letting $u=\sec(x), dv=\sec^2(x)$, we have $$F(x)=\sec(x)\tan(x)-\int \sec(x)\tan^2(x)$$ But now: $$G(x)=\int \sec(x)\tan^2(x)=\int \sec(x)(\sec^2(x)-1)=F(x)-\int\sec(x)$$ And finally(and somewhat magically) $\int\sec(x)=\ln(|\sec(x)+\tan(x)|)$, which gives us: $$F(x)=\sec(x)\tan(x)-(F(x)-\ln(|\sec(x)+\tan(x)|)))$$ $$\implies F(x)=\frac{\sec(x)\tan(x)+\ln(|\sec(x)+\tan(x)|)}{2}$$
The last integral was written as a derivation excercise some weeks ago, so there is where my motivation comes from. But, is there a logical way to come up with it?