lecture 17 generating functions. recap generating functions are defined by a sequence as follows:...

15
Lecture 17 Generating Functions

Upload: ethelbert-roberts

Post on 16-Dec-2015

213 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Lecture 17 Generating Functions. Recap Generating functions are defined by a sequence as follows: Thus: For every sequence there a generating function

Lecture 17

Generating Functions

Page 2: Lecture 17 Generating Functions. Recap Generating functions are defined by a sequence as follows: Thus: For every sequence there a generating function

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.

Page 3: Lecture 17 Generating Functions. Recap Generating functions are defined by a sequence as follows: Thus: For every sequence there a generating function

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

Page 4: Lecture 17 Generating Functions. Recap Generating functions are defined by a sequence as follows: Thus: For every sequence there a generating function

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.

Page 5: Lecture 17 Generating Functions. Recap Generating functions are defined by a sequence as follows: Thus: For every sequence there a generating function

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

Page 6: Lecture 17 Generating Functions. Recap Generating functions are defined by a sequence as follows: Thus: For every sequence there a generating function

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

Page 7: Lecture 17 Generating Functions. Recap Generating functions are defined by a sequence as follows: Thus: For every sequence there a generating function

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 ?

Page 8: Lecture 17 Generating Functions. Recap Generating functions are defined by a sequence as follows: Thus: For every sequence there a generating function

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

Page 9: Lecture 17 Generating Functions. Recap Generating functions are defined by a sequence as follows: Thus: For every sequence there a generating function

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

Page 10: Lecture 17 Generating Functions. Recap Generating functions are defined by a sequence as follows: Thus: For every sequence there a generating function

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!

Page 11: Lecture 17 Generating Functions. Recap Generating functions are defined by a sequence as follows: Thus: For every sequence there a generating function

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!

Page 12: Lecture 17 Generating Functions. Recap Generating functions are defined by a sequence as follows: Thus: For every sequence there a generating function

Some Exercises

(white board)

Page 13: Lecture 17 Generating Functions. Recap Generating functions are defined by a sequence as follows: Thus: For every sequence there a generating function

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.

Page 14: Lecture 17 Generating Functions. Recap Generating functions are defined by a sequence as follows: Thus: For every sequence there a generating function

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

Page 15: Lecture 17 Generating Functions. Recap Generating functions are defined by a sequence as follows: Thus: For every sequence there a generating function

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