Mathematics for Computer Science Infinite Geometric Sum MIT 6.042J/18.062J S(x) ::= 1+ x + x2 + + xn + xS(x) = x + x2 + + xn + Generating Functions Albert R Meyer, lec 11F.1 April 23, 2010 Albert R Meyer, April 23, 2010 lec 11F.2 Ordinary Generating Functions Infinite Geometric Sum S(x) ::= 1+ x + x2 + + xn + x + x2 + + x n + xS(x) = The ordinary generating function for the infinite sequence g0, g1, g2, , gn, S(x)xS(x) = 1 is the power series: G(x) = g0 + g1x + g2x2 + + gn xn + Albert R Meyer, lec 11F.3 April 23, 2010 April 23, 2010 lec 11F.5 In how many ways can we fill a bag with n fruits given the following constraints? “corresponds to” Albert R Meyer, April 23, 2010 Bags of fruit Infinite Geometric Sum = Albert R Meyer, • At most 2 oranges. 1 • Any number of apples. 1x • Any number of bananas that only come in bunches of 3. lec 11F.6 Albert R Meyer, April 23, 2010 lec 11F.8 1 At most 2 oranges Bags with n = 4 fruits # ways to pick k oranges • 0 oranges, 1 apple, 3 bananas • 0 oranges, 4 apples, 0 bananas • 1 orange, 0 apples, 3 bananas • 1 orange, 3 apples, 0 bananas • 2 oranges, 2 apples, 0 bananas Number of 4-fruit bags: 5 Albert R Meyer, April 23, 2010 lec 11F.9 Albert R Meyer, April 23, 2010 lec 11F.10 Substituting xk for x Any number of apples There is only 1 way to pick a bag of k apples: ak = 1 Albert R Meyer, April 23, 2010 lec 11F.11 Albert R Meyer, April 23, 2010 lec 11F.12 Convolution Rule Bananas in bunches of 3 We can use the individual generating functions to solve original fruit problem! Albert R Meyer, April 23, 2010 lec 11F.13 Albert R Meyer, April 23, 2010 lec 11F.14 2 Convolution Rule Convolution Rule Ways to pick 12 apples & bananas: # ways • 0 apples and 12 bananas 1 • 1 apple and 11 bananas 0 • 12 apples and 0 bananas Ways to pick 12 apples & bananas: aj = # ways to pick j apples bk = # ways to pick k bananas ajb12-j = # ways to pick j apples and rest bananas 1 Total=5 Albert R Meyer, April 23, 2010 lec 11F.15 Convolution Rule Albert R Meyer, April 23, 2010 lec 11F.16 Convolution Rule # ways to pick 12 apples & bananas The coefficient of x12 in the product A(x)·B(x): = a 0b 12 + a 1b 11 + … + a 11b 1 + a 12b 0 But this is the coefficient of x12 in A(x)·B(x) Albert R Meyer, April 23, 2010 lec 11F.17 Convolution Rule Albert R Meyer, April 23, 2010 lec 11F.18 Convolution Rule # ways to pick 12 apples & bananas The gen func for choosing from a union of disjoint sets is the product of the gen funcs for choosing from each set. is the coefficient of x12 in A(x)·B(x) the generating function for picking apples & bananas Albert R Meyer, April 23, 2010 lec 11F.19 Albert R Meyer, April 23, 2010 lec 11F.20 3 Bags of Fruit A Familiar Generating Function? Gen func for the bags of fruit: so # of our bags with n fruits is the coefficient of xn in 1 / (1 x ) 2 = We can easily relate 1/(1-x)2 to something we already know how to count! 1 (1 x ) 2 Albert R Meyer, April 23, 2010 lec 11F.21 A Familiar Generating Function? The gen func for selecting n donuts of a given flavor: Albert R Meyer, April 23, 2010 Albert R Meyer, April 23, 2010 lec 11F.22 A Familiar Generating Function? The gen func for selecting n donuts using both flavors: lec 11F.24 A Familiar Generating Function? The gen func for selecting n donuts among k flavors: Albert R Meyer, April 23, 2010 lec 11F.25 The Donut Number! Using k different flavors, how many ways are there to form a bag of n donuts? (You already know the answer to this one.) Albert R Meyer, April 23, 2010 lec 11F.26 Albert R Meyer, April 23, 2010 lec 11F.27 4 The Donut Number! The Donut Number! Using k different flavors, how many ways are there to form a bag of n donuts? so coeff of xn in n + k 1 n Albert R Meyer, n + k 1 n lec 11F.28 April 23, 2010 Conclusion: Bags of Fruit (1 x ) 2 fn = n + 2 1 = n + 1 n lec 11F.30 April 23, 2010 Partial Fraction Expansions H(x) ::= Albert R Meyer, April 23, 2010 lec 11F.34 Partial Fractions for H(x) x 2x2 3x + 1 lec 11F.29 If a generating function polynomials H(x) is a quotient rational of function there is a simple way to find the nth coefficient hn 1 Albert R Meyer, April 23, 2010 Finding coefficients In how many ways can we fill a bag with n of our fruits? F(x) = Albert R Meyer, Factor denominator 1 1 H(x) = A 1 + A2 1 2x 1 x h n = A 1 2n + A 2 1 Express as sum TO DO: find A1 and A2. Albert R Meyer, April 23, 2010 lec 11F.35 Albert R Meyer, April 23, 2010 lec 11F.36 5 Solve for A1 and A2 Solve for A1 and A2 Substitute in values for x. Multiply both sides by denom of LHS. Albert R Meyer, lec 11F.37 April 23, 2010 Finding the coefficients 1 = 1 2x April 23, 2010 lec 11F.38 In General… 1 The partial fraction expansion of P(x)/Q(x) contains terms of the form 1x the partial fraction expansion h n = 2n 1 Albert R Meyer, Albert R Meyer, …+ A (1 x ) k +… We know the nth coeff of this! n + k - 1 n A n where 1/ is a root of Q(x). lec 11F.39 April 23, 2010 Partial Fractions Caveat #1 Albert R Meyer, April 23, 2010 lec 11F.40 Partial Fractions Caveat #2 For roots with multiplicity k>1 in factored denominator of gen func (1 x ) If deg(N) > deg(D)… use polynomial long division to find Q(x) and R(x) such that k need k partial fractions: A1 + A2 (1 x ) (1 x ) 1 2 Albert R Meyer, ++ Ak (1 x ) April 23, 2010 k + lec 11F.41 and deg(R) < deg(D). Albert R Meyer, April 23, 2010 lec 11F.42 6 Team Problems Problems 1&2 Albert R Meyer, April 23, 2010 lec 11F.44 7 MIT OpenCourseWare http://ocw.mit.edu 6.042J / 18.062J Mathematics for Computer Science Spring 2010 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.