A few weeks ago I gave an example of a non-Hopfian finitely-presented group. Recall that a group $G$ is said to be Hopfian if every surjective group homomorphism $G\to G$ is actually an isomorphism. All finitely-generated, residually finite groups are Hopfian. So for example, the group of the integers $\Z$ is Hopfian.

Another example of a group that is not Hopfian was given by Gilbert Baumslag and Donald Solitar. Their group is the one-relator group
$$G = \langle a,t ~|~ t^{-1}a^2t = a^3\rangle.$$ The first thing to notice is that this group is the HNN extension of the integers forcing the subgroups $2\Z$ and $3\Z$ to be conjugate. Why is this group not Hopfian? Consider $f:G\to G$ given on generators by $f(a) = a^2$ and $f(t) = t$. Then $f(a^2t^{-1}a^{-2}t) = a$ and so $f$ is surjective. It is not injective, however, because it sends the commutator $[t^{-1}at,a]$ to the identity. Wait, why is this commutator not the identity? It's because of Britton's lemma, that I talked about before. Let's recall Britton's result.

Theorem. (Britton's Lemma) Let $G$ be a group and $\varphi:A\to B$ be an isomorphism between two subgroups $A$ and $B$ of $G$. Define the group $G^*$ by $\langle G, t ~|~ \{ t^{-1}at\}_{a\in A} \}$ (the HNN extension of $G$ by $\varphi$). Suppose the sequence of elements
$$g_0,t^{\epsilon_1}, g_1, \dots t^{\epsilon_k}, g_k$$ with $k \geq 1$ and $\epsilon_i\in \{\pm 1\}$ has no consecutive subsequence of the form $t^{-1}at$ with $a\in A$ or $tbt^{-1}$ with $b\in B$. Then the element
$$g_0t_{n_1}^{\epsilon_1}g_1\cdots t_{n_k}^{\epsilon_k}g_k$$ does not represent the identity element in the HNN extension $G^*$.

Actually, this version of Britton's lemma is stated just for a single isomorphism $\varphi:A\to B$. You could also have a family of isomorphisms $\varphi_i:A_i\to B_i$. For that case, Britton's lemma also holds and the precise statement for a family of isomorphisms is given in the post on Britton's lemma. Here, we only need the statement for one isomorphism, which in our case is the isomorphism between $2\Z$ and $3\Z$.

Britton's lemma is supposed to help us verify that the commutator $[t^{-1}at,a]$ is not the identity. If we write out this commutator, it is $1_Gt^{-1}atata^{-1}t^{-1}a^{-1}$. Is there any consecutive subsequence that looks like $t^{-1}xt$ where $x\in \langle a^2\rangle$ or any consecutive subsequence that looks like $txt^{-1}$ where $x\in \langle a^3\rangle$? Nope, didn't think so. Therefore, $[t^{-1}at,a]$ is a nontrivial element sent to the identity by the surjective homomorphism $f$, and thus $G$ cannot be Hopfian.

The reason why we could prove $f$ to be not Hopfian is that we found an element in $G$ that did not commute with $a$ (namely $t^{-1}at$), but which was sent to an element that did commute with $a$ under the homomorphism $f$. Thus, for example, the same idea would not work to prove that the group
$$\langle a,t ~|~ t^{-1}at = a^3\rangle$$ is not Hopfian. But of course it wouldn't work, because this group is Hopfian, right? In fact:

Theorem. (Baumslag and Solitar) The group
$$\langle a,t ~|~ t^{-1}a^\ell t = a^m\rangle$$ is Hopfian if and only if exactly one of the two conditions hold:

$|\ell| = 1$ or $|m| = 1$

Neither $|\ell|$ or $|m|$ are equal to one, and the set of prime divisors of $\ell$ is the same as the set of prime divisors of $m$.

For a good starting point with references as well as extensions of this result, check out the paper: