TITLE: Why doesn't integration by substitution work in this case?
QUESTION [7 upvotes]: I am asked to solve $\int_0^\frac{\pi}{4}\tan x\, \mathrm{d}x$.
This is what I did:
$$
\begin{align}
&\int_0^\frac{\pi}{4}\tan x \,\mathrm{d}x&\\
= {} &\int_0^\frac{\pi}{4}\frac{\sin x}{\cos x}\, \mathrm{d}x&\\
= {} &\int_0^\frac{\pi}{4}\sin x\frac{-1}{-\cos x} \,\mathrm{d}x&\\
= {} &-\int_0^\frac{\pi}{4}\varphi'(x)\frac{1}{\varphi(x)} \,\mathrm{d}x &\text{where $\varphi(x):=-\cos x$} \\
= {} &-\int_{\varphi(0)}^{\varphi(\frac{\pi}{4})} \frac{1}{z} \,\mathrm{d}z \\
= {} &-\int_{-1}^{-\frac{1}{\sqrt{2}}} \frac{1}{z}\, \mathrm{d}z \\
= {} &\Big[\ln z\Big]_{-1}^{-\frac{1}{\sqrt{2}}} \\
= {} &\ln \left(-\frac{1}{\sqrt{2}}\right) - \ln (-1)
\end{align}
$$
And this is where I am stuck, because the solution is definitely not a complex number. I know the correct answer (it's $-\ln\left(\frac{1}{\sqrt{2}}\right)$, my problem is that I don't know where I made a mistake.

REPLY [6 votes]: You have
$$
\int_a^b\frac{1}{z}\,dz
$$
with $a<0$ and $b<0$. The antiderivative to use is $\ln(-z)$, which is a function defined on $(-\infty,0)$.
You can avoid the problem by writing instead
$$
\int_0^{\pi/4}(-\sin x)\frac{-1}{\cos x}\,dx=
\int_0^{\pi/4}\varphi'(x)\frac{-1}{\varphi(x)}\,dx
$$
where $\varphi(x)=\cos x$. For $x=0$ we have $\varphi(x)=1$; for $x=\pi/4$ we have $\varphi(x)=1/\sqrt{2}$, so the integral becomes
$$
\int_1^{1/\sqrt{2}}-\frac{1}{z}\,dz=
\int_{1/\sqrt{2}}^1 \frac{1}{z}\,dz=
\Bigl[\ln z\Bigr]_{1/\sqrt{2}}^1=-\ln\frac{1}{\sqrt{2}}=\ln\sqrt{2}=
\frac{1}{2}\ln2
$$