10

Let there be: $|A|=n$ and $|B|=m$ if $m>n$ then there are $$m(m-1)\cdots(m-n+1)$$ injective functions, so in this case we have $|A|=30$ and $|B|=20$ that means $m<n$ so there exists a surjective function, but I'm not sure if I can find the number of surjective functions in the same way that I did find the number of injective functions.

Ayman Hourieh
  • 40,828

2 Answers2

18

To construct a surjective function from $A$ to $B$, we want to distribute the elements of $A$ into $m$ bins (each representing an element of $B$) so that each bin contains at least one element. In other words, we want to partition the set $A$ consisting of $n$ elements into $m$ non-empty subsets, and assign an element of $B$ to each partition.

The number of ways to partition a set of $n$ elements into $m$ non-empty subsets is called the Stirling number of the second kind and usually denoted by $$ \left\lbrace{n\atop m}\right\rbrace. $$

There is no simple closed form for this number, but the wiki page contains a number of identities to calculate it, as well as a table for some values. In particular, we have $$ \left\lbrace{30 \atop 20}\right\rbrace = 581535955088511150. $$

For each partitioning of $A$, we can associate $m!$ surjective functions. Thus, the total number of surjective functions from $A$ to $B$ is $$ \left\lbrace{30 \atop 20}\right\rbrace 20! = 1414819992961759105672223809536000000. $$

Ayman Hourieh
  • 40,828
2

The number of surjective functions from a set $A$ with $n$ elements to a set $B$ with $m$ elements with $n \geq m$ is given by $m! \cdot S(n,m)$, where $S(m,n)$ denotes the Stirling's number of second kind (as beautifully explained in the previous answer).

For the future readers, I would like to derive an explicit expression for the same, using the principle of inclusion and exclusion.

Firstly, let's find out the total number of functions from $A$ to $B$. We see that for every element in $A$, we have $m$ choices to map it to in $B$. So in total, we have $m^n$ functions from $A$ to $B$.

Now, there are $m\choose r$ ways to choose $r$ elements from the co-domain $B$, such that they will not be mapped to, hence leaving at most $m-r$ elements in the range of the function. Again, there are $(m-r)^n$ functions from $A$ to a subset of $B$ with $m-r$ elements. So we need to subtract the number of functions which are not onto (out of the total number of functions), and add back those which have been subtracted more than once (the principle of inclusion and exclusion!)

So, we have the number of surjective functions as: $$m^n - {m\choose 1}(m-1)^n + {m\choose 2} (m-2)^n + \ldots + (-1)^m {m\choose m} (m-m)^n$$ $$= \sum_{r = 0}^{m} (-1)^{m-r} {m\choose r} (m-r)^n$$

$$$$ As noted in the previous answer, there is no closed form to the Stirling's number of second kind. However, by double counting the number of surjective functions this way, you can get a formula for $S(n,m)$ involving summation.

Rajdeep
  • 444