TITLE: Is mapping generators to generators, and then extending, a well-defined homomorphism?
QUESTION [6 upvotes]: I was trying to define a homomorphism between some finite groups and I had the following idea. 
Suppose that $G = \langle a, b\rangle $, and $H = \langle x, y\rangle$. We define $\varphi:G \to H$ by $\varphi(a)=x,$ $\varphi(b)=y$, and for an arbitrary element of $G$,  $g_1^{\epsilon_1}g_2^{\epsilon_2} \cdots g_n^{\epsilon_n}$ (where each $g_i$ is either $a$ or $b$, and each $\epsilon_i$ is either $1$ or $-1$), then $\varphi(g_1^{\epsilon_1}g_2^{\epsilon_2} \cdots g_n^{\epsilon_n}) = \varphi(g_1)^{\epsilon_1} \varphi(g_2)^{\epsilon_2} \cdots \varphi(g_n)^{\epsilon_n}$.
If this is well-defined, then this is obviously a homomorphism. However, I do not know if this is well defined. I suspect not.

REPLY [2 votes]: Look at it this way. If what you propose was well-defined in general, then your $\varphi$ would always have inverse $\psi\colon H\to G$ just by setting $\psi(x)=a$, $\psi(y) = b$. But not all groups generated by two elements are isomorphic. For example look at $\mathbb Z_2\times\mathbb Z_2$, $\mathbb Z\times \mathbb Z_2$, $\mathbb Z\times\mathbb Z$, $F_2$ (free group generated by two elements), and any dihedral group $D_n$.
In general, for the group $G$ to be generated by two elements, it means that there is an epimorphism $\varepsilon\colon F_2\to G$ and by the first isomorphism theorem $G\cong F_2/\ker\varepsilon$. So, to define $\varphi\colon G\to H$, you need to have a homomorhpism $\psi\colon F_2 \to H$ such that $\ker\varepsilon\subseteq \ker\psi$, by the fundamental homomorphism theorem.
To explain what it means precisely, let $F_2 = \langle x,y\rangle$ and $G = \langle a,b\rangle$. In this case, $\varepsilon$ is just $x\mapsto a$ and $y\mapsto b$. To specify $\psi$, it is enough to pick any two elements $h_1,h_2\in H$ and let $\psi(x) = h_1$, $\psi(y) = h_2$. This always does define homomorphism - this is by definition of a free group, and this is essentially what you wanted to do, but for group $G$. Now, condition $\ker\varepsilon\subseteq \ker\psi$ is equivalent to saying that for all $a^{\alpha_1}b^{\beta_1}\ldots a^{\alpha_n}b^{\beta_n} = e_G$, it must be that $h_1^{\alpha_1}h_2^{\beta_1}\ldots h_1^{\alpha_n}h_2^{\beta_n} = e_H.$  If that's true, you can set $\varphi(a) = h_1$, $\varphi(b) = h_2$, and it will be well-defined.
For more concrete example, let's take $G = \mathbb Z_2\times\mathbb Z_2$ and $H = \mathbb Z\times\mathbb Z$. Let $a = (1,0)$ and $b = (0,1)$. Note that $2a = 2b = (0,0)$ (I've switched to additive notation, as is customary). However, for any hypothetical $\varphi\colon G\to H$, $2\varphi(a) = \varphi(2a) = \varphi(0,0) = (0,0)$. Since the only $h\in H$ such that $2h = (0,0)$ is $h = (0,0)$, we need to have $\varphi(a) = (0,0)$ and similarly $\varphi(b) = (0,0)$. So, the only homomorphism is trivial.