Is every function between finite sets a restriction of a morphism of finite abelian groups (up to bijection)? Hopefully this is a quick question with an easy answer.
Can every function between finite sets be written as the restriction of a group homomorphism of finite abelian groups, up to bijection of the domain and codomain?
More explicitly, it it the case that for every $f : X \to Y$ with $X, Y$ finite sets, there is a group homomorphism $\phi : A \to B$ of finite abelian groups, subsets $S \subseteq A$ and $T \subseteq B$, and bijections $h_X : X \to S$ and $h_T : T \to Y$, such that
$$f = h_T \circ (\phi|_S : S \to T) \circ h_X?$$
 A: Yes. For any finite set $X$ you can consider the group $\mathcal P(X)$ with the operation being symmetric difference.
Identify the elements of $X$ with the singletons in $\mathcal P(X)$. Then any $f:X\to Y$ extends uniquely to a homomorphism $\mathcal P(X)\to\mathcal P(Y)$.

Or in general, pick any nontrivial abelian group $G$ and an element $g\ne 1_G$ and consider the groups $G^X$ and $G^Y$ with pointwise operations. $x\in X$ then corresponds to the element of $G^X$ that maps $x$ to $g$ and everything else to $1_G$. (But the extension will not be unique unless $g$ is a generator of $G$).
A: In general, a map $f:A\to B$ between nonempty sets is a homomorphism with respect to some abelian group structure on $A$ and $B$ iff the following two conditions hold:


*

*There exists a cardinal number $n$ such that for each $b\in B$, either $|f^{-1}(\{b\})|=n$ or $|f^{-1}(\{b\})|=0$.

*$|B|$ is a multiple of $|f(A)|$.


Indeed, both of these conditions are clearly necessary.  Conversely, if both conditions hold, choose a set $S$ such that $|B|=|S\times f(A)|$.  Choose an abelian group structure on the sets $S$ and $f(A)$, and give $B$ an abelian group structure isomorphic to $S\times f(A)$ such that $f(A)\subseteq B$ corresponds to the subgroup $\{0\}\times f(A)\subseteq S\times f(A)$.  Let $G$ be an abelian group of cardinality $n$ and choose a bijection $A\to G\times f(A)$ so that the sets of the form $f^{-1}(\{b\})\subseteq A$ correspond to sets of the form $G\times\{x\}\subseteq G\times f(A)$.  Now note that when we identify $A$ with $G\times f(A)$ and $B$ with $S\times f(A)$, the map $f$ is just the projection $G\times f(A)\to f(A)$ followed by the inclusion $f(A)\to S\times f(A)$, which is a homomorphism.

Now, to answer your question, we just have to extend the domain and codomain of an arbitrary map $f:X\to Y$ to make conditions (1) and (2) hold.  We can do this by letting $n$ be any positive integer which is greater than or equal to $|f^{-1}(\{y\})|$ for each $y\in Y$ and then adding new elements to $X$ which map to elements $y\in Y$ such that $|f^{-1}(\{y\})|<n$ until every element of $Y$ has $n$ different preimages.  This makes (1) hold, and then (2) holds automatically since $f$ is surjective.
