Introduction

A generating function packs an entire sequence a0,a1,a2,…a_0, a_1, a_2, \ldots into one power series. Algebra on the series (adding, multiplying, shifting, differentiating) then corresponds to combinatorial operations on the sequence. This gives a uniform way to count selections with constraints ("how many ways to make 25 rupees from 1, 2 and 5 rupee coins?") and to solve recurrence relations. The working tasks are finding the sequence of a given generating function, the generating function of a given sequence, or a single coefficient.

Prerequisites

  • Counting: binomial coefficients, combinations with repetition, stars and bars.
  • Recurrence Relations: linear recurrences and initial conditions.
  • Geometric series and partial fractions.

Core concepts

Definition

The (ordinary) generating function (OGF) of the sequence (an)n≥0(a_n)_{n \ge 0} is the formal power series

G(x)=∑n=0∞anxn=a0+a1x+a2x2+⋯ .G(x) = \sum_{n=0}^{\infty} a_n x^n = a_0 + a_1 x + a_2 x^2 + \cdots .

xx is a placeholder: we manipulate the series formally and do not need it to converge. When a closed form like 1/(1−x)1/(1 - x) is used, it means the series whose product with 1−x1 - x is 1. The coefficient of xnx^n in G(x)G(x) is written [xn] G(x)[x^n]\,G(x).

A finite sequence a0,…,ama_0, \ldots, a_m has a polynomial generating function: the sequence (n0),…,(nn)\binom{n}{0}, \ldots, \binom{n}{n} has G(x)=(1+x)nG(x) = (1 + x)^n.

Standard generating functions

Sequence ana_n (n≥0n \ge 0)Generating function
1,1,1,…1, 1, 1, \ldots11−x\dfrac{1}{1 - x}
cnc^n11−cx\dfrac{1}{1 - cx}
(−1)n(-1)^n11+x\dfrac{1}{1 + x}
1,0,1,0,…1, 0, 1, 0, \ldots11−x2\dfrac{1}{1 - x^2}
n+1n + 11(1−x)2\dfrac{1}{(1 - x)^2}
nnx(1−x)2\dfrac{x}{(1 - x)^2}
n2n^2x(1+x)(1−x)3\dfrac{x(1 + x)}{(1 - x)^3}
(n+k−1k−1)\binom{n + k - 1}{k - 1} = (n+k−1n)\binom{n + k - 1}{n}1(1−x)k\dfrac{1}{(1 - x)^k}
(kn)\binom{k}{n}(1+x)k(1 + x)^k
1,1,…,11, 1, \ldots, 1 (first m+1m + 1 terms), then 01−xm+11−x\dfrac{1 - x^{m+1}}{1 - x}
1n!\dfrac{1}{n!}exe^x

The row 1/(1−x)k1/(1-x)^k is the extended binomial theorem: the coefficient of xnx^n is the number of multisets of size nn from kk types, the stars-and-bars count.

Operations

If A(x)=∑anxnA(x) = \sum a_n x^n and B(x)=∑bnxnB(x) = \sum b_n x^n:

Operation on seriesEffect on sequence
A(x)+B(x)A(x) + B(x)an+bna_n + b_n
c A(x)c\,A(x)c anc\,a_n
xkA(x)x^k A(x)shift right: 0,…,0,a0,a1,…0, \ldots, 0, a_0, a_1, \ldots (kk zeros)
(A(x)−a0)/x\big(A(x) - a_0\big)/xshift left: a1,a2,…a_1, a_2, \ldots
A(cx)A(cx)cnanc^n a_n
xA′(x)x A'(x)n ann\, a_n
A(x)/(1−x)A(x)/(1 - x)partial sums a0+⋯+ana_0 + \cdots + a_n
A(x) B(x)A(x)\,B(x)convolution cn=∑k=0nakbn−kc_n = \sum_{k=0}^{n} a_k b_{n-k}

The product rule is the key counting fact: if aka_k counts ways to choose kk items of one kind and bjb_j ways to choose jj items of another, then cnc_n counts ways to choose nn items in total.

Counting with generating functions

To count selections of nn objects from several types, write one factor per type, listing the allowed quantities as powers of xx, multiply, and read off [xn][x^n].

Example: coins. Ways to pay nn rupees with any number of 1 and 2 rupee coins (order irrelevant):

11−x⋅11−x2,[xn]=⌊n/2⌋+1.\frac{1}{1 - x} \cdot \frac{1}{1 - x^2}, \qquad [x^n] = \lfloor n/2 \rfloor + 1 .

Example: bounded quantities. Ways to choose 6 fruits with at most 2 apples, at least 1 banana, and any number of cherries:

(1+x+x2) (x+x2+⋯ ) (1+x+x2+⋯ )=(1+x+x2)⋅x(1−x)2.(1 + x + x^2)\,(x + x^2 + \cdots)\,(1 + x + x^2 + \cdots) = (1 + x + x^2) \cdot \frac{x}{(1 - x)^2}.

[x6][x^6] of x/(1−x)2x/(1-x)^2 is 6 (sequence nn), so [x6][x^6] of the product is 6+5+4=156 + 5 + 4 = 15.

Example: dice. The number of ways to roll a total of 10 with three six-sided dice is the coefficient of x10x^{10} in (x+x2+⋯+x6)3=x3((1−x6)/(1−x))3(x + x^2 + \cdots + x^6)^3 = x^3\big((1 - x^6)/(1 - x)\big)^3, which is the coefficient of x7x^7 in ((1−x6)/(1−x))3\big((1 - x^6)/(1 - x)\big)^3. Expanding (1−x6)3=1−3x6+⋯(1 - x^6)^3 = 1 - 3x^6 + \cdots and using 1/(1−x)31/(1-x)^3 (coefficients (n+22)\binom{n+2}{2}): (92)−3(32)=36−9=27\binom{9}{2} - 3\binom{3}{2} = 36 - 9 = 27.

Example: a parity constraint. Non-negative integer solutions of x1+x2+x3=10x_1 + x_2 + x_3 = 10 with x1x_1 even: the generating function is 11−x2⋅1(1−x)2\dfrac{1}{1 - x^2} \cdot \dfrac{1}{(1 - x)^2}. Choosing x1=jx_1 = j (even) leaves 10−j+110 - j + 1 solutions for x2+x3=10−jx_2 + x_3 = 10 - j, so the coefficient of x10x^{10} is 11+9+7+5+3+1=3611 + 9 + 7 + 5 + 3 + 1 = 36.

Solving recurrences

Procedure.

  1. Multiply the recurrence by xnx^n and sum over all nn for which it holds.
  2. Express every sum through G(x)G(x), using shifts; insert the initial conditions.
  3. Solve the resulting equation for G(x)G(x).
  4. Split G(x)G(x) into partial fractions and read off ana_n from the standard table.

Example 1: first order

an=3an−1+2a_n = 3a_{n-1} + 2 for n≥1n \ge 1, a0=1a_0 = 1.

∑n≥1anxn=3x∑n≥1an−1xn−1+2∑n≥1xn  ⇒  G(x)−1=3x G(x)+2x1−x.\sum_{n \ge 1} a_n x^n = 3x \sum_{n \ge 1} a_{n-1} x^{n-1} + 2\sum_{n \ge 1} x^n \;\Rightarrow\; G(x) - 1 = 3x\,G(x) + \frac{2x}{1 - x}.
G(x)=1+x(1−x)(1−3x)=21−3x−11−x⇒an=2⋅3n−1.G(x) = \frac{1 + x}{(1 - x)(1 - 3x)} = \frac{2}{1 - 3x} - \frac{1}{1 - x} \quad\Rightarrow\quad a_n = 2 \cdot 3^n - 1 .

Check: a1=3⋅1+2=5=6−1a_1 = 3 \cdot 1 + 2 = 5 = 6 - 1.

Example 2: Fibonacci

Fn=Fn−1+Fn−2F_n = F_{n-1} + F_{n-2} for n≥2n \ge 2, F0=0F_0 = 0, F1=1F_1 = 1. The same steps give

G(x)−x=x G(x)+x2G(x)⇒G(x)=x1−x−x2.G(x) - x = x\,G(x) + x^2 G(x) \quad\Rightarrow\quad G(x) = \frac{x}{1 - x - x^2}.

Factoring 1−x−x2=(1−φx)(1−ψx)1 - x - x^2 = (1 - \varphi x)(1 - \psi x) with φ,ψ=(1±5)/2\varphi, \psi = (1 \pm \sqrt{5})/2 and splitting into partial fractions yields Binet's formula Fn=(φn−ψn)/5F_n = (\varphi^n - \psi^n)/\sqrt{5}.

Example 3: reading a sequence from a function

Find ana_n for G(x)=1(1−x)(1−2x)G(x) = \dfrac{1}{(1 - x)(1 - 2x)}. Partial fractions: 21−2x−11−x\dfrac{2}{1 - 2x} - \dfrac{1}{1 - x}, so an=2n+1−1a_n = 2^{n+1} - 1. Equivalently GG is 1/(1−2x)1/(1 - 2x) divided by 1−x1 - x: partial sums of 2n2^n, which are 2n+1−12^{n+1} - 1.

Example 4: Catalan numbers

The recurrence Cn+1=∑i=0nCiCn−iC_{n+1} = \sum_{i=0}^{n} C_i C_{n-i}, C0=1C_0 = 1, is a convolution, so C(x)=1+x C(x)2C(x) = 1 + x\,C(x)^2. Solving the quadratic and choosing the root that is finite at x=0x = 0:

C(x)=1−1−4x2x,Cn=1n+1(2nn).C(x) = \frac{1 - \sqrt{1 - 4x}}{2x}, \qquad C_n = \frac{1}{n + 1}\binom{2n}{n}.

Exponential generating functions (for reference)

The exponential generating function (EGF) of (an)(a_n) is ∑anxn/n!\sum a_n x^n / n!. EGFs suit labelled structures (including linear orders on labelled objects), because the product of EGFs counts ways to split a set of labels between two structures (cn=∑k(nk)akbn−kc_n = \sum_k \binom{n}{k} a_k b_{n-k}). Examples: the EGF of 1,1,1,…1, 1, 1, \ldots is exe^x; permutations (an=n!a_n = n!) have EGF 1/(1−x)1/(1 - x); derangements have EGF e−x/(1−x)e^{-x}/(1 - x).

Important properties and observations

  • Generating functions are formal: equal series have equal coefficients, so comparing coefficients is always valid.
  • [xn] (1−x)−k=(n+k−1n)[x^n]\,(1 - x)^{-k} = \binom{n + k - 1}{n} is the key coefficient formula.
  • A rational generating function P(x)/Q(x)P(x)/Q(x) with Q(0)=1Q(0) = 1 corresponds exactly to a sequence satisfying a linear recurrence with constant coefficients, read from QQ. For Q(x)=1−c1x−⋯−ckxkQ(x) = 1 - c_1 x - \cdots - c_k x^k, the recurrence is an=c1an−1+⋯+ckan−ka_n = c_1 a_{n-1} + \cdots + c_k a_{n-k} for large enough nn.
  • The reciprocals of the roots of QQ are the roots of the characteristic equation of that recurrence.

GATE examination perspective

  • Sequence from function. Expand with the standard table and partial fractions; check a0a_0 and a1a_1 directly by series expansion.
  • Function from sequence. Recognise shifts and scalings of the table entries (for example an=n 2na_n = n\,2^n has G(x)=2x/(1−2x)2G(x) = 2x/(1 - 2x)^2).
  • Coefficient extraction. Products of geometric series for bounded counting; (1−xm+1)/(1−x)(1 - x^{m+1})/(1 - x) for "at most mm".
  • Trap: off-by-one in shifts: x/(1−x)2x/(1-x)^2 gives nn, 1/(1−x)21/(1-x)^2 gives n+1n + 1.
  • Trap: the generating function equation must use the recurrence only for the nn where it holds; the initial terms enter separately.

Summary

Sources

  1. K. H. Rosen, Discrete Mathematics and Its Applications, 7th ed., McGraw-Hill, 2012: Section 8.4 (Generating Functions).
  2. H. S. Wilf, generatingfunctionology, 2nd ed., Academic Press, 1994: Chapters 1 (Introductory ideas and examples) and 2 (Series). The author offers the second edition free on his download page, (consulted 2026-11-11).

Next steps