General Question about number of functions I am wondering if there is any sort of algorithm , or if not, at least some general approach to the following;
Lets say we have two finite sets
$$A=\{a_1,a_2,…a_n\}$$ and $$B=\{b_1,b_2,…,b_m\}$$
and suppose that it may be that $m=n$ but that is not required. Assuming we know the size of m and n, is there a method to answer the following
How many surjections are there from A onto B and vice versa,
How many injections are there from A to B and vice versa,
and How many functions at all are there from A to B and vice versa.
Thanks for any input.
I will add a short worked example of one of the most simple cases, just to help get across what if I am looking for,
take 
$$A=\{1,2,3,4\}$$ and $$B=\{a,b,c\}$$
There would be $3^4=81$ functions from A to B which can be seen easily.
For surjective from A onto B, we know one element of B must be mapped to twice. There is 3 choices for which element of B this is, and 6 choices for which two elements of A get mapped to the same B, and then 2 choices for the remains elements, i.e. 36 surjections.
 A: As the discussion in the comments is getting involved, I'll summarize the conclusions here.
EDIT:  I have worked out the count in the final case and have included that here.
Total number:  The total number of functions $A\rightarrow B$ is $m^n$ because each of n slots can be filled with any of m things.
Case I: $n = m$
In that case surjections are the same as injections are the same as permutations, so there are n! of them.
Case II:  $m>n$  
In this case there are no surjections.  An injection is defined by picking a subset, S, of B which has m elements and ordering it (the order corresponding to the order in A).  Thus there are $m(m-1)(m-2)...(m-(k-1))$ injections.
Case III $m<n$  
In this case there are no injections.  To count surjections, we'll instead count functions which fail to be surjections (as we know there are $m^n$ functions in all this will suffice).  If a function is not a surjection then it maps to a proper subset. First, then, we remove the functions which map to a subset of size m - 1.  There are $\binom {m}{m-1}$ of these and there are $(m-1)^n$ functions that map to any given one. Alas, we have double counted (or, rather, double subtracted).  Accordingly, we have to add back those functions that mapped to a set of order m-2.  There are $\binom {m}{m-2}$ of these and there are $(m-2)^n$ functions that map to any given one.  Continuing in this manner we finally see that the number of surjections from A to B is: $$\sum_{i=0}^{m}(-1)^{m-i}\binom{m}{m-i}i^n$$
