Calculating a definite integral when $1/0$ arises twice and seems to cancel out. We have
\begin{align*} I=&\int_{0}^{\frac{\pi}{2}}\frac{1}{1+\sin x}dx \\
=&\int_{0}^{\frac{\pi}{2}}\frac{1-\sin x}{\cos^{2}x}dx \\
=&[\tan x]^{\frac{\pi}{2}}_{0} -\int_{0}^{\frac{\pi}{2}}\frac{\sin x}{\cos^2x}dx
\end{align*}
And by letting $u=\cos x \Rightarrow du =-\sin x dx$
We get \begin{align*} I=&[\tan x]^{\frac{\pi}{2}}_{0} +\left[ \frac{1}{u}\right]^{1}_{0}  \\
=&\frac{1}{0}+1-\frac{1}{0} \\ =&1\end{align*}
Is the last step right? Can you just cancel these out like that or should you do it another way? Because the answer here is in fact $1$. This might be more of an algebra question and that's why I tagged it as such. I've never come across this before.
 A: The LHS equals $1,$ but neither integrand on the RHS is bound on the integration interval and neither improper converges:
$$\int_{0}^{\frac{\pi}{2}}\frac{1-\sin x}{\cos^{2}x}\,\mathrm dx \ne
\int_{0}^{\frac{\pi}{2}}\frac{1}{\cos^{2}x}\:\mathrm dx-\int_{0}^{\frac{\pi}{2}}\frac{\sin x}{\cos^{2}x}\:\mathrm dx $$

*

*As the given integrand is a rational function of $\sin$ and $\cos$ and its interval of integration doesn't contain any odd multiple of $\pi,$ the Weierstrass substitution $$u=\tan\frac x2$$ works, giving $$\int_0^1\frac1{u^2+2u+1}\,\mathrm du,$$ which equals $1.$


*Alternatively we can take limits, as suggested in Robert's comment:
\begin{align}&\int_{0}^a\frac{1-\sin x}{\cos^{2}x}\,\mathrm dx = \cdots=\big[\tan x\big]_0^{a}-\left[ \frac{1}{u}\right]^{\cos a}_{1}=\frac{\sin a-1}{\cos a}+1,\\
&\int_{0}^{\frac{\pi}2}\frac{1-\sin x}{\cos^{2}x}\,\mathrm dx\\
={}&\lim_{a\to\frac{\pi}2}\int_{0}^{a}\frac{1-\sin x}{\cos^{2}x}\,\mathrm dx\\
={}&\lim_{a\to\frac{\pi}2}\left(\frac{\sin a-1}{\cos a}+1\right)\\
={}&1,\end{align} by L'Hopital's Rule.
A: In enforcing $u=\cos(x)\iff x=\cos^{-1}(u)$, we have $dx=-\frac{du}{\sqrt{1-u^2}}$ and the integral transforms to
$$\int_0^{\frac\pi2} \frac{1-\sin(x)}{\cos^2(x)} \, dx = \int_0^1 \frac{1-\sqrt{1-u^2}}{u^2\sqrt{1-u^2}} \, du = \int_0^1 \left(\frac1{u^2\sqrt{1-u^2}} - \frac1{u^2}\right) \, du$$
followed by another substitution of $u=-\frac{2v}{1+v^2}\iff v=\frac{\sqrt{1-u^2}-1}u$ (to avoid invoking another trigonometric substitution) and $du=-\frac{2(1-v^2)}{(1+v^2)^2} \, dv$,
$$\int_0^1 \left(\frac1{u^2 \sqrt{1-u^2}} - \frac1{u^2}\right) \, du = \int_{-1}^0 dv = 1$$
Note how the integral is not distributed over the difference to avoid the issue with the indeterminate form $\infty-\infty$.
