MAT5107 : Combinatorial Enumeration
Course Notes (this version: December 2018)
Mike Newman
These notes are intended for the course MAT5107. They somewhat follow approaches in the two (ex- cellent!) books generatingfunctionology by Herbert Wilf [2] and Analytic Combinatorics by Phillipe Flajolet and Robert Sedgewick [1]. Both of these are available in relatively inexpensive print versions, as well as free downloadable .pdf files.
W: https://www.math.upenn.edu/~wilf/DownldGF.html F&S: http://algo.inria.fr/flajolet/Publications/AnaCombi/anacombi.html Both of these books are highly recommended and both could be considered unofficial textbooks for the course (and both are probably not explicitly cited as much as they should be in these notes). The origin of these notes traces back to old course notes scribed by students in a course given by Jason and/or Daniel.
I typically cover most of the material in these notes during one course. Wilf’s book covers more than a course’s worth of material; Flajolet and Sedgewick cover much more.
These notes are available on my webpage. Please don’t post them elsewhere. Feel free to share the link; the current url is http://web5.uottawa.ca/mnewman/notes/.
Despite my best efforts to eliminate typos, there “may” be some that remain. Please let me know if you find any mistakes, big or small. Thanks to those who have pointed out typos in the past!
References
[1] Philippe Flajolet and Robert Sedgewick. Analytic Combinatorics. Cambridge University Press, Cambridge, 2009. [2] Herbert S. Wilf. generatingfunctionology. A K Peters, Ltd., Wellesley, MA, third edition, 2006.
∗ These notes are intended for students in mike’s MAT5107. For other uses please say “hi” to [email protected]. MAT5107 : Combinatorial Enumeration Mike Newman, December 2018 1. generating functions
basic ideas and setup
Combinatorial enumeration is about counting combinatorial (discrete) structures such as sequences, permutations, graphs, polynomials over finite fields, and partitions. We start with a set A of objects (graphs, permutations, etc.), as well as a function ω : A → N that measure the “size” of an object. The exact meaning of “size” depends on the objects and how we wish to treat them. Then we set An to be the pre-image of n and an = |An|; that is An is the set of objects of size n, and an is the number of such objects. The sequence
a0, a1, a2, ··· , an, ··· is an answer to the question “How many objects are there of size n?” We might have an explicit formula for the an, we might have an asymptotic formula that is close for large n, we might only know a relation with some other sequence. In this course we will be dealing with both exact enumeration and asymptotic enumeration. For example, let an be the number of permutations√ of n elements. Then an = n! gives an exact answer. n Using Stirling’s formula, we have an ∼ 2πn(n/e) , which gives an asymptotic expression for an. Here fn ∼ gn means fn/gn → 1 as n → ∞. So the asymptotic expression of an gives the main order of magnitude of an. Of special interest is the fact that there are many cases where we are unable to get an exact formula for an but we can get an asymptotic one.
The unifying tool is the generating function. Given a sequence of numbers (an)n≥0, its ordinary generating function (OGF) and exponential generating function (EGF) are, respectively, 2 3 X n a0 + a1x + a2x + a3x + ··· = anx n≥0 x2 x3 X xn a + a x + a + a + ··· = a 0 1 2 2 3 6 n n! n≥0 These are formal sums, so the question of convergence does not arise (for the moment!); it is just a quirky way of writing the sequence a0, a1, a2, ··· . As we will see later, ordinary generating functions are usually associated with unlabelled structures while exponential generating functions are usually associated with labelled structures (though the reasons for that might seem a little mysterious at the moment).
formal power series
We define a formal power series in the indeterminate x to be an expression of the form 2 X n A(x) = a0 + a1x + a2x + ··· = anx . n≥0
The coefficients an are typically integers or rational numbers; this is the most useful case for us. Formal power series form a ring, in particular if the coefficients are rational then this ring is denoted by Q[[x]].
∗ These notes are intended for students in mike’s MAT5107. For other uses please say “hi” to [email protected].
1 The “x” that appears is not really a variable in the traditional sense; it might more properly be called an indeterminate or even a marker. It is a way of associating the numerical value an that appears as the coefficient, with the value n that appears as the exponent. In other words, you should think of a formal power series as being a strange way of representing a sequence. In fact there will come a point where it will be useful to consider a formal power series as a “function” of its variable x, but this will not alter its formal nature. Note that the exponents that appear are exactly the non-negative integers; this corresponds with the choice to start indexing our sequences at n = 0. This is a somewhat arbitrary but useful choice, motivated by the fact that the exponent usually represents the size of a discrete object, and most natural ways of measuring the size of a discrete object are as a natural number. It is elementary but still worth noticing that the letter n is not really part of A(x), it is just a dummy variable of summation. So in particular we have things like the following. X n X k−3 X i+2 anx = ak−3x = a0 + a1x + ai+2x n≥0 k≥3 i≥0 These are somewhat spurious examples, but there will be other instances where it will be useful to “re-index” a formal power series. Note that both ordinary generating functions and exponential generating functions are elements of Q[[x]]. In particular, whether a generating function is ordinary or exponential is really a question of interpretation. For instance, is the following an ordinary generating function or an exponential one? ( 2 3 P n X n 1 + x + x + x + ··· = n≥0 anx OGF with an = 1 x = 2 3 n 1 + x + 2 x + 6 x + ··· = P a x EGF with a = n! n≥0 2 6 n≥0 n n! n
We use the notation [xn] F (x) to mean the coefficient of xn in F (x). So given an OGF F (x), the n corresponding sequence is exactly ([x ] F (x))n≥0. If we know F (x), then we know (implicitly at least) [xn] F (x) for every n ≥ 0, and vice versa. Note that what we typically want is not the coefficient of n x , but rather the value an. So for exponential generating functions there is a slight twist. P xn Problem 1.1. Let A(x) = n≥0 an n! be an exponential generating function. xn n Explain why an = [ n! ] A(x) = n![x ] A(x).
We will sometimes commit a small but heinous abuse of notation. Namely we will write down expressions like the left-hand equation, when what we “should” write is something like the right- hand expression. n X n n X k [x ] anx = an [x ] akx = an n≥0 k≥0 We are using n for two different things: both as a dummy variable, and as an operator that extracts the coefficient of something (namely xn). So n has two meanings, in the same equation. This is clearly insane. . . but in fact presents no practical difficulty. The index-of-summation n has no existence outside the sum, so there is no risk of confusion with the coefficient-extractor n. So we will tolerate this. In fact it is surprisingly natural, helpful even, and you quite possibly would not have even noticed without prompting.
operations on formal power series
We can add or subtract formal power series in a natural way, as we might add a sequence: X n X n X n anx ± bnx = (an ± bn)x n≥0 n≥0 n≥0
2 We can also multiply formal power series (which was not an obvious operation for sequences):
n ! X n X n X X n anx bnx = akbn−k x n≥0 n≥0 n≥0 k=0
Note that determining the coefficient of xn in the product is a finite process. Of course this process takes longer and longer as n increases, but for each n it is finite. This means we can determine coef- ficients in the product, and thus the product is well-defined as a formal power series. We emphasize that this has nothing to do with convergence. Problem 1.2. Consider the arithmetic of Q[[x]]. • Show that addition and multiplication are commutative and associative. • Show that the additive identity is 0 + 0x + 0x2 + ··· . P n P n • Show that the unique additive inverse of n≥0 anx is n≥0(−an)x . • Show that the multiplicative identity is 1 + 0x + 0x2 + ··· .
For simplicity, we often write 0 and 1 for the additive and multiplicative inverses, even though they are indeed formal power series. For that matter, we permit ourselves to omit any terms in a formal power series whose coefficients are zero; in particular all polynomials are formal power series. There remains the question of which elements of Q[[x]] have multiplicative inverses, i.e., reciprocals. Given a formal power series A(x), the formal power series B(x) is said to be the reciprocal of A(x) if A(x)B(x) = 1.
Lemma 1.3. A(x) has a reciprocal if and only if [x0] A(x) 6= 0. Furthermore the reciprocal is unique.
Proof. We need only consider whether or not the equation A(x)B(x) = 1 has a solution for B(x). Extracting coefficients on each side we get the following equations, where the n-th equation is [xn] A(x)B(x) = [xn] 1.
a0b0 = 1
a1b0 + a0b1 = 0
a2b0 + a1b1 + a0b2 = 0
a3b0 + a2b1 + a1b2 + a0b3 = 0 . . −1 The zeroth equation shows that a0 6= 0 is necessary. Given this, we find b0 = a0 . A simple induction shows that all bn are uniquely determined. So a0 6= 0 is also sufficient. This specifies uniquely the coefficients of B(x), and so B(x) exists. Thus A(x) has a unique reciprocal.
Note that this proof also gives a way to compute the reciprocal of A(x). In fact, this is exactly the method of solving a triangular system of linear equations by back-substitution. P n Problem 1.4. Use the algorithm implicit in the proof of Lemma 1.3 to find the reciprocal of n≥0 x P xn and n≥0 n! . We define the derivative of a formal power series as follows. d X X a xn = na xn−1 dx n n n≥0 n≥0
3 Notice that (assuming we are taking the sum over n ≥ 0) there is not actually a term of x−1 in this sum. It is often useful to combine the previous two, by first differentiating and then multiplying by x (which is itself a formal power series!): d X X x a xn = na xn dx n n n≥0 n≥0 We define the integral of a formal power series as well. Z X X an a xn dx = xn+1. n n + 1 n≥0 n≥0 d R R d We see that dx A dx = A for any formal power series A, but that dx A dx = A − a0. Though we use the language and notation of calculus, there is no suggestion of limits or convergence. We have defined these operations as applying the power rule from calculus on a term-by-term basis. In particular, every formal power series is infinitely differentiable and integrable.
composition of formal power series
One further operation we can do with formal power series is to compose them. That is, given P n P n A(x) = n≥0 anx and B(x) = n≥0 bnx we could consider the expression n X X k C(x) = A(B(x)) = an bkx n≥0 k≥0 Unlike the sum and product of two formal power series, this may not be defined for every A and B. The given expression for C(x) is meaningful exactly when the expression uniquely determines coefficients for each power of x.
P n P n Lemma 1.5. Let A(x) = n≥0 anx and B(x) = n≥0 bnx . Then A(B(x)) is a well-defined formal power series if and only if A(x) is a polynomial or b0 = 0.
n m P P k Proof. Let cm = [x ] n≥0 an k≥0 bkx . We need to show that the cm are well-defined. n m P k First, we note that [x ] k≥0 bkx is well defined for any fixed n since it is the coefficient of m x in a finite product of formal power series. So if A(x) is a polynomial then cm is obtained as a finite sum and hence A(B(x)) is a well-defined formal power series. To put it another way, if A(x) is a polynomial then A(B(x)) is a finite sum of formal power series.
Now let b0 = 0. n n n m−n X k X X [x ] bk+1x m ≥ n [xm] b xk = [xm] xn b xk = k k+1 k≥0 k≥0 k≥0 0 m < n
So in order to compute cm, we can ignore terms in A(x) with degree greater than m, and treat A(x) as if it were a polynomial of degree m. Again cm is a finite sum so A(B(x)) is well-defined.
For the converse, assume that A(x) is not a polynomial and that b0 6= 0. Then we see that n 0 X X k X n c0 = [x ] an bkx = an (b0) . n≥0 k≥0 n≥0
4 It is possible for this series to converge. However, as an algebraic object, the question of con- vergence makes no sense. What we really require is that [xm] A(B(x)) can be determined as an arithmetic process, i.e., finite.
Therefore A(B(x)) is well-defined if and only if A(x) is a polynomial or b0 = 0.
Note that Lemma 1.5 not only gives conditions for the composition to be well-defined, but gives an algorithm for computing it. A compositional inverse of a formal power series A(x) is a formal power series B(x) such that A(B(x)) = B(A(x)) = x.
Problem 1.6. Show that in order for A(B(x)) and B(A(x)) to both be well-defined then we must have one of the following.
• A and B are both polynomials
• A is a polynomial and a0 = 0
• B is a polynomial and b0 = 0
• a0 = b0 = 0
Further, show that if A(B(x)) and B(A(x)) are both well-defined and A(B(x)) = B(A(x)) = x then a0 = b0 = 0 and a1b1 = 1.
Lemma 1.7. Assume B(x) is a formal power series with b0 = 0 and b1 6= 0. Then there exists a unique A(x) such that A(B(x)) = x. Furthermore a0 = 0 and a1 = 1/b1 6= 0.
Proof. The composition is well defined since b0 = 0. We consider A(B(x)) = x as a system of equations of the form [xn] A(B(x)) = [xn] x, much as we did for Lemma 1.3. We write the equations by grouping terms according to the an since these are the unknowns.
0 = a0
1 = a1(b1) 2 0 = a1(b2) + a2(b1) 3 0 = a1(b3) + a2(2b1b2) + a3(b1) 2 2 4 0 = a1(b4) + a2(2b1b3 + b2) + a3(3b1b2) + a4(b1) . .
The zeroth equation is straightforward. The first equation gives a1 = 1/b1. Then an induction gives that all further an are uniquely determined So A(x) is uniquely determined.
As in Lemma 1.3, this is the method of back-substitution applied to a triangular linear system. The algorithm for finding the coefficients of A(x) might be termed a “computational recurrence”, in that it gives an in terms of all of the ak with k < n. It can’t be solved in the way a linear recurrence can, but it is straightforward to compute it (preferably by computer). Lemma 1.7 doesn’t seem to actually tell us when a formal power series has a compositional inverse. Except that it turns out that if A(B(x)) = x, then B(A(x)) = x also. We leave this fact as an interesting exercise.
5 Lemma 1.8. A formal power series A(x) has a compositional inverse if and only if a0 = 0 and a1 6= 0.
formal and analytic power series
We are interested in the set of formal power series, but we will frequently pretend that they are analytic functions. Why can we do this? Consider the set of all analytic power series, thought of as functions, and let φ be the mapping that takes an analytic power series to the corresponding formal power series.
2 φ 2 a0 + a1x + a2x + ··· −→ a0 + a1x + a2x + ···
Although φ looks like the identity mapping, it isn’t. On the left, x is a variable, whose value is constrained by the region of convergence of the power series. On the right, x is an indeterminate which never takes any value at all and serves only to mark different coefficients ak. Of course φ is not in general invertible (many formal power series do not correspond to analytic power series), but if we consider the image of φ, then we see that all of the operations on formal power series that we have defined are exactly consistent with the corresponding operations on analytic power series.
Theorem 1.9 (meta-theorem). Let fA, fB, fC , ··· be formal power series, and let A = −1 −1 −1 φ (fA), B = φ (fB), C = φ (fC ), etc. Then valid operations on fA, fB, fC , ··· are compatible with operations on A, B, C, ··· .
The notation is supposed to evoke the fact that A is some generating function and fA is the lex- icographically identical expression viewed as a function. Of course not all generating functions A have an fA. Valid operations include addition, subtraction, multiplication, division, differentiation, integration, composition, and evaluation. Of course division doesn’t always work, but Lemma 1.3 tells us when it does. Likewise for composition. Note that evaluation at a particular value for x corresponds to finding the value of a series. If A(x) is a formal power series that we care about, and it happens that A(x) = φ−1 (f(x)) for some analytic power series f(x), then we can choose to either operate on A(x), or to operate on f(x) and then take φ of the result. In many cases we don’t even need to know what the radius of convergence is, just that f(x) is analytic on some open region — we don’t even need to know what that region is! For example, here is the operation “integration” applied to a formal power series, and to its image under φ−1. The point is that when we consider the image under φ−1, we are free to make use of any analytic property we want. In other words, this diagram (and others like it) commutes.
X φ−1 1 xn −→ , |x| < 1 1 − x n≥0 n+1 Z X X x φ−1 Z 1 1 xn = −→ dx = log , |x| < 1 n + 1 1 − x 1 − x n≥0 n≥0
P xn+1 If we want to manipulate the formal power series n≥0 n+1 , then we are free to manipulate the 1 analytic function log 1−x , and then consider the analytic power series of the result. In essence, we are making use of theorems like “the derivative of an analytic power series is the term-by-term derivative” and the like. Our formal power series operations are all lexicographically
6 identical to the term-by-term operations on analytic power series, so as long as our formal power series corresponds to an analytic one we may go back and forth at will. n Example 1.10. Describe the OGF and EGF for the sequences an = n! and bn = 2 . Do they correspond to functions?
P n The OGF for an = n! is n≥0 n!x , which is not an analytic power series. It does not correspond P n 1 to any function. The EGF for an = n! is n≥0 n!x /n! = 1−x , which is a function. n P n n 1 P n n For the sequence bn = 2 , n ≥ 0, the OGF and EGF are n≥0 2 x = 1−2x and n≥0 2 x /n! = exp(2x).
The symbol “=” is being used in two (very!) different ways. In particular, in each case the final equality should be seen in a different light. Equality of formal power series simply means that the coefficients are all equal. The fact that generating functions are sometimes “equal to” analytic functions is a bonus.
exercises
1. Write down some sequences whose OGF and/or EGF corresponds to an analytic function, and some that do not. 2. Is there a sequence whose OGF gives an analytic function but whose EGF does not? P xn 3. Find the reciprocal of the formal power series 1 + x and n≥0 n! . x x 4. Verify that 1−x and 1+x are compositional inverses as formal power series. You need to first verify that the composition is legal (in both directions!). Check that the composition gives x in both directions, first by substituting one closed form in to the other, and next by expressing both as actual formal power series, and composing them. 5. Characterize all polynomials A(x) and B(x) that are compositional inverses. (hint: degree) 6. In the notes it was stated that the set of formal power series Q[[x]] is a ring. Prove this. If necessary, look up the definition of a ring. 7. Prove that if F (x) is a formal power series such that F 0(x) = 0, then F (x) is a constant. 0 8. Consider the functional equation F (x) = F (x). Show that for every f0 there is a unique 0 formal power series that satisfies the equation with [x ] F = f0. Note that we are not presuming that F corresponds to an analytic power series, so calculus is useless here. Pt (j) (j) 9. Consider the functional equation j=0 αjF (x) = 0, where F means the j-th derivative of F and the αj are constants. Show that given any values f0, f1, ··· , ft−1 there is a unique j formal power series F that satisfies the equation with [x ] F = fj for 0 ≤ j ≤ t − 1. Again, no calculus! 10. Characterize all polynomials A(x) and B(x) that are compositional inverses. (hint: degree)
11. Show that if A(x) and B(x) are formal power series with b0 = 0 and A(B(x)) = x, then a0 = 0 and B(A(x)) = x. 12. “Find” the compositional inverse of x + x2. By this is meant: write out the first few terms, and explain how you could go on computing them forever if you cared. 13. Consider the formal power series corresponding to ex and log(x). Explain why these are not compositional inverses of each other. Show that the formal power series corresponding to ex − 1 and log(x + 1) are compositional inverses of each other.
7 MAT5107 : Combinatorial Enumeration Mike Newman, December 2018 2. some examples: generating functions and counting
We are typically interested in counting the number of objects of some particular type according to their “size”. The “size” of an object is a deliberately vague term; in fact, we will often be interested in several different notions of “size”.
strings
Example 2.1. Let an be the number of 01-strings of length n. Find an, using generating functions.
We notice that a0 = 1 and that an = 2an−1 for n ≥ 1. This gives X n X n anx = 2an−1x n≥1 n≥1 X n X n−1 −a0 + anx = x 2an−1x n≥0 n≥1 X n X n −a0 + anx = x 2anx n≥0 n≥0 −1 + A(x) = 2xA(x) P n n n n Thus we see that A(x) = 1/(1 − 2x) = n 2 x and therefore an = [x ] A(x) = 2 . n Of course, in this case we could have just noticed that an = 2 right away. But this method will prove useful for situations that aren’t so simple.
Example 2.2. Let bn be the number of 01-strings of length n with no adjacent 0’s. Find bn, using generating functions.
It is easy to see b0 = 1, b1 = 2 and b2 = 3. Consider such a string of length n. If it ends with 1 then after deleting the final 1 we obtain a string of length n − 1 with no adjacent 0’s. Clearly all such strings of length n − 1 arise in this way so the number of strings of length n with no adjacent 0’s that end with 1 is the same as the number of strings of length n − 1 with no adjacent 0’s. If such a string of length n ends with 0 then it must end with 10. Removing the final 10 leaves a string of length n − 2, and all such arise in this way. So the number of strings of length n with no adjacent 0’s that end in 0 is the same as the number of strings of length n − 2 that have no adjacent 0’s.
Therefore for n ≥ 2, we have bn = bn−1 + bn−2.
∗ These notes are intended for students in mike’s MAT5107. For other uses please say “hi” to [email protected].
8 P n Now we find the OGF B(x) = n≥0 bnx using the recursion.
bn = bn−1 + bn−2 X n X n X n bnx = bn−1x + bn−2x n≥2 n≥2 n≥2 X n X n−1 2 X n−2 bnx = x bn−1x + x bn−2x n≥2 n≥2 n≥2 X n X n 2 X n bnx = x bnx + x bnx n≥2 n≥1 n≥0 B(x) − 1 − 2x = x B(x) − 1 + x2 B(x) Alternatively, we just plug the recursion into the OGF directly. X n X n X n B(x) = bnx = 1 + 2x + bnx = 1 + 2x + (bn−1 + bn−2)x n≥0 n≥2 n≥2 X n−1 2 X n−2 = 1 + 2x + x bn−1x + x bn−2x n≥2 n≥2 X n 2 X n = 1 + 2x + x bnx + x bnx n≥1 n≥0 = 1 + 2x + x B(x) − 1 + x2B(x) √ √ 1 + x 1 + x 1 + 5 1 − 5 Hence B(x) = , or B(x) = where γ = , γ = . 1 − x − x2 (1 − γx)(1 − γx) 2 2 We use partial fraction decomposition: 1 + x a b γ2 1 γ2 1 = + = − . (1 − γx)(1 − γx) 1 − γx 1 − γx γ − γ 1 − γx γ − γ 1 − γx
√ n+2 √ n+2 Using geometric series, we have b = √1 1+ 5 − 1− 5 . n 5 2 2
Notice that a partial fraction decomposition gives the generating function as a sum of terms of the P n n form α/(1−rx), and since this corresponds to the geometric series n≥0 αr x , we can easily extract coefficients. The above should convince you that in fact for any sequence determined by a linear recurrence (of fixed order!) we can easily derive the ordinary generating function. Ps Problem 2.3. Let an be a sequence satisfying 0 = t=0 ptan+t for n ≥ 0 where the pt are given P n constants. Give a nice closed form expression for n≥0 anx .
In fact we can handle more general recurrences too. As long as we can deal with the result of applying P n n () x to the expression, we can find a generating function. P n Example 2.4. Suppose that an = 2an−1 + n for n ≥ 1 with a0 = 1. Find A(x) = n≥0 anx .
P n From the recurrence we deduce that A(x) − 1 = 2xA(x) + n≥1 nx . We have two ways (at least) of dealing with the un-simplified part. We can observe that the coefficient of xn in (1+x+x2+··· )2 is n + 1, which leads to the following. X X x nxn = nxn = x(1 + x + x2 + ··· )2 = (1 − x)2 n≥1 n≥0
9 Or we can see the n as the consequence of a derivative. X X d d 1 x nxn = x xn = x = dx dx 1 − x (1 − x)2 n≥1 n≥0 In either case we obtain the following. 1 x A(x) = + 1 − 2x (1 − 2x)(1 − x)2 Since our next step would be to expand in terms of partial fractions and extract coefficients, it n seems pointless to add the fractions. Note that already we can see that an is the sum of 2 and “something”, which is perhaps not surprising (or maybe it is?) given the initial recurrence.
derangements
We use the notation [n] = {1, . . . , n}.A derangement of [n] is a bijection σ :[n] → [n] with no fixed points; that is σ(i) 6= i for all i ∈ [n]. Let dn be the number of derangements of [n].
Lemma 2.5. For n ≥ 1, we have dn+1 = n(dn + dn−1).
Proof. Let σ be a derangement of [n + 1], and let j be such that j = σ−1(n + 1). If σ(n + 1) = j, then σ induces a derangement of the set [n + 1] \{j, n + 1}. By relabelling this set, we see that σ corresponds to a unique derangement of [n − 1]. This gives a total of dn−1 derangements that swap j and n + 1. There are n choices for j, so this gives ndn−1 derangements of [n + 1] that swap n + 1 with something. If σ(n+1) 6= j, then construct a derangement σ0 on [n] according to the following rule: σ0(i) = σ(i) for i 6= j and σ0(j) = σ(n + 1). We leave as an exercise to show that this gives a bijection between the derangements of [n + 1] that map j to n + 1 but not n + 1 to j, and the derangements of [n]. So the number of such derangements of [n + 1] is ndn (again, n choices for j).
P xn We will derive the EGF for derangements, so let D(x) = n≥0 dn n! . By Lemma 2.5 we have
dn+1 = ndn + ndn−1 d nd nd n+1 xn = n xn + n−1 xn n! n! n! X dn+1 X ndn X ndn−1 xn = xn + xn n! n! n! n≥1 n≥1 n≥1 Why is the sum is over n ≥ 1? Why can’t we take n ≥ 0? We now try to identify each term as a function of D.
X dn+1 X dn+1 d d X dn+1 d X dn xn = xn+1 = xn+1 = xn = D0(x) n! (n + 1)! dx dx (n + 1)! dx n! n≥1 n≥1 n≥1 n≥2
X ndn X dn d d X dn xn = x xn = x xn = xD0(x) n! n! dx dx n! n≥1 n≥1 n≥1
X ndn−1 X dn−1 X dn xn = x xn−1 = x xn = xD(x) n! (n − 1)! n! n≥1 n≥1 n≥0
10 Continuing with the example, we have a differential equation D0(x) = xD0(x) + xD(x). D0(x) x = D(x) 1 − x d x log D(x) = dx 1 − x Z x 1 log D(x) = dx = log − x 1 − x 1 − x e−x D(x) = 1 − x
There are a number of things we can do with D(x). Notably, these are operations on the formal power series itself, but they give us information about the coefficients. The point being that even if the sequence is wajht interests us, it might be profitable to study the generating function.
• We can get an exact formula for dn as n n 1 X 1 X (−1)k d = [xn/n!] D(x) = n![xn] e−x = n! [xk] e−x[xn−k] = n! n 1 − x 1 − x k! k=0 k=0
• We can also use the EGF to get a nice identity in terms of the dn. First rewrite as X xn 1 ex d = n n! 1 − x n≥0 n n X 1 dk X n Taking [xn] of both sides we get = 1, or nicer as d = n!. (n − k)! k! k k k=0 k=0 • We can also use the EGF to get another recursion for the sequence dn. First rewrite as X xn (1 − x) d = e−x n n! n≥0 d d (−1)n Taking [xn] of both sides we get n − n−1 = or nicer as d = nd + (−1)n. n! (n − 1)! n! n n−1
direct approach to generating functions : partition the set of objects
n Instead of thinking of a generating function as a formal sum of terms anx over all possible sizes n, n P |α| we can think of it as a sum of terms x , one term for each object of size n, so A(x) = α∈A x . Previously, we thought of a generating function as a formal way of writing a sequence; now we think of it as a formal way of writing the set of all objects (well, a set that is in bijective correspondence with the set of all objects). Thus the GF of a disjoint union is the sum of the GFs.
This suggests that instead of trying to write a recurrence for the sequence an, we should write the set of all objects as a disjoint union, where we can easily determine the GF for each part. Example 2.6. Let A be the set of all 01-strings. Find the ordinary generating function for A.
For convenience, let denote the empty string (i.e., the string of length zero). Also, if σ is a string and S is a set of strings, we will use the notation σS to denote the set of all strings obtained by concatenating σ with some string in S. This is just a special case of the cartesian product of two sets: σS = {σ} × S. We can write A as a disjoint union as follows, which then translates directly
11 into a functional equation for the GF. A = ∪˙ 0A ∪˙ 1A A(x) = 1 + xA(x) + xA(x) = 1 + 2xA(x). 1 Solving, we obtain A(x) = . 1 − 2x
Example 2.7. Let B denote the set of all 01-strings with no adjacent 0’s. Find the ordinary gener- ating function for B.
We have the following disjoint union, and the resulting functional equation for the GF. B = ∪˙ 1B ∪˙ 0 ∪˙ 01B B(x) = 1 + xB(x) + x + x2B(x). 1 + x Solving this gives, as before, B(x) = . 1 − x − x2
Example 2.8. Let B denote the set of all 01-strings with no adjacent 0’s. Find the ordinary gener- ating function for B.
Let bn,k be the number of 01-strings of length n with k 1’s and with no adjacent 0’s. This is an example where each object has two “sizes”: the length and the number of 1’s. This means we will have two indeterminates: x for length and y for weight (number of 1’s). So we will have P P n k n k B(x, y) = n k bn,kx y and we want [x y ] B(x, y). Let B denote the set of all 01-strings with no adjacent 0’s. We have the same disjoint union, but now we have a different GF, so the functional equation is a little different. B = ∪˙ 1B ∪˙ 0 ∪˙ 01B B(x, y) = 1 + xyB(x, y) + x + x2yB(x, y). Hence we have the generating function 1 + x X X B(x, y) = = (1 + x) (x + x2)kyk = xk(1 + x)k+1yk 1 − (x + x2)y k≥0 k≥0 This gives the coefficients: k + 1 b = [xnyk] B(x, y) = [xn−k] (1 + x)k+1 = n,k n − k Notice that we have n n X X k + 1 b = b = n n,k n − k k=0 k=0 Compare this with the expression for bn that we obtained in Example 2.2.
The previous two examples can be done with a recursion on the coefficients; here we would have a system of two recursions in two indices. The direct approach bypasses this completely: the generating function does the work for us! Sometimes one needs to be clever in partitioning the set of objects in a nice way. Here “nice” means that we can easily relate the generating function of each of the parts to the generating function of the whole thing and/or something known.
12 Example 2.9. Let sn,k be the number of 01 strings of length n and k occurrences of 001. Find the ordinary generating function.
Firstly, we note that the set of objects is just the set of all 01 strings. But because of the fact that we care about occurrences of 001, we need to in some way make them stand out. In particular, if a string ends in 0, then that 0 is not involved in an occurrence of 001, but if it ends in a 1 then it may or may not be. So we need to further partition the strings ending in 1 into those that end in 001 and those that don’t. S = ∪˙ S0 ∪˙ (S1 \S001) ∪˙ S001 The rest of the details are left as an exercise (see below).
a quick “application”
Suppose we wish to know the average number of 1’s in a 01-string with no adjacent 0’s. The answer (using previous notation) is given by the following expression. 1 X µn = kbn,k bn k Why do we not need to worry about the right-hand side converging? Using the OGF directly we see that:
X X n k B(x, y) = bn,kx y n k d X X B(x, y) = kb xnyk−1 dy n,k n k
d X X n B(x, y) = kbn,kx dy y=1 n k
n d X [x ] B(x, y) = kbn,k dy y=1 k The summations are over “all n and k”. What are the ranges, precisely? Is the evaluation at y = 1 really valid? Since we already found a closed form for B(x, y), we can evaluate this sum directly by applying the same operations to the closed form.
1 n d 1 + x µn = [x ] 2 (1) bn dy 1 − (x + x )y y=1 The last step is left as an exercise.
Problem 2.10. Find a closed-form expression for µn. That is, evaluate equation (1).
You will discover in the previous exercise some messy-looking partial fractions. Here is one way of cutting the work in half. If you have an irreducible rational quadratic with irrational roots, then those roots come in “conjugate pairs”. What that means is that the roots lie in an extension field of Q that has an automorphism that fixes Q and swaps the two roots. This means that if you take any equation in the extension field (for instance, a partial fraction decomposition) then you can “conjugate” that equation and it remains valid. An example of this that you’ve already seen: if a real polynomial has complex roots, then these come in complex conjugate pairs.
13 exercises
1. Considering the OGF A(x) in Example 2.1, let B(x) = 1 + xA(x). Is B(x) an OGF? Does it count anything? 2. Try and find the EGF for the sequences in Example 2.1 and Example 2.2. What goes wrong? Can you find a way around it?
3. Find an expression for an in Example 2.4. That is, use a partial fraction decomposition of the generating function found there and extract coefficients. 2 n 4. Consider the sequence (bn)n≥0, where bn = 2bn−1 − bn−2 + n + 3 for n ≥ 0 a) Give the OGF, in terms of b0 and b1. b) Give the OGF as a partial fraction decomposition. You don’t need to find the constants in the numerator, but you should have the right form. c) Using your partial fraction decomposition, give an expression for bn in terms of n. Your answer will be in terms of the unknown constants of your partial fraction decomposition. d) For b0 = b1 = 1, find the constants in your partial fraction decomposition, and find an expression for bn. 5. Give the derangements of {1, 2, 3, 4}, according to the classification suggested by Lemma 2.5. 6. In deriving the equation D0(x) = xD0(x) + xD(x), we twice wrote D0(x) when what we had was the derivative of a function that was not D(x). Explain this.
The next two questions are not meant to suggest that GFs are superfluous. Using GFs, we did not just prove these relations, we derived them. Also sometimes direct proofs are much harder, or even not known at all.
P n 7. Prove by a direct counting argument (without GFs) that k k dk = n!, where dk is the number of derangements on [k]. 8. Prove by a direct counting argument (without GFs) that the number of 01-strings of length P k+1 n with no adjacent 0’s is k n−k . 9. We found that the number of 01-strings of length n with no consecutive 0’s is given by the following.
√ n+2 √ n+2 ! ! √ √ 1 1 + 5 1 − 5 1 n+2 n+2 √ − = √ (1 + 5) − (1 − 5) 5 2 2 2n+2 5
m P n k Using the fact that (1+x) = k k x , “simplify” this to show that the number of 01-strings of length n with no consecutive 0’s is given by the following.
n+1 b 2 c 1 X n + 2 5j 2n+1 2j + 1 j=0
n+1 n b 2 c X k + 1 1 X n + 2 Conclude that = 5j n − k 2n+1 2j + 1 n j=0 k=b 2 c P n 10. Let D(x) = n dnx be the OGF for derangements. The point of this exercise is that one can use the generating function approach without even finding the generating function. a) Using the recurrence dn+1 = ndn + ndn−1, obtain a functional equation for D(x). n b) By rearranging this equation and extracting coefficients, prove that dn = ndn−1 +(−1) .
14 11. Consider the GF A(x, y) above for 01-strings with no consecutive zeros. In extracting the coefficients of A(x, y) in Example 2.8 we did not use partial fractions. Could we have used the same method when we considered these strings in Example 2.2? 12. As part of finding the average number of 1’s in a 01 string with no adjacent 0’s we evaluated d a generating function at y = 1. The expression dy B(x, y) above is certainly a bivariate generating function. Why does evaluating this at y = 1 result in a well-defined single-variable n d generating function? (hint: look at [x ] dy B(x, y))
13. Let cn,t be the number of 01 strings of length n with at most t consecutive 0’s. Find the OGF for cn,t. For t = 1 verify that this is consistent with Example 2.2. For t = 0, extract coefficients to find cn,0 and verify that it makes sense.
14. Let cn,k,t be the number of 01 strings of length n with k 1’s and at most t consecutive 0’s. Find the (bivariate) OGF for cn,k,t. For t = 1 verify that this is consistent with Example 2.8. For t = 0, extract coefficients to find cn,k,0 and verify that it makes sense. 15. Find the average number of 1’s in a 01 string with at most t consecutive 0’s.
16. Let sn,k be the number of strings of length n with k occurrences of 001. Let S(x, y) = P P n k n≥0 k≥0 sn,kx y . a) Without calculating S(x, y), what should S(x, 1) be? Why should evaluating this at y = 1 make sense? b) Find a simple closed form for S(x, y). Your answer should be a rational function. (hint: partition the set of objects)
17. Let sn,k,t be the number of strings of length n with k occurrences of t 0s followed by a 1, for some positive integer t. So t = 2 corresponds to the previous question. Let S(x, y) = P P n k n≥0 k≥0 sn,k,tx y . a) For t = 1, give another interpretation of k. b) Find a simple closed form for S(x, y). c) What should happen for t = 0? Does it?
15 MAT5107 : Combinatorial Enumeration Mike Newman, December 2018 3. set partitions
many generating functions for one sequence