# Evaluate the integral $\int x \tan(x)\mathrm{d}x$

Problem: Evaluate the integral: $$\int x\tan(x)\mathrm{d}x$$

Source: One of my friends gave me this problem. He even made a bet that I couldn't solve it. I tried hard for an hour or so; then I gave up and went to Wolfram to figure out the answer. I was shocked to see it

I can't even understand the answer!

My try on it: At first it looked like a simple IBP(integration by parts) problem. But upon IBPing it I got even messy functions and finally it became impossible to handle. So just for the sake of getting rid of the question, I just solved it by using the Maclaurin series for tangent. $$\tan(x) = x + \frac{1}{3}x^3 + \frac{2}{15}x^5 +....$$ $$x\tan(x) = x^2 + \frac{1}{3}x^4 + \frac{2}{15}x^6 +....$$ Integrating with respect to $x$ $$\int x\tan(x)\mathrm{d}x = \int (x^2 + \frac{1}{3}x^4 + \frac{2}{15}x^6 +....)\mathrm{d}x$$ $$\int x\tan(x)\mathrm{d}x = \frac{x^3}{3} + \frac{1}{15}x^5 + \frac{2}{105}x^7 +....$$ Is this answer presentable? As it tells us nothing much about the nature of the curve. Or so, why it cannot be integrated simply? Or in other words, can we find an alternate solution by applying some known techniques of integral. Please keep in mind while answering that I'm a high school student with a little knowledge of uni level integral. Thanks!

Edit 1: WARNING! Not a high school level question. I got baited in it for the sake of a bet and now I feel really bad for asking something beyond my reach!(as of now)

• This is a notorious example: it cannot be done by "elementary" functions. Sep 24 '17 at 9:40
• "why" is my question @LordSharktheUnknown Sep 24 '17 at 9:41
• BTW you didn't say anything about the radius of convergence. The Taylor series solution does not converge for all $x\in \mathbb{R}$. Sep 24 '17 at 9:42
• it is not a solution, just an attempt. I don't know what you're talking about! Can you please give any references @MrYouMath? Sep 24 '17 at 9:44
• When using a Taylor series (here Maclaurin series) you always have to give a radius of convergence $R$. Only for $|x|<R$ the Maclaurin series is guaranteed to converge. The series should converge for $|x|<1$. In order to show that this integral cannot be solved by elementary (finite) expression, you could use Liouville's theorem or the Risch-algorithm (which will show that you cannot express it by elementary functions). Sep 24 '17 at 9:47

$$\text{About }\quad \int x\tan(x)dx$$ $x\tan(x)\quad$is an example of elementary function which antiderivative cannot be written with a finite number of elementary functions. They are an infinity of other examples like that. In those cases, one can proceed on different manners, depending the level of knowledge and the context.

• In practical use of the integral (engineering for example) one use numerical methods of integration.
• For analytical but limited purpose, one can express the function as an infinite series and integrate each term, insofar the series remains convergent in the range considered for the argument. So your anser on the form of limited series is an acceptable answer, provided warning about approximate of infinite series by limited series and about the validity domain.
• For analytical and general purpose, the integral is expressed thanks to some "special functions" (when they are available). In the present case, the special function involved is Li$_2 (x)$ a polylogarithm function. This supposes higher level maths. Just for an overview of the use of special function, this paper for general public : https://fr.scribd.com/doc/14623310/Safari-on-the-country-of-the-Special-Functions-Safari-au-pays-des-fonctions-speciales

NOTE :

The fact that there is no elementary closed form for an indefinite integral doesn't mean that there is no elementary closed form for a definite integral. For example : $$\int_0^{\pi/4}x\tan(x)dx=\frac{C}{2}-\frac{\pi}{8}\ln(2)$$ $C$ is the Catalan's constant.

• Nice answer (+1). Sep 24 '17 at 11:17
• That was extremely informative @JJacquelin Thank you ! Sep 24 '17 at 13:53

Although the function $x\tan x$ may look somewhat easy to integrate, the function that you seem to have seen is a non-elementary function i.e. one that doesn't have a closed form consisting of any of $+,-,\times,\div$, complex logarithms, exponentials, and nth root(or roots of an algebraic equation) expressions.

It's not easy to explain why a certain function does/does not have an elementary antiderivative. I think the field of Differential Galois Theory deals with this rather difficult problem. At your level, your textbook and friends simply hesitate, and offer these as challenges, and I cannot offer an explanation at your level, of this phenomena. You can look up the Risch's algorithm to integrate elementary functions.

There are plenty of examples of such functions. For example, $\int \frac{\sin x}{x} dx$ also doesn't have a closed form, neither does $\int e^{-x^2} dx$.

However, this does not mean that some definite integrals don't look nice. For example, $\int_{-\infty}^{\infty} e^{-x^2}dx = \sqrt{\pi}$, a result called the Gaussian integral.

Similarly, it's known that $\int_0^{\infty} \frac{\sin x}{x} = \frac \pi 2$. So these functions definitely do not have elementary antiderivatives, but "certain" definite integrals of these functions are computable.

• Thank you very much for the post! Highly informative and I do understand that certain things are beyond my reach at this age. I remember my teacher telling me something about $$\int_{-\infty}^{\infty} e^{-x^2}dx = \sqrt{\pi}$$ He told that it is a difficult one for us. Now I know that it's called a Gaussian integral. Thanks @E-dantaD-VantaC'Bhujadhaari Sep 24 '17 at 14:03

$\phantom{0}(1)$: prepare to integrate by parts
$\phantom{0}(2)$: integrate by parts
$\phantom{0}(3)$: add and subtract $x\log(2)$
$\phantom{0}(4)$: write $\cos(x)$ as a sum of complex exponentials
$\phantom{0}(5)$: factor out $e^{ix}$
$\phantom{0}(6)$: factor out $e^{-ix}$ (from $(4)$)
$\phantom{0}(7)$: average $(5)$ and $(6)$
$\phantom{0}(8)$: use the series for $\log(1+x)$
$\phantom{0}(9)$: integrate term by term
$(10)$: apply the series for $\Li_2$
$(11)$: $\Im(z)=\frac1{2i}(z-\bar{z})$

• thank you very much for trying, but I didn't get the last few lines. Maybe I'l look up later when I'm more wiser in the field of mathematics! Sep 25 '17 at 8:45
• @YourAverageEuler: I have added some explanation
– robjohn
Sep 25 '17 at 9:26

Even though $\int x \tan x \,dx$ is a difficult integral there are indirect ways of approaching the problem which provide a clearer path for calculating closed form definite integral results and studying convergence.

Given that $\int \tan x \;dx=-\log \cos x$, integrating $\int x\tan x \; dx$ by parts leads to $$\int x\tan x \; dx=\left[x (-\log \cos x) \right]-\int (-\log \cos x) \;dx$$

Although at first sight there does not seem to be much progress here, one reason for switching to the $\log \cos x$ integral is that there are now two different infinite series forms to study...

First Infinite Series $$\log \cos x=-\sum_{k=1}^{\infty}\frac{2^{2k}\lambda(2k)}{k\pi^{2k}}\,x^{2k}=-\sum_{k=1}^{\infty}\frac{(2^{2k}-1)\zeta(2k)}{k\pi^{2k}}\,x^{2k}$$

where $\zeta(2k)=\sum_{k=1}^{\infty}\frac{1}{n^{2k}}=\frac{(-1)^{k-1}(2\pi)^{2k}B_{2k}}{2(2k)!}=\frac{(2\pi)^{2k}}{2(2k)!}|{B_{2k}}|=\frac{2^{2k}}{2^{2k}-1}\lambda(2k)$, with $B_{2k}$ being Bernoulli Numbers.

Assuming convergence this series can be integrated term by term to give

$$\int \log \cos x \; dx=-\sum_{k=1}^{\infty}\frac{2^{2k}\lambda(2k)}{k(2k+1)\pi^{2k}}\,x^{2k+1}=-\sum_{k=1}^{\infty}\frac{(2^{2k}-1)\zeta(2k)}{k(2k+1)\pi^{2k}}\,x^{2k+1}$$

From this first integral it is easy to see that integrating over the interval $[0,\pi/4]$ gives

$$\int_0^{\frac{\pi}{4}} \log \cos x \; dx=-\frac{\pi}{4}\sum_{k=1}^{\infty}\frac{\lambda(2k)}{k(2k+1)}$$

It is easy to see that this infinite sum converges by studying the convergence of the monotonically increasing bounding sum $\sum_{k=1}^{\infty}\frac{\zeta(2k)}{k^2}$, by holding $\zeta{(2k)}$ constant at the initial value of $\zeta(2)$. In this case giving an upper bound of $\zeta(2)^2$.

Second Infinite Series

$$\log \cos x=-\log 2 + \sum_{k=1}^{\infty} \frac{(-1)^{k-1}\cos 2kx}{k}$$

Which assuming convergence can be integrated giving

$$\int \log \cos x \; dx=-x\log2+\frac{1}{2}\sum_{k=1}^{\infty} \frac{(-1)^{k-1}\sin 2kx}{k^2}$$

From this second integral it is easy to see that integrating over the interval $[0,\pi/4]$ gives

$$\int_0^{\frac{\pi}{4}} \log \cos x \; dx=-\frac{\pi}{4}\log2+\frac{1}{2}\sum_{k=1}^{\infty} \frac{(-1)^{k-1}\sin \left(2k\frac{\pi}{4} \right)}{k^2}$$

which simplifies to

$$\int_0^{\frac{\pi}{4}} \log \cos x \; dx=-\frac{\pi}{4}\log2+\frac{G}{2}$$

where $G=\sum_{k=1}^{\infty}\frac{(-1)^{k-1}}{(2k-1)^2}$ is Catalan's Constant.

• Thank you for taking out some time and solving it. I didn't get it for the most part, but some of my wiser counterparts can certainly benefit from your work above. Sep 25 '17 at 8:47