Examples of generating functions

From HandWiki

The following examples of generating functions are in the spirit of George Pólya, who advocated learning mathematics by doing and re-capitulating as many examples and proofs as possible.[citation needed] The purpose of this article is to present common ways of creating generating functions.

Worked example A: basics

New generating functions can be created by extending simpler generating functions. For example, starting with

G(1;x)=n=0xn=11x

and replacing x with ax, we obtain

G(1;ax)=11ax=1+(ax)+(ax)2++(ax)n+=n=0anxn=G(an;x).

Bivariate generating functions

One can define generating functions in several variables, for series with several indices. These are often called super generating functions, and for 2 variables are often called bivariate generating functions.

For instance, since (1+x)n is the generating function for binomial coefficients for a fixed n, one may ask for a bivariate generating function that generates the binomial coefficients (nk) for all k and n. To do this, consider (1+x)n as itself a series (in n), and find the generating function in y that has these as coefficients. Since the generating function for an is just 1/(1ay), the generating function for the binomial coefficients is:

11(1+x)y=1+(1+x)y+(1+x)2y2+,

and the coefficient on xkyn is the (nk) binomial coefficient.

Worked example B: Fibonacci numbers

Consider the problem of finding a closed formula for the Fibonacci numbers Fn defined by F0 = 0, F1 = 1, and Fn = Fn−1 + Fn−2 for n ≥ 2. We form the ordinary generating function

f=n0Fnxn

for this sequence. The generating function for the sequence (Fn−1) is xf and that of (Fn−2) is x2f. From the recurrence relation, we therefore see that the power series xf + x2f agrees with f except for the first two coefficients:

f=F0x0+F1x1+F2x2++Fixi+xf=F0x1+F1x2++Fi1xi+x2f=F0x2++Fi2xi+(x+x2)f=F0x1+(F0+F1)x2++(Fi1+Fi2)xi+=F2x2++Fixi+

Taking these into account, we find that

f=xf+x2f+x.

(This is the crucial step; recurrence relations can almost always be translated into equations for the generating functions.) Solving this equation for f, we get

f=x1xx2.

The denominator can be factored using the golden ratio φ1 = (1 + 5)/2 and φ2 = (1 − 5)/2, and the technique of partial fraction decomposition yields

f=15(11φ1x11φ2x).

These two formal power series are known explicitly because they are geometric series; comparing coefficients, we find the explicit formula

Fn=15(φ1nφ2n).

Worked example C: Number of ways to make change

The number of unordered ways an to make change for n cents using coins with values 1, 5, 10, and 25 is given by the generating function

G(an,x)=n=0anxn=1(1x)(1x5)(1x10)(1x25).

For example there are two unordered ways to make change for 6 cents; one way is six 1-cent coins, the other way is one 1-cent coin and one 5-cent coin. See OEISA001299.

On the other hand, the number of ordered ways bn to make change for n cents using coins with values 1, 5, 10, and 25 is given by the generating function

G(bn,x)=n=0bnxn=11xx5x10x25.

For example there are three ordered ways to make change for 6 cents; one way is six 1-cent coins, a second way is one 1-cent coin and one 5-cent coin, and a third way is one 5-cent coin and one 1-cent coin. Compare to OEISA114044, which differs from this example by also including coins with values 50 and 100.