# Doubt while evaluating $\int_0^{\pi}\frac{1}{\cos x} \text{d}x$

I know that this integral can be evaluated in many ways, but my doubt comes by doing a thing in this specific way.

I was trying to evaluate $$\int_0^{\pi}\frac{1}{\cos x} \text{d}x$$ I would like to multiply for $$\frac{\cos x}{\cos x}$$, but $$\cos x=0$$ if $$x=\frac{\pi}{2}$$ and the integration interval contains $$x=\frac{\pi}{2}$$; so I suspect that the fractions $$\frac{1}{\cos x}$$ and $$\frac{\cos x}{\cos^2 x}$$ aren't equivalent because of this.

So my doubts are:

(1) Can I avoid this problem by using the fact that two integrals are the same if I separate the integration interval in a finite number of points? Like this: $$\int_0^{\pi}\frac{1}{\cos x} \text{d}x=\int_0^{\frac{\pi}{2}}\frac{1}{\cos x} \text{d}x+\int_\frac{\pi}{2}^{\pi}\frac{1}{\cos x} \text{d}x$$ But I'm suspicious, because both integrals on RHS are divergent while the one on LHS isn't. What is the error in doing this? I suspect that this comes by the fact that the fractions aren't equivalent. Am I right? If I'm wrong, what is the reason why this doesn't work?

(2) When am I allowed to manipulate the integrand function? Only when I'm sure that the integrand functions are equivalent in the integration interval?

Note that when we solve this as an improper integral we get a limit that tends to infinity, so we can only assign a Cauchy Principal Value to this integral which is $$0$$. This is quite logical if you use the graph of $$y=\sec x$$ to determine the area under the curve from $$x=0$$ to $$x=\pi$$. By the symmetry about the asymptote $$x=\pi/2$$, the algebraic area is $$0$$ and so is the value of the integral.
\begin{aligned}\int_{0}^{\pi}\sec x\mathrm dx &=\lim_{a\to \pi/2}\left(\int_{0}^{a}\sec x\mathrm dx+\int_{a}^{\pi}\sec x\mathrm dx\right)\\ &=\bigg[\ln |\sec x+\tan x|\bigg]_{0}^{\pi/2}+\bigg[\ln |\sec x+\tan x|\bigg]_{\pi/2}^{\pi}\\&=\left(\lim_{x\to \pi/2}\ln|\sec x+\tan x|-0\right)+\left(0-\lim_{x\to \pi/2}\ln|\sec x+\tan x|\right)\end{aligned}