Solving integral $\int \frac{\sqrt{x^2 + x}}{x}dx$ (problem 36 in section $6.25$ in Tom Apostol's calculus) Integrals which involve $\sqrt{(cx + d)^2 - a^2}$ could often be simplified if we do a substitution $cx + d = a \sec t$. If we take a concrete example, $\int \frac{\sqrt{x^2 + x}}{x}dx$, then the substitution would be
$$
x + \frac{1}{2} = \frac{1}{2}\sec t \\
dx = \frac{1}{2} \sec t \tan t dt \\
t = arcsec (2x+1)
$$
If I carry on that substitution, I get to
$$
\frac{1}{2} \int \frac{\sqrt{\tan ^ 2t}}{\sec t - 1} \sec t \tan t dt
$$
As far as I understand, that is
$$
\frac{1}{2} \int \frac{|\tan t|}{\sec t - 1} \sec t \tan t dt
$$
Now, there are two cases, $\tan t \ge 0$ and $\tan t < 0$.
$\tan t \ge 0$ case leads me to the solution also written in the book (and here):
$$
\frac{1}{2} \int \frac{1 + \cos t}{\cos ^ 2 t} dt = \\
\frac{1}{2} \tan t + \frac{1}{2} \log{\frac{1 + \tan \frac{t}{2}}{1 - \tan \frac{t}{2}}} + C = \\
\sqrt{x^2 + x} - \frac{1}{2}\log{|2\sqrt{x^2 + x} + 2x + 1|} + C
$$
But if I try the second case (i.e. $\tan t < 0$), I get to the negation of the previous case, so I wonder where did I go wrong? Should I maybe not even consider the negative case?
Thanks!
 A: In the first step we try to guess the result basing on our personal experience
and check if the derivative gives back the integrand. If we miss, we can  correct our guess and see what happens. In case we are unable to  make a good guess, we try to simplify the integrand. In our case
$$x^2+x=\left (x+{1\over 2}\right)^2-{1\over 4}={1\over 4}[(2x+1)^2-1]$$
It seems convenient to perform the substitution $u=2x+1.$ In this way we get
$${1\over 2}\int {\sqrt{u^2-1}\over u-1}\,du$$ The integrated function is defined on two disjoint intervals $u<-1$ and $u>1.$ For $u>1$ it is tempting to make the substitution $u=\cosh t={1\over 2}(e^t+e^{-t}),$ for $t>0,$  having in mind that $\cosh ^2t-\sinh^2 t=1$ (where $\sinh t={1\over 2}[e^t-e^{-t}]).$
Then $du=\sinh t\,dt$ and we end up with the integral
$${1\over 2}\int {\sinh ^2t\over \cosh t-1}\,dt={1\over 2}\int {\cosh^2t-1\over \cosh t-1}\,dt ={1\over 2}\int [\cosh t+1]\,dt={1\over 2}\sinh t +{1\over 2}t$$ Next we have to get back to the original variable $x.$ Solving $$u=\cosh t ={1\over 2}[e^t+e^{-t}],\qquad t>0$$ leads to the quadratic equation for $e^t$
$${1\over 2}\,(e^{t})^2-u\,e^t+{1\over 2}=0$$ from which we get $$e^t=u+\sqrt{u^2-1},\quad \sinh t=\sqrt{u^2-1},\quad t=\log (u+\sqrt{u^2-1}) $$
Remark There are two roots of the equation and their product is equal $1.$ We choose the  greater greater root, as $e^t>1$ for $t>0.$
Eventually, as $u=2x+1>1,
$ i.e. $x>0,$ we obtain $$\int {\sqrt{x^2+x}\over x}\,dx = {1\over 2}\log(2x+1+\sqrt{4x^2+4x})+{1\over 2}\sqrt{4x^2+4x}\\ ={1\over 2}\log (2x+1+2\sqrt{x^2+x})+\sqrt{x^2+x}\qquad \qquad (*)$$
It remains to consider the case left behind, when $u<-1,$ i.e. $x<-1.$ But since  formula $(*)$  holds for $x>1$ and $2x+1+2\sqrt{x^2+x}<0,$  for $x<-1,$
we get the final result
$$\int {\sqrt{x^2+x}\over x}\,dx  ={1\over 2}\log \mid 2x+1+2\sqrt{x^2+x}\mid+\sqrt{x^2+x}\qquad x\notin [-1,0]$$
Remark Mind that if we are looking for  a particular antiderivative $F(x),$  satisfying $F(1)=a $ and $F(-2)=b,$ we have to add to the solution above different constants, depending on the cases $x<-1$ or $x>0.$   Therefore I resist from writing $\int f(x)\,dx =F(x)+C,$ when $f(x)$ is defined on several disjoint open intervals. The formula $\int f(x)\,dx =F(x)$ is just equivalent to $F'(x)=f(x).$ For example $\int 2x\,dx =x^2$ and also $\int 2x\,dx =x^2+1,$ but it does not imply  $0=1.$
A: You may avoid worrying about square-roots or absolute signs by integrating as follows
\begin{align}
\int \frac{\sqrt{x^2 + x}}{x}dx
=& \int \frac{x+\frac12}{\sqrt{x^2 + x}}\>dx+ 
\int \frac{\frac12}{\sqrt{x^2 + x}}dx\\
=&\>\sqrt{x^2+x}+\frac12\tanh^{-1}\frac{\sqrt{x^2+x}}{x+\frac12}+C
\end{align}
which is valid for all domain $x$.
