<s>[INST] Real function with complex antiderivative $\frac{\sqrt{x+\sqrt{x^2+1}}}{\sqrt{x}\sqrt{x^2+1}}$? Consider this indefinite integral (I'm interested in the interval $x>0$):
$$\int \frac{\sqrt{x+\sqrt{x^2+1}}}{\sqrt{x}\sqrt{x^2+1}}dx$$
By substitution:
$$u=\sqrt{\frac{1}{2}+\frac{1}{2}\sqrt{1+\frac{1}{x^2}}}, \qquad x=\frac{1}{2u \sqrt{u^2-1}}$$
We get a closed form antiderivative:

$$\int \frac{\sqrt{x+\sqrt{x^2+1}}}{\sqrt{x}\sqrt{x^2+1}}dx=\sqrt{2} \tanh^{-1} \sqrt{\frac{1}{2}+\frac{1}{2}\sqrt{1+\frac{1}{x^2}}} +C$$

Now the inverse hyperbolic tangent is real only for the argument in $(-1,1)$. But in our case the argument for all real $x$ is $ > 1$.

How can the function with real values on $x>0$ have a complex antiderivative?


Edit
To be clear, this is the correct antiderivative. I.e. by differentiating it we get the function under the integral.

How would you explain this without appealing to complex analysis, i.e. branches? This is a real valued function for positive $x$, so this can be given as an assignment to a first year calculus student for example


Edit 2
The derivation of the antiderivative after the substitution:
$$\int \frac{\sqrt{x+\sqrt{x^2+1}}}{\sqrt{x}\sqrt{x^2+1}}dx=\sqrt{2} \int \sqrt{\frac{1}{2}+\frac{1}{2}\sqrt{1+\frac{1}{x^2}}} \frac{dx}{\sqrt{x^2+1}}=\sqrt{2} \int u \frac{dx}{\sqrt{x^2+1}}$$
$$\sqrt{x^2+1}=x(2u^2-1)$$
$$dx=-x\frac{2u^2-1}{u(u^2-1)}du$$
$$\frac{dx}{\sqrt{1+x^2}}=-\frac{du}{u(u^2-1)}=\frac{du}{u(1-u^2)}$$
$$\int \frac{\sqrt{x+\sqrt{x^2+1}}}{\sqrt{x}\sqrt{x^2+1}}dx=\sqrt{2} \int \frac{du}{1-u^2}=\sqrt{2} \tanh^{-1} u$$
 [/INST] I got the answer 
$$\text{arctanh} = \frac12 \ln \frac{1+x}{1-x}$$
consider $\ln(x)$ where $x < 0 $
$$\ln(x) = \ln(|x| (-1))=$$
$$ = \ln(x) + \ln(-1)= \qquad  \text{(properties of logs)} $$
$$= \ln(x) + \ln(e^{i \pi}) $$
$$= \ln(x) + i \pi$$
so in your integration, the log of a negative number generates a constant $i \pi$ (or $ki \pi$ where $k$ is a constant)- this just disappears into the constant of integration, similar to other constants that can be generated and absorbed in integrations involving inverse hyperbolic functions
</s>