Recently I come across the term “Twelvefold way” of combinatorics. I wish I knew the term earlier as I studied quite many of those in the graduate schools and collected “recipes” for them. I always thought of them as some cases of urn models of George Pólya but they indeed have a neat classification. I try to reiterate the twelve and derive the solution below.

## Terms

Generically, the twelvefold is modeling the count of possible mappings between two finite sets, and , which each has cardinality of and respectively. The mapping is and the property of the mapping identifies the twelve cases. First the nature of mapping:

- No condition, simply
- Injective , so is unique:
- Surjective :

Then the equivalence of mappings:

- , simple
- , equality up to a permutation of
- , equality up to a permutation of
- , equality up to a permutation of and

If we visualize the above using a ball and urn model, we have a finite set of balls and a finite set of urns , and we are counting how many ways are can put the balls into the urns under different definition. The three natures of mapping means:

- No condition as long as we put all balls into urns
- Injective: All urns contain no more than one ball
- Surjective: All urns contain at least one ball, i.e., no urn can leave empty

and the four equivalence of mapping means:

- : All balls and urns are labelled, so everything is distinguishable from each other ()
- : All urns are labelled, but the balls are identical ()
- : All balls are labelled, but urns are indistinguishable from each other ()
- : Neither balls nor urns are labelled ()

Twelvefold way gets its name from the different possible models. We can try to make up problems, as follows.

## (1) Unrestricted f maps labelled N to labelled X

Problem: How many different ways to put distinct balls into distinct urns?

Solution: Each of the balls can put into one of the urns, so there are ways

## (2) Unrestricted f maps unlabelled N to labelled X

Problem: How many ways to put identical balls into urns?

Solution: We can rephrase the problem as: “If we line up balls, how many ways can we put separators between the balls”. Then, from left to right, the separators partitioned the sequence of (identical) balls into groups. Because we do allow urns to be empty, more than one separators can be put between two balls. It is like in a sequence of spaces, we put balls and separators. For example, the following is one result of :

```
O O | | O | O O O
```

So the number of combinations is

## (3) Unrestricted f maps labelled N to labelled X

Problem: How many ways to put distinct balls into identical urns?

Solution: Problem (11) is similar to this problem except with an extra condition that no urn can leave empty. The solution of problem (11) is . So for this problem, if we count only the non-empty urns, there can be 1, 2, up to urns (unless , in which case all urns will be empty). So the total count of possible ways is

Note that the above summation should have only up to terms as we can have at most urns non-empty if . But in those cases, we always have .

## (4) Unrestricted f maps unlabelled N to unlabelled X

Problem: How many ways to put identical balls into indistinguishable urns?

Solution: If we further requires the urns to be non-empty, this becomes problem (12) and it is called the partitioning problem, which means how many ways we can break down integer into sum of smaller positive integers. Let us denote the count of partition problem to be .

Using similar reasoning as in problem (3), if we relaxed the condition to allow urns to be empty, unless , we can have 1, 2, up to non-empty urns. So the answer is

which similarly, the above summation should have only up to terms because if , all . But indeed, using the recurrence relation explained in problem (12),

we can derive that:

So we can avoid the summation and find the answer to this problem to be

## (5) Injective f maps labelled N to labelled X

Problem: How many ways to put balls into urns such that no urn can hold more than one ball?

Solution: Because of the restriction that no urn can have more than one ball, it makes sense only for . When we place the first ball, we pick one of the urns. Then the second ball, we pick one of the remaining urns, and so on. So the number of ways is:

## (6) Injective f maps unlabelled N to labelled X

Problem: How many ways to put identical balls into urns such that no urn can hold more than one ball?

Solution: Again, this makes sense only for . As the result is only out of urns can have a ball, so it is a combination problem with solution

## (7) Injective f maps labelled N to unlabelled X

Problem: How many ways to put distinct balls into indistinguishable urns such that no urn can hold more than one ball?

Solution: Assume . As the urns are indistinguishable, we will find urns with balls labelled as 1, 2, up to and the remaining urns (if any) are empty. So there will only be one way. The general answer is either 1 or 0, depends on whether . Using the Iverson bracket notation:

## (8) Injective f maps unlabelled N to unlabelled X

Problem: How many ways to put identical balls into indistinguishable urns such that no urn can hold more than one ball?

Solution: Indeed this is identical to problem (7) as the balls are labelled or not does not matter in the reasoning of the solution in that problem. So the count of ways is .

## (9) Surjective f maps labelled N to labelled X

Problem: How many ways to put balls into urns such that no urn is left empty?

Solution: If the urns are indistinguishable, it becomes problem (11), which has solution . But if urns are labeled, each solution in problem (11) correspond to a permutation of urns in this problem, which urns has such rearrangement possible. So the solution is

## (10) Surjective f maps unlabelled N to labelled X

Problem: How many ways to put identical balls into urns such that no urn is left empty?

Solution: If we line up balls, there are spaces between two balls. We pick of them to place a separator, then we resulted in a partition of the balls into groups, each is non-empty. So the number of ways is

## (11) Surjective f maps labelled N to unlabelled X

Problem: How many ways to put balls into indistinguishable urns such that no urn is empty?

Solution: This is the simplified problem for problems (3) and (9). We will denote the answer as

Which it has the following properties. For the trivial case of or , there can only be one way so we denote

also, if , we can have no solution, thus

and for the degenerated cases:

Then we consider for other cases of : Assume we already have an answer for the case of balls and we are adding the -th ball into the problem. We can have two cases:

- The -th ball is in its own urn and the other balls are in urns
- The balls already scattered across urns and the -th ball is put into one of the urns

For the latter case, there is possibilities of the -th ball. So these two cases forms the recurrence relation, when :

Indeed, this is called the Stirling number of the second kind, which is the number of ways to partition elements into subsets:

## (12) Surjective f maps unlabelled N to unlabelled X

Problem: How many ways to put identical balls into indistinguishable urns such that no urn is left empty?

Solution: This is the simplified problem of (4) and the solution is the partition number, which is the number of ways to write integer as sum of positive integers. We denote such number as

and it has the following properties. The trivial case that and has only one way, so

For , we have no solution, so

and for the degenerated cases:

Then we consider for other cases of :

- If one urn has one ball, take away that urn is a solution for the case of balls and urns
- If all urns has at least two balls, take away one ball form each urn is a solution for balls and urns

So combining the two cases above we have the following recurrence relation, when :

## Summary

f | injective f | surjective f | |
---|---|---|---|

(LN → LX) | sequence |
permutation |
set partition |

(UN → LX) | multicombination |
combination |
composition |

(LN → UX) | set partition |
pigeon hole |
set partition |

(UN → UX) | partitioning |
pigeon hole |
partitioning |

## Extension

The twelvefold way is attributed to Gian-Carlo Rota (according to Wikipedia) and the Wikipedia page also mentioned an extension to twentyfold way, which include the cases that all urn must have exactly one ball (i.e., the mapping is bijective).

A paper Let’s Expand Rota’s Twelvefold Way For Counting Partitions! also extends the twelvefold way into thirtyfold.