Problem.
Let $G$ be a group. Define a function $f : G \longrightarrow G$ by for all $a \in G$, $f(a) = a^{-1}$.
Prove that $f$ is a homomorphism if and only if $G$ is commutative.
My attempt.
Assume G is commutative;
Then $$f(x * y) = (x * y)^{-1}$$ $$\Rightarrow f(x * y) = y^{-1} * x^{-1}$$ Note: (am I making this up? I remember this from linear algebra and seem to recall it from this course as well.)
$$\Rightarrow f(y) * f(x) = f(x) * f(y)$$ as $G$ is commutative.
Let us now assume that $G$ is homomorphism;
$$f(x * y) = f(x) * f(y)$$ $$\Rightarrow f(x * y) = x^{-1} * y^{-1}$$
At this point I would try to show that $$x^{-1} * y^{-1} \neq y^{-1} * x^{-1}$$
Does not work and therefore it has to be commutative as well, but I don't want to spend more energy on this before knowing that I am doing this right and not just making things up! Thank you.
Hint: if $f$ is a homomorphism, then $$ f((xy)^{-1})=xy $$ by definition, but also \begin{align} f((xy)^{-1})&=f(y^{-1}x^{-1}) &&\text{basic identity}\\ &=f(y^{-1})f(x^{-1}) &&\text{homomorphism}\\ &=\dots \end{align}
For the other direction your reasoning is correct.