If $f$ preserves identity and inverses, is it necessarily a group homomorphism?

It is a well-known fact that for any group homomorphism $f\colon (G,*)\to (H,\circ)$ we have \begin{gather*} f(1_G)=1_H\\ f(x^{-1})=f(x)^{-1} \end{gather*}

What about the converse?


Question. If $f$ is a function which preserves the identity and the inverses, is it necessarily a group homomorphism? Is it true if we additionally assume that $f$ is bijection? Is it true if $(G,*)=(H,\circ)$ (i.e., for functions - or bijective functions - $(G,*) \to (G,*))$?

Or maybe the question is better formulated like this: What are some nice/natural counterexamples to the above claims?


There should be some easy-to-find counterexamples. For example, if we take a group $G$ such that each element is self-inverse, i.e., $x*x=e$ for each $x\in G$, then the condition about inverses is trivially true; it just says $f(x)=f(x)$. So we are left with the maps preserving the identity. Such maps (even bijections) are unlikely to be always homomorphisms.


Different group structures on the same set could have the same identity (nullary) and inversion (unary) operations. For example, one could define $g \circ h$ to be $h*g$ to get the so-called opposite group, and $\circ$ is not the same as $*$ unless $(G,*)$ is abelian. Nonetheless, the identity in $(G,\circ)$ is the same as the one in $(G,*)$, and so is inversion. This means that the identity map $(G,*) \to (G,\circ)$ preserves the identity and inversion but is not a homomorphism.


Suppose $G$ is a nonabelian Lie group with lie algebra $\mathfrak{g}$. Its exponential map $\exp:\mathfrak{g}\to G$ (viewing $\mathfrak{g}$ as a Lie group under addition) is not a homomorphism, but it intertwines with inversion. Indeed, not only does it intertwine with inversion, it intertwines with all powers: $\exp(nX)=\exp(X)^n$. Even beyond this, its restriction to any 1D subspace is a homomorphism!

If you're unfamiliar with Lie theory, take $\exp:(M_2(\mathbb{R}),+)\to\mathrm{GL}_2\mathbb{R}$, where $M_2(\mathbb{R})$ is the group of $2\times2$ real matrices under addition, $\mathrm{GL}_2\mathbb{R}$ is the group of invertible $2\times2$ real matrices under matrix multiplication, and the exponential function is defined by the usual power series, only applied to matrices instead of scalars (it always converges).