Often, complex exponential functions are used to represent trigonometric functions, since
$$ e^{i\theta} \equiv \cos\theta + i\sin\theta . $$
Thus, if for example I want to express the quantity $\cos x$, I might write:
$$ \cos x \equiv \Re\left\{e^{i x}\right\} . $$
I'm told that I can manipulate the LHS just like I would the RHS, and at the end just take the real part to get the same answer as other methods, but I have come across some trouble.
Let's say I wanted to square the LHS to get $\cos^2 x$. On the RHS, this would give me: $$ \begin{align} e^{2ix} &= (\cos x + i \sin x)^2 \\ &= (\cos^2x - \sin^2 x + 2i\cos x \sin x) \\ \implies \Re\{e^{2ix}\} &= \cos^2 x - \sin^2 x \end{align} $$
Now, of course I recognise that the RHS is the identity for $\cos 2x$, which makes complete sense since $e^{2ix} \equiv e^{i(2x)}$. My question then is, why do the rules suddenly break down as soon as I attempt to square my complex exponential as I would my trig function? And what are the most conventional steps to take to work around this? Many thanks.