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.

  • 4
    $\begingroup$ A primitive of $1/x$ is $\ln(|x|)$. $\endgroup$ Jun 8, 2018 at 20:36
  • 2
    $\begingroup$ you've forgotten negative sign at the pre-last line, and l$n|x|$ $\endgroup$
    – haqnatural
    Jun 8, 2018 at 20:37

3 Answers 3


It turns out that $\displaystyle\int\frac1z\,\mathrm dz=\log|z|$, not $\log z$.


You have lost a $-$ sign, so you should actually get $$\ln\left(-1\right)-\ln\left(-\frac{1}{\sqrt{2}}\right)$$ And now, you can use the fact that $$\ln(a)-\ln(b)=\ln\left(\frac{a}{b}\right)$$ to reach the desired result: $$\ln\left(-1\right)-\ln\left(-\frac{1}{\sqrt{2}}\right)=\ln\left(\frac{-1}{-\frac{1}{\sqrt{2}}}\right)=\ln\left(\frac{1}{\frac{1}{\sqrt{2}}}\right)=\frac{\ln 2}{2}$$ It works, because the logaritm of a negative number (the main branch) $-x$ (where $x>0$) is $\ln(-x)=\ln(x)+i \pi$, and in your case, the $i\pi$'s will cancel each other out. They would not cancel out if you were trying to compute, for example $\int_{-2}^{2} \frac{1}{x} \mathrm{d}x$. In this case, the complex result can tell you that you did something wrong.

But you can avoid the mess with the complex numbers by simply saying that $\int \frac{1}{x} \mathrm{d}x=\ln|x|$, as José Carlos Santos mentioned it already.

  • $\begingroup$ What do you mean by $\ln(-1)$? $\endgroup$ Jun 8, 2018 at 21:08
  • $\begingroup$ @NajibIdrissi What do you mean? I think you know the answer. It's either a complex number or just "a formal thing" which will lead you to the desired result. $\endgroup$
    – Botond
    Jun 8, 2018 at 21:15
  • $\begingroup$ The main branch of the logarithm is not defined on negative numbers... $\endgroup$ Jun 8, 2018 at 22:00
  • 3
    $\begingroup$ @NajibIdrissi The main branch of $\log$ is usually defined such that its imaginary part is in the interval $(-\pi,\pi]$ (see e.g. wikipedia). Therefore, $\log(-1)$ is perfectly well-defined and equal to $i\pi$. More generally, the main branch of $\log$ is well-defined on negative numbers and equal to $\log(-x)=\log x+i\pi$. $\endgroup$ Jun 9, 2018 at 0:45
  • 2
    $\begingroup$ @NajibIdrissi the main branch isn't continuous there, but it's perfectly well defined. $\endgroup$ Jun 9, 2018 at 1:36

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 $$


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .