TITLE: Methods for counting the number of homomorphisms
QUESTION [6 upvotes]: Are there any standard methods for counting the number of homomorphisms between groups? For example, how big is $Hom(\mathbb{Z}_2\times\mathbb{Z}_2,D_8)$? 
My attempt at this was to show that there are exactly 2 subgroups of $D_8$ isomorphic to $\mathbb{Z}_2\times\mathbb{Z}_2$, then the problem reduces to calculating the size of $Hom(\mathbb{Z}_2\times\mathbb{Z}_2,\mathbb{Z}_2\times\mathbb{Z}_2)$ then multiplying that number by two. Since we are now talking about abelian groups, we can distribute the Hom to give $Hom(\mathbb{Z}_2\times\mathbb{Z}_2) \cong \oplus^{4}Hom(\mathbb{Z}_2,\mathbb{Z}_2) $. Now the answer follows easily.
This all seemed a bit ad hoc to me. What would I do if, for example I wanted $Hom(Q_8,A_5)$? 
Thanks

REPLY [13 votes]: This is a hard problem in general; whether it's easy in a particular case depends a lot on the particular groups involved. 
First, here is a general observation. Suppose $\pi$ is a finitely presented group and $G$ is a finite group. Then $\text{Hom}(\pi, G)$ is finite, and its cardinality can in principle be computed by looking at all possible assignments of elements of $G$ to the generators of $\pi$, and checking which such assignments also satisfy the relations in the presentation. In other words, problems of this form reduce in principle to "counting solutions to equations" in $G$. The more complicated presentations of $\pi$ are, the harder it is to do this. But, for example, $Q_8$ has a fairly small presentation so it shouldn't be so hard in this case.  
Second, here are some relatively easy special cases and observations.

If $G$ is abelian, then any homomorphism $\pi \to G$ factors through the abelianization $\pi/[\pi, \pi]$ of $\pi$, which may be much simpler to work with than $\pi$ itself; at this point the structure theorem for finitely generated abelian groups can be put to work.
$|\text{Hom}(\mathbb{Z}, G)| = |G|$ has the same cardinality as $G$. More generally, $|\text{Hom}(F_n, G)| = |G|^n$. 
$|\text{Hom}(\mathbb{Z}_n, G)|$ is the number of elements of $G$ of order dividing $n$.
$|\text{Hom}(\mathbb{Z} \times \mathbb{Z}, G)|$ is the number of pairs of commuting elements in $G$. You can use Burnside's lemma to show that this is equal to $|G|$ times the number of conjugacy classes in $G$. 

Combining the last two, $|\text{Hom}(\mathbb{Z}_2 \times \mathbb{Z}_2, G)|$ is the number of pairs of commuting elements in $G$ both of which have order dividing $2$. You can compute this number by first finding all elements of order dividing $2$ (don't forget the identity!) and then checking which ones commute.
Third, here is a favorite example of mine that shows that this problem has some real depth to it. Choose a positive integer $g$ and consider the group with presentation
$$\pi = \langle a_1, b_1, ... a_g, b_g | [a_1, b_1] ... [a_g, b_g] = 1 \rangle.$$
This is the fundamental group of a surface (in this case the compact orientable surface of genus $g$), but you don't need to know that. Mednykh's formula asserts that
$$\frac{ |\text{Hom}(\pi, G)|}{|G|} = \sum_V \left( \frac{\dim V}{|G|} \right)^{2 - 2g}$$
where the sum runs over all complex irreducible representations $V$ of $G$. (In particular when $g = 1$ this gives a proof that the number of conjugacy classes of $V$ is equal to the number of complex irreducible representations.)
This can be proven using character theory, but it also admits an interpretation in terms of a 2-dimensional topological quantum field theory called Dijkgraaf-Witten theory. The formula shows in particular that knowing $|\text{Hom}(\pi, G)|$ for all $g$ is equivalent to knowing the dimensions of the complex irreducible representations of $G$, which is far from obvious in either direction.