Generating Functions

advertisement
Mathematics for Computer Science
The Rabbit Population
• A breeding pair of rabbits
produces a newborn pair every month.
• Rabbits breed after one month.
• After n months:
wn::= # newborn pairs
bn::= # breeding pairs
• Start with a newborn pair: w0 = 1
b0 = 0
MIT 6.042J/18.062J
Generating Functions
for Recurrences
Albert R Meyer,
April 26, 2010
lec 12M.1
The Rabbit Population
lec 12M.7
bn = bn-1 + bn-2
It was Fibonacci who was
studying rabbit population
growth!
Therefore,
April 26, 2010
lec 12M.8
Generating Function for Rabbits
Albert R Meyer,
April 26, 2010
The Rabbit Population
wn::= # newborn pairs
bn::= # breeding pairs
Albert R Meyer,
Albert R Meyer,
April 26, 2010
lec 12M.10
Albert R Meyer,
April 26, 2010
lec 12M.9
Generating Function for Rabbits
Albert R Meyer,
April 26, 2010
lec 12M.11
1
Generating Function for Rabbits
Coefficient notation
[xn ]B(x) ::= b n = coeff of xn in power
series for B(x)
[xn ]
Albert R Meyer,
April 26, 2010
lec 12M.12
Generating Function for Rabbits
1
(1 x)
x)
Albert R Meyer,
= 1n
April 26, 2010
lec 12M.13
Closed Form for [xn]B(x)
factor the denominator
use partial fraction expansion
n
to find closed form for [x ]B(x).
use quadratic formula
Albert R Meyer,
April 26, 2010
lec 12M.14
Closed Form for [xn]B(x)
Albert R Meyer,
April 26, 2010
lec 12M.15
Closed Form for [xn]B(x)
xn B(x) = a n + b n
factor the denominator
need to solve for a and b
Albert R Meyer,
April 26, 2010
lec 12M.16
Albert R Meyer,
April 26, 2010
lec 12M.18
2
the answer
Closed Form for [xn]B(x)
a
1 x
+
b
1 x
=
xn B(x) =
x
(1 x ) (1 x )
Multiply both sides by (1-x)(1-x)
(
)
a 1 x + b (1 x ) = x
amazing!
Solve for a and b letting
x be 1/, then 1/ makes it easy
Albert R Meyer,
April 26, 2010
lec 12M.19
the answer
Albert R Meyer,
April 26, 2010
xn B(x) =
n
n
1 1+ 5
1 1 5
2
2
5 5 n
1 1+ 5
1
2 5 5
0.62
1.62
n
1 5
2 (
April 26, 2010
lec 12M.21
the answer
xn B(x) ~ 1 1 + 5 5 2 April 26, 2010
n
April 26, 2010
lec 12M.22
Simpler Closed Form
n
n
xn B(x) = 1 1 + 5 5 2 rabbit population grows
exponentially
Albert R Meyer,
Albert R Meyer,
)
0.62
converges to 0 as n grows
Albert R Meyer,
lec 12M.20
the answer
xn B(x) =
1.62
n
n
1 1 5
1 1+ 5
2
5 2 5
round to nearest integer
lec 12M.23
Albert R Meyer,
April 26, 2010
lec 12M.24
3
Towers of Hanoi
}
Towers of Hanoi
n
Move1,2(n)::= [Move1,3(n-1);
big disk 12;
Move3,2(n-1)]
move stack to Post #2
larger disc not above smaller
Albert R Meyer,
April 26, 2010
lec 12M.25
Towers of Hanoi
lec 12M.26
hn = 2hn-1 + 1
h0 = 0
hn = 2hn-1 + 1
h0 = 0
April 26, 2010
April 26, 2010
Hanoi Generating Function
hn::=# steps by Move1,2(n)
Albert R Meyer,
Albert R Meyer,
2xH(x) =
2h 0 x 2h 1 x2 2
1 (1 x) = 1 1x 1x lec 12M.27
Hanoi Generating Function
Albert R Meyer,
April 26, 2010
lec 12M.28
Hanoi Generating Function
by partial fractions
from last lecture
xn H(x) = 2n 1
(The gen func from last lecture)
Albert R Meyer,
April 26, 2010
lec 12M.29
Albert R Meyer,
April 26, 2010
lec 12M.30
4
linear recurrences
nonhomogeneous terms
this method solves
fn = a 1fn1 + a 2fn2 + + a kfnk +1
Albert R Meyer,
April 26, 2010
lec 12M.31
handle
+ 1
+ 2n
+ n
+ n2
+ nnk
Albert R Meyer,
with
1/(1-x)
1/(1-2x)
x/(1-x)2
x(1+x)/(1-x)3
P(x)/Q(x)
April 26, 2010
lec 12M.32
Team Problems
Problems
1&2
Albert R Meyer,
April 26, 2010
lec 12M.34
5
MIT OpenCourseWare
http://ocw.mit.edu
6.042J / 18.062J Mathematics for Computer Science
Spring 2010
For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.
Download