Generating Functions
Generating Functions
M11
Generating functions
Even quite straightforward counting problems can lead to laborious and lengthy
calculations. These are greatly simplified by using generating functions. 2
Definition 1.1. Given a collection of real numbers (ak )k0 , the function
def
G(s) = Ga (s) =
ak sk
(1.1)
k=0
G(s) GX (s) = E s
sk P(X = k) ,
(1.2)
k=0
(1.3)
Solution. This is a straightforward application of the partition theorem for expectations. Alternatively, the result follows from the standard properties of conditional
expectations:
h `
i
N
`
E z SN = E E z SN | N = E GX (z)
= GN GX (z) .
2 introduced
then f (X) and g(Y ) are independent random variables and E f (X)g(Y ) = Ef (X) Eg(Y );
4 from now on we shall often abbreviate this to just i.i.d.r.v.
3 recall:
http://maths.dur.ac.uk/stats/courses/StochProc34/
O.H.
M11
Example 1.6. [Renewals] Imagine a diligent janitor who replaces a light bulb
the same day as it burns out. Suppose the first bulb is put in on day 0 and let
Xi be the lifetime of the ith light bulb. Assume that the individual lifetimes
Xi are i.i.d.r.v.s with values in {1, 2, . . . } having a common distribution with
generating function Gf (s). Consider the probabilities
def
rn = P a light bulb was replaced on day n ,
def
fk = P the first light bulb was replaced on day k .
We obviously have r0 = 1, f0 = 0, and for n 1,
rn = f1 rn1 + f2 rn2 + + fn r0 =
n
X
fk rnk .
k=1
A standard computation implies that Gr (s) = 1 + Gf (s) Gr (s) for all |s| 1,
so that Gr (s) = 1/(1 Gf (s)).
In general, we say a sequence (cn )n0 is the convolution of (ak )k0 and
(bm )m0 (write c = a b), if
cn =
n
X
ak bnk ,
n 0,
(1.4)
k=0
(1.5)
a power series Ga (s) is finite for |s| < r with r > 0, then it can be differentiated in the
disk |s| < r.
http://maths.dur.ac.uk/stats/courses/StochProc34/
O.H.
M11
s1
s1
Exercise
1.11.
Let
S
be
defined
as
in
Example
1.5.
Use
(1.3)
to
compute
E
SN
N
and Var
S
N in terms
of E[N ], E[N ], Var[X] and Var[N ]. Now check your result
for E SN and Var SN by directly applying the partition theorem for expectations.
Example 1.12. A bird lays N eggs, each being pink with probability p and
blue otherwise. Assuming that N Poi(), find the distribution of the total
number K of pink eggs.
Solution. a) A standard approach in the spirit of Core A gives the value P(K = k)
directly; as a by-product of this computation one deduces that K and M = N K
are independent (do this!).
b) One can also think in terms of a two-stage probabilistic experiment similar to one
described in Example 1.5. Here K has the same distribution as SN with N Poi()
and X Ber(p); consequently, GN (s) = e(s1) and GX (s) = 1 + p(s 1), so that
GSN (s) = ep(s1) , ie., K Poi(p).
6 here,
G(k) (1) is the shorthand for G(k) (1) lims1 G(k) (s), the limiting value of the
kth derivative of G(s) at s = 1;
7 As |G (s)| E|sX | 1 for all |s| 1, the generating function G (s) can be differentiated
X
X
many times for all s inside the disk, |s| < 1.
8 The Abel theorem says: If a is non-negative for all k and G (s) is finite for |s| < 1, then
a
k
P
lim Ga (s) =
ak , whether this sum is finite or equals +. By the previous remark, the
s1
k=0
http://maths.dur.ac.uk/stats/courses/StochProc34/
O.H.
M11
P(Xk = 1) = q = 1 p .
GT (s) E sT = E sT | X1 = 1 p + E sT | X1 = 1 q = ps + qs E sT2 ,
m1
X
k=1
P T1 = k, T2 = m .
O.H.
M11
m1
X
k=1
m1
m
X
X
`
P T2 = m | T1 = k P(T1 = k)
pk pmk =
pk pmk ,
k=1
k=0
`
2
ie., GT2 (s) = GT (s) . We deduce that GT (s) solves the quadratic equation =
ps + qs2 , so that 9
p
1 1 4pqs2
2ps
p
=
.
GT (s) =
2qs
1 + 1 4pqs2
We finally deduce that
1 |p q|
P(T < ) GT (1) =
=
2q
(
1,
p/q ,
p q,
p < q.
In particular, E(T ) = for p < q (because P(T = ) = (q p)/q > 0). For p q we
obtain
(
1
,
p > q,
1
|p
q|
E(T ) GT (1) =
= pq
2q|p q|
,
p = q,
ie., E(T ) < if p > q and E(T ) = otherwise.
Notice that at criticality (p = q = 1/2), the variable T is finite with probability 1,
but has infinite expectation.
Example 1.15. In a sequence of independent Bernoulli experiments with success probability p (0, 1), let D be the first moment of two consecutive successful outcomes. Find the generating function of D.
Solution. Every sequence contributing to dn = P(D = n) contains at least two successes. The probability of having exactly two successes is q n2 p2 (of course, n 2).
Alternatively, let 1 k < n 2 be the position of the first success in the sequence; it
necessarily is followed by a failure, and the remaining n k 1 results produce any
possible sequence corresponding to the event {D = n k 1}. By independence, we
deduce the following renewal relation:
dn = q n2 p2 +
n3
X
q k1 pq dnk1 ,
k=1
pqs2
p2 s2
+
GD (s) ,
1 qs
1 qs
or
GD (s) =
p2 s2
.
1 qs pqs2
1+p
, so that on average it takes 42
p2
tosses of a standard symmetric dice until the first two consecutive sixes appear.
Exercise 1.16. Generalize the argument above to the first moment of m consecutive successes.
9 by
http://maths.dur.ac.uk/stats/courses/StochProc34/
O.H.
M11
Exercise 1.17. In the setup of Example 1.15, show that d2 = p2 , d3 = qp2 , and,
conditioning on the value of the first outcome, that
dn = q dn1 + pq dn2 ,
n > 3.
where G(s) =
b
k0
P(Xk
(n)
= 1) = 1 P(Xk
Assume that as n
def
(n)
(n) = max pk
1kn
and that
n
X
k=1
(n)
pk
n
X
(n)
Xk
(n)
= 0) = pk .
0
(0, ) .
k=1
Pn
(n)
Using generating functions or otherwise, show that the distribution of k=1 Xk
converges to that of a Poisson() random variable. This result is known as the law
of rare events.
http://maths.dur.ac.uk/stats/courses/StochProc34/