Solution (source code)

= Solution

Since $x=\cos y$ with real $y$, necessarily $-1\leq x\leq1$. Use <Euler's formula> and set $w=e^{iy}\ne0$. Then
$$
2x=w+w^{-1},\qquad w^2-2xw+1=0,
$$
so the <quadratic equation> gives $w=x\pm i\sqrt{1-x^2}$. Let $q=x+i\sqrt{1-x^2}$. It lies on the upper half of the <unit circle>, so $q=e^{i\theta}$ with $0\leq\theta\leq\pi$. Choose the <complex logarithm> value $\ln q=i\theta$, taking $\ln(-1)=i\pi$ at $x=-1$. The two roots are $e^{\pm i\theta}$, so $e^{iy}=e^{\pm i\theta}$ gives $y=\pm\theta+2n\pi$.

Because $i\ln q=-\theta$, this set of real solutions is exactly
$$
\boxed{y=\pm i\ln\left(x+i\sqrt{1-x^2}\right)+2n\pi,\qquad n\in\mathbb Z.}
$$
The formula includes $x=\pm1$: the two sign families then coincide after adjusting $n$. No real $y$ exists if $|x|>1$.