If $ab=ba$, Prove $a^2$ commutes with $b^2$

From Dr. Pinter’s “A Book of Abstract Algebra”:

Given $a$ and $b$ are in $G$ and $ab=ba$, we say that $a$ and $b$ commute.

1. Prove $a^2$ commutes with $b^2$

I tried:

$$ab=ba$$
$$a^{2}b^{2}=b^{2}a^{2} \text{ // to prove that a^2 commutes with b^2}$$
$$aabb=bbaa$$

Then, knowing that $$a=b^{-1}ab,$$ I substituted that ‘$a$’ into ‘$aabb=bbaa$’.

But that simplified to ‘$aabb=bbaa$’, i.e. I got nowhere with it.

How can I prove that $$aabb=bbaa$$ per this problem?

Solutions Collecting From Web of "If $ab=ba$, Prove $a^2$ commutes with $b^2$"

Here is the proof (it only uses that $ab=ba$, which is given):

\begin{align} a^2b^2 &=aabb = a(ab)b \\ &= a(ba)b = (ab)(ab) \\ &= (ba)(ba) = b(ab)a \\ &= b(ba)a =bbaa\\ &=b^2a^2 \end{align}

Well, let’s be explicit on everything, including the associativity (i.e. using parentheses everywhere). We have
\begin{align} a^2 b^2 &= (aa)(bb) && \text{definition of x^2}\\ &= ((aa)b)b && \text{associativity}\\ &= (a(ab))b && \text{associativity}\\ &= (a(ba))b && \text{a and b commute}\\ &= ((ab)a)b && \text{associativity}\\ &= ((ba)a)b && \text{a and b commute}\\ &= (ba)(ab) && \text{associativity}\\ &= (ba)(ba) && \text{a and b commute}\\ &= ((ba)b)a && \text{associativity}\\ &= (b(ab))a && \text{associativity}\\ &= (b(ba))a && \text{a and b commute}\\ &= ((bb)a)a && \text{associativity}\\ &= (bb)(aa) && \text{associativity}\\ &= b^2a^2 && \text{definition of x^2} \end{align}
Now normally you would not write it this way, because after recognizing that because of associativity it doesn’t matter how you set brackets, you usually decide to just omit all brackets, and then a lot of steps (namely all marked with “associativity”) don’t change anything. Therefore the whole thing collapses into the following sequence, where I in each expression mark red the two items which are exchanged in the following step (i.e. the one which ends up in the innermost parentheses in the detailed derivation above):
$$a^2b^2 = a\color{red}{ab}b = \color{red}{ab}ab = ba\color{red}{ab} = b\color{red}{ab}a = bbaa = b^2a^2$$
Now as you can see, that $a$ and $b$ commutes just means that everywhere where $a$ and $b$ are next to each other, you can exchange them.

Also note that at no point I needed to use the inverse; indeed, the only thing I used is associativity (and the presumed property that $a$ and $b$ commute, of course), so the derivation works whenever you have an associative operation, even if you have no group, and in particular no inverses.

Here is a hint:

Writing it like $aabb=a(ab)b$ try to use $ab=ba$.

Start with $abab=baba$ then $a(bab)=b(aba)$ and $a(ba)b=b(ab)a$ using associativity twice. Then using commutativity $a(ab)b=b(ba)a$ or $aabb=bbaa$ as required.

$$ab^2 = bab = b^2 a \\ a^2b^2 = a(ab^2)=a(b^2a)= (ab^2)a=(b^2a)a = b^2a^2$$