How do you prove that $\int \frac{1}{\sqrt{x^2+r^2}} \,dx = \ln{\left\lvert x + \sqrt{x^2+r^2} \right\rvert + C}$? I would like to prove that
$$\int \frac{1}{\sqrt{x^2+r^2}} \,dx = \ln{\left\lvert x + \sqrt{x^2+r^2} \right\rvert} + C$$
I tried with applying derivative with respect to $x$ to $\ln{\left\lvert x + \sqrt{x^2+r^2}\right\rvert}$ and show it is equal to $\frac{1}{\sqrt{x^2+r^2}}$, but I ended up with $$ \frac{d}{dx} \ln{\left\lvert x + \sqrt{x^2+r^2}\right\rvert} = \dots = \frac{1}{x + \sqrt{x^2+r^2}}\left(1+\frac{1}{\sqrt{x^2+r^2}}\right)$$ and I do not see how it can be simplified to $\frac{1}{\sqrt{x^2+r^2}}$.
Any help would be appreciated (even involving complex calculus, if needed).
 A: HINT
What about the substitution $x = r\sinh(u)$? In such case, one has that
\begin{align*}
\int\frac{1}{\sqrt{x^{2}+r^{2}}}\mathrm{d}x & = \int\frac{r\cosh(u)}{\sqrt{r^{2}\sinh^{2}(u) + r^{2}}}\mathrm{d}u = \int1\mathrm{d}u = u + c
\end{align*}
Can you take it from here?
EDIT
Since the $\sinh$ function is bijective, there is always a solution to
\begin{align*}
z = \sinh(w) = \frac{e^{w} - e^{-w}}{2} & \Longleftrightarrow (e^{w})^{2}  - 2ze^{w} - 1 = 0\\\\
& \Longleftrightarrow e^{w} = \frac{2z + 2\sqrt{z^{2}+1}}{2}\\\\
& \Longleftrightarrow w = \ln(z + \sqrt{z^{2}+1})
\end{align*}
At your case, we have that
\begin{align*}
\int\frac{\mathrm{d}x}{\sqrt{x^{2}+r^{2}}} = \sinh^{-1}\left(\frac{x}{r}\right) + c = \ln\left(\frac{x + \sqrt{x^{2} + r^{2}}}{r}\right) + c = \ln\left(x + \sqrt{x^{2} + r^{2}}\right) + C
\end{align*}
and we are done.
Hopefully this helps!
A: Your calculation of the derivative is incorrect.
Note $$\begin{align}
\frac{d}{dx}\left[ x + \sqrt{x^2 + r^2} \right] 
&= 1 + \frac{1}{2}\left(x^2 + r^2 \right)^{-1/2} \cdot \frac{d}{dx}\left[x^2 + r^2\right] \\
&= 1 + \frac{1}{2 \sqrt{x^2 + r^2}} \cdot 2x \\
&= 1 + \frac{x}{\sqrt{x^2 + r^2}}. \end{align}$$  You are missing the $x$ in the numerator of the second term.
Then we obtain $$\begin{align}
\frac{d}{dx}\left[\log \left| x + \sqrt{x^2 + r^2} \right| \right] 
&= \frac{1}{x + \sqrt{x^2 + r^2}} \left(1 + \frac{x}{\sqrt{x^2 + r^2}}\right) \\
&= \frac{1}{x + \sqrt{x^2 + r^2}} \left( \frac{\sqrt{x^2 + r^2} + x}{\sqrt{x^2 + r^2}} \right) \\
&= \frac{1}{\sqrt{x^2 + r^2}},
\end{align}$$ as claimed.
In order to perform the integration in the first place, there are a variety of substitutions that can be performed.  One is via the tangent identity $$\tan^2 \theta + 1 = \sec^2 \theta,$$ hence the choice $$x = r \tan \theta, \quad dx = r \sec^2 \theta \, d\theta$$ yields
$$\int \frac{1}{\sqrt{x^2 + r^2}} \, dx = \int \frac{1}{\sqrt{r^2 (\tan^2 \theta + 1)}} \cdot r \sec^2 \theta \, d\theta = \int \frac{\sec^2 \theta}{\sec \theta} \, d\theta = \int \sec \theta \, d\theta.$$
Now we perform the algebraic manipulation
$$\sec \theta = \frac{\sec \theta (\sec \theta + \tan \theta)}{\sec \theta + \tan \theta} = \frac{\sec^2 \theta + \sec \theta \tan \theta}{\sec \theta + \tan \theta}.$$  Then the derivative of the denominator equals the numerator; i.e. $$\frac{d}{d\theta}[ \sec \theta + \tan \theta] = \sec \theta \tan \theta + \sec^2 \theta,$$ from which we may choose the substitution $u = \sec \theta + \tan \theta$ and obtain $$\begin{align}
\int \sec \theta \, d\theta &= \int \frac{1}{u} \, du \\ &= \log |u| + C \\
&= \log |\sec \theta + \tan \theta| + C \\
&= \log \left| \sqrt{(x/r)^2 + 1} + x/r \right| + C \\
&= \log \left| \frac{x + \sqrt{x^2 + r^2}}{r} \right| + C \\
&= \log \left| x + \sqrt{x^2 + r^2} \right| - \log |r| + C \\
&= \log \left| x + \sqrt{x^2 + r^2} \right| + C,
\end{align}$$
since $\log |r|$ is a constant with respect to $x$ and may be absorbed into $C$.
