<s>[INST] Let $z = x+iy$ be a complex number and denote $z^2 = A + Bi$. Solve for $x,y$ in terms of $A,B$. Here, $x, y, A, B$ are all real numbers. 
I am just having some problems with the algebra of putting it all together to get a solution. 
What I have currently is:
$z^2 = (x+iy)^2 = x^2 + 2xyi - y^2$
This gives $A = x^2 - y^2$ and $B = 2xy$. 
I also know that $|z|^2 = |z^2|$, which gives:
$|x+iy|^2 = |A+Bi|$ => $x^2+y^2 = \sqrt{(A^2+B^2)}$.
I know that I must be making some silly error (either in the above calculations or when I try substituting things in) but I keep going in circles with my algebra and not able to get a final answer. How should I proceed from here?
 [/INST] You already have $x^2- y^2= A$ and $x^2+ y^2= \sqrt{A^2+ B^2}$.  Adding those two equations eliminates $y^2$ and gives $2x^2= A+ \sqrt{A^2+ B^2}$.
</s>