The Ohio State University October 10, 2016

Combinatorics —

1 Functions and sets

Enumerative (or ), at its heart, is all about finding functions between different sets in such a way that reveals their size. A little combinatorics goes a long way: you’ll probably run into it in every discipline that involves numbers. Beyond numbers and sets, there is not much additional formal theory needed to get started. For sets A and B, a f : A → B is any assignment of elements of B defined for every element of A. All f needs to do to be a function from A to B is that there is a rule defined for obtaining f(a) ∈ B for every element of a ∈ A. In some situations, it can be non-obvious that a rule in unambiguous (we will see examples), in which case it may be necessary to prove that f is well-defined. We will be interested in counting, which motivates the following three definitions.

Definition 1: A function f : A → B is injective if and only if for all x, y ∈ A, f(x) = f(y) ⇒ x = y.

These are sometimes called one-to-one functions. Think of injective functions as rules for placing A inside of B in such a way that we can undo our steps.

Lemma 1: A function f : A → B is injective if and only if there is a function g : B → A so that ∀x ∈ A g(f(x)) = x. This function g is called a left-inverse for f

Proof. ⇒ : We need to define g on all B. Let S ⊂ B be all those elements of B that can be reached using f (also called the range of f). Formally:

S = {b ∈ B : ∃ a ∈ A, f(a) = b} .

Then for each b ∈ S, define g(b) to be an arbitrary a so that f(a) = b. For each b ∈ B \S (the elements of B not in S), just define g to be any arbitrary assignment. Then by definition, for any a ∈ A, a0 = g(f(a)) is an element of A so that f(a0) = f(a), which by assumption implies a = a0 = g(f(a)), as desired. ⇐: Suppose x, y ∈ A have f(x) = f(y). Then x = g(f(x)) = g(f(y)) = y. There is a complementary definition for surjective functions.

Math 3345 Combinatorics1 Fall 2016 Definition 2: A function f : A → B is surjective if and only if for all y ∈ B there exists x ∈ A so that f(x) = y.

These are sometimes called onto functions. Think of surjective functions as rules for surely (but possibly inefficiently) covering every B by elements of A.

Lemma 2: A function f : A → B is surjective if and only if there is a function g : B → A so that ∀y ∈ B f(g(y)) = y. This function is called a right-inverse for f.

Proof. ⇒ : We need to define g on all B. By assumption, for any b ∈ B, there is an a ∈ A so that f(a) = b. Hence, let g(b) be any arbitrary choice of such an a. Then by definition, for any b ∈ B, f(g(b)) = b. ⇐: Suppose y ∈ B is arbitrary. Let a = g(y). Then f(a) = f(g(y)) = y, and so since y was arbitrary, f is surjective. Combining these two lemmas, we see that if g is the left-inverse of f (so that f is injective) then we also have that f is a right-inverse of g. This automatically implies that the left-inverse of an f is surjective. By the same argument, the right-inverse of a f is injective. Finally, we define the main object of combinatorics, the function that is both injective and surjective.

Definition 3: A function f : A → B is bijective if it is both injective and bijective.

Just like with injective and surjective functions, we can characterize bijective functions according to what type of inverse it has.

Lemma 3: A function f : A → B is bijective if and only if there is a function g : B → A so that 1. ∀a ∈ A, g(f(a)) = a. 2. ∀b ∈ B, f(g(b)) = b. This function g is called a two-sided-inverse for f.

Proof. ⇒ : Using Lemmas 1 and 2, we know there are functions g, h : B → A so that 1. ∀a ∈ A, g(f(a)) = a. 2. ∀b ∈ B, f(h(b)) = b. The only trouble is that we don’t know g = h just from invoking the lemmas, but it turns out that must be true. Let b ∈ B be arbitrary. Then

h(b) = g(f(h(b))) = g(b),

Math 3345 Combinatorics2 Fall 2016 where in the first equality, we apply f followed by g to h(b), and in the second equality, we use that f(h(b)) = b. This shows g = h. ⇐: Because g exists, by Lemmas 1 and 2, we have f is both injective and surjective, and hence bijective.

Example 1: Let f : Z → Z be given by f(x) = 2x. Then f is injective because if f(x) = f(y), then 2x = 2y, which implies x = y. However, f is not surjective because there is no x ∈ Z so that f(x) = 1.

Example 2: Let f : R → R be given by f(x) = x3. Then f is bijective. The function g : R → R given by x 7→ x1/3 is a two-sided inverse for f.

Example 3: Let f : R → R≥0, where

R≥0 = {x ∈ R : x ≥ 0} ,

2 be given by f(x) =√x . Then f is surjective but not injective. The function g : R≥0 → R defined by g(x) = x which gives the non-negative square-root of a non-negative number x is a right-inverse for f. This is to say that ∀x ∈ R≥0, f(g(x)) = x. Therefore f is surjective. However, f(1) = 1 = f(−1), and so f is not injective. Also, ∀x ∈ R≥0, g(f(x)) = |x|, so g is not a left-inverse for f.

Exercise 1: Fix a ∈ R with 0 ≤ a ≤ 2π. Define the function fa(x) = sin(a + x) mapping [0, π] to [−1, 1]. For what values of a is fa injective? Surjective? Exercise 2: Fix b ∈ N. By the division algorithm, for every z ∈ Z, there are unique q, r ∈ Z with {0, 1, 2, . . . , b − 1} so that z = bq + r. Let fb : Z → {0, 1, 2, . . . , b − 1} be the function that sends z to r.

(a) Prove that the function fb is surjective.

(b) Prove that the function fb is not injective. (c) Fix a ∈ Z. Define the function g : {0, 1, 2, . . . , b − 1} → {0, 1, 2, . . . , b − 1} by g(z) = fb(a + z). Prove that the function g is bijective. (d) Fix a, b ∈ N. Define the function m : {0, 1, 2, . . . , b − 1} → {0, 1, 2, . . . , b − 1} by m(z) = fb(a · z). Prove that the function m is bijective if gcd(a, b) = 1. Comment: this is the basis of modular arithmetic, which allows one to define an addition and multiplication rule on {0, 1, 2, ··· , b − 1} that satisfy the normal axioms of addition and multiplication. Even better, one can show this has multiplicative inverses when b is prime.

Math 3345 Combinatorics3 Fall 2016 Composition We also need to be able to talk about compositions of functions. If f : A → B and g : B → C are functions, then g ◦ f : A → C (said “g compose f”) is the function that for all x ∈ A, (g ◦ f)(x) = g(f(x)). Injectivity, surjectivity, and bijectivity all behave nicely with respect to composition

Lemma 4: Let f : A → B and g : B → C be two functions. 1. If both f and g are injective, then g ◦ f is injective. 2. If both f and g are surjective, then g ◦ f is surjective. 3. If both f and g are bijective, then g ◦ f is bijective.

Exercise 3: Prove this lemma.

Set operations Finally, we need to define a few common set operations. For any two sets, A and B we define the union, intersection, and set difference by the following rules.

x ∈ A ∪ B ⇐⇒ (x ∈ A) ∨ (x ∈ B) x ∈ A ∩ B ⇐⇒ (x ∈ A) ∧ (x ∈ B) x ∈ A \ B ⇐⇒ (x ∈ A) ∧ (x∈ / B) Like with the logical operations ∨ and ∧, the set operations have distributivity rules, but for the moment we mostly need these for notation. When we do set theory, we will cover these rules further.

Example 4: Let A = {1, 2} and B = {2, 3} . Then A ∪ B = {1, 2, 3} A ∩ B = {2} A \ B = {1}

2

One way to think of two sets A and B for which there exists a f : A → B is that B is somehow a relabeling of A. The function f tells us how to do the relabeling, and its properties ensure that for every element of B there is one and only one element of A in correspondence with it. The only information left over is the size, or cardinality, of the set.

Math 3345 Combinatorics4 Fall 2016 Definition 4: Two sets A and B have the same cardinality if and only if there exists a bijection f : A → B.

Cardinality makes sense for finite sets and infinite sets. Combinatorics is concerned with the finite case, for which reason we introduce the following.

Definition 5: Let [n] ⊂ N be the set [n] = {1, 2, 3, . . . , n} . Say a set A has cardinality n if and only if there is bijection f : A → [n] and write |A| = n.

The two basic counting principles, on which everything is built, are the addition principle and the multiplication principle.

Lemma 5 (Addition Principle): If A and B are two disjoint finite sets, then the union A ∪ B (the set which contains everything that is either in A or in B) has cardinality |A ∪ B| = |A| + |B|.

Proof. Let S = A ∪ B. Let |A| = n and |B| = m. Then by definition, there are f1 : A → [n] and f2 : B → [m]. Define a function g : S → [n + m] by ( f (x) if x ∈ A, and g(x) = 1 n + f2(x) if x ∈ B. This rule would not be well-defined if A and B had any overlap. As we assume they are disjoint, this rule is unambiguous. Checking that g is a bijection is elementary and left as an exercise. The addition principle extends by induction to larger collections of disjoint sets. That is, if A1,A2,...,Ak are finite, disjoint sets, then

|A1 ∪ A2 ∪ · · · ∪ Ak| = |A1| + |A2| + ··· + |Ak|.

Example 5: If A is a set of 7 apples, B is a set of 2 bananas, and C is a set of 6 cherries, then the set of all fruit S has |S| = |A ∪ B ∪ C| = |A| + |B| + |C| = 15.

The addition principle, has many consequences as related to finite . To start we can generalize this principle slightly:

Lemma 6: If A and B are finite sets, then |A ∪ B| = |A| + |B| − |A ∩ B|.

Math 3345 Combinatorics5 Fall 2016 Proof. This follows from the original addition principle in the following way. Let C = B \ A. Then on the one hand, A ∪ B = A ∪ C, but A and C are disjoint by construction. Therefore

|A ∪ B| = |A ∪ C| = |A| + |C|. (0-1)

On the other hand, B = C ∪ (A ∩ B), and C is disjoint from A ∩ B. Therefore

|B| = |C| + |A ∩ B|.

Rearranging this equation (solving for |C|) and substituting it into (0-1), the equation in the statement of the lemma follows. We can also use this principle to show that an injection from a finite set to itself is necessarily a bijection.

Lemma 7: Suppose A is a finite set and f : A → A is an injection. Then f is a bijection.

Proof. Define the range of f by

Range(f) = {a ∈ A : ∃ b ∈ A, f(b) = a} .

These are exactly the points in A that can be reached using f. By definition, f takes values in Range(f), more specifically than taking values in A. So, f : A → Range(f). Moreover, f is a surjection to Range(f), and hence as it is still an injection (check!)

|A| = | Range(f)|.

On the other hand A = Range(f) ∪ (A \ Range(f)), which is a decomposition of A into disjoint sets. Therefore by the addition principle,

|A| = | Range(f)| + |A \ Range(f)|.

Combining this with what we know about the size of Range(f), it follows that |A\Range(f)| = 0. Hence, there are no elements in this set. Or in other words, Range(f) = A. Since f is a surjection on Range(f), it follows f is surjection to A. This shows f is a bijection. The same idea holds for surjections, which follows from this as a simple consequence.

Corollary 1: Suppose A is a finite set and f : A → A is a surjection. Then f is a bijection.

Math 3345 Combinatorics6 Fall 2016 Proof. This proof is what is called, half-jokingly, abstract nonsense. It is automatic in a sense from the definitions and from the Lemma. Let’s begin. If f is a surjection, there is a right-inverse g for f. A right-inverse is necessarily an injection (because f is a left-inverse for g), and therefore applying the Lemma to g, g is a bijection. A one-sided inverse for a bijection is necessarily a two-sided inverse (check!), and so f is a bijection. To state the multiplication principle, we first need to introduce a corresponding multi- plcation for sets.

Definition 6: For two sets A, B, the cartesian product A × B is the set of all pairs (a, b) where a ∈ A and b ∈ B.

The multiplication principle states that the cardinality of a product of sets is the product of cardinalities of those sets.

Lemma 8 ((weak) Multiplication Principle): If A and B are two finite sets, then the cartesian product A × B has cardinality

|A × B| = |A| · |B|.

We will first give a more general, stronger version of the multiplication principle that has more applications. So, we’ll delay the proof until that point. This multiplication also extends to larger products in a natural way, so for multiple finite sets A1,A2,...,Ak the product A1 × A2 × · · · × Ak is the set of all k-tuples (a1, a2, . . . , ak) where each ai ∈ Ai. By applying induction and the multiplication principle, the cardinality of this set is the product of cardinalities:

|A1 × A2 × · · · × Ak| = |A1| · |A2| · · · |Ak|.

There is a much more useful, strong version of the multiplication principle that generalizes the weak multiplication principle given above. To introduce this principle, we need the idea of a k-to-one map.

Definition 7: Fix a k ∈ N. A function f : A → B is called k-to-one if for every b ∈ B, there are either 0 elements a ∈ A so that f(a) = b or there are k elements of A so that f(a) = b.

Example 6: Let A and B be finite sets with cardinalities n and m. Define f : A×B → B by f(a, b) = b for all (a, b) ∈ A × B. Then f is n-to-one.

Math 3345 Combinatorics7 Fall 2016 Lemma 9 (Multiplication Principle): If S and A are two sets, and f : S → A is a k-to-one surjection, then |S| = k|A|.

Proof. Let |A| = n. For each a ∈ A, let Va ⊂ S be all those elements that get mapped to a by f. By assumption, |Va| = k for all a ∈ A. Moreover, [ S = Va, a∈A that is to say, every element of S is in some Va (since every element of S gets mapped to something by f). Furthermore, for any a 6= b that are elements of A, Va and Vb are disjoint, since any element of S is only mapped to at most one element of A. Hence by the addition principle X |S| = |Va| = k|A|. a∈A

Example 7: We will count the number of two digit numbers in N whose digits are neither 0 nor equal to one another. These numbers are all written as ab for some a, b ∈ [9]. Let S be the set of all pairs (a, b) for which ab is one of the two digit numbers discussed. Define a mapping f : S → [9] by letting f(a, b) = a. For every pair (a, b), we have that b can be any number in [9] except for a. Therefore f is 8-to-one. So |S| = 72.

Exercise 4: Let n = 2635.

(a) How many positive divisors are there of n?

(b) How many positive divisors of n are there whose prime factorization contains a different number of 2’s and 3’s?

Exercise 5: Fix n, m ∈ N. Prove, by counting [n + 1] × [n + m] in two ways, that

m + (m + 2) + (m + 4) + ··· + (m + 2n) = (n + 1)(n + m).

Exercise 6: Two integers are called relatively prime if their greatest common divisor is 1.

(a) How many positive integers in [15] are relatively prime to both 3 and 5?

(b) Let p and q be two prime numbers. Find a formula for the number of integers between 1 and p · q (in [pq]) that are relatively prime to both p and q and prove it.

Math 3345 Combinatorics8 Fall 2016 3 Counting Stuff!

To get started with combinatorics, these are all the formal tools we will need. There are essentially 12 basic combinatorial counting problems, which taken together are called the twelvefold way. We’ll summarize this later. For now, we will introduce some of the most important counting problems in this array. The first counting problem we’ll do is just to count the number of functions between two sets.

Definition 8: Let AB denote the set of all functions from B → A.

Example 8: {0, 1}{x,y} is the set of all functions from {x, y} to {0, 1} . These functions are

1. f(x) = 0, f(y) = 0.

2. f(x) = 0, f(y) = 1.

3. f(x) = 1, f(y) = 0.

4. f(x) = 1, f(y) = 1.

Theorem 1: For finite sets A, B the cardinality of AB is |A||B|.

In effect, the idea here is that a function from B to A is just an ordered list of information, with no constraints. Proof. Let |B| = m. Define a set

S = A × A × · · · × A | {z } m copies

So S is a collection of m-tuples, where each entry is an element of A. By the multiplication principle |S| = |A|m. To finish the proof, we define a bijection ϕ from AB to S. This bijection should take the data in a function from A to B and recast it as a vector. Since |B| = m, there is a bijection g from [m] → B. Then define, for any f ∈ AB

ϕ(f) = (f(g(1)), f(g(2)), f(g(3)), . . . , f(g(m))) .

Checking that ϕ is a bijection is an exercise. The most important special case of this counting problem is to count the number of subsets of a set.

Definition 9: For a set S, let P(S) be the set of all subsets (including S and ∅) of S.

Math 3345 Combinatorics9 Fall 2016 Example 9: The subsets of [3] are

{1, 2, 3} {1, 2}{1, 3}{2, 3} , {1}{2}{3} ∅ for a total of 8.

Theorem 2: For a finite set S, |P(S)| = 2|S|.

Exercise 7: Prove this theorem. Hint: construct a bijection between P(S) and {0, 1}S .

4

Permutations are a rich source of counting problems, which tie naturally to many other counting problems.

Definition 10: For any set S, let Let Per(S) be the set of all bijections from S to itself. These are called the permutations of S. The set Per(∅) is conventionally considered to have one element in it, the function that does nothing (the identity map).

Exercise 8: Prove that if X,Y are finite sets with |X| = |Y | then:

(a) | Per(X)| = | Per(Y )| (Hint: X and Y must be in bijective correspondence, as they have the same cardinality. Use this bijection to construct a bijection of Per(X) and Per(Y )).

(b) The number of bijections from X to Y is | Per(X)|.

Moreover, there’s no particular reason to study Per(S) instead of Per([n]), since we can always identify the two sets of permutations. This allows us to develop some notation. The first and most useful notation for us will be one-line notation for a . To write a permutation f :[n] → [n] in one-line notation, just write the ordered list f(1), f(2), . . . , f(n). Conventionally, we don’t write the commas so long as it doesn’t cause confusion.

Example 10: The permutation f ∈ Per([3]) that is defined by f(1) = 2, f(2) = 3, f(3) = 1 is given in this notation by 231

Math 3345 Combinatorics10 Fall 2016 in one-line notation. The complete list of permutations of [3] is 123 132 213 231 312 321

Inversion table We want to show that Per([n]) = n(n − 1)(n − 2) ··· (2)(1), that is to say that Per([n]) = n! We will do this by finding an explicit bijection between Per([n]) and the set [1] × [2] × [3] × · · · × [n]. This bijection is constructed algorithmically, and we’ll start by illustrating it with an example.

Example 11: We will build a permutation by specifying the relative location of numbers to one another in one-line notation. We will work with the permutation 14532. Let’s start by placing the largest number on a line: 5 Now we’ll place the 4 in relative position to the 5. There are two places for it: before or after the 5. We place it before. 45 We now place the 3. There are now 3 places to put it: to the left of the 4, between the 4 and 5 or after the 5. We put it at the end. 453 This continues, until all the numbers have been placed. Summarizing the whole procedure. 5 45 453 4532 14532

The data we needed to record at each step was the relative location of the number j.

Definition 11: The inversion table map ϕ : [1] × [2] × [3] × · · · × [n] → Per([n])

Math 3345 Combinatorics11 Fall 2016 is given by the following iterative algorithm. Suppose (a1, a2, . . . , an) is an element of [1] × [2] × · · · × [n]. Start with an empty list of numbers. For each j = n, n − 1, n − 2,..., 1 insert j into this list in the an−j+1 position.

Formally, there are lots of things to check to see that this algorithm actually produces a permutation: for exmaple are there n − j + 1 positions before the insertion at step j? In principle, one could use induction to give a formal proof that the algorithm produces a permutation, but it’s relatively obvious if the algorithm itself makes sense. To show the map ϕ is a bijection, we need to either work with the definition of a bijection or produce a two-sided inverse for ϕ. In this situation, it’s almost certainly easier to create the inverse map. We pose this as an exercise. Exercise 9: Define (using an algorithm) the inverse map of ϕ, which maps Per([n]) to [1] × [2] × [3] × · · · × [n].

Corollary 2: The cardinality of Per([n]) is n!

We also provide, for comparison, a non-algorithmic approach to showing this corollary.

Lemma 10: For any n ≥ 1, | Per([n])| = n · | Per([n − 1])|.

Proof. Let B(X,Y ) denote the set of bijections between two sets. When |X| = |Y |, we know from exercise 8 that |B(X,Y )| = | Per(X)|. The idea now is to partition the permutations f :[n] → [n] according to the value of f(n). After restricting f to [n − 1], what remains is a bijection from [n − 1] to [n] \ f(k). Hence, if m = | Per([n − 1])|, then the function

ϕ : Per([n]) → [n]

given by ϕ(f) = f(n) is an m-to-one surjection. By the multiplication principle, | Per([n])| = nm, which is the statement of the lemma. Using induction, this gives rise to the same formula for the cardinality of the set of permutations of [n]. The inversion table provides other useful information, though. For example, the inversion number of a permutation is one measure of how scrambled it is:

Definition 12: The inversion number Inv(f) of a permutation f ∈ Per([n]) is the sum −1 −1 of the numbers that appear in ϕ (f) minus n. In symbols, if (a1, a2, . . . , an) = ϕ (f) then

n X Inv(f) = (ai − 1). i=1

Exercise 10: This exercise tests some basic properties of the inversion number.

(a) Which permutations of n have inversion number 0?

Math 3345 Combinatorics12 Fall 2016 (b) How many permutations of n have inversion number 1? (c) A permutation is called even (resp. odd) if it has an even (resp. odd) number of inversions? Prove that there are the same number of even and odd permutations. Hint: map a permutation to is inversion table, do something to the table and then map it back.

Counting injections In light of Lemma 7, counting permutations of [n] could also be considered as counting injections from [n] to [n]. It turns out the related problem of counting injections from [k] to [n] is of similar difficulty. Let I (k, n) be the set of injections from [k] to [n]. The idea is the same as what is given in Lemma 10. Exercise 11: In this exercise, we assume k and n are positive integers with k ≤ n. (a) Show that so long as k ≥ 1, |I (k, n)| = n|I (k − 1, n − 1)| using the multipli- cation principle.

(b) Conclude using induction that |I (k, n)| = n(n − 1)(n − 2) ··· (n − k + 1). Because of its frequent appearance, this formula is given a specific name.

Definition 13: The falling is denoted by [n]k. It is defined by n(n − 1)(n − n! 2) ··· (n − k + 1). When k ≤ n are positive integers this can also be written as (n−k)! .

Remark 1: Mathematical conventions vary wildly when it comes to how to notate the falling factorial. Be warned!

5 Subsets

S Definition 14: For any finite set S, let k be the set of all k-element subsets of S.

In a similar spirit to Exercise 8, different labelings of S do not change the number of subsets of S. In more mathematical words, if f : S → T is a bijection of finite sets, then we S T  can construct a bijection g : k → k , and hence     S [|S|] = . k k This suggests the natural definition     n [n] = . k k Many of you know that this expression has a formula in terms of . We start by showing that this formula holds.

Math 3345 Combinatorics13 Fall 2016 Lemma 11: For 0 ≤ k ≤ n integers

n n! [n] = = k . k (n − k)!k! k!

At first sight, it may not even be obvious that the ratio of factorials is an integer. This lemma shows, as a biproduct, that this is true, since the size of a set is always an integer. In some sense, the appearance of this fraction is a hint: the proof of this identity starts by clearing the fraction on both sides. High-level proof. We show n [n] = k! . k k The left hand side counts the number of injections from [k] to [n]. An injection can be built by first choosing the set to which it maps inside of [n] (its range) and then by choosing which points in k map to which points in its range. Every such ordering is possible, so the total n number of injections is k! k , and each such ordering produces a distinct injection. Formal proof. We show the equivalent statement that

n [n] = k! . k k

The left hand side of this equation counts the number of injections from [k] to [n]. The k! counts the number of bijections from [k] to [k]. So, to prove this identity, we use the multiplication principle. Recall that I (k, n) is the set of injections from [k] to [n]. We want to map an injection to either a permutation or a subset of [n] of size k in a useful fashion. We’ll do this by mapping an injection to its range. Remember that for a function f : A → B,

Range(f) = {b ∈ B : ∃ a ∈ A, f(a) = b} .

If f is an injection from [k] to [n], then its range is some subset of [n] of size k (an injection is always a bijection to its range, and so the range must have size k). This lets us define a [n] function ϕ from I (k, n) to k by ϕ(f) = Range(f).

Let m = k!. We need to show that this ϕ is an m-to-one surjection. To see it is a [n] surjection, we need to show that for every subset S ∈ k , we can find an injection from [k] to [n] so that its image is S. However, since S has size k, there is by definition a bijection g from [k] to S. As this function g maps to S, it also maps to [n]. Hence ϕ(g) = S.

Math 3345 Combinatorics14 Fall 2016 To see that it is m-to-one, we need to count the number of functions that get mapped to [n] the same thing. For an S ∈ k , let

VS ⊂ I (k, n)

be the functions that map to S under ϕ. We know this set is nonempty as ϕ is surjective, −1 −1 so let f ∈ VS be some arbitrarily chosen element. Let f be the inverse map f :[k] → S. Define a new function Ψ: VS → Per([k]) by Ψ(g) = f ◦ g. Then Ψ is a bijection (its two-sided inverse is the map h 7→ f −1 ◦ h from Per([k]) → VS).

The binomial theorem n The coefficients k are typically called the binomial coefficients. Their namesake is the expansion known as the binomial theorem.

Theorem 3: For real x, y and a natural number n

n X n (x + y)n = xkyn−k. k k=0

This can established many ways, for example by induction. To use induction, however, it will be necessary to establish an identity for binomial coefficients first. A more direct proof n is possible, using only the definition of k as the cardinality of set of subsets of [n] with k elements. Proof. We take for granted that it is possible to expand

n n X k n−k (x + y) = an,kx y k=0 for some coefficients an,k. This could be proven formally by induction on n, requiring no information on the coefficients. k n−k Moreover, an,k is the number of ways to get x y by choosing from each (x + y) term in the product (x + y)(x + y) ··· (x + y) | {z } n copies either x or y in such a way that one has chosen k x’s and n−k y’s. Formally, we can represent these choices by a function f :[n] → {x, y} , and so an,k counts the number of functions from [n] → {x, y} that map exactly k elements of [n] to x. We can bijectively identify these n functions with subsets of [n] of size k by recording the set that maps to x. So an,k = k .

Math 3345 Combinatorics15 Fall 2016 Pascal’s triangle and the binomial identities Binomial coefficients satisfy many identities. The most classic of these identities, and one which could actually be used to define the binomial coefficients, is called Pascal’s identity

Lemma 12 (Pascal’s identity): For all 0 ≤ k ≤ n, n n − 1 n − 1 = + . k k k − 1

[n] Proof. The left hand side counts S = k . Decompose S into the sets that contain n and those that do not contain n. The sets in S that do not contain n are exactly the k-element subsets of [n − 1]. Let T be the sets in S that do contain n. We can create a bijection from [n−1] T to k−1 by simply dropping the n from each element of T. This is invertible as we could [n−1] take any element of k−1 and add n to it to produce an element of T. Hence [n] [n − 1] = T ∪ , k k and the union is disjoint. So, n n − 1 n − 1 n − 1 = |T | + = + . k k k − 1 k

This identity allows one to quickly produce a complete table of binomial coefficients by hand.

Example 12 (Pascal’s triangle):

n k k = 0 1 2 3 4 5 6 n = 0 1 0 0 0 0 0 0 n = 1 1 1 0 0 0 0 0 n = 2 1 2 1 0 0 0 0 n = 3 1 3 3 1 0 0 0 n = 4 1 4 6 4 1 0 0 n = 5 1 5 10 10 5 1 0 n = 6 1 6 15 20 15 6 1 One can produce the next row of this table by summing adjacent terms in the n = 6 7 row,i.e. by using Pascal’s identity. So for example 2 is the sum of 6 and 15.

Many other identities can be discovered within the binomial coefficients besides these. Here is a sampling

Math 3345 Combinatorics16 Fall 2016 1. The diagonal recurrence: for 0 ≤ k ≤ n,

k X n − k + j n = . j k j=0

2. The column sum recurrence: for 0 ≤ j ≤ n,

n X k n + 1 = . j j + 1 k=0

3. Subsets of subsets: for 0 ≤ k ≤ m ≤ n,

 n m n n − k  = . m k k m − k

4. The marked point identity: for 1 ≤ n,

n X n i = n2n−1. i i=0

5. Abitrary partition identity: for m, n, r ≥ 0 with 0 ≤ r ≤ m + n,

r X m n  m + n = . k r − k r k=0

These are relatively standard identities, and all have beautiful double counting proofs, where one counts a set in two different ways. There are additionally more exotic identities which require further thought, for example

1. For n ≥ 0, n X 2i2(n − i) = 4n. i n − i i=0

2. Let F0 = 0,F1 = 1 and Fn+1 = Fn + Fn−1 for all n ≥ 1, i.e. Fn are the Fibonacci numbers. Then bf/nc X n − k = F . k n+1 k=0

Math 3345 Combinatorics17 Fall 2016 6 Distinguishability

The subset counting problem can actually be considered as a function counting problem. To do so, we need the idea of distinguishability. Sometimes in counting problems, we don’t want to count all functions from [n] to [k]. Instead, we want to think of some functions as meaning the same thing and count the number of different classes of functions. To illustrate this, it’s helpful to switch to the terminology of balls and bins. Suppose there are n balls and k bins. A function f :[n] → S can be considered as a way of assigning balls to bins labeled by the elements of S. For example if n = 3 and S = {a, b, c} , the function f(1) = a, f(2) = a, f(3) = c. represents the assignment of balls 1 and 2 to a and ball 3 to c. Another assignment might be

g(1) = a, g(2) = c, g(3) = a.

These are different assignments, provided we care which balls end up where. However, if we don’t care about the labels of the balls, that is if the balls are indistin- guishable, then we would consider f and g equivalent assignments. Formally, we would say the following

Definition 15: Suppose f1, f2 :[n] → [k] are two functions. If the domain of these functions are indistinguishable, we say that f1 and f2 are equivalent assignments of [n] → [k] if and only if there exists a permutation g :[n] → [n] so that f1 = f2 ◦ g. In the same way, if the codomain of these functions are indistinguishable, we say that f1 and f2 are equivalent if and only if there is a permutation h of [k] so that f1 = h ◦ f2. If both domain and codomain of f1, f2 are indistinguishable, then these functions are equivalent if and only if there exist some g and h like before so f1 = h ◦ f2 ◦ g.

When we deal with indistinguishability, we no longer want to count functions, we want to count different types of functions. Formally, the correct idea here is an . We will talk about these properly when we do set theory. An equivalence class of functions is just a set of functions where everything inside is equivalent, and nothing inside the set is equivalent to anything outside the set. In terms of balls and bins, if the balls are indistinguishable, an equivalence class is all the different ways of adding labeling the balls without moving them around. We’ll focus to begin on the problem of counting functions having indistinguishable do- main. In terms of balls and bins, these are assignments of balls to bins where we do not distinguish between balls. Using the examples f and g given above between [3] → {a, b, c} , if [n] is indistinguishable, then f and g are equivalent functions. In contrast, the function

h(1) = a, h(2) = c, h(3) = c. is not equivalent to f or g.

Math 3345 Combinatorics18 Fall 2016 Thinking in terms of balls and bins, if the balls are indistinguishable, then every assign- ment of balls to bins is completely determined by the number of balls in each bin. This leads us to the following definition.

Definition 16: A k-composition of n is a k-tuple (a1, a2, . . . , ak) of positive integers so that a1 + a2 + ··· + ak = n.

A weak k-composition n is a k-tuple (a1, a2, . . . , ak) of non-negative integers so that

a1 + a2 + ··· + ak = n.

Example 13: The 3-compositions of 5 are

(3, 1, 1) (1, 3, 1) (1, 1, 3) (2, 2, 1) (2, 1, 2) (1, 2, 2).

The weak 3-compositions of 2 are

(2, 0, 0) (0, 2, 0) (0, 0, 2) (1, 1, 0) (1, 0, 1) (0, 1, 1).

These combinatorial objects are more convenient to use in this context than the more cumbersome equivalence classes of functions.

Theorem 4: If [n] is indistinguishable, then the equivalence classes of f :[n] → [k] are in bijective correspondence with the weak k-compositions of n. Further, f is injective if and only if the corresponding weak composition consists of only 1s and 0s. Likewise, f is surjective if and only if all entries of the composition are at least 1 (the weak composition is a composition).

The language here may look daunting; in terms of balls and bins, with indistinguishable balls, that an assignment of balls to bins is determined up to equivalence by the number of

Math 3345 Combinatorics19 Fall 2016 balls in each bin (the composition). Further, if the assignment is injective, there will be at most 1 ball in each bin. If the assignment is surjective, there will be at least 1 ball in each bin. This theorem is more definition checking than anything, so we don’t give it. Instead, we focus on counting the number of compositions.

n−1 Lemma 13: The number of k-compositions of n is k−1 .

Proof. We construct a bijection here known as the stars and bars. The binomial coefficient counts the number of (k − 1)-subsets of [n − 1]. We define a bijection from these subsets to k-compositions of n by placing n stars in a row. To illustrate this, we consider placing n stars in a row. In the example below, we place 7 :

∗ ∗ ∗ ∗ ∗ ∗ ∗

Between each ∗ we find a space n − 1 spaces (e.g. 6). For the subset of n − 1 that we take as input, we place bars in the corresponding spaces. If as an example k = 4 and the input set is {2, 4, 5} , we would draw bars like

∗ ∗ | ∗ ∗| ∗ | ∗ ∗

This subdivides the stars into k blocks of stars. We then give the output k-composition of n as the number of stars in each block. In the example, this would be (2, 2, 1, 2). [n−1] It’s not hard to check that this mapping from k−1 to k-compositions of n is a bijection, as it is easy to define the inverse map by a similar procedure. Having counted the number of k-compositions of n, we turn to counting the weak k- compositions of n. This turns out to be related to the k-compositions of n by the fol- lowing idea. As illustrated in example 13, we can get between k-compositions and weak k-compositions just by subtracting 1 from each entry of the tuple. This leads us to the following

Lemma 14: The number of weak k-compositions of n is the same as the number of k-compositions of n + k.

Proof. Define a function

ϕ : {weak k-compositions of n} → {k-compositions of n + k} ,

that takes a tuple and adds 1 to each entry. In symbols,

ϕ(a1, a2, . . . , ak) = (a1 + 1, a2 + 1, . . . , ak + 1).

This function has a two-sided inverse, defined by just subtracting 1 from each entry. Hence ϕ is a bijection.

Math 3345 Combinatorics20 Fall 2016 7 Set-partitions

Compositions and subsets provided a language to describe the case of counting functions with an indistinguishable domain. What about the reverse problem? How does one count the ways to assign balls to bins where the balls are distinguishable, but the bins are indistinguishable? This leads us to the idea of a set-partition.

Definition 17: A partition of a finite set S is a set π = {B1,B2,...,Bk} of subsets of S so that

1. Bi 6= ∅ for all 1 ≤ i ≤ k.

2. The sets {Bi : 1 ≤ i ≤ k} are disjoint.

k 3. ∪i=1Bi = S.

Example 14: The set-partitions of [3] are

{{1, 2, 3}} {{1, 2} , {3}} {{1, 3} , {2}} {{2, 3} , {1}} {{1} , {2} , {3}} .

The Stirling numbers of the second kind S(n, k) count the number of ways to partition the set [n] into k parts. By convention, S(0, 0) = 1, while S(n, 0) = 0 for all n ≥ 1. From the example, S(3, 1) = 1,S(3, 2) = 3,S(3, 3) = 1. While there is not as simple a closed formula for Stirling numbers as for subsets or compo- sitions, there is a recurrence very similar to Pascal’s identity.

Lemma 15 (Stirling Recurrence): For 0 ≤ k ≤ n,

S(n, k) = kS(n − 1, k) + S(n − 1, k − 1).

Proof. The proof of this identity is nearly the same as Pascal’s identity. For a set partition π = {B1,B2,...,Bk} of [n], there are two possibilities for the location of n. Either n is by itself or n is not by itself. If n is by itself, then we can remove that part from π. This leaves a set-partition of [n − 1] with k − 1 parts. This leaves us with the task of counting the number of π for which n is not by itself. Let T be the set of set-partitions of [n] for which n is not by itself. Let W be the set of all

Math 3345 Combinatorics21 Fall 2016 set-partitions of [n − 1] into k parts. Define a function

ϕ : T → W which deletes n from whichever set in which it appears. For example, if n = 5, k = 2 and

π = {{1, 2, 4} , {3, 5}} , then ϕ(π) = {{1, 2, 4} , {3}} . This function is not a bijection. On the other hand, for any π0 ∈ W, there are exactly k elements of T that map to π0 under ϕ, given by adding n to each of the parts of π0. In the example, if π0 = {{1, 2, 4} , {3}} , then both {{1, 2, 4, 5} , {3}} and {{1, 2, 4} , {3, 5}} are mapped to π0 by ϕ. In particular, ϕ is a k-to-one surjection. Therefore

|S(n, k)| = |T | + S(n − 1, k − 1) = kS(n − 1, k) + S(n − 1, k − 1).

Just like with Pascal’s triangle, this recurrence lets us build a Stirling triangle.

Example 15 (Stirling triangle):

n k k = 0 1 2 3 4 5 6 n = 0 1 0 0 0 0 0 0 n = 1 0 1 0 0 0 0 0 n = 2 0 1 1 0 0 0 0 n = 3 0 1 3 1 0 0 0 n = 4 0 1 7 6 1 0 0 n = 5 0 1 15 25 10 1 0 n = 6 0 1 31 90 65 15 1

8 Partitions

The final counting problem we’ll consider is the partition counting problem. In the language of distinguishability, this concerns counting functions f :[n] → [k] where both the domain and codomain are indistinguishable. In the language of balls and bins, we put balls into bins, but we neither distinguish between balls nor bins. Since we don’t care which bins are which, we can arrange the bins in any order we wish after having placed the balls. Conventionally, we arrange bins so that the fullest bins appear first. This leads to the following definition.

Math 3345 Combinatorics22 Fall 2016 Definition 18: A partition of n into k parts is a k-tuple (a1, a2, . . . , ak) of natural num- bers that are decreasing, i.e. a1 ≥ a2 ≥ · · · ≥ ak. Let pk(n) be the number of partitions of n into k parts. Let p(n), the partition number, be the sum n X p(n) = pk(n). k=1

Example 16: The partitions of 5 are 5 4, 1 3, 2 3, 1, 1 2, 2, 1 2, 1, 1, 1 1, 1, 1, 1, 1. Therefore p(5) = 7, and

(p1(5), p2(5), p3(5), p4(5), p5(5)) = (1, 2, 2, 1, 1).

Partitions are beautiful objects, but they are notoriously difficult objects to understand. While it is possible to compute a few of the terms, it is notoriously difficult to actually say anything about them. Two famous, elementary results are given in terms of generating Pk functions. To state these, we let pk(n) = j=1 pj(n) be the number of partitions of n of length at most n. Then it is relatively easy to justify the following identity ∞ X n −1 2 −1 3 −1 k −1 pk(n)x = (1 − x) (1 − x ) (1 − x ) ··· (1 − x ) . n=0 In fact, letting k tend to ∞, it is also possible to justify ∞ ∞ X Y p(n)xn = (1 − xk)−1. n=0 k=1 9 The Twelvefold Way

In terms of the counting problems introduced, we can complete the following table of counting problems, which taken together, give the twelvefold way. All of these counting problems are formulated in terms of counting the equivalence classes of functions f :[n] → [k], where we do or do not distinguish the domain or codomain. Equivalently, all these counting problems can be phrased in terms of placing n balls in k bins where the balls and bins may be distinguishable or not.

Math 3345 Combinatorics23 Fall 2016 [n] dist. [k] dist. All Injective Surjective n Y Y k [n]k k!S(n, k) N Y n+k−1 n n−1 k−1 (k k−1 1, if n ≤ k Y N Pk S(n, j) S(n, k) j=1 0, else ( 1, if n ≤ k N N p (n) pk(n) k 0, else

Math 3345 Combinatorics24 Fall 2016