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
Generating Functions A robust tool to solve a wide variety of problems that deal with sequences, series, permutations, combinations, and more. A generating function gives us a way to mathematically represent or encode such problems. – Definition – Purpose – Examples Generating function • A polynomial with either – Interesting choices for its coefficients (useful for recurrence relations) – Interesting choices for its exponents (useful for permutations/combinations) • Customary to write in ascending powers of x – Coefficients can correspond to terms of a sequence Sequences have no mathematical operators. Writing as a polynomial provides a way to manipulate sequences. – Convenient if number of terms is infinite • We almost never substitute a value for x Purpose • Our textbook shows how to solve simple: – Permutation & combinations – Recurrence relations Using techniques that are narrowly defined. • Generating functions allow you to solve a much wider variety of problems in a systematic, less ad-hoc way. • Disadvantage: not very easy to use – Can be tedious – Requires techniques such as binomial expansion or partial fractions along the way Preliminary remarks • How many terms do you get if you multiply…? (a + b)(c + d) (a + b)(c + d)(e + f) (a + b + c)(d + e + f + g) • Notice that each term of the product tells you which number you selected inside each ( ). – If you replace each letter with “1”, you get # of terms! • Analogous concept: how many factors does a number have, e.g. 1200? Combinations • Consider the multiplication of (1+ax)(1+bx)(1+cx) • We need to create terms, where we select something from each factor: – Select the 1 or ax from (1+ax) – Select the 1 or bx from (1+bx) – Select the 1 or cx from (1+cx) – And you sum all 8 possibilities to get: 1 + (a+b+c)x + (ab + bc + ac)x2 + (abc)x3 • What are the coefficients saying? • If you take away the letters a,b,c, you get the answer to a different question: (1+x)3 = 1 + 3x + 3x2 + x3 continued • A simple generating function for combinations is (1+x)(1+x)(1+x)…(1+x) = (1+x)n – The coefficient of xr is the number of ways to choose r objects from a set of n distinct objects. – You are basically deciding which x’s to multiply to produce the xr. • What if the collection from which we are selecting has duplicates? Notice the contrast: – Select 2 objects from { A, B, C, D } – Select 2 objects from ( A, A, B, B ). Duplicates • To select from ( A, A, B, B ) is like selecting from a set { A, B} with the ability to choose up to two of each! • Try this generating function: (1 + ax + a2x2) (1 + bx + b2x2) = 1 + (a+b)x + (a2 + ab + b2)x2 + (ab2 + a2b)x3 + a2b2x4. • If we just want the number of ways, we don’t need to specify “a” and “b”: (1+x+x2) (1+x+x2) = 1 + 2x + 3x2 + 2x3 + x4. • What do the coefficients 1, 2, 3, 2, 1 tell us? • Try another problem like this. Duplicates (2) • I have 10 A’s and 3 B’s. How many ways are there to select r objects, given that the number of A’s I can select must be a multiple of 5? (1 + x5 + x10)(1 + x + x2 + x3) = 1 + x + x2 + x3 + x5 + x6 + x7 + x8 + x10 + x11 + x12 + x13 • What answers do you see in this polynomial? • Restriction on A’s: this problem can be stated as a coin problem with pennies and nickels! Exponent on x = total number of cents • We can easily generalize to different numbers plus more categories such as C’s, D’s, etc. Formulating • We need a separate factor for each distinct value we are selecting, or for each distinct category, die roll, digit in a number, etc. • Decide on what the exponent of x means. Possibilities: – Number of objects we select – The sum of the numbers selected – How many odd / even / multiple of 3 … • When done, coefficient of some term gives us our answer. – You want to know just how many, or a full enumeration? • More than one variable can be used if you need to keep track of more than one quantity about the selection. Applications • How to select r objects from a set – Allowing for repetition of the same element – Restrictions – Answer = coefficient of xr in some ( ) ( ) generating function. • Similar problems that are only superficially different – Coin problems – Dice problems Review • What combination question would this generating function help solve? (1 + ax + a2x2) (1 + bx) (cx + c2x2) – We can elegantly encode restrictions: maximum, minimum, even number, etc. – What if we just wanted the # of possibilities? – What if the a’s were unlimited? • The number of ways to choose coins to obtain c cents from pennies and nickels. – Think of the set { P, N } but the number of N’s you choose must be a multiple of 5. Dice application • How many ways can we roll a sum of 7 with 2 dice? • Formulation: (x + x2 + x3 + x4 + x5 + x6) (x + x2 + x3 + x4 + x5 + x6) = (x + x2 + x3 + x4 + x5 + x6)2 And we want the coefficient of x7. • We can match x with x6; x2 with x5; etc. – Thought process is parallel to how you might do with without generating functions. – The answer is 6. • Note that this question is equivalent to asking for coefficient of x5 in (1 + x + x2 + x3 + x4 + x5)2. 3 dice • But, what if we had more than 2 dice? Generating functions “scale” very well. • Sum of 7 for 3 dice? No problem: • We want coefficient of x7 in (x + x2 + x3 + x4 + x5 + x6)3 • Equivalent to asking for coefficient of x4 in (1 + x + x2 + x3 + x4 + x5)3. • Inside ( ) we have a geometric series = (1 – x6)/(1 – x) • So (1 + x + x2 + x3 + x4 + x5)3 = (1 – x6)3(1 – x)–3 • Let’s work out (1 – x6)3 and (1 – x)–3…. continued We need to use the fact that the coefficients of (a+b)n are 1, n, n(n – 1)/2!, n(n – 1)(n – 2)/3!, n(n – 1)(n – 2)(n – 3)/4!, etc. (1 – x6)3 = 1 – 3x6 + 3x12 – x18 (1 – x)–3 = 1 + 3x + (3)(4)/2! x2 + (3)(4)(5)/3! x3 + … • If we multiply these polynomials, how do we find a term containing x4? – x18, x12 and x6 can’t help us, because 2nd polynomial has only positive powers of x. – The only possibility is to multiply “1” from first polynomial by the x4 term from the 2nd polynomial. – Its coefficient is (3)(4)(5)(6)/4! = (5)(6) / 2 = 15. Alternate calculation • Determining the coefficient of a single term can be phrased as a combination question. • The coefficient of x4 in (1 + x + x2 + x3 + x4 + x5)3 means we want 3 exponents to sum to 4, where each exponent ranges from 0 to 5. – – – – – In other words, e1 + e2 + e3 = 4 where each ei = 0,1,…,5. How can 3 numbers sum to 4? 0+0+4, 0+1+3, 0+2+2, 1+1+2 In each case, decide which ei represents each number. Total number of ways = 3 + 6 + 3 + 3 = 15. Ball in urn • Many combination questions are of the ball-in-urn type. We have n identical balls to place in r urns. The balls are identical, so we simply need to know how many wind up in each urn. • Basic approach: the generating function is of the form (1 + x + x2 + x3 + …)r and we want the coefficient of xn. Highest term in each factor can simply be xn. • Distribute 12 bottles of wine among 4 tables… – What if each table must get 1+ bottle? – What if no table may get more than 4? – The first table must have at most 1 bottle, the 2nd must receive at least 1, the third must receive 0, 2 or 4; and the last must receive 2 or 3? Practice formulating • A combination problem can be encoded as a generating function. Try these… • How many ways are there to select 4 objects from [ 5 A’s, 5 B’s, 5 C’s ]? – Now, what if we wanted an equal number of A’s and C’s? • How many ways can you make $1 change using pennies, nickels, dimes and/or quarters? • How many integers from 0 to 999 have a sum of digits of 12? Two variables • Yes, it’s possible for a generating function to have 2 variables. • Why? Maybe you want to keep track of two quantities at the same time. • Example: (1, 1, 2, 3, 3, 4, 4, 5, 5, 6). How many ways to… – select r different numbers – select numbers that have a sum of r – select r numbers that have a sum of s. • Example: (0, 1, 2, 2, 3, 4) (1 + x)(1 + xy)(1 + xy2 + x2y4)(1 + xy3)(1 + xy4) Some of the terms include 3x3y5, 2x3y4, 3x2y4, x2y7 Review • The coefficient of x4 in (1 + x + x2)5 can answer what combinatorical question? • What if we had several dice, and… – – – – You don’t have to roll all of them. The dice do not all have the same number of sides. You want to achieve a certain sum with a certain number of dice. You want a sum of 31 with 4 6-sided, 2 8-sided, 2 12-sided and you must roll at least 1 of each. • Can you think of a question that would need 3 variables? • Using the Coefficient command in Wolfram Alpha – Example: Coefficient[(1+x+x^2)^10 (1+y)^4,x^5 y]