<s>[INST] Real and imaginary parts of $(x + iy)^n$ For $z = x + iy$, we have, for example:
$\Re (z)=x$ and $\Im (z)=y$
$\Re (z^2)= x^2-y^2$ and $\Im (z^2)=2xy$
$\Re(z^3)=x^3-3xy^2$ and $\Im (z^3)=3yx^2-y^3$
I know that I have seen the formulas for $\Re (z^n)$ and $\Im (z^n)$ as explicit functions of $x$ and $y$ (polynomials in two variables, $x$ and $y$) in one book, but I do not know where that book is. So:

What are the formulas for $\Re (z^n)$ and $\Im (z^n)$?

 [/INST] Expanding $(x + i y)^n$ with the binomial formula gives
$$(x + i y)^n = \sum_{k = 0}^n {n \choose k} x^{n - k} (iy)^k $$
Now, we can split the sum into real and imaginary parts using $i^{2 k} = (-1)^k$ and $i^{2 k + 1} = (-1)^k i$:
$$(x + i y)^n = \underbrace{\sum_{\begin{array}{c}k = 0 \\ k \equiv 0 \pmod 2\end{array}}^{n} (-1)^{k / 2} {n \choose k} x^{n - k} y^k}_{\Re [(x + iy)^n]} + i \underbrace{\sum_{\begin{array}{c}k = 0 \\ k \equiv 1 \pmod 2\end{array}}^{n} (-1)^{(k - 1) / 2} {n \choose k} x^{n - k} y^k}_{\Im [(x + iy)^n]} .$$
One can eliminate the modulus conditions $k \equiv r \pmod 2$ in the summations by reindexing. For example,
$$\Re[(x + iy)^n] = \sum_{j = 0}^{\lfloor\frac{n}{2}\rfloor} (-1)^j {n \choose 2j} x^{n - 2j} y^{2j} .$$
These formulas tell us, by the way that we can read the coefficients off of Pascal's Triangle. For each $n$, the coefficients of the real part are given by looking at the $n$th row of Pascal's Triangle (here, we take the initial row, $1$ to be the $0$th row), and reading off every other entry with alternating signs, starting with the first. For the imaginary part, we do the same, but starting with the second entry. For example, for $n = 4$, the corresponding row is
$$\matrix{\color{blue}{1} & \color{red}{4} & \color{blue}{6} & \color{red}{4} & \color{blue}{1}} .$$
Our algorithm then tells us that we can read off these coefficients to give
$$\Re[(x + iy)^4] = + \color{blue}{1} x^4 - \color{blue}{6} x^2 y^2 + \color{blue}{1} y^4 = x^4 - 6 x^2 y^2 + y^4$$
and
$$\Im[(x + iy)^4] = + \color{red}{4} x^3 y - \color{red}{4} x y^3 = 4 x^3 y - 4 x y^3 .$$
</s>