Let $G$ be a group. Define $f:G\to G, a↦a^2$ for all $a∈G$. Prove that $f$ is a group homomorphism if and only if $G$ is abelian. So, I am lost and tried to work it out through definitions, but am unsure where to go to solve.
If G and H are groups, a homomorphism from G to H is a function $f:G→H$ such that for any two elements $a,b∈G$, $f(ab)=f(a)f(b)$.
If the commutative law holds in a group G, such that a group is called a commutative group or, more commonly, an abelian group,
 A: Suppose $f$ is a homomorphism.
$$
f(ab) = f(a) f(b) = a^2 b^2 \\
f(ab) = (ab)^2 = abab \\
a^2 b^2 = abab \\
a^{-1} a^2 b^2 b^{-1} = a^{-1} abab b^{-1} \\
a b = b a \\
$$
Therefore $f$ being a homomorphism implies that $G$ is abelian.
A: ($\implies$) Suppose $f: G\to G$, where $a\mapsto a^2$, is a homomorphism. We wish to show that for $a,b\in G$, $ab=ba$. We have:
$$ f(ab) =f(a)f(b)=a^2b^2$$
since $f$ is a homomorphism. By definition of $f$, we also have that:
$$ f(ab) = (ab)^2=abab\qquad$$
Equating the two, we arrive at:
$$ \begin{aligned}
a^2b^2 &= abab\\
a^{-1}a^2b^2b^{-1} &= a^{-1}ababb^{-1}\\
\end{aligned}$$
which follows from multiplying on the left by $a^{-1}$ and on the right by $b^{-1}$, and the existence of such an inverse element for $a$ and $b$ is guaranteed since $G$ is a group. Following the rule for powers in $G$, it follows that:
$$ ab=ba $$
as desired.
($\impliedby$) Suppose $G$ is abelian, we wish to show that $f:G\to G$, given by $f(a)=a^2$ is a homomorphism. Let $a,b\in G$, then:
$$\begin{aligned}
f(ab) &=(ab)^2\qquad \textrm{by definition of $f$}\\
&=(ab)(ab)\\
&= a^2b^2\qquad \textrm{since G is abelian}\\
&= f(a)f(b)
\end{aligned}$$
as was to be shown.
A: ($\Leftarrow$) $G$ abelian$\implies f(ab)=(ab)^2=abab=aabb=a^2b^2=f(a)f(b)$.
($\Rightarrow$) $f$ a homomorphism $\implies (ab)^2=f(ab)=f(a)f(b)=a^2b^2\implies abab=a^2b^2\implies a^{-1}ababb^{-1}=a^{-1}a^2b^2b^{-1}\implies ba=ab$.
