Integrating the following $\int \sqrt{\tan x+1}\,dx$ 
Question: Integrate the following, $$\int\sqrt{\tan x+1}\;dx.$$

Wolfram Alpha returns a non-elementary answer. Can someone please spot the mistake I have made here:
First consider this integral: 
$$\int \frac{1}{(x+1)\sqrt{x+3}} \, dx = -\sqrt{2}\tanh^{-1}\frac{\sqrt{x+3}}{\sqrt{2}} + c$$
Wolfram Alpha confirms that result. 
Then, we have
$$I=\int \sqrt{\tan x+1} \, dx, \quad \tan x=u+2,
\quad dx=\frac{du}{\sec^{2}x}=\frac{du}{(u+2)^{2}-1}=\frac{dx}{(u+3)(u+1)}$$
So this transforms the integral to the first integral on this post, which we can evaluate. Then after evaluation and resubstitution I get:
$$I=-\sqrt{2}\tanh^{-1}\frac{\sqrt{\tan x+1}}{\sqrt{2}}+c$$
However differentiating this with Wolfram Alpha gives me a messy trigonometric expression which doesn't seem to be equal (I tested some values in both expressions and get different answers). I also estimated the area under the integral between some values and also obtained different answers using the closed form. Any ideas why?
EDIT: I used the wrong identity. Nevertheless, we can still use this method to integrate sqrt(tanhx integrals). E.g:
$$I=\int \sqrt{\tanh x+1} \, dx, \tanh x=u+2,\quad 
-dx = \frac{du}{\operatorname{sech}^2 x} = \frac{du}{(u+2)^2-1} = \frac{dx}{(u+3)(u+1)}$$
To obtain:
 $\int \sqrt{\tanh x+1} \, dx = I=\sqrt{2}\tanh^{-1} \dfrac{\sqrt{\tanh x+1}}{\sqrt{2}}+c$
 A: Hint:
Let $u=\sqrt{\tan x+1}$ ,
Then $x=\tan^{-1}(u^2-1)$
$dx=\dfrac{2u}{(u^2-1)^2+1}du$
$\therefore\int\sqrt{\tan x+1}~dx=\int\dfrac{2u^2}{(u^2-1)^2+1}du$
A: This integral is not non-elementary. Following from @Harry Peter's hint, we have 
$$ \begin{align} \frac{2u^2}{u^4 - 2u^2 + 2} &= \frac{2}{u^2 + \dfrac{2}{u^2} - 2} \\ &= \frac{1 - \dfrac{\sqrt{2}}{u^2}}{\left(u+\dfrac{\sqrt{2}}{u}\right)^2-2\sqrt{2}-2} + \frac{1 + \dfrac{\sqrt{2}}{u^2}}{\left(u - \dfrac{\sqrt{2}}{u}\right)^2 + 2\sqrt{2} - 2 }
\end{align} $$
Then you can substitute $s = u + \dfrac{\sqrt{2}}{u}$ and $t = u - \dfrac{\sqrt{2}}{u}$, respectively.  The first integral is in terms of logarithms and the second is in terms of arctangent. As you can see, this can be expressed in terms of elementary functions.
A: Let $I=\int \sqrt{\tan x+1} d x$ and $u=\sqrt{\tan x+1}$.
\begin{aligned}
I &=\int \frac{2 u^{2} d u}{\left(u^{2}-1\right)^{2}+1} \\
&=2 \int \frac{u^{2}}{u^{4}-2 u^{2}+2} d u \\
&=2 \int \frac{d u}{u^{2}+\frac{2}{u^{2}}-2} \\
&= 2 \int \frac{\left(1+\frac{\sqrt{2}}{u}\right)+\left(1-\frac{\sqrt{2}}{u}\right)}{u^{2}+\frac{2}{u^{2}}-2} d u\\
&=\int \underbrace{\frac{1+\frac{\sqrt{2}}{u}}{u^{2}+\frac{2}{u^{2}}-2} d u}_{I}+\underbrace{\int \frac{1-\frac{\sqrt{2}}{u}}{u^{2}+\frac{2}{u^{2}}-2} d u}_{J}\end{aligned}
$$I=\int \frac{d\left(u-\frac{\sqrt{2}}{u}\right)}{\left(u-\frac{\sqrt{2}}{u}\right)^{2}+2(\sqrt{2}-1)}=\frac{1}{\sqrt{2(\sqrt{2}-1)}} \tan ^{-1}\left(\frac{u-\frac{\sqrt{2}}{u}}{\sqrt{2 (\sqrt{2}-1)}}\right)$$
$$J=\int \frac{d\left(u+\frac{\sqrt{2}}{u}\right)}{\left(u+\frac{\sqrt{2}}{u}\right)^{2}-2(\sqrt{2}+1)}=\frac{1}{2 \sqrt{2(\sqrt{2}+1)}} \ln \left|\frac{u+\frac{\sqrt{2}}{u}-\sqrt{2 (\sqrt{2}+1)}}{\left.u+\frac{\sqrt{2}}{u}+\sqrt{2(\sqrt{2}+1}\right)}\right|$$
Now we can conclude that
$$I=\frac{1}{\sqrt{2(\sqrt{2}-1})} \tan ^{-1}\left(\frac{\tan x+1-\sqrt{2}}{\sqrt{2(\sqrt{2}-1)(\tan x+1})}\right)+ \frac{1}{2\sqrt{2(\sqrt{2}+1)}} \ln \left| \frac{\tan x+1-\sqrt{2(\sqrt{2}+1)(\tan x+1)}+\sqrt2}{\tan x+1+\sqrt{2(\sqrt{2}+1)(\tan x+1)}+\sqrt2}\right|+C$$
A: directly use:$$u=\sqrt{\tan x+1}$$
it's possible to solve with that
A: $$I=\int\sqrt{\tan x+1}\ dx$$
The substitution $u=\sqrt{\tan x+1}$ gives 
$$I=2\int\frac{u^2du}{(u^2-1)^2+1}$$ 

A (not) Quick Detour:
Now we're gonna do a sneaky fraction decomposition. If $H(x)$ is a polynomial of degree $n$, then it has $n$ roots. If the roots of $H(x)$ are non-repeating, then $H(x)$ can be factored as follows: 
$$H(x)=F\prod_{r\in Q}(x-r)$$ 
Where $Q=\{x:H(x)=0\}$ is the set of roots of $H(x)$, and $F$ is some constant. And 
$$\prod_{i=1}^ka_i:=a_1\cdot a_2\cdots a_k=\prod_{i\in\{1,2,...,k\}}a_i$$
Because of this we know that $\frac1{H(x)}$ can be represented like so, as a decomposed fraction:
$$\frac1{H(x)}=\frac1F\sum_{r\in Q}\frac{b(r)}{x-r}$$
Where $b(r)$ represents the constants that come as a result of the fraction decomposition. These constants are independent of $x$. Here's how we do the thing:
$$\frac1{H(x)}=\frac1F\sum_{r\in Q}\frac{b(r)}{x-r}$$
$$\frac1{F\prod_{r\in Q}(x-r)}=\frac1F\sum_{r\in Q}\frac{b(r)}{x-r}$$
$$\prod_{r\in Q}\frac1{x-r}=\sum_{r\in Q}\frac{b(r)}{x-r}$$
$$\bigg(\prod_{a\in Q}(x-a)\bigg)\bigg(\prod_{r\in Q}\frac1{x-r}\bigg)=\bigg(\prod_{a\in Q}(x-a)\bigg)\sum_{r\in Q}\frac{b(r)}{x-r}$$
$$1=\sum_{r\in Q}\frac{b(r)}{x-r}\prod_{a\in Q}(x-a)$$
$$1=\sum_{r\in Q}b(r)\prod_{r\neq a\in Q}(x-a)$$
Thus, for any $k\in Q$,
$$1=\sum_{r\in Q}b(r)\prod_{r\neq a\in Q}(k-a)$$
$$1=b(k)\prod_{k\neq a\in Q}(k-a)$$
$$b(k)=\prod_{k\neq a\in Q}\frac1{k-a}$$
Which of course gives:
$$\frac1{H(x)}=\frac1F\sum_{r\in Q}\frac1{x-r}\prod_{r\neq a\in Q}\frac1{r-a}$$
Which is integrated easily. 
Again this can only be done with $H(x)$ if it's roots are non-repeating, because they weren't non-repeating, there would exist a pair of distinct $r_1,r_2\in Q$, were $r_1=r_2$, which would make the $$\prod_{r\neq a\in Q}\frac1{r-a}$$ 
bit become $\frac10$ in the case that $r=r_1$, and $a=r_2$. That was probably worded horribly, but just take my word for it that the roots of $H(x)$ must be non-repeating. 

Back to the Integral:
We may choose $H(u)=(u^2-1)^2+1$, which has $4$ (non-repeating: yay!) roots all in the form $$u=\pm\sqrt{1\pm i}$$
Thus we have, when $R=\{u:(u^2-1)^2+1=0\}$,
$$I=2\int u^2\sum_{r\in R}\frac1{u-r}\prod_{r\neq a\in R}\frac1{r-a}\ du$$
Which simplifies: 
$$I=2\sum_{r\in R}\prod_{r\neq a\in R}\frac1{r-a}\int\frac{u^2du}{u-r}$$

Another Detour:
Consider now 
$$K=\int\frac{x^2dx}{x-r}$$
The substitution $w=x-r$ gives
$$K=\int\frac{(w+r)^2 dw}w$$
$$K=\int\frac{w^2+2rw+r^2}w dw$$
$$K=\int\frac{w^2}w dw+2r\int\frac{w}wdw+r^2\int\frac1wdw$$
$$K=\frac{w^2}2+2rw+r^2\log|w|$$
$$K=\frac{(x-r)^2}2+2r(x-r)+r^2\log|x-r|$$
$$K=\frac{(x-r)(x-3r)}2+r^2\log|x-r|$$

The final bit:
Plugging in $K$ gives 
$$I=2\sum_{r\in R}\bigg(r^2\log|u-r|+\frac{(u-r)(u-3r)}2\bigg)\prod_{r\neq a\in R}\frac1{r-a}$$
$$I=\sum_{r\in R}\big(2r^2\log|u-r|+(u-r)(u-3r)\big)\prod_{r\neq a\in R}\frac1{r-a}$$
$$I=\sum_{r\in R}\frac{2r^2\log|u-r|+(u-r)(u-3r)}{\prod_{r\neq a\in R}(r-a)}$$
Don't forget to plug in $u=\sqrt{\tan x+1}$. :)
A: For the general integral below, substitute $t=\sqrt{\frac{\tan x+\cot a}{\csc a}}$
\begin{align}
I(a)&=\int \sqrt{\tan x +\cot a} \ dx= \int\frac{ 2 \sqrt{\sin a}}{t^2+\frac1{t^2} -{2\cos a} }dt\\
\end{align}
which can be integrated readily to obtain
$$I(a)= \sqrt{\frac{\cot\frac a2}2}\tan^{-1}\frac{\sqrt{{\cot\frac a2}} \tan x - \sqrt{{\tan\frac a2}} }{\sqrt{2(\tan x +\cot a} )}
- \sqrt{\frac{\tan\frac a2}2}\coth^{-1}\frac{\sqrt{{\tan\frac a2}} \tan x +\sqrt{{\cot\frac a2}} }{\sqrt{2(\tan x +\cot a} )}
$$
Then, specifically
$$\int \sqrt{\tan x +1} \ dx=I\left(\frac\pi4\right)
$$
