Professional Documents
Culture Documents
Mathematics For Algorithm and System Analysis: Outline
Mathematics For Algorithm and System Analysis: Outline
Day 8
Generating Functions
!
unlimited repetition
5 6
Example Example
Find a generating function to model: Find a generating function for ar, the number of ways a roll of six
!
the number of ways to distribute r identical objects into five boxes with distinct dice can show a sum of r if
an even number of objects not exceeding 10 in the first two boxes and !
The first three dice are odd and the second three even
between 3 and 5 in the other boxes.
!
The ith die does not show a value of i
7 8
Finding the Desired Coefficient Product of Generating Functions
Reduce complicated generating function to simple function or If
product of simple functions !
f(x) = a0 + a1x + a2x2 + …
!
The simple functions: !
g(x) = b0 + b1x + b2x2 + …
and
1 − xm+1
= 1 + x + x2 + · · · + xm !
h(x) = f(x)g(x)
1−x
then
1 !
h(x) = a0b0 +
= 1 + x + x2 + · · · (a0b1 + a1b0)x +
1−x
(a0b2 + a1b1 + a2b0)x2 +
! " ! " ! " ! " …+
n 0 n 1 n r n n
(1 + x)n = x + x +···+ x +···+ x (a0br + a1br-1 + … + ar-1b1 + arb0)xr +
0 1 r n
…
! " ! " ! " ! "
n m n 2m n km n nm
(1 − xm )n = 1 − x + x + · · · + (−1)k x +···+ x
1 2 k n
9 10
Example Example
Find the coefficient of x16 in (x2 + x3 + x4 + …)5 Find the number of ways to collect $15 from 20 distinct people if
!
Rewrite as product of simpler functions each of the first 19 people can give $0 or $1 and the 20th
person can give either $0 or $1 or $5
!
Generating function: g(x) =
!
Final simplification:
!
Simplify
!
Find coefficient
!
Find coefficient
11 12
Example Example
How many ways to distribute 25 identical balls into seven How many ways are there to select 25 toys from seven types of
distinct boxes if the first box can have no more than 10 balls? toys with between two and six of each type?
!
Generating function !
Generating function
!
Simplify !
Simplify
!
Find coefficient !
Find coefficient
13 14
15 16
Example Example
Find a generating function for the number of ways to express r Show with generating functions that every integer can be
as a sum of distinct integers expressed as a unique sum of distinct powers of 2
!
Generating function
!
To show: g(x) = 1 + x + x2 + x3 + …
17 18
19 20
Exponential Generating Functions Exponential Generating Function
Used to model problems involving arrangements and Function of form:
distributions of distinct objects !
g(x) = a0 + a1x + a2x2/2! + a3x3/3! + … + arxr/r! + …
Example problem
!
find number of different arrangements of four letters, choosing from Example
a’s, b’s, and c’s with at least two a’s. !
g(x) = (x2/2! + x3/3! + x4/4! + …)(1+x+x2/2! + x3/3! + …)2
Solution 1
!
Four letter combinations: !
Coefficient of xr in g(x) is equal to: !
– {a, a, a, a}: 4!/4!0!0! e1+e2+e3=r 1 2 !e3 !
e !e
– {a,a,a,b}:4!/3!1!0! r!
!
Coefficient of xr/r! in g(x) is equal to:
– {a,a,a,c}:4!/3!0!1! !
– {a,a,b,b}:4!/2!2!0! e1+e2+e3=r 1 2 !e3 !
e !e
– {a,a,b,c}:4!/2!1!1!
– {a,a,c,c}:4!/2!0!1!
!
Total is sum, so we want that sum as the coefficient of x4
!
Ordinary generating function can solve number of integer solutions to:
– e1 + e2 + e3 = 4 e1"2 e2, e3 "0
!
But, we want each solution to above problem to contribute:
– (e1+e2+e3)!/e1!e2!e3!
21 22
Example Example
Find the exponential generating function for ar, the number of Find the number of ways to place r (distinct) people into three
different arrangements of r objects chosen from four different rooms with at least one person in each room
type of objects with each type of object appearing at least 2 and
no more than 5 times
23 24
Finding Desired Coefficients Example
Useful identities Find the number of different r arrangements of objects chosen
from unlimited supplies of n types of objects
!
Generating function
x2 x3 xr
ex = 1 + x + + + · · · + + · · ·
2! 3! r!
!
Simplify
nx n2 x2 n3 x3 nr x r
e = 1 + nx + + +···+ +···
2! 3! r!
1 x x2 x4 x6
(e + e−x ) = 1 + + + + · · · +
2 2! 4! 6!
!
Find coefficient
1 x x3 x5 x7
(e − e−x ) = x + + + + · · · +
2 3! 5! 7!
25 26
Example Example
Find the number of ways to place 25 people into 3 rooms with at Find the number of r-digit quaternary sequences (digits: 0, 1, 2,
least one person in each room 3) with an even number of 0’s and an odd number of 1’s
!
Generating function !
Generating function
!
Simplify
!
Simplify
!
Find coefficient
!
Find coefficient
27 28