Ordinary Generating Functions
How many ways can you make change for a dollar using pennies, nickels, dimes, and quarters? How many sequences of coin flips of length avoid two consecutive heads? Both questions are counting problems in disguise. Both dissolve almost effortlessly once the counting sequence is repackaged. That repackaging turns it into a single algebraic object: a formal power series whose coefficients are the numbers we want. This repackaging is the ordinary generating function, one of the most powerful ideas in enumerative combinatorics. The idea matters because it converts combinatorial operations into algebraic operations on power series. Choosing, arranging, splitting into parts, restricting counts — all become addition, multiplication, substitution, and differentiation. A combinatorial construction that would require an intricate inductive argument or a clever bijection often becomes simple. It becomes a two-line computation with power series. After that, a closed form or an asymptotic estimate can be extracted. This is done by standard algebraic manipulation, such as partial fractions. The big picture is this. A sequence of numbers and a formal power series carry exactly the same information. But the series form supports operations that have no easy description on the sequence level. For example, multiplying two series corresponds to a specific convolution of the sequences. Generating functions turn a "sequence problem" into a "function problem." There, the immense toolkit of algebra becomes available, and later, complex analysis too. This article develops the ordinary generating function rigorously. It covers the formal definition as an element of a power series ring, with no convergence required. It covers the algebra of sums, products, and compositions. It covers the product rule for combinatorial classes built by disjoint union and Cartesian product. It also gives a full worked derivation of the generating function for linear recurrences and for Combinations with Repetition. It closes with the machinery's reach toward Exponential Generating Functions, Catalan Numbers, and Integer Partitions.
- An ordinary generating function (OGF) for is the formal power series ; convergence is irrelevant.
- OGFs are elements of the ring of formal power series , with addition and multiplication defined coefficientwise/by convolution.
- The Product Rule: if a combinatorial object decomposes uniquely into an ordered pair of independent pieces, the OGF of the whole is the product of the OGFs of the pieces.
- Multiplying by takes partial sums; multiplying two OGFs computes a convolution — this is the algebraic engine behind almost every application.
- Rational OGFs (ratios of polynomials) correspond exactly to sequences satisfying a linear recurrence with constant coefficients, extractable via Partial Fractions.
- Key idea: encode a whole sequence as one formal power series, so combinatorial constructions become algebraic operations on that series.
Where this lives today
Ordinary generating functions are the working language of enumerative combinatorics: counting lattice paths, set partitions, compositions of integers, and the coefficients of the Catalan Numbers (via the quadratic equation ) all reduce to algebraic manipulation of an OGF. In Integer Partitions, infinite products such as generate the partition function , and Euler's pentagonal number theorem is proved by manipulating the reciprocal product. In computer science, OGFs analyze the running time of divide-and-conquer algorithms whose recurrences (e.g. in disguise, or more directly integer sequence recurrences) are solved exactly as in Example 2 above, and they underlie automatic complexity analysis in the "symbolic method" of analytic combinatorics. In probability and statistics, OGFs specialize to probability generating functions , whose derivatives at recover moments and whose products encode independence of sums of random variables. In cryptography and coding theory, generating functions count weight distributions of linear codes and track the structure of feedback shift registers. In physics, OGFs (and their exponential cousins) organize partition functions in statistical mechanics, where the formal variable becomes a fugacity or Boltzmann weight — a direct descendant of Euler's original partition-counting insight.
:::quiz[If is the OGF of with , when does have a multiplicative inverse in ?]
- Never, formal power series are never invertible
- Only if is a polynomial
- Always, precisely because ✓
- Only if all
Ask the tutor: How does the functional equation for the Catalan numbers get derived and solved using the Product Rule?
Let be a sequence of real (or complex) numbers. The ordinary generating function (OGF) of this sequence is the formal power series
Here is a formal indeterminate: is regarded as an element of the ring of formal power series, i.e. as the sequence of coefficients itself, packaged with a bookkeeping device that tracks the "weight" (or size) of each term. No claim is made, or needed, about whether the series converges for any nonzero value of . Two formal power series and are equal iff for every . Addition and multiplication are defined by
The multiplication rule is called the Cauchy product or convolution of the two sequences. With these operations, is a commutative ring with identity , and has a multiplicative inverse in if and only if .
Intuition
Think of as a clothesline: the exponent is a peg, and is the item hanging from it. The variable carries no numeric meaning by itself; its powers are just labels that keep the sequence's terms from getting mixed up. This is why we can add and multiply these objects with total disregard for convergence — a formal power series is really just a sequence with a multiplication rule attached, and the notation is a convenient way to remember which coefficient goes where. The convolution formula is the heart of every application. If counts the number of ways, , to build an object of "size" from parts of type-1, and counts ways to build a size- object from parts of type-2, then the coefficient of in is : the number of ways to split into a type-1 piece of size and a type-2 piece of size , and build each piece independently. This is exactly the count of ordered pairs (type-1 object, type-2 object) whose sizes sum to — the combinatorial content behind the algebra. A second key move is division by . Since formally (check: ), multiplying any by replaces each coefficient by the partial sum . This single algebraic fact recovers, instantly, formulas that would otherwise need induction.
Central results
Let be a set of combinatorial objects equipped with a size function such that for every the number
is finite. Suppose is in size-preserving bijection with the Cartesian product of two such classes, where the size function on is defined by
and where and each have finitely many objects of every size (so their counting sequences and OGFs are well defined). Then the OGF of is
More generally, if is a disjoint union with the size function restricting on each part to the given one, then .
Proof technique: direct computation of coefficients via bijection and Fubini-type counting (rearranging a finite double sum).
Disjoint union. If (disjoint as sets), then every object of size in lies in exactly one of or , so
using that the two sets and partition with no overlap. Summing over termwise gives , where termwise addition of formal power series is legitimate because equality of formal series means equality coefficient by coefficient, which we have just shown.
Cartesian product. Since is in size-preserving bijection with , it suffices to prove the claim for itself, because a size-preserving bijection carries objects of size to objects of size and hence preserves the counting sequence exactly: . Fix . Partition the finite set according to the value (note since , and similarly). For fixed , the objects with number , and the objects with number ; by the multiplication principle there are exactly pairs with . These classes () are disjoint and exhaust all pairs of total size , so
This is finite since each is finite by hypothesis and the sum has finitely many () terms — this finiteness is exactly what was assumed about having finitely many objects of each size, and it is needed for itself to be a well-defined finite count. Now compare with the definition of the Cauchy product: . The coefficient of in is exactly , the coefficient of in . Since this holds for every , and equality of formal power series is equality of all coefficients, .
∎The all-ones sequence for all has OGF , and more generally the sequence (the number of multisets of size from a -element set, i.e. Combinations with Repetition) has OGF .
Proof technique: telescoping for the base case, then induction using the Product Rule.
Base case : Let . Then
where the middle equality reindexes the second sum () and the terms cancel exactly, term by term, since it is a formal identity (each coefficient of for appears once with and once with , and the constant term is ). Hence is the multiplicative inverse of in , i.e. . This is precisely the OGF of the constant sequence , which counts multisets of size from a -element set (there is exactly one such multiset for each ), confirming the case of the general claim, since .
Inductive step: Suppose the claim holds for : the class of size- multisets from a -set has OGF . A size- multiset from a -element set is equivalent to a choice of the number of times that the element appears, together with a size- multiset from ; this is a size-preserving bijection between and , where is the class of nonnegative integers with size function (one object of each size, OGF by the base case), because specifying the multiset is equivalent to specifying both pieces independently and the sizes add: . By the Product Rule, the OGF of is
By induction, the OGF of is for every . Finally, the coefficient of in is ; this is the standard Combinations with Repetition identity, itself provable independently by a stars-and-bars bijection, so the two derivations agree.
∎Worked examples
Example 1: Making change with four coin denominations (an asymmetric convolution). Suppose we have unlimited supplies of pennies (1¢), nickels (5¢), dimes (10¢), and quarters (25¢), and we ask for , the number of ways to make exactly cents using these coins, where order does not matter (a "way" is a choice of how many of each coin to use). We build the generating function using the Product Rule for four independent choices — how many pennies, how many nickels, how many dimes, how many quarters — whose contributed values must sum to . The class of "some number of pennies contributing value " has one object for each multiple of , so its OGF (in the variable tracking value, not count of coins) is . Similarly, a choice of nickels contributing value a multiple of has OGF (one way to contribute value for each , none otherwise); dimes give ; quarters give . By the Product Rule (applied three times, since choices of different coin types are independent and their values add):
To find — the number of ways to make a dollar — one option is to extract the coefficient via partial fractions or a computer algebra system; here we illustrate the method by computing a smaller, fully explicit case, , by hand using the structure of the product. Write . We want . First combine the two "coarse" factors:
The exponents with are: , , , , . So up to degree ,
Next we need up to degree ; its coefficient of is the number of ways to write with , i.e. ranges over and is determined, so . Now is obtained by convolving the coefficient sequence (from pennies+nickels) against the finite sequence (from dimes+quarters), restricted to :
matching , i.e. . Compute each: , , , , . Sum: . So there are ways to make cents from pennies, nickels, dimes, and quarters — a fact one can sanity-check directly (quarters used ; if quarter, remaining cents needs ways; if quarters, remaining cents from pennies/nickels/dimes needs enumerating , matching the computation above), confirming the generating-function method.
Example 2: A linear recurrence with non-constant-free initial data. Let satisfy , , and for ,
We find a closed form for using its OGF. Let . Multiply the recurrence by and sum over :
The left side is . On the right, , and . Substituting:
Expand and collect terms:
So
Apply partial fractions: seek . Clearing denominators, . Setting : , so . Setting : , so . Check the constant term: , matching the constant term of at — consistent. So , using (the geometric series with replaced by , valid formally by the same telescoping argument as the Corollary above). Reading off the coefficient of :
Check: ✓. ✓. ; formula gives ✓. ; formula gives ✓. The closed form matches on all four checked terms.
The Product Rule for combinatorial classes requires that and be finite for every , so that the coefficient is a finite sum of finite numbers, hence itself finite and well-defined as an honest count. Drop this hypothesis: let be the class of all finite subsets of , with size function (number of elements of ) — wait, refine the example to make the failure sharp. Instead let with the size function for every (so every natural number is declared to have "size "). Then , and for . The "OGF" one would naively write is , which is not an element of at all — the very first coefficient fails to be a real number, so does not exist as a formal power series. Now let be the one-point class with , so , a perfectly good OGF. Form (in bijection with itself, since is a single point), with size . Then again, and the "Product Rule" is meaningless because itself is not a legitimate object of : the equation used inside the proof requires each to be a finite number to even state the sum, let alone to conclude it equals a coefficient of a product of well-defined power series. This shows the finiteness hypothesis is not a technicality: without it, the counting sequence is not a sequence of natural numbers at all, the "OGF" is not an element of the ring , and the entire apparatus (addition, multiplication, coefficient extraction) collapses before the Product Rule can even be stated, let alone proved.
Scope, edge cases & common traps
| Situation | What happens | Why |
|---|---|---|
| has no multiplicative inverse in | Inverting requires solving first; if no such exists | |
| Sequence eventually zero (finite support) | is literally a polynomial | Power series with finitely many nonzero coefficients is a polynomial by definition |
| Infinitely many objects of some size | undefined as a natural number, OGF does not exist | See the counterexample above; finiteness of each is a standing hypothesis |
| Asking "does converge at ?" | Irrelevant to the formal theory | Formal power series need no convergence; analytic questions (radius of convergence, asymptotics) are a separate, optional layer built on top of the algebra |
| Composing | Legal only if | Otherwise the composite series' coefficients involve infinite sums, which need not be finite |
The mathematician behind it
Origins · 1 minLeonhard Euler and how this was discovered
Euler did not invent the modern formalism of , which crystallized later, but he was the first to wield generating functions as a systematic combinatorial weapon — most famously in his treatment of Integer Partitions, where he showed that the number of partitions of into distinct parts equals the number of partitions of into odd parts, by manipulating the infinite products and . His 1748 Introductio in analysin infinitorum laid out power-series methods that became the direct ancestor of the generating-function calculus used throughout combinatorics today.
Do I need the series to converge to use an OGF?
No. An OGF is defined as a formal power series, an algebraic object encoding a sequence of coefficients, with no reference to convergence at any numeric value of . Addition, multiplication, and even composition (when the inner series has zero constant term) are defined purely combinatorially via finite sums, so every manipulation in this article is legitimate without ever asking whether converges for some real or complex . Convergence becomes relevant only if you want to evaluate the series at a specific point, for instance to use complex-analytic techniques (residues, singularity analysis) for asymptotic estimates of as . That is a genuinely separate, optional layer built on top of the purely algebraic theory presented here.
What is the difference between an ordinary and an exponential generating function?
An OGF encodes as ; an EGF encodes the same sequence as . The choice matters combinatorially: OGFs are natural when objects of size decompose into unordered or unlabeled pieces (like multisets of coins), because the Product Rule's convolution matches unlabeled composition. EGFs are natural when the size- objects carry a labeling of their atoms (like permutations or labeled trees), because the in the denominator correctly accounts for interleaving labels between two independently-labeled pieces during a "labeled product." Both live in the same formal framework; the choice of normalization is dictated by the combinatorial structure being modeled.
How does the OGF approach solve linear recurrences with constant coefficients?
Given a recurrence like for , with fixed initial values , multiply both sides by and sum over . Reindexing each shifted sum in terms of turns the recurrence into a single linear equation for , whose solution is always a rational function with . Partial fractions then decompose into a sum of simple geometric-series pieces , each contributing a term to the closed form, exactly as carried out in Example 2 of this article.
Can generating functions handle recurrences that are not linear or not constant-coefficient?
Yes, though the algebra becomes more intricate. The Catalan Numbers satisfy the nonlinear recurrence , which translates, via the Product Rule applied to a self-referential combinatorial decomposition, into the quadratic functional equation for the OGF, solvable by the quadratic formula to give . Recurrences with polynomial (non-constant) coefficients typically produce a differential equation for rather than an algebraic one, opening the door to the broader theory of D-finite (holonomic) generating functions, a genuinely more advanced topic.
Is every formal power series the OGF of a "nice" combinatorial sequence?
Every sequence of real numbers gives a formal power series, but not every such series arises from counting the size classes of a natural combinatorial construction with the Product Rule's finiteness hypotheses. What makes OGFs useful in enumerative combinatorics specifically is that natural set-theoretic operations (disjoint union, Cartesian product, sequences, sets, cycles) correspond to simple algebraic operations (sum, product, geometric series, exponential, logarithm-type corrections) on OGFs — this dictionary is the "symbolic method." A generic power series with no combinatorial origin can still be manipulated formally, but there is no guarantee its coefficients count anything meaningful.
Why does multiplying by compute partial sums?
Because and the Cauchy product coefficient of in is , using that every coefficient of equals . This single algebraic fact instantly reproves identities like (multiply the OGF of by to get , whose coefficients are ) without induction.
What role do generating functions play beyond pure combinatorics?
Probability generating functions are OGFs of a probability mass function; their product rule recovers, instantly, that the sum of two independent random variables has a PGF equal to the product of the individual PGFs, mirroring the combinatorial Product Rule exactly. In computer science, OGFs analyze algorithm running times and structure counts (e.g. binary trees via the Catalan recurrence). In physics, partition functions in statistical mechanics are literally generating functions in a fugacity variable, tracking energy levels the way an OGF tracks combinatorial size.