# How can I integrate $\int \arctan(\sec x + \tan x) dx$

I got this problem in my homework exercise:

$$\int \arctan(\sec x + \tan x) dx$$

I simplified it to

$$\int \arctan\left(\dfrac{1+\sin x}{\cos x}\right) dx$$

$$=\int \arctan\left(\sqrt{\dfrac{1+\sin x}{1-\sin x}}\right) dx$$

now, I tried putting $\sqrt{\dfrac{1+\sin x}{1-\sin x}} = \tan t$

Then $x = \arcsin(\sin^2 t-\cos^2 t)$ but it becomes complete mess after that!

## 6 Answers

$${1+\sin(x)\over \cos(x)}={\sin(x/2)+\cos(x/2)\over \cos(x/2)-\sin(x/2)}={1+\tan(x/2)\over 1-\tan(x/2)}=\tan(\pi/4+x/2)$$

Also keep in mind: $$\tan^{-1}(\tan(z))=\begin{cases}z&-\pi/2\le z\le\pi/2\\ z-\pi&\ \ \ \pi/2\lt z\le \pi\\z+\pi&\ \ -\pi\le z\lt-\pi/2 \end{cases}$$

• That was fast. Did you do this before? Aug 15 '16 at 7:15
• @N.S.JOHN Had a lot of practice in trigonometry and integration in 11th and 12th standard ;-) Aug 15 '16 at 7:16
• @N.S.JOHN Since $\arctan(\tan(x))$ is not always equal to $x$, the primitive you are looking for is not $\int (\pi/4+x/2)\,dx$. Aug 15 '16 at 7:36
• I think My edit will help @N.S.JOHN about the problem he was about to face. Aug 15 '16 at 7:51

An direct way to use the integration by parts:

Let $u = \arctan(\sec(x)+\tan(x))$ then $du = \frac{1}{2} dx$

$dv = dx$ then $v = x$.

Then the integral becomes $$x \arctan(\sec(x)+\tan(x)) - \int \frac{x}{2}dx$$

Using integration by parts, we get:

$$\int \arctan(\sec x + \tan x) dx=x\arctan(\sec x + \tan x)-\dfrac{x^2}{4}+C$$

By integration by parts we obtain $$\int \arctan(\sec x + \tan x) dx=x\arctan(\sec x + \tan x)-\dfrac{x^2}{4}+C.$$ Since we have the identity (see Qwerty's answer): $$\sec x + \tan x={1+\sin(x)\over \cos(x)}=\tan(\pi/4+x/2),$$ the primitive can be simplified (!?) to $$x\arctan(\sec x + \tan x)-\dfrac{x^2}{4}+C=x\arctan(\tan(\pi/4+x/2))-\dfrac{x^2}{4}+C\\=\frac{x^2+\pi x}{4}-\pi x \left\lfloor \frac{x}{2\pi}+\frac{3}{4}\right\rfloor+C.$$

P.S. Note that if we erroneously write that $\arctan(\sec x + \tan x)=\pi/4+x/2$, then we get a different answer $$\int \arctan(\sec x + \tan x) dx=\int (\pi/4+x/2) dx=\frac{x^2+\pi x}{4}+C.$$

sec x + tan x = tan t. then sec x - tan x = cot t. sec x = (cot t + tan t)/2. (sec t)^2 dt = sec x(sec x + tan x)dx = (tan t(tan t + cot t)/2)dx. Substitute dx and simplify.

A bit late to the party but I guess I could provide a general piecewise solution from where Qwerty left off.

From Qwerty you would end up with $$\arctan(\tan(x/2+\pi/4))$$, but you go further and break down this expression into a piecewise definition for all $$x\in\mathbb{R}$$.

Recall that $$\tan(\theta)$$ is invertible on the interval $$-\pi/2\lt \theta\lt\pi/2$$ so for those values we have $$\arctan(\tan(\theta))=\theta$$.

Notice that since the interval $$(-\pi/2,\pi/2)$$ is of length $$\pi$$, we can reach every other input by shifting the open interval $$(-\pi/2,\pi/2)$$ by some integer multiple of $$\pi$$. But given that $$\tan(\theta)$$ is periodic on $$\pi$$ (which you can confirm with the formula for $$\tan(a+b)$$), then $$\arctan(\tan(\theta))$$ also has a period of $$\pi$$, therefore the outputs repeat so the graph of $$\arctan(\tan(\theta))$$ is the line segment of $$y=\theta$$ that goes from the points $$(-\pi/2,-\pi/2)$$ to $$(\pi/2,\pi/2)$$ shifted laterally by $$\pi k$$ units for $$k\in\mathbb{Z}$$.

This can be summarized as follows

$$\arctan(\tan(\theta))=\left\{\theta-\pi k: -\frac{\pi}{2}+\pi k\lt \theta\lt\frac{\pi}{2}+\pi k\space, k\in\mathbb{Z}\right\}$$

Replacing $$\theta$$ with $$x/2+\pi/4$$ gives the graph $$y=x/2+\pi/4-\pi k$$ for $$k\in\mathbb{Z}$$ over the interval $$-\pi/2+\pi k\lt x/2+\pi/4\lt\pi/2+\pi k$$, which in turn solves to $$-3\pi/2+2\pi k\lt x\lt\pi/2+2\pi k$$.

So the piecewise definition of $$\arctan(\sec(x)+\tan(x))$$ becomes

$$\arctan(\sec(x)+\tan(x))=\left\{\frac{x}{2}+\frac{\pi}{4}-\pi k:-\frac{3\pi}{2}+2\pi k\lt x\lt\frac{\pi}{2}+2\pi k\space, k\in\mathbb{Z}\right\}\space (1)$$

so the indefinite integral evaluates to

$$\int\arctan(\sec(x)+\tan(x))dx=\left\{\frac{1}{4}x^2+\frac{1}{4}\pi(1-4k)x+C:-\frac{3\pi}{2}+2\pi k\lt x\lt\frac{\pi}{2}+2\pi k\space, k\in\mathbb{Z}\right\}$$

Or you can use the expression proved in previous answers using IBP and then substitute $$(1)$$ in place of $$\arctan(\sec(x)+\tan(x))$$ and you would obtain the exact same answer.