Calculating The Total Number Of Surjective Functions


Answer :

Consider f1(y)f^{-1}(y), yYy \in Y. This set must be non-empty, regardless of yy. What you're asking for is the number of ways to distribute the elements of XX into these sets.

The number of ways to distribute m elements into n non-empty sets is given by the Stirling numbers of the second kind, S(m,n)S(m,n). However, each element of YY can be associated with any of these sets, so you pick up an extra factor of n!n!: the total number should be S(m,n)n!S(m,n) n!

The Stirling numbers have interesting properties. They're worth checking out for their own sake.


Here is a solution that does not involve the Stirling numbers of the second kind, S(n,m)S(n,m). The number of surjective functions from a set XX with mm elements to a set YY with nn elements is

i=0n1(1)i(ni)(ni)m \sum_{i=0}^{n-1} (-1)^i{n \choose i}(n-i)^m

or more explicitly (n0)nm(n1)(n1)m+(n2)(n2)m±(nn2)2m(nn1)1m {n \choose 0}n^m - {n \choose 1}(n-1)^m + {n \choose 2}(n-2)^m - \cdots \pm {n \choose n-2}2^m \mp {n \choose n-1}1^m

We begin by counting the number of functions from XX to YY, which is already mentioned to be nmn^m. Next we subtract off the number n(n1)mn(n-1)^m (roughly the number of functions that miss one or more elements). Of course this subtraction is too large so we add back in (n2)(n2)m{n \choose 2}(n-2)^m (roughly the number of functions that miss 2 or more elements). But again, this addition is too large, so we subtract off the next term and so on. This is a rough sketch of a proof, it could be made more formal by using induction on nn.


This gives an overcount of the surjective functions, because your construction can produce the same onto function in more than one way.

Consider a simple case, m=3m=3 and n=2n=2. There are six nonempty proper subsets of the domain, and any of these can be the preimage of (say) the first element of the range, thereafter assigning the remaining elements of the domain to the second element of the range. In other words there are six surjective functions in this case.

But your formula gives 3!1!232=12\frac{3!}{1!} 2^{3-2} = 12.

Added: A correct count of surjective functions is tantamount to computing Stirling numbers of the second kind. The Wikipedia section under Twelvefold way has details. For small values of m,nm,n one can use counting by inclusion/exclusion as explained in the final portion of these lecture notes.


Comments

Popular posts from this blog

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?