40.01.01 · combinatorics / enumeration-generating-functions

Basic Counting and the Twelvefold Way

shipped3 tiersLean: none

Anchor (Master): Stanley 2012 *Enumerative Combinatorics, Volume 1* 2e §1.2-1.9 and Notes (Rota's twelvefold way, the q-analogues, the exponential formula prelude); Rota 1964 *Amer. Math. Monthly* 71 (the Mobius-function programme that frames enumeration); Andrews 1976 *The Theory of Partitions* Ch. 1 for the integer-partition column

Intuition Beginner

Counting sounds like the easiest thing in mathematics, and for small collections it is: you point at the things and recite numbers. The difficulty starts when the collection is described rather than displayed. How many five-letter passwords are there? How many ways can ten students be sorted into three project teams? How many ways can you make change for a dollar? You cannot point at these things one at a time, because there are far too many. You need rules that count without listing.

Two rules do most of the work. The first is the sum rule: if a choice can be made in one of two separate ways, with no overlap, the total number of outcomes is the two counts added. The second is the product rule: if a task breaks into steps done one after another, and each step has its own number of options regardless of the earlier choices, the total is the counts multiplied. A meal with three starters and four mains offers three plus four single dishes but three times four full meals.

The deepest counting trick is the bijection: to count a hard collection, match its members one-for-one with the members of an easier collection you already understand. If every item in one bag pairs with exactly one item in another bag and nothing is left over, the two bags hold the same number of items, even if you never count either bag directly. Most of the surprising formulas in this unit are really just one well-chosen pairing.

The organising idea of this unit is that an enormous range of counting questions are secretly the same question asked twelve different ways. You are placing some balls into some boxes, and the answer depends only on four yes-or-no settings: are the balls labelled, are the boxes labelled, and do you forbid two balls sharing a box, or instead require every box to be used? Those settings give a table of twelve famous answers — the twelvefold way — and learning to read the table replaces memorising a dozen formulas.

Visual Beginner

Picture balls and boxes. A way of placing the balls is a rule that assigns each ball to a box. Whether two placements count as the same depends on what you can tell apart. If the balls carry names you can distinguish them; if not, only the count in each box matters. The same holds for the boxes.

The table below names the twelve cells. Across the top: are the balls (the elements being placed) distinguishable, and are the boxes (the targets) distinguishable. Down the side: is the placement unrestricted, at most one per box (injective), or every box used (surjective).

balls \ boxes any placement at most one per box every box used
labelled balls, labelled boxes surjections,
plain balls, labelled boxes multiset count
labelled balls, plain boxes one if , else zero
plain balls, plain boxes partitions of into parts one if , else zero partitions of into exactly parts

Every entry is a count you can verify by hand for small and , and the rest of the unit explains where each one comes from.

Worked example Beginner

Place labelled balls, call them , into labelled boxes, call them and . We fill in the top row of the table for these numbers.

Step 1. Any placement. Each ball independently picks a box: ball has choices, ball has choices, ball has choices. By the product rule the total is . Listing confirms it: , where the three letters say where balls go.

Step 2. At most one ball per box. With only boxes and balls, some box must receive two balls, so no placement avoids a repeat. The count is , matching the falling-factorial rule once the third factor reaches zero.

Step 3. Every box used. From the placements in Step 1, remove the two that leave a box empty: uses only , and uses only . That leaves placements in which both boxes are occupied. The formula gives , where counts the ways to split three balls into two unlabelled groups.

What this tells us: a single small example pins down three different cells of the table, and the formulas agree with brute-force listing. The product rule handles the unrestricted case, a falling product handles the no-repeat case, and removing the empty-box placements handles the every-box-used case.

Check your understanding Beginner

Formal definition Intermediate+

Throughout, is a set of size and a set of size ; we count maps . The four symmetry regimes arise because two finite symmetric groups act: by precomposition (relabelling the domain) and by postcomposition (relabelling the codomain). Declaring the elements of distinguishable or not amounts to counting maps, or -orbits of maps; likewise for and .

Definition (ordinary and falling powers). The ordinary power is ( factors). The falling factorial is , a product of terms, with . The rising factorial is . For a set of size , the number of functions is and the number of injective functions is .

Definition (binomial and multiset coefficients). The binomial coefficient counts the -element subsets of an -set. The multiset coefficient counts the -element multisets drawn from a -set, equivalently the weak compositions with .

Definition (Stirling numbers). The Stirling number of the second kind is the number of partitions of an -set into exactly nonempty unlabelled blocks. The (unsigned) Stirling number of the first kind is the number of permutations of an -set with exactly cycles. The signed Stirling number of the first kind is . These are the entries of the two change-of-basis matrices between the monomial basis and the falling-factorial basis of the polynomial ring, defined by $$ (x)n = \sum{k=0}^{n} s(n,k),x^k, \qquad x^n = \sum_{k=0}^{n} S(n,k),(x)_k . $$

Definition (integer partitions). A partition of into at most parts is a sequence of integers summing to ; we write for the count, and for the count with all (exactly positive parts). The elementary/bijective theory of these counts is owned here; their analytic and generating-function depth is developed at 21.16.01.

Definition (twelvefold way). The twelvefold way is the table whose entry is the number of maps counted (rows) without restriction, with injective, or with surjective, and (columns) with and each either distinguishable (count maps) or indistinguishable (count - or -orbits). The twelve cells are filled by the objects above, as tabulated in the Visual section and proved below.

Counterexamples to common slips Intermediate+

  • "Multisets are counted by ." The count is for functions (labelled balls into labelled boxes, any placement). An -multiset from a -set forgets the labels on the balls, so it is the -orbit count , generally far smaller. For the function count is while the multiset count is .

  • " counts surjections onto a -set." It counts set partitions into unlabelled blocks. Surjections onto a labelled -set are , since each partition can be matched to the boxes in ways. Confusing the two drops or inserts a factor of .

  • "Injective and surjective are symmetric, so their indistinguishable-codomain cells look alike." They are not symmetric here. The injective cell with plain boxes is when and otherwise (an injection into unlabelled boxes records only whether it fits), whereas the surjective cell with plain boxes is , a rich count.

  • " means to the , just written oddly." The falling factorial agrees with only at . The two bases are related by the Stirling numbers, not by a typographical convention.

Key theorem with proof Intermediate+

The signature theorem is the closed form for the labelled-into-labelled surjective cell, because it forces the appearance of the Stirling numbers of the second kind and ties the surjection count to set partitions and to inclusion-exclusion in one stroke.

Theorem (surjection count). The number of surjective functions from an -set onto a -set is $$ \operatorname{Surj}(n,k) ;=; k!,S(n,k) ;=; \sum_{j=0}^{k} (-1)^j \binom{k}{j} (k-j)^n . $$

Proof. First we prove by a bijection. A surjection has fibres , which are nonempty (by surjectivity), pairwise disjoint, and cover ; they form an ordered partition of into nonempty blocks, the order being the labelling of . Conversely an unordered partition of into nonempty blocks, together with a bijection from the blocks to the elements of , determines a surjection. The number of unordered partitions into blocks is by definition, and the number of bijections from the blocks to is . Composing these choices is a bijection between surjections and (partition, labelling) pairs, so .

Next the inclusion-exclusion form. For a subset let be the set of functions whose image misses every element of , i.e. lands in ; then . A function is a surjection precisely when it lies in none of the sets for . By the inclusion-exclusion principle, $$ \operatorname{Surj}(n,k) = \sum_{T \subseteq X} (-1)^{|T|} |A_T| = \sum_{j=0}^{k} (-1)^j \binom{k}{j}(k-j)^n, $$ grouping the subsets of each size . Both expressions count the same set of surjections, so they are equal, and in particular .

Corollary (Stirling recurrence). For , , with and for . Indeed, in any partition of into blocks the element either sits in a block by itself — leaving a partition of the remaining elements into blocks, counted by — or joins one of the blocks of a partition of the first elements, giving . The two cases are disjoint and exhaustive.

Bridge. This theorem is the foundational reason the twelvefold table is one object rather than twelve coincidences: every cell is an orbit count of the function space under a subgroup of , and the surjective–labelled–labelled cell is the hinge where the orbit count first appears multiplied by the codomain symmetry . The two formulas for are dual descriptions of the same set — one bijective, one by inclusion-exclusion — and this is exactly the pattern that builds toward the generating-function machinery of the chapter, where the same counts reappear as coefficients: has the closed form , putting these together so that the exponential generating function repackages the surjection count as a product. The bijective half generalises to the orbit-counting (Burnside) reading of all twelve cells, and the inclusion-exclusion half is the central insight that links elementary counting to the Mobius function on the Boolean lattice, which appears again in 40.02.01 as Mobius inversion on a poset.

Exercises Intermediate+

Advanced results Master

The elementary table is the degree-zero stratum of enumerative combinatorics; its cells acquire structure once read through symmetry, generating functions, and -analogues.

Theorem 1 (twelvefold way as orbit counts). Each cell of the table is the cardinality of the quotient of the function space by a subgroup , restricted to the arbitrary, injective, or surjective locus. With the count is , , down the first column; with it is , , ; with it is , , ; with it is , , [Stanley §1.9]. The cells in a row are related by Burnside's orbit-counting lemma, which expresses each orbit count as the average number of fixed functions over the acting group.

Theorem 2 (exponential generating functions). The Stirling numbers of the second kind have the bivariate exponential generating function $$ \sum_{n \ge 0}\sum_{k \ge 0} S(n,k),y^k \frac{x^n}{n!} = e^{y(e^x - 1)}, \qquad \sum_{n \ge k} S(n,k)\frac{x^n}{n!} = \frac{(e^x - 1)^k}{k!}, $$ the second being a direct consequence of the surjection formula and the product rule for exponential generating functions: a set partition into blocks is an unordered collection of nonempty sets, and the exponential formula turns "a set of structures" into an exponential of the structure's generating function. The unsigned Stirling numbers of the first kind satisfy , the logarithm encoding cycles as the connected pieces of a permutation [Comtet 1974].

Theorem 3 (Bell numbers and Dobinski). The total number of set partitions of an -set is the Bell number , with exponential generating function , the recurrence , and Dobinski's formula , a series expressing an integer as an infinite sum weighted by a Poisson distribution.

Theorem 4 (-analogues and the Gaussian binomial). The subset count has the -analogue , the Gaussian binomial coefficient, which counts -dimensional subspaces of an -dimensional vector space over the field and, combinatorially, lattice paths weighted by area. As it degenerates to . The falling factorial has the -analogue -Pochhammer, and the whole twelvefold table admits a -deformation whose limit is the classical table; the integer-partition cells -deform to the Gaussian-binomial generating function for partitions in a box.

Theorem 5 (twelvefold way and species). In Joyal's theory of combinatorial species, the rows of the table are the structures and the columns are the operations of taking the species (labelled), its quotient by relabelling (unlabelled), and the corresponding exponential and ordinary generating functions. The surjection-equals- identity is the species isomorphism at the level of exponential generating functions, and the exponential formula for "sets of -structures" is the structural source of the generating function for set partitions [Stanley §1.9].

Synthesis. The twelvefold way is the foundational reason elementary enumeration is a single subject: every classical count — powers, falling factorials, binomial and multiset coefficients, both kinds of Stirling numbers, and the partition counts — is the cardinality of one quotient of the function space , and reading the four columns is reading off the orbits of , , both, or neither. The central insight is that the surjective–labelled cell is the hinge: it is exactly the bijective decomposition that makes a counting statement, and its inclusion-exclusion form is dual to the Mobius function on the Boolean lattice, which generalises to Mobius inversion on any poset in 40.02.01. Putting these together, the exponential generating functions and are not separate facts but the species-level images of the row structures under the labelled-to-generating-function operation, so the table is the base case of analytic combinatorics; this is exactly the bridge that builds toward the symbolic method, where each cell becomes a construction (sequence, set, cycle) on generating functions, and the -analogue layer shows the same combinatorics governing subspace counts over finite fields. The elementary table and the deep theory are one object viewed at different resolutions.

Full proof set Master

Proposition 1 (function and injection counts). The number of functions with , is , and the number of injections is the falling factorial .

Proof. Order the elements of as . A function assigns to each an independent value in , so by the product rule the count is . For an injection, may map to any of values, to any of the remaining (distinct from ), and in general to any of values not yet used; the choices are independent given the earlier ones, so the product rule gives . When the product reaches a zero factor, correctly recording that no injection exists.

Proposition 2 (subset and multiset counts). The number of -subsets of a -set is , and the number of -multisets from a -set is .

Proof. Ordered injective sequences of length from the -set number by Proposition 1; each -subset is the image of exactly such sequences (its orderings), so the number of subsets is . For multisets, encode an -multiset from by its multiplicity vector with and ; by the stars-and-bars bijection (Exercise 3) these number .

Proposition 3 (Pascal's recurrence and the binomial theorem). For , , and .

Proof. Fix an element with . The -subsets of split into those containing — equivalently -subsets of , numbering — and those omitting — equivalently -subsets of , numbering . The two classes are disjoint and exhaustive, so the sum rule gives Pascal's recurrence. For the binomial theorem, expand into monomials, one per choice of or from each factor; a monomial equals exactly when is chosen from of the factors, and the number of such choices is . Collecting like monomials gives the stated sum.

Proposition 4 (the two indistinguishable-domain surjective cells). The number of surjections counted up to relabelling the domain is ; counted up to relabelling both domain and codomain it is , the number of partitions of into exactly positive parts.

Proof. A surjection up to domain relabelling records only the fibre sizes over the labelled targets : a composition with each and . Subtracting from each part gives a weak composition of into parts, counted by via stars and bars. If the codomain is also unlabelled, the order of the is forgotten and only the multiset of fibre sizes survives: a partition of into exactly positive parts, counted by . The injective and arbitrary cells in these columns are obtained the same way, giving and the multiset count , respectively, and for the arbitrary-both-unlabelled cell.

Connections Master

  • The inclusion-exclusion form of the surjection count is the Boolean-lattice instance of Mobius inversion; the general theory on an arbitrary locally finite poset, with the Mobius function as the inverse of the zeta function in the incidence algebra, is developed in 40.02.01. The foundational reason the alternating sum counts surjections is that is the Mobius function of the subset lattice, so this unit is the elementary shadow of poset inversion.

  • The integer-partition cells and are the elementary, bijective face of a theory whose analytic depth — generating functions, the pentagonal number theorem, the Hardy-Ramanujan asymptotic — is owned by 21.16.01. This unit supplies the finite, hand-countable partition data; that unit supplies the modular and circle-method machinery. The boundary is deliberate: addition of parts here, the eta function there.

  • The exponential generating functions for Bell numbers and for fixed-block-count set partitions are the first instances of the symbolic method that organises 40.08.01: the labelled constructions sequence, set, and cycle correspond to the operations , , and on exponential generating functions, and the surjection-equals- identity is the set-construction applied to nonempty blocks. The twelvefold way is the base case those generating-function constructions specialise from.

Historical & philosophical context Master

Systematic enumeration predates its name. The binomial coefficients appear in Pingala's Chandahsastra (c. 2nd century BCE) and in the medieval "Pascal" triangle of al-Karaji, Yang Hui, and Khayyam; the Stirling numbers were introduced by James Stirling in his 1730 Methodus Differentialis as the coefficients relating powers to falling factorials, the change-of-basis viewpoint that still defines them. The partition counts trace to Euler's 1748 generating-function method, whose analytic continuation this unit defers to 21.16.01.

The unifying frame is modern. Gian-Carlo Rota's 1964 paper On the foundations of combinatorial theory I [Rota 1964] reorganised enumeration around the incidence algebra of a poset and the Mobius function, making inclusion-exclusion a special case of a single inversion principle and giving combinatorics the structural standing of the rest of mathematics. Within that programme the twelvefold way is the elementary base case: the name was coined by Rota and popularised through Richard Stanley's Enumerative Combinatorics [Stanley §1.9], where the table first appears in textbook form, with the phrasing attributed to Joel Spencer. Joyal's 1981 theory of species later recast the rows as functors and the columns as the passage from labelled structures to generating functions, situating the table inside category theory and analytic combinatorics.

Bibliography Master

@book{stanley2012ec1,
  author    = {Stanley, Richard P.},
  title     = {Enumerative Combinatorics, Volume 1},
  series    = {Cambridge Studies in Advanced Mathematics},
  volume    = {49},
  edition   = {2},
  publisher = {Cambridge University Press},
  year      = {2012}
}

@article{rota1964mobius,
  author  = {Rota, Gian-Carlo},
  title   = {On the foundations of combinatorial theory I: Theory of M\"{o}bius functions},
  journal = {Zeitschrift f\"{u}r Wahrscheinlichkeitstheorie und verwandte Gebiete},
  volume  = {2},
  year    = {1964},
  pages   = {340--368}
}

@book{stirling1730methodus,
  author    = {Stirling, James},
  title     = {Methodus Differentialis: sive Tractatus de Summatione et Interpolatione Serierum Infinitarum},
  publisher = {Gul. Bowyer},
  address   = {London},
  year      = {1730}
}

@book{comtet1974advanced,
  author    = {Comtet, Louis},
  title     = {Advanced Combinatorics: The Art of Finite and Infinite Expansions},
  publisher = {D. Reidel},
  year      = {1974}
}

@article{joyal1981species,
  author  = {Joyal, Andr\'{e}},
  title   = {Une th\'{e}orie combinatoire des s\'{e}ries formelles},
  journal = {Advances in Mathematics},
  volume  = {42},
  number  = {1},
  year    = {1981},
  pages   = {1--82}
}

@book{vanlintwilson2001,
  author    = {van Lint, J. H. and Wilson, R. M.},
  title     = {A Course in Combinatorics},
  edition   = {2},
  publisher = {Cambridge University Press},
  year      = {2001}
}

@book{andrews1976partitions,
  author    = {Andrews, George E.},
  title     = {The Theory of Partitions},
  series    = {Encyclopedia of Mathematics and its Applications},
  volume    = {2},
  publisher = {Addison-Wesley},
  year      = {1976}
}