# Counting binary operations on a set with $n$ elements

I am trying to solve following problem but not able to find any way to proceed.

Let $S$ be a set having $n$ elements. Can we count about number of binary operations that can be defined on a set? Can we also count number of commutative binary operations defined on $S$?

Thanks for the help and suggestions

-
A binary operation can be thought of as a function $S\times S\to S$. Does that help? –  anon Apr 28 '13 at 20:09
@anon Thanks for the hint. Now all I need to do is to find out the number of functions from $S\times S \to S$. Am i right? What about commutative binary operations? –  srijan Apr 28 '13 at 20:11
Well, almost. A commutative binary operation can be thought of as a function whose codomain is $S$ and whose domain is the set of all $2$-subsets as well as singletons (to account for things like $a*a$). –  anon Apr 28 '13 at 20:28

If $A$ and $B$ are two finite sets with $|A| = m$ and $|B| = n$ then the number of maps from $A$ to $B$ is $|B|^{|A|} = n^m$. This is because the function must be defined on each of $|A|=m$ members of $A$ and for each of those m members there are $|B|=n$ possible values. Thus, there are $$\Pi_{i=1}^{m}n=n^m$$ different possible functions from $A$ to $B$.
If we apply this to maps from $S\times S\rightarrow S$ we get $|S|^{|S\times S|}=n^{(n^2)}$.
For commutative maps, we require that $(p,q)$ and $(q,p)$ be mapped to the same value. The elements of $S\times S$ are in $1$-$1$ correspondence with the entries of a square $n\times n$ matrix. Commutative maps map an entry of the lower triangle of this matrix to the same value of the corresponding entry of the upper trianglular matrix. Therefore the domain will have cardinality $\frac{n(n+1)}{2}$ and so there will be $n^{(\frac{n(n+1)}{2})}$ commutative maps from $S\times S$ to $S.$