Given $(G,*)$ a group. Show the function $f: G \to G$ defined as $f(a)=a^{2}$ is an homomorphism if and only if G is abelian.
My attemp was:
$\to$ suposse $f$ and homomorphism, to show $a*b=b*a$ \begin{align} f(a*b)=f(a)*f(b) \\ & = a^2*b^2 \\ & = (a*a)*(b*b) \\ & = (b*b)*(a*a) \\ & =f(b)*f(a) \\ \end{align}
I think it is wrong because I used commutative property.
For the last part:
$\leftarrow$ suposse G is abelian, to show $f$ is homomorphism
\begin{align} f(a)=a^2 \\ & = a*a \\ \end{align}
Can you help me to clarify the proof?
If $f$ is homomorphism then $$a^2b^2 =(ab)^2\implies aabb = abab $$
So after cancelacion on left with $a$ and on right with $b$ you get $ab=ba$. So group is abel.
Vice versa. If $G$ is abel then $$f(a)f(b) = a^2b^2 = aabb = abab = (ab)^2 = f(ab)$$