Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The following integral can be obtained using the online Wolfram integrator:

$$\int \frac{dx}{1+\cos^2 x} = \frac{\tan^{-1}(\frac{\tan x}{\sqrt{2}})}{\sqrt{2}}$$

Now assume we are performing this integration between $0$ and $2\pi$. Hence the result of the integration is zero.

On the other hand when looking at the integrand, $\displaystyle \frac{1}{1+\cos^2 x}$, we see that it is a periodic function that is never negative. The fact that it is never negative guarantees that the result of the integration will never be zero (i.e., intuitively there is a positive area under the curve).

What is going on here?

share|cite|improve this question
No paradox here, simply the fact that one applies a result out of its applicability range. To wit, the RHS is not continuous on $(0,2\pi)$ but jumps at points $\pi/2$ and $3\pi/2$. Since the size of each jump is $\pi/\sqrt2$ and there are two jumps, one can even use this very formula to get the correct value of the LHS, namely $\pi\sqrt2$. – Did Jul 14 '12 at 21:37
It's a pretty common problem with things like Wolfram Alpha. See this and this for instance. – J. M. Jul 15 '12 at 1:09
A related question. – J. M. Jul 16 '12 at 16:23
up vote 1 down vote accepted

An unusual substitution, the "$\tan(z/2)$"substitution, is being done here. You must take a careful look at what you are integrating. Here is a reference on this substitution.

share|cite|improve this answer
In your case, integrate on $[0,\pi/2]$ and multiply by 4. You can do this because of symmetries. – ncmathsadist Jul 14 '12 at 21:57
Yeah got it thanks. So the antiderivative must be continuous across the domain of integration to be able to substitute with the integral limits, right? – Revo Jul 14 '12 at 22:00
Yes. You have to watch out for that. – ncmathsadist Jul 14 '12 at 22:03
@Revo If $F$ is an antiderivative of $f$, this means that $F' = f$ so in particular $F$ must be continuous. (Otherwise $F$ can't be differentiable.) – mrf Jul 14 '12 at 22:34
@Revo: "Every calculus student knows that antiderivatives can contain an arbitrary additive constant. But in fact, there’s more arbitrariness than that: one can add different constants on different parts of the interval." – J. M. Jul 15 '12 at 1:11

(This is an expansion of my earlier comment.)

Consider the function

$$f_c(x)=\frac{x}{\sqrt 2}-\frac1{\sqrt 2}\arctan\left(\frac{\sin\,2x}{3+2\sqrt{2}+\cos\,2x}\right)$$

You can check that the derivative of $f_c(x)$ is $\dfrac1{1+\cos^2 x}$. The relevance of this function is that $f_c(x)$, unlike the function $f(x)=\dfrac1{\sqrt 2}\arctan\left(\dfrac{\tan\,x}{\sqrt 2}\right)$ given in the OP, has no discontinuities within the integration interval $[0,2\pi]$:

plot of two antiderivatives


$$\int_0^{2\pi}\frac{\mathrm dx}{1+\cos^2 x}=\left.\frac{x}{\sqrt 2}-\frac1{\sqrt 2}\arctan\left(\frac{\sin\,2x}{3+2\sqrt{2}+\cos\,2x}\right)\right|_0^{2\pi}=\pi\sqrt 2$$

One wonders how the two functions $f(x)$ and $f_c(x)$ could look so different and yet have the same derivative. A plot of $f_c(x)-f(x)$ shows the difference:


Here, we see that the two functions differ not by a constant, but by a piecewise constant function (i.e., a step function). In fact, the Fundamental Theorem of the Calculus can be stated a bit more generally than is usual in textbooks. To quote Oleksandr Pavlyk's blog entry on this subject,

Every calculus student knows that antiderivatives can contain an arbitrary additive constant. But in fact, there’s more arbitrariness than that: one can add different constants on different parts of the interval.

As already mentioned in the previous answers, the trouble lies in the use of the Weierstrass substitution; the source of the problem, simply put, is that the substitution function used happens to be discontinuous within the interval of integration. Thus, to properly evaluate definite integrals of rational functions of sine and cosine, one has to be careful in using the Weierstrass substitution, and must pay attention to the behavior near the singularities.

Jeffrey and Rich, in their paper, discuss methods for computer algebra systems to cope with this particular weakness of the Weierstrass substitution.

For the sake of completeness, here's a general formula for an antiderivative of $\dfrac1{p+q\cos^2 x}$ that is continuous over the real line:

$$\int\frac{\mathrm dx}{p+q\cos^2 x}=\frac1{\sqrt{p(p+q)}}\left(x-\arctan\left(\frac{q\sin\,2x}{2p+q+2\sqrt{p(p+q)}+q\cos\,2x}\right)\right)$$

share|cite|improve this answer
the paper is available at Jeffrey's homepage ('Offprint service'). – Raymond Manzoni Jul 15 '12 at 10:51
Thanks @Raymond! – J. M. Jul 15 '12 at 10:52

Quite simple: the $\arctan$ function is multivalued, so you have to add the appropriate multiples of $\pi$ to the function to get at the right result, i.e. $\sqrt{2}\pi$

share|cite|improve this answer

The antiderivative you are using is not continuous from $0$ to $2\pi$. Ask Wolfram to graph it. Then try to see if you can adjust it by constants on various intervals to make it continuous, and you will see that the integral is quite far from $0$.

share|cite|improve this answer

The problem here is not with the integrand; instead, it is with the antiderivative of the integrand on the interval of integration $(0,2\pi)$, where the antiderivative of the integrand is discontinuous at $\pi/2$ and $3\pi/2$. This suggests that we split the interval of integration to three intervals; namely, $(0,\pi/2)$, $(\pi/2,3\pi/2)$, and $(3\pi/2,2\pi)$. Doing that, we get the right answer $\sqrt 2 \pi$.

share|cite|improve this answer

If $\tan(y)=a\tan(x)$, then $\tan(y-x)=\frac{(a-1)\tan(x)}{1+a\tan^2(x)}$, and therefore, $$ y=x+\tan^{-1}\left(\frac{(a-1)\tan(x)}{1+a\tan^2(x)}\right)\tag{1} $$ Since $\left|\frac{(a-1)\tan(x)}{1+a\tan^2(x)}\right|\le\frac{\left|a-1\right|}{2\sqrt{a}}$, $(1)$ is a nice continuous function of $x$.

In this question, $a=\frac1{\sqrt2}$, so we get $$ \int\frac{\mathrm{d}x}{1+\cos^2(x)}=\frac{x-\tan^{-1}\left(\frac{(\sqrt2-1)\tan(x)}{\sqrt2+\tan^2(x)}\right)}{\sqrt2}\tag{2} $$

share|cite|improve this answer
This is nice. But isn't it covered in the answer of J.M. above, in particular in the link in the comment by Raymond Manzoni? – mickep Jun 18 at 18:58
I haven't dug into those links. In any case, I think having a local derivation is good. This is how I dealt with a similar problem when handling Kepler's Equation. – robjohn Jun 19 at 3:39
+1. Fine. It kills any disease. – Felix Marin Jun 19 at 7:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.