<s>[INST] Help with $\int \frac{\sqrt{x^2 + 1}}{x}\:dx$ I have been starting at the following integral for the past 2 hours and can not see where I have gone wrong. Can anyone please assist in isolating where I've made a mistake. 
My sanity thanks you in advance, 
\begin{equation*}
I = \int \frac{\sqrt{x^2 + 1}}{x}\:dx
\end{equation*}
Let $x = \tan(s)$:
\begin{equation*}
    \frac{dx}{ds} = \sec^2(s) \rightarrow dx = \sec^2(s)\:ds
\end{equation*}
Thus,
\begin{align*}
    I &= \int \frac{\sqrt{x^2 + 1}}{x}\:dx =  \int \frac{\sqrt{\tan^2(s) + 1}}{\tan(s)}\cdot  \sec^2(s)\:ds = \int \frac{\sec(s)}{\tan(s)}\sec^2(s)\:ds = \int \frac{\sec^3(s)}{\tan(s)}\:ds \\
    &= \int \frac{\frac{1}{\cos^3(s)}}{\frac{\sin(s)}{\cos(s)}}\:ds = \int \frac{1}{\cos^3(s)} \cdot \frac{\cos(s)}{\sin(s)}\:ds = \int \frac{1}{\cos^2(s)\sin(s)}\:ds = \int \frac{1}{\left(1 - \sin^2(s)\right)\sin(s)}\:ds \\
    &= \int \frac{1}{\left(1 + \sin(s)\right)\left(1 - \sin(s)\right)\sin(s)}\:ds
\end{align*}
Applying a Partial Fraction Decomposition we see:
\begin{equation*}
    \frac{1}{\left(1 + \sin(s)\right)\left(1 - \sin(s)\right)\sin(s)} = \frac{1}{\sin(s)} - \frac{1}{2}\cdot \frac{1}{1 + \sin(s)} - \frac{1}{2}\cdot \frac{1}{1 - \sin(s)}
\end{equation*}
Thus,
\begin{align*}
    I  &= \int \frac{1}{\left(1 + \sin(s)\right)\left(1 + \sin(s)\right)\sin(s)}\:ds =  \int \left[\frac{1}{\sin(s)} - \frac{1}{2}\cdot \frac{1}{1 + \sin(s)} - \frac{1}{2}\cdot \frac{1}{1 - \sin(s)} \right]\:ds \\
    &= \int \frac{1}{\sin(s)}\:ds - \frac{1}{2} \int \frac{1}{1 + \sin(s)}\:ds  - \frac{1}{2} \int \frac{1}{1 - \sin(s)}\:ds
\end{align*}
We now employ the Weierstrass Substitution $t = \tan\left(\frac{s}{2} \right)$:
\begin{equation*}
    ds = \frac{2}{1 + t^2}\:dt, \quad \sin(s) = \frac{2t}{1 + t^2}
\end{equation*}
Thus, 
\begin{align*}
   I&= \int \frac{1}{\sin(s)}\:ds - \frac{1}{2} \int \frac{1}{1 + \sin(s)}\:ds  - \frac{1}{2} \int \frac{1}{1 - \sin(s)}\:ds \\
    &= \int \frac{1}{\frac{2t}{1 + t^2}} \cdot \frac{2}{1 + t^2}\:dt - \frac{1}{2} \int \frac{1}{1 + \frac{2t}{1 + t^2}}\cdot \frac{2}{1 + t^2}\:dt  - \frac{1}{2} \int \frac{1}{1 - \frac{2t}{1 + t^2}}\cdot \frac{2}{1 + t^2}\:dt \\
    &= \int \frac{1}{t}\:dt - \int \frac{1}{1 + t^2 + 2t}\:dt - \int \frac{1}{1 + t^2 - 2t}\:dt \\
    &= \int \frac{1}{t}\:dt - \int \frac{1}{\left(t + 1\right)^2}\:dt - \int \frac{1}{\left(t - 1\right)^2}\:dt = \ln\left|t\right| - -\frac{1}{t + 1} - - \frac{1}{t - 1} + C \\
    &= \ln\left|t\right| +\frac{1}{t + 1} + \frac{1}{t - 1} + C = \ln\left|t\right| +\frac{2t}{t^2 - 1} + C
\end{align*}
Where $C$ is the constant of integration. Here:
\begin{equation*}
    t = \tan\left(\frac{s}{2} \right) = \tan\left(\frac{\arctan(x)}{2} \right) = \frac{\sqrt{x^2 + 1} - 1}{x}
\end{equation*}
Thus, 
\begin{align*}
   I&=  \ln\left|t\right| +\frac{2t}{t^2 - 1} + C = \ln\left|\frac{\sqrt{x^2 + 1} - 1}{x}\right| +\frac{2\left(\frac{\sqrt{x^2 + 1} - 1}{x}\right)}{\left(\frac{\sqrt{x^2 + 1} - 1}{x} \right)^2 - 1} + C \\
   &= \ln\left|\frac{\sqrt{x^2 + 1} - 1}{x}\right| + 2 \cdot \frac{\sqrt{x^2 + 1} - 1}{x}  \cdot \frac{1}{\left(\frac{x^2 + 1 - 2\sqrt{x^2 + 1} + 1}{x^2} \right) - 1} + C \\
   &= \ln\left|\frac{\sqrt{x^2 + 1} - 1}{x}\right| + 2 \cdot \frac{\sqrt{x^2 + 1} - 1}{x}  \cdot \frac{x^2}{\left(x^2 + 1 - 2\sqrt{x^2 + 1} + 1\right) - x^2} + C \\
  &= \ln\left|\frac{\sqrt{x^2 + 1} - 1}{x}\right| + 2 \cdot \frac{\sqrt{x^2 + 1} - 1}{x}  \cdot \frac{x^2}{2\left(1 - \sqrt{x^2 + 1} \right)} + C =  \ln\left|\frac{\sqrt{x^2 + 1} - 1}{x}\right| - x + C \\
\end{align*}
 [/INST] In some cases trigonometric substitution should be avoided
$$\displaystyle I=\int\dfrac{\sqrt{1+x^2}}xdx=\int x\cdot\dfrac{\sqrt{1+x^2}}{x^2}dx$$
Let $\sqrt{1+x^2}=u\implies1+x^2=u^2,x\ dx=u \ du$
$$I=\int\dfrac u{u^2-1}udu=1+\dfrac1{u^2-1}=1+\dfrac{1+u+1-u}{(1+u)(1-u)}=?$$
</s>