lecture 17 generating functions. recap generating functions are defined by a sequence as follows:...
TRANSCRIPT
Lecture 17
Generating Functions
Recap
0 10
( ) ... ...k kk k
k
G x a a x a x a x
Generating functions are defined by a sequence as follows:
Thus: For every sequence there a generating function and for every sequence there is a generating function.
Idea: Use properties of functions to solve problems about sequences.
Recap: Important Gen. Functions
0
( 1) ( , ) ( )m
m k
k
x C m k x G x
0
1| | 1
1k k
k
a x axax
0 0
0
0 0
( ) ( )
( ) ( )
( ) ( )
k kk k
k k
kk k
k
kk
j k jk j
F x a x G x b x
F x G x a b x
F x G x a b x
binomial coefficients
adding sequences
multiplying sequences
Recap: Extended Binomial Coeff.
0
(1 ) , , | | 1u k
k
ux x u R x R x
k
( 1)( 2)...( 1),
!
1 0
u u u u u kif u R k Z
k k
uif k
k
The binomial theorem was extended to real values for u,using the definition of extended binomial coefficients.
Application to Counting Problems
What is the number of r-combinations from a set with n elements when repetition is allowed?
I.e. in how many ways can we pick r element from a bag of n elements, when the supply of these elements in infinite (imagine we replace the elements).
n colors
r indistinguishable slots
the balls are replacedwhen they have been drawn
Application to Counting(1+x+x^2+x^3+x^4+....)
(1+x+x^2+x^3+x^4+....)
(1+x+x^2+x^3+x^4+....)
(1+x+x^2+x^3+x^4+....)
(1+x+x^2+x^3+x^4+....)
(1+x+x^2+x^3+x^4+....)
x x^3 1 1 1 1 = x^4
This is just one combination of dividing 4 balls into 6 slots. In general we can choose any combination of terms as long as the powers addup to 4.The number of r-combinations of a set with n elements with repetition is therefore equal to the coefficient in front of the term x^4 in the generating function: G(x)=(1+x+x^2+...)^n
r-Combinations with repetion
2 3
0
0 0
0
1( ) (1 ...)
1
(1 ( )) ( )
( 1) ( 1, )( 1) ( 1)
( 1, )
nn
n k
k
k k k k k
k k
k
k
G x x xx
nx x
k
nx C n k k x
k
C n k k x
Now let’s compute that coefficient:
Looks familiar ?
r-combinations without repetitionthe balls are not replacedwhen they have been drawn
X
X
XX
r indistinguishable slots
n colors
(1+x)
(1+x)
(1+x)
(1+x)
(1+x)
(1+x)
A ball can only be used once, thusit is there or it is not there in the collectionof slots.
x x x x 1 1 = x^4
The number of r-combinations of a set with n elements without repetition is thereforeequal to the coefficient in front of the generating function G(x)=(1+x)^n
r-combinations without repetition
0
( ) (1 ) ( , )n
n k
k
G x x C n k x
So let’s compute that coefficient:
Looks familiar?
binomial theorem
Counting with constraints
Now let’s say, we want to make sure that we pick r elements out of nwith repetition allowed, but we want at least 1 element from each kind:
G(x) = (x+x^2+x^3+...)^n
We are looking for the coefficient of x^r.
2 3
2
0
( ) ...
(1 ...)
1
1
( 1, )
( 1, )
n
n n
nn
n k
k
j
j n
G x x x x
x x x
xx
C n k k x
C j j n x
Here we used the calculationof a few slides back.
Here we redefined: j=n+k
Note that choosing less than n objects is not possible!
Solving Recurrence Relations
1 0
0 0 1 0 01 1 0
00
0 0
3 2.
( ) 3 3 3 ( )
( ) 3 (2 3 )1 3
k k
k k jk k j
k k j
k k k k
k k
a a a
G x a a x a a x a x a x a xG x
aG x a x x
x
therefore we have found that a[k]=2x3^k is the solution!
Some Exercises
(white board)
6.5 Inclusion-Exclusion
AA B
U
A B | | | | | | | |A B A B A B
It’s simply a matter of not over-counting the blue area in the intersection.
Now three Sets
A B
C
A B
A C B CA B C
U
Image a blue circle has area 4. The intersections between 2 circles have area 2 and the intersection between three circles 1. What is the total areacovered?
A=4+4+4 – 2 -2 -2 + 1 = 12 – 6 + 1 = 7.
area = 2-1=1
area = 1
area = 4-3=1
| | | | | | | | | | | | | | | |A B C A B C A B B C C A A B C
General Case
1 21 ( ) ( )
1
| ... | | | | | | | ...
( 1) | ... |
n
n i i j i j ki pairs ij triples ijk
ni j k n
A A A A A A A A A
A A A A
Proof: We show that each element is counted exactly once.Assume element ‘a’ is in r sets out of the n sets A1,...,An.-The first term counts ‘a’ r-times=C(r,1).-The second term counts ‘a’ -C(r,2) times (there are C(r,2) pairs in a set of r elements).-The k’th term counts ‘a’ -C(r,k) times (there are C(r,k) k-subsets in a set of r elements).-...- If k=r then there are precisely (-1)^(r+1) C(r,r) terms.- For k>r ‘a’ is not in the intersection: it is counted 0 times.Total: C(r,1)-C(r,2)+...+(-1)^(r+1)C(r,r)
Now use: to show that each element is counted exactly once. 0
1
1
( 1) ( , ) 0
1 ( 1) ( , )
rk
k
rk
k
C r k
C r k