Вы находитесь на странице: 1из 33

GENERATING FUNCTIONS AND RECURRENCE

RELATIONS
Generating Functions
Recurrence Relations
Suppose a
0
, a
1
, a
2
, . . . , a
n
, . . . ,is an innite sequence.
A recurrence recurrence relation is a set of equations
a
n
= f
n
(a
n1
, a
n2
, . . . , a
nk
). (1)
The whole sequence is determined by (1) and the values of
a
0
, a
1
, . . . , a
k1
.
Generating Functions
Linear Recurrence
Fibonacci Sequence
a
n
= a
n1
+ a
n2
n 2.
a
0
= a
1
= 1.
Generating Functions
b
n
= |B
n
| = |{x {a, b, c}
n
: aa does not occur in x}|.
b
1
= 3 : a b c
b
2
= 8 : ab ac ba bb bc ca cb cc
b
n
= 2b
n1
+ 2b
n2
n 2.
Generating Functions
b
n
= 2b
n1
+ 2b
n2
n 2.
Let
B
n
= B
(b)
n
B
(c)
n
B
(a)
n
where B
()
n
= {x B
n
: x
1
= } for = a, b, c.
Now |B
(b)
n
| = |B
(c)
n
| = |B
n1
|. The map f : B
(b)
n
B
n1
,
f (bx
2
x
3
. . . x
n
) = x
2
x
3
. . . x
n
is a bijection.
B
(a)
n
= {x B
n
: x
1
= a and x
2
= b or c}. The map
g : B
(a)
n
B
(b)
n1
B
(c)
n1
,
g(ax
2
x
3
. . . x
n
) = x
2
x
3
. . . x
n
is a bijection.
Hence, |B
(a)
n
| = 2|B
n2
|.
Generating Functions
Towers of Hanoi
Peg 1
Peg 2 Peg 3
H
n
is the minimum number of moves needed to shift
n rings from Peg 1 to Peg 2. One is not allowed to
place a larger ring on top of a smaller ring.
Generating Functions
Hn-1 moves
1 move
Hn-1 moves
H
n
= 2H
n1
+ 1
Generating Functions
A has n dollars. Everyday A buys one of a Bun (1 dollar), an
Ice-Cream (2 dollars) or a Pastry (2 dollars). How many ways
are there (sequences) for A to spend his money?
Ex. BBPIIPBI represents Day 1, buy Bun. Day 2, buy Bun etc..
u
n
= number of ways
= u
n,B
+ u
n,I
+ u
n,P
where u
n,B
is the number of ways where A buys a Bun on day
1 etc.
u
n,B
= u
n1
, u
n,I
= u
n,P
= u
n2
.
So
u
n
= u
n1
+ 2u
n2
,
and
u
0
= u
1
= 1.
Generating Functions
If a
0
, a
1
, . . . , a
n
is a sequence of real numbers then its
(ordinary) generating function a(x) is given by
a(x) = a
0
+ a
1
x + a
2
x
2
+ a
n
x
n
+
and we write
a
n
= [x
n
]a(x).
Generating Functions
a
n
= 1
a(x) =
1
1 x
= 1 + x + x
2
+ + x
n
+
a
n
= n + 1.
a(x) =
1
(1 x)
2
= 1 + 2x + 3x
2
+ + (n + 1)x
n
+
a
n
= n.
a(x) =
x
(1 x)
2
= x + 2x
2
+ 3x
3
+ + nx
n
+
Generating Functions
Generalised binomial theorem:
a
n
=

a(x) = (1 + x)

n=0

x
n
.
where

=
( 1)( 2) ( n + 1)
n!
.
a
n
=

m+n1
n

a(x) =
1
(1 x)
m
=

n=0

m
n

(x)
n
=

n=0

m + n 1
n

x
n
.
Generating Functions
General view.
Given a recurrence relation for the sequence (a
n
), we
(a) Deduce from it, an equation satised by the generating
function a(x) =

n
a
n
x
n
.
(b) Solve this equation to get an explicit expression for the
generating function.
(c) Extract the coefcient a
n
of x
n
from a(x), by expanding a(x)
as a power series.
Generating Functions
Solution of linear recurrences
a
n
6a
n1
+ 9a
n2
= 0 n 2.
a
0
= 1, a
1
= 9.

n=2
(a
n
6a
n1
+ 9a
n2
)x
n
= 0. (2)
Generating Functions

n=2
a
n
x
n
= a(x) a
0
a
1
x
= a(x) 1 9x.

n=2
6a
n1
x
n
= 6x

n=2
a
n1
x
n1
= 6x(a(x) a
0
)
= 6x(a(x) 1).

n=2
9a
n2
x
n
= 9x
2

n=2
a
n2
x
n2
= 9x
2
a(x).
Generating Functions
a(x) 1 9x 6x(a(x) 1) + 9x
2
a(x) = 0
or
a(x)(1 6x + 9x
2
) (1 + 3x) = 0.
a(x) =
1 + 3x
1 6x + 9x
2
=
1 + 3x
(1 3x)
2
=

n=0
(n + 1)3
n
x
n
+ 3x

n=0
(n + 1)3
n
x
n
=

n=0
(n + 1)3
n
x
n
+

n=0
n3
n
x
n
=

n=0
(2n + 1)3
n
x
n
.
a
n
= (2n + 1)3
n
.
Generating Functions
Fibonacci sequence:

n=2
(a
n
a
n1
a
n2
)x
n
= 0.

n=2
a
n
x
n

n=2
a
n1
x
n

n=2
a
n2
x
n
= 0.
(a(x) a
0
a
1
x) (x(a(x) a
0
)) x
2
a(x) = 0.
a(x) =
1
1 x x
2
.
Generating Functions
a(x) =
1
(
1
x)(
2
x)
=
1

1

2

1
x

1

2
x

=
1

1

2


1
1
1 x/
1


1
2
1 x/
2

where

1
=

5 + 1
2
and
2
=

5 1
2
are the 2 roots of
x
2
+ x 1 = 0.
Generating Functions
Therefore,
a(x) =

1
1

1

2

n=0

n
1
x
n


1
2

1

2

n=0

n
2
x
n
=

n=0

n1
1

n1
2

1

2
x
n
and so
a
n
=

n1
1

n1
2

1

2
=
1

5 + 1
2

n+1

5
2

n+1

.
Generating Functions
Inhomogeneous problem
a
n
3a
n1
= n
2
n 1.
a
0
= 1.

n=1
(a
n
3a
n1
)x
n
=

n=1
n
2
x
n

n=1
n
2
x
n
=

n=2
n(n 1)x
n
+

n=1
nx
n
=
2x
2
(1 x)
3
+
x
(1 x)
2
=
x + x
2
(1 x)
3

n=1
(a
n
3a
n1
)x
n
= a(x) 1 3xa(x)
= a(x)(1 3x) 1.
Generating Functions
a(x) =
x + x
2
(1 x)
3
(1 3x)
+
1
1 3x
=
A
1 x
+
B
(1 x)
2
+
C
(1 x)
3
+
D + 1
1 3x
where
x + x
2

= A(1 x)
2
(1 3x) + B(1 x)(1 3x)
+ C(1 3x) + D(1 x)
3
.
Then
A = 1/2, B = 0, C = 1, D = 3/2.
Generating Functions
So
a(x) =
1/2
1 x

1
(1 x)
3
+
5/2
1 3x
=
1
2

n=0
x
n

n=0

n + 2
2

x
n
+
5
2

n=0
3
n
x
n
So
a
n
=
1
2

n + 2
2

+
5
2
3
n
=
3
2

3n
2

n
2
2
+
5
2
3
n
.
Generating Functions
General case of linear recurrence
a
n
+ c
1
a
n1
+ + c
k
a
nk
= u
n
, n k.
u
0
, u
1
, . . . , u
k1
are given.

(a
n
+ c
1
a
n1
+ + c
k
a
nk
u
n
) x
n
= 0
It follows that for some polynomial r (x),
a(x) =
u(x) + r (x)
q(x)
where
q(x) = 1 + c
1
x + c
2
x
2
+ + c
k
x
k
=
k

i =1
(1
i
x)
and
1
,
2
, . . . ,
k
are the roots of p(x) = 0 where
p(x) = x
k
q(1/x) = x
k
+ c
1
x
k1
+ + c
0
.
Generating Functions
Products of generating functions
a(x) =

n=0
a
n
x
n
, b(x)) =

n=0
b
n
x
n
.
a(x)b(x) = (a
0
+ a
1
x + a
2
x
2
+ )
(b
0
+ b
1
x + b
2
x
2
+ )
= a
0
b
0
+ (a
0
b
1
+ a
1
b
0
)x +
(a
0
b
2
+ a
1
b
1
+ a
2
b
0
)x
2
+
=

n=0
c
n
x
n
where
c
n
=
n

k=0
a
k
b
nk
.
Generating Functions
Combinatorially, suppose that A, B are sets of objects and A
contains a
n
objects of weight n and B contains b
n
objects of
weight n, for all n 0.
We now consider pairs of objects (a, b) where a A, b B.
The weight of pair (a, b) is the weight of a plus the weight of b.
c
n
is the number of pairs of weight n.
Generating Functions
Simple example:
Let A = B = {0, 1, 2, . . . , } where the weight of i is i .
We want to count the number of pairs (a, b) with a + b = n.
(This is of course n + 1).
a
n
= b
n
= 1, n 0 and so a(x) = b(x) = 1/(1 x).
Thus
c(x) =
1
(1 x)
2
=

n=0
(n + 1)x
n
.
Generating Functions
Suppose that we have r generating functions
a
1
(x), a
2
(x), . . . , a
r
(x) where
a
i
(x) =

n=0
a
i ,n
x
n
and a
i ,n
is the number of objects in A
i
and weight n. Then if
c(x) = a
1
(x)a
2
(x) a
r
(x) =

n0
c
n
x
n
then c
n
is the number
of sequences x
1
x
2
x
r
where
weight (x
1
) + weight (x
2
) + + weight (x
r
) = n
This can be proved by induction on r .
Generating Functions
As an example, let A
1
= A
2
= = A
r
= {0, 1, 2, . . . , }. Then
the number of sequences x
1
, x
2
, . . . , x
r
0 satisfying
x
1
+ x
r
= n is given by
[x
n
]
1
(1 x)
r
= (1)
n

r
n

n + r 1
n

.
Generating Functions
Derangements
n! =
n

k=0

n
k

d
nk
.
Explanation:

n
k

d
nk
is the number of permutations with
exactly k cycles of length 1. Choose k elements (

n
k

ways) for
which (i ) = i and then choose a derangement of the
remaining n k elements.
So
1 =
n

k=0
1
k!
d
nk
(n k)!

n=0
x
n
=

n=0

k=0
1
k!
d
nk
(n k)!

x
n
. (3)
Generating Functions
Let
d(x) =

m=0
d
m
m!
x
m
.
From (3) we have
1
1 x
= e
x
d(x)
d(x) =
e
x
1 x
=

n=0
n

k=0

(1)
k
k!

x
n
.
So
d
n
n!
=
n

k=0
(1)
k
k!
.
Generating Functions
Triangulation of n-gon
Let
a
n
= number of triangulations of P
n+1
=
n

k=0
a
k
a
nk
n 2 (4)
a
0
= 0, a
1
= a
2
= 1.
+1
1
n+1
k
Generating Functions
Explanation of (4):
a
k
a
nk
counts the number of triangulations in which edge
1, n + 1 is contained in triangle 1, k + 1, n + 1.
There are a
k
ways of triangulating 1, 2, . . . , k + 1, 1 and for
each such there are a
nk
ways of triangulating
k + 1, k + 2, . . . , n + 1, k + 1.
Generating Functions
x +

n=2
a
n
x
n
= x +

n=2

k=0
a
k
a
nk

x
n
.
But,
x +

n=2
a
n
x
n
= a(x)
since a
0
= 0, a
1
= 1.

n=2

k=0
a
k
a
nk

x
n
=

n=0

k=0
a
k
a
nk

x
n
= a(x)
2
.
Generating Functions
So
a(x) = x + a(x)
2
and hence
a(x) =
1 +

1 4x
2
or
1

1 4x
2
.
But a(0) = 0 and so
a(x) =
1

1 4x
2
=
1
2

1
2

1 +

n=1
(1)
n1
n2
2n1

2n 2
n 1

(4x)
n

n=1
1
n

2n 2
n 1

x
n
.
So
a
n
=
1
n

2n 2
n 1

.
Generating Functions

Вам также может понравиться