Question inside $\int \tan^2 x dx$

indefinite-integralsintegrationtrigonometric-integralstrigonometry

$$\int \tan^2 x dx$$ the question isn't behind on how to do it but rather on its solution, let me go through my solution quickly:

If we do a substitution $u=\tan(x)$ then $du=\sec^2 x dx=(u^2+1)dx$ hence we get $$\int \frac{u^2}{1+u^2}du=\int\left(1-\frac{1}{1+u^2}\right)du=\tan x-\arctan(\tan x)+C$$ so no problem until here. The solution from the book or WolframAlpha is: $\tan x-x+C$ so it raised a question, since $\tan $ isn't injective and only has an inverse for $x\in(-\frac{\pi}{2},\frac{\pi}{2})$, for which then $\arctan(\tan(x))=x$ is only true for $x\in(-\frac{\pi}{2},\frac{\pi}{2})$. But then why if we do $\arctan(\tan x)=x$ in my solution we then get $$\tan x-x+C$$ which is the same as the correct solution the book or WolframAlpha shows, while we have only just considered the $x\in(-\frac{\pi}{2},\frac{\pi}{2})$ in my method? Isn't the indefinite integral considering $\forall x\in \mathbb{R}$? Why is this happening?

Note: Not looking at all for an alternative solution or how to get there, rather why I get the correct solution by considering $x\in(-\frac{\pi}{2},\frac{\pi}{2})$ while an integral should be $\forall x\in \mathbb{R}$

Best Answer

This is a phenomenon that happens with all indefinite integrals. The original integral

$$\int \tan^2 x\:dx$$

has singularities at $\frac{\pi}{2} + \pi k$ for $k\in\Bbb{Z}$, therefore, no, the original integral was not for all $x\in\Bbb{R}$. Whenever you have discontinuities like that, they are tucked away in the $+C$. For example, take the textbook case of

$$\int \frac{dx}{x} = \log|x| + C$$

but this answer is a little misleading misleading. Consider the function

$$f(x)=\begin{cases}\log( -x) +7 & x<0 \\ \log (x )-2 & x>0\end{cases}$$

Taking the derivative, we see that it is still $\frac{1}{x}$. That is because $f$ can still be written as

$$f(x) = \log|x| + C$$

but in this case, the constant $C$ changes values across the discontinuity

$$C = \begin{cases}7 & x<0 \\ -2 & x>0\end{cases}$$

and that is allowed for $+C$. In your answer, we have that

$$x = \arctan(\tan x) + C$$

where the $+C$ hides the arbitrary constant (s)

$$C = \pi\left\lfloor\frac{x+\frac{\pi}{2}}{\pi}\right\rfloor$$

which makes the two answers equivalent, since they are only off by an arbitrary constant.

Related Question