TITLE: Non-Abelian group $G$ in which $x\mapsto x^3$ is a homomorphism
QUESTION [9 upvotes]: Arpit Kansal showed here that a group $G$ in which $x\mapsto x^3$ is an isomorphism is Abelian. He first showed that we have $a^3b^3=b^3a^3$ for all $a,b\in G$ (only using that $x\mapsto x^3$ is homomorphism) and then used injectivity of $x\mapsto x^3$ to get $ab=ba$ for all $a,b\in G$.
Is there a non-Abelian group $G$ in which $x\mapsto x^3$ is a homomorphism?

REPLY [3 votes]: As suggested by @Nicky Hekster Consider the Heisenberg group of all matrices of the form
$$\left(\begin{array}{ccc}
1 & x & y\\
0 & 1 & z\\
0 & 0 & 1
\end{array}\right),$$
where $x,y,z\in\mathbb{Z}/3\mathbb{Z}$.This group has exponent $3$ i.e. for every $g \in G$ we have $g^3=e$. Just to make sure that $G$ is non abelian consider the following matrices and show that these matrices don't commute.  $$\left(\begin{array}{ccc}
1 & 1 & 0\\
0 & 1 & 2\\
0 & 0 & 1
\end{array}\right),$$ $$\left(\begin{array}{ccc}
1 & 1 & 0\\
0 & 1 & 1\\
0 & 0 & 1
\end{array}\right)$$