If for $x,y \in S$, $x^2\circ y =y = y \circ x^2 $, then prove that $(S, \circ)$ is an abelian group. Let $(S, \circ)$ be a semigroup. If for $x,y \in S$, $x^2\circ y =y = y \circ x^2 $, then prove that $(S, \circ)$ is an abelian group.
My Try: Let $p \in S$. Then $p^2 \in S$ and for all $a \in S,p^2\circ a =a = a \circ p^2 $, by the given condition. This shows that $p^2$ is an identity. Similarly if $q \in S$ then $q^2$ is an identity.
By the given condition $p^2\circ q^2 =q^2 = q^2 \circ p^2$ and also $q^2 \circ p^2 = p^2 =p^2\circ q^2 $. So $p^2 = q^2$. This proves that there exists only one identity element in $S$.
Let $e$ be the identity in $S$. Then for all $x \in S, x^2\circ e =e = e \circ x^2$ by the given condition , $x^2 = e, x = x^{-1}$.
Therefore for all $x \in S, x^{-1} \in S$. Thus $(S, \circ)$ is a group.
Let $a,b \in S$ then $a \circ b \in S$ and $a = a^{-1}, b = b^{-1}, a \circ b = (a \circ b )^{-1}$. $a \circ b  = (a \circ b )^{-1} = b^{-1} \circ a^{-1} = b \circ a$.
Therefore $a \circ b = b \circ a$ for all $a,b \in S$. Hence $(S, \circ)$ is an abelian group.
Is the solution correct?
 A: As Mariano points out in the comments above, there's no need to prove the uniqueness of an identity element in this semigroup, as any semigroup with an identity element has exactly one such element. To see this, suppose that $e$ and $e'$ are identity elements of a semigroup $(S',*).$ Since $e$ is an identity element, then $e*e'=e'.$ On the other hand, $e'$ is an identity element, and so $e*e'=e.$ Thus, existence implies uniqueness.

You've started well by observing that for any $p\in S,$ we have that $p^2$ is an identity element of $(S,\circ),$ and so (by the reasoning above) is the unique identity element, say $e.$
Thus, $p=p^{-1},$ and so $(S,\circ)$ is a group, as a semigroup with identity and inverses. At that point, it remains only to show that it is abelian. Your method of proving this is just fine! Another way you could do it is as follows: $$(a\circ b)\circ(b\circ a)=a\circ\bigl((b\circ b)\circ a\bigr)=a\circ\left(b^2\circ a\right)=a\circ a=a^2=e.$$ Similarly, $(b\circ a)\circ(a\circ b)=e,$ so $b\circ a=(a\circ b)^{-1}=a\circ b,$ completing the proof.
