Given two groups $A$ and $B$ and an injective homomorphism $f : A \to B$. When does a homomorphism $g : B \to A$ exist with $g\circ f = \mathrm{id}_A$ (but not necessarily $f\circ g = \mathrm{id}_B$)?

$\begingroup$ You may assume that $f$ is the inclusion of a subgroup $A \subseteq B$. I don't think that there is a general simple criterion. If $B$ is abelian, you have the splitting lemma which says that $A \subseteq B$ has a retract if and only if $B \to B/A$ has a section if and only if $A$ is a direct summand of $B$. $\endgroup$ – Martin Brandenburg Jun 28 '10 at 10:49

$\begingroup$ BB in his answer below mentions semidirect products, you talk about direct sums. Who of you is right (or both)? $\endgroup$ – HansPeter Stricker Jun 28 '10 at 10:57

$\begingroup$ I only adressed the case that $B$ is abelian. $\endgroup$ – Martin Brandenburg Jun 28 '10 at 11:05

$\begingroup$ @Martin: I see. $\endgroup$ – HansPeter Stricker Jun 28 '10 at 11:07
If and only if $B$ is a semidirect product of $A$ and another group (the latter is normal). One direction is obvious, and another direction is easy: $B$ is a semidirect product of the image of $f$ and the kernel of $g$.
If you look at this problem from the side of $B$, i. e. how do we find endomorphic retracts of a given group, then there's also somewhat definite answer.
Define equation over group $G$ with coefficients in $H \le G$ as a collection of elements $w_i \in H * \mathrm{Free}(x_1, x_2, \dots)$. Solution of an equation is a homomorphism $\phi: H * \mathrm{Free}(x_1, x_2, \dots) \to G$ identical on $H$ and such that $\phi(w_i) = 1$.
Let's call $H \le G$ algebraically closed (should be not confused with algebraic closure of a group, nor by Levine nor Farjoun)
if every system of equations $w_i(X_1, \dots, X_l) = 1$ with coefficients in $H$ have solution in $G$ if and anly if it has solution in $H$ already.
It's clear that every retract of a group is algebraically closed; сonverse is true if subgroup is f. g. (A. Myasnikov, V. Roman’kov, Verbally closed subgroups of free groups, 2014). Also see this paper about conditions weaker than algebraic closedness https://arxiv.org/pdf/1702.07761.pdf.