Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
78 Topics in Discrete Mathematics Example 3.5. According to these rules, the sum of F (z) = z + z 2 + 2z 3 + 3z 4 + · · · and C(z) = 1 + z + 2z 2 + 5z 3 + 14z 4 + · · · is just obtained by adding the coefficients term-by-term: F (z) + C(z) = 1 + 2z + 3z 2 + 7z 3 + 17z 4 + · · · . We obtain each coefficient of the product by adding appropriate products of one coefficient from F (z) and one coefficient from C(z): coefficient of z 0 in F (z)C(z) = 0×1=0 coefficient of z 1 in F (z)C(z) = 0×1+1×1=1 coefficient of z 2 in F (z)C(z) = 0×2+1×1+1×1=2 coefficient of z 3 in F (z)C(z) = 0×5+1×2+1×1+2×1=5 coefficient of z 4 in F (z)C(z) = 1 × 5 + 1 × 2 + 2 × 1 + 3 × 1 = 12 so F (z)C(z) = z + 2z 2 + 5z 3 + 12z 4 + · · · It is often useful to write formal power series in sigma notation as follows. Definition 3.6. The symbol ∞ X an z n means a0 + a1 z + a2 z 2 + a3 z 3 + · · · . n=0 The P∞ lowern limit of the3 sum 4can be5 varied in the obvious way: for instance, n=3 bn z means b3 z + b4 z + b5 z + · · · . The summation variable n can of course be replaced with any other letter. In this notation the rules for addition and multiplication become: ! ! ∞ ∞ ∞ X X X n n an z + bn z = (an + bn ) z n , n=0 ∞ X n=0 ! an z n n=0 ∞ X n=0 ! bn z n = n=0 ∞ X n X n=0 m=0 (3.1) ! am bn−m n z . 85 CHAPTER 3. GENERATING FUNCTIONS Remark 3.18*. Theorem 3.17 is equivalent to saying that for all s ≥ 1, ∞ X n+s−1 n 2 3 s (1 + z + z + z + · · · ) = z . (3.8) n n=0 To get a z n term on the left-hand side of (3.8), one must select from the various factors the z n1 , z n2 , · · · , z ns terms where n1 , n2 , · · · , ns are nonnegative integers such that n1 + n2 + · · · + ns = n. So (3.8) is equivalent to the statement that the number of s-tuples (n1 , n2 , · · · , ns ) ∈ Ns such that n1 + n2 + · · · + ns = n is n+s−1 . Thus Theorem 3.17 is just a disguised form n of Theorem 1.60. Multiplying Theorem 3.17 on both sides by z k gives a generalization of (3.6): ∞ X n n zk z = . (3.9) k (1 − z)k+1 n=0 (You would normally change the summation sothat it started from n = k, but in this case it makes no difference because nk = 0 for n = 0, 1, · · · , k−1.) Since we can express nm as a linear combination of binomial coefficients nk for various k by Theorem 1.86, we can use (3.9) to get a closed formula for the generating function of the sequence 0m , 1m , 2m , · · · for any m, and hence of any sequence where the nth term is a polynomial function of n. Example 3.19. To find a closed formula for 02 + 12 z + 22 z 2 + 32 z 3 + · · · , we first express n2 as an integer linear combination of binomial coefficients: n2 = n 1 1 n 2 . 2 + Hence ∞ X 2 n n z = n=0 ∞ X n=0 = 1 n 1 n z + ∞ X 2 n 2 zn n=0 z 2z 2 z + z2 + = (1 − z)2 (1 − z)3 (1 − z)3 Another seemingly dubious operation which is often useful is to take a formal power series A(z) and substitute for z another formal power series F (z), expanding out each F (z)n and collecting terms; the result is denoted A(F (z)). 88 Topics in Discrete Mathematics 2−9z Example 3.25. To find the coefficient of z n in 1−7z+12z 2 , we need to write it in partial-fractions form. The denominator factorizes as (1 − 3z)(1 − 4z), so this amounts to finding constants C1 and C2 such that C1 C2 2 − 9z = + . (1 − 3z)(1 − 4z) 1 − 3z 1 − 4z Multiplying both sides by (1 − 3z)(1 − 4z), this equation becomes 2 − 9z = C1 (1 − 4z) + C2 (1 − 3z) = (C1 + C2 ) − (4C1 + 3C2 )z Equating coefficients, we get two linear equations for the two unknowns of 3 which the unique solution is C1 = desired partial-fractions expression is: 2 − 9z = 1 − 7z + 12z 2 and C2 = −1 . So the 1 3 − 1 − 3z 1 − 4z We can use (3.10) to read off that the coefficient of z n in 2 − 9z is 1 − 7z + 12z 2 3n+1 − 4n 5−9z Example 3.26. Let us find the coefficient of z n in 1−6z+9z 2 . The denomi2 nator factorizes as (1 − 3z) ; when we have a repeated factor like this, the partial-fractions form should include a term for every power of the factor up to the multiplicity, which in this case means C1 C2 5 − 9z = + . 2 (1 − 3z) 1 − 3z (1 − 3z)2 Clearing the denominators, this becomes 5 − 9z = C1 (1 − 3z) + C2 = (C1 + C2 ) − 3C1 z, which has the unique solution C1 = 3, C2 = 2. So 5 − 9z 3 2 = + . 2 1 − 6z + 9z 1 − 3z (1 − 3z)2 By (3.10) and (3.11), the coefficient of z n is 3 × 3n + 2(n + 1)3n = (2n + 5)3n . 95 CHAPTER 3. GENERATING FUNCTIONS Example 3.40. Recall the tower of Hanoi sequence satisfying h0 = 0 and the recurrence relation hn = 2hn−1 + 1 for all n ≥ 1. If H(z) denotes the generating function, we have the following equation for H(z) in terms of itself and the geometric series: H(z) = h0 + h1 z + h2 z 2 + h3 z 3 + · · · = 0 + (2h0 + 1)z + (2h1 + 1)z 2 + (2h2 + 1)z 3 + · · · = 2zH(z) + z 1−z which shows that H(z) = 1 1 z = − (1 − z)(1 − 2z) 1 − 2z 1 − z From this we deduce the formula hn = 2n − 1 immediately. Example 3.41*. Recall from Example 2.47 the sequence defined by a0 = 3, a1 = 5, an = 2an−1 + 3an−2 + 8n − 4 for n ≥ 2. P n Let A(z) = ∞ n=0 an z be the generating function. Then A(z) = a0 + a1 z + ∞ X an z n n=2 = 3 + 5z + ∞ X (2an−1 + 3an−2 + 8n − 4) z n n=2 ∞ X = 3 + 5z + 2 ∞ X n an−1 z + 3 n=2 ∞ X = 3 + 5z + 2z an z n + 3z an−2 z + 8 n=2 ∞ X 2 n=1 n n=0 2 ∞ X n nz − 4 n=2 an z n + 8 ∞ X n zn − 4 n=2 = 3 + 5z + 2z(A(z) − 3) + 3z A(z) z 1 +8 −z −4 −1−z , (1 − z)2 1−z where the last line uses (3.3) and (3.6). Tidying this up gives (1 − 2z − 3z 2 )A(z) = 3 − 7z + 17z 2 − 5z 3 , (1 − z)2 ∞ X zn n=2 ∞ X n=2 zn 100 Topics in Discrete Mathematics which implies that C(z) = ∞ X 2n (2n − 1)!! n=0 (n + 1)! zn. (3.23) From this we can read off our desired formula for the Catalan numbers: 2n (2n − 1)!! (2n)! cn = = , (3.24) (n + 1)! (n + 1)!n! where the second equality uses (2n − 1)!! = (2n)! (see Example 1.40). Note 2n n! 2n 2n+1 1 1 that cn is not quite a binomial coefficient, but cn = n+1 n = 2n+1 . n Generating functions can be very helpful in finding closed formulas for sums f (0) + f (1) + · · · + f (n). The reason is that if A(z) is the generating function of a0 , a1 , a2 , · · · , then by (3.3) and the multiplication rule, ∞ X A(z) (a0 + a1 + · · · + an ) z n , = 1−z n=0 so A(z) 1−z (3.25) is the generating function of the sequence of partial sums of a0 , a1 , · · · . Example 3.46. To find a closed formula for 0×20 +1×21 +· · ·+n×2n , we first need a formula for the generating function of the sequence 0 × 20 , 1 × 21 , · · · : by (3.11), this is ∞ X n2n z n = n=0 2z (1 − 2z)2 Now divide both sides by 1 − z, and use (3.25): 0×20 +1×21 +· · ·+n×2n = coefficient of z n in 2z (1 − z)(1 − 2z)2 We already found this coefficient in Example 3.27: it is (n − 1)2n+1 + 2. Example 3.47. In Example 2.22 we were unable to guess a closed formula for the sum of squares 12 +22 +· · ·+n2 . To solve this problem using generating functions, we first need a formula for the generating function of the sequence of squares itself, i.e. 02 + 12 z + 22 z 2 + · · · . We found this in Example 3.19: ∞ X z 2z 2 nz = + . (1 − z)2 (1 − z)3 n=0 2 n