How can I prove the following equation for the angle between two vectors? I'm new in the Mathematics forum, I hope such questions are accepted. This is a problem I had to solve in a job interview, I still can't find the answer, which I guess it's pretty basic.
Given two vectors $x,y$, prove that the angle between them can be calculated as:
$$\theta = 2\arctan\left(\frac{\Big| |x| y- |y| x\Big|}{\Big| |x| y+ |y|x\Big|}\right)$$
I already tried writing $x$ and $y$ as vectors in the complex plane, I tried some graphical "methods" and using various trigonometric identities, but nothing got me close to an equation similar to that.
A second question asked what numerical advantages does this formula give with respect to the usual $\theta=\arccos\left(\frac{{x}\cdot{y}}{|x||y|}\right)$. I thought that $\arctan$ can accept any input, while $\arccos$ limits them in $[-1,1]$, but this doesn't sound like a numerical matter. Moreover, I see a subtraction in the first equation, which I guess might lead to some loss of significance problems. Is the first equation really numerically superior than the second one?
 A: $\|x\|$y and $\|y\|x$ are two vectors with the same length.
Geometrically they would form two sides of a rhombus, where one diagonal length is the length of $\|x\|y+\|y\|x$ as from the parallelogram addition rule, and the other diagonal length is the length of $\|x\|y-\|y\|x$.

The two diagonals intersect at their midpoints at a right angle. Diagonals bisect rhombus corners. Consider one of the four right angles in the rhombus,
$$\tan\frac\theta2 = \cfrac{\left\|\cfrac{\|x\|y-\|y\|x}{2}\right\|}{\left\|\cfrac{\|x\|y+\|y\|x}{2}\right\|}$$

For question 2, my guess would be related to rounding error when $\theta$ is small? Then $\cos \theta$ would be close to $1$, and inverting $\cos$ precisely would require more significant figures.
Inspired by the comment in the spherical law of cosines about rounding errors and the alternative formulation of the law of haversines.
A: We can assume wlog, by homogeneity, that $|x|=|y|=1$, then by a simple geometric construction we obtain that
$$\frac{| |x|y- |y|x|}{| |x|y+ |y|x|} = \frac{| y- x|}{| y+ x|} =\frac{2\sin \frac \theta 2}{2\sin \left(\frac{\pi -\theta}2\right)}=\frac{\sin \frac \theta 2}{\cos \frac \theta 2}=\tan \frac \theta 2$$

A: If you divide top and bottom by $|x||y|$ the expression becomes
$$\theta = 2\arctan\left(\frac{|\hat y- \hat x|}{|\hat y +\hat x|}\right)$$
where $\hat x$ indicates the unit vector in the $x$ direction. Then the length of the vector $\hat y+\hat x$ is $|\hat y+\hat x|=2\cos(\theta/2)$ and the length of the vector $\hat y-\hat x$ is $|\hat y-\hat x|=2\cos(90-\theta/2)=2\sin(\theta/2)$.
I've left explanation of the geometry to the following crudely-drawn figure. Note that $(\hat x+\hat y )\cdot(\hat x-\hat y)=0$, so the two lines are perpendicular. Another way to see that is to view $2\hat x$ as a diameter and $\hat y$ as the radius of a circle, then the angle between these becomes the inscribed angle of a diameter, which is a right angle.

I don't have an answer for the second part of your question, something to do with numerical stability for relatively small or large values?
