Exponential Generating Functions

The exponential generating function (EGF) of a sequence aa is the formal power series:

F^(x)=∑nanxnn!\hat{F}(x)=\sum_{n}a_n \frac{x^n}{n!}

Basic operations

Addition and subtraction of exponential generating functions are the same as for ordinary generating functions: add the coefficients of corresponding terms.

Consider multiplication of exponential generating functions. For two sequences a,ba,b, let their exponential generating functions be F^(x),G^(x)\hat{F}(x),\hat{G}(x), respectively. Then

F^(x)G^(x)=∑i≥0aixii!∑j≥0bjxjj!=∑n≥0xn∑i=0naibn−i1i!(n−i)!=∑n≥0xnn!∑i=0n(ni)aibn−i\begin{aligned} \hat{F}(x)\hat{G}(x) &=\sum_{i\ge 0}a_i\frac{x^i}{i!}\sum_{j\ge 0}b_j\frac{x^j}{j!}\\ &=\sum_{n\ge 0}x^{n}\sum_{i=0}^na_ib_{n-i}\frac{1}{i!(n-i)!}\\ &=\sum_{n\ge 0}\frac{x^{n}}{n!}\sum_{i=0}^n\binom{n}{i}a_ib_{n-i} \end{aligned}

Therefore, F^(x)G^(x)\hat{F}(x)\hat{G}(x) is the exponential generating function of the sequence

⟨∑i=0n(ni)aibn−i⟩\left\langle \sum_{i=0}^n \binom{n}{i}a_ib_{n-i} \right\rangle

It is therefore the exponential generating function of this sequence.

Closed forms

We likewise consider closed forms for exponential generating functions.

The exponential generating function of the sequence ⟨1,1,1,⋯ ⟩\langle 1,1,1,\cdots\rangle is

F^(x)=∑n≥0xnn!=ex\hat{F}(x) = \sum_{n \ge 0}\frac{x^n}{n!} = \mathrm{e}^x

This is because the Taylor expansion of ex\mathrm{e}^x at x=0x = 0 gives exactly its power-series form.

Similarly, the exponential generating function of the geometric sequence ⟨1,p,p2,⋯ ⟩\langle 1,p,p^2,\cdots\rangle is

F^(x)=∑n≥0pnxnn!=epx\hat{F}(x) = \sum_{n\ge 0}\frac{p^nx^n}{n!}=\mathrm{e}^{px}

Exponential and ordinary generating functions

How should we understand exponential generating functions? Define the exponential generating function of a sequence aa as

F(x)=∑n≥0anxnn!F(x)=\sum_{n\ge 0}a_n\frac{x^n}{n!}

But F(x)F(x) is also the ordinary generating function of the sequence ⟨ann!⟩\left\langle \dfrac{a_n}{n!} \right\rangle.

There is no contradiction between these two interpretations. In other words, different generating functions merely reflect different ways of viewing a problem.

The combinatorial meaning of polynomial exp in EGF

If you have not learned polynomial exp, skip this section for now. It develops the meaning of exp and can deepen your understanding of EGF.

In an EGF, the function fn(x)f^n(x) contains ff, which is itself an EGF. First consider the product of two arbitrary EGFs:

H^(x)=F^(x)G^(x)=∑n≥0[∑i=0n(ni)fign−i]xnn!\hat{H}(x) = \hat{F}(x)\hat{G}(x) = \sum_{n\geq 0} \left[ \sum_{i = 0}^n\binom {n}{i}f_ig_{n-i} \right] \frac{x^n}{n!}

For the product of two EGFs, the coefficient [xk]H^(x)[x^k]\hat{H}(x) is a convolution. If we consider the product of several EGFs, [xk]H^(x)[x^k]\hat{H}(x) is the sum of the coefficients of all cases in which one term xaix^{a_i} is selected from each EGF and ∑iai=k\sum_ia_i=k. From the set-theoretic perspective, this counts the ways to partition nn labeled elements into k>0k>0 labeled sets.

If k=0k=0, the coefficient is clearly the product of the constant terms of the original EGFs. However, some requirements in polynomial exp⁡\exp force the constant term of exp⁡\exp's f(x)f(x) to be 00; the details are explained below.

In the definition of polynomial coefficients (see the combinatorial meaning of polynomial coefficients in the permutations and combinations section), sets are implicitly ordered; however, in exp⁡(f(x))\exp(f(x)), multiplying fk(x)f^k(x)—that is, kk copies of f(x)f(x)—gives the same EGF regardless of order, while a partition of sets is clearly unordered. Therefore, its coefficient should be multiplied by 1k!\dfrac{1}{k!}.

Let Fk(n)F_k(n) be the number of ways to partition nn labeled elements into kk nonempty unordered sets (nonempty because of exp⁡\exp), and let fif_i be the number of specific combinatorial structures on a finite set of ii elements (the original EGF counts structures for an ii-element set and depends only on the set size). Then Fk(n)F_k(n) is

Fk(n)=n!k!∑∑ikai=n∏j=1kfajaj!F_k(n)=\frac{n!}{k!}\sum_{\sum_{i}^ka_i=n}\prod_{j=1}^{k}\frac{f_{a_j}}{a_j!}

Let the EGF of fnf_n be F^(x)\hat{F}(x), namely:

F^(x)=∑n≥0fnxnn!\hat{F}(x) = \sum_{n \geq 0} f_n\frac{x^n}{n!}

Let the EGF of Fk(n)F_k(n) be Gk(x)G_k(x). Then

Gk(x)=∑n≥0Fk(n)xnn!=∑n≥0xn1k!∑∑ikai=n∏j=1kfajaj!=1k!∑n≥0∑∑ikai=n∏j=1kfajxajaj!=1k!F^k(x)\begin{aligned} G_k(x)&=\sum_{n \geq 0} F_k(n)\frac{x^n}{n!}\\ &=\sum_{n \geq 0} x^n\frac{1}{k!}\sum_{\sum_i^k a_i=n}\prod_{j=1}^{k}\frac{f_{a_j}}{a_j!}\\ &=\frac{1}{k!}\sum_{n \geq 0}\sum_{\sum_i^k a_i=n}\prod_{j=1}^{k}\frac{f_{a_j}x^{a_j}}{a_j!}\\ &=\frac{1}{k!}\hat{F}^k(x) \end{aligned}

For all k≥0k \geq 0,

∑k≥0Gk(x)=∑k≥0F^k(x)k!=exp⁡F^(x)\sum_{k \geq 0}G_k(x) = \sum_{k \geq 0}\frac{\hat{F}^k(x)}{k!} = \exp{\hat{F}(x)}

The derivation above directly writes the expression from the combinatorial viewpoint. We can also prove the relationship between exp⁡(f(x))\exp(f(x)) and f(x)f(x) recursively.

Again let Fk(n)F_k(n) be the number of ways to partition nn labeled elements into kk nonempty unordered sets, let gig_i be the number of structures on a set of ii elements (with the same meaning as fif_i above), and let G(x)G(x) be the EGF of {gi}\{g_i\} and Hk(x)H_k(x) the EGF of {Fk(n)}\{F_k(n)\}.

Among the nn elements, choosing ii of them as one separate set gives gig_i choices; the remaining n−in-i elements form k−1k-1 sets in Fk−1(n−i)F_{k-1}(n-i) ways. But each set in a partition is enumerated as the separate set once, so every partition is counted kk times and we must divide by kk.

Hk(x)=∑n≥0xnn!Fk(n)=∑n≥0xnn!∑i=1n−k+1(ni)Fk−1(n−i)×gi×1k=1k∑n≥0xnn!∑i=0n(ni)Fk−1(n−i)×gi=1k⋅Hk−1(x)G(x)\begin{aligned} H_k(x) &= \sum_{n\ge 0}\cfrac{x^n}{n!}F_k(n)\\ &=\sum_{n\ge 0}\cfrac{x^n}{n!}\sum_{i=1}^{n-k+1}\binom n {i} F_{k-1}(n-i)\times g_i\times \cfrac{1}{k}\\ &=\cfrac{1}{k}\sum_{n\ge 0}\cfrac{x^n}{n!}\sum_{i=0}^{n}\binom n {i}F_{k-1}(n-i)\times g_i\\ &=\cfrac{1}{k}\cdot H_{k-1}(x)G(x) \end{aligned}

The upper bound comes from partitioning into nonempty sets, which gives n−(k−1)≥in-(k-1)\geq i because each of the first k−1k-1 sets contains at least one element. If we define Fk−1(n−i)F_{k-1}(n-i) to be 00 beyond this bound, there is no effect.

After obtaining the recurrence, expand it recursively; when k=1k=1, the boundary is H1(x)=G(x)H_1(x)=G(x).

Hk(x)=1k⋅Hk−1(x)G(x)=1k⋅1k−1⋅Hk−2(x)G2(x)=⋯=1k⋅1k−1⋯12⋅H1(x)Gk−1(x)=1k!Gk(x)\begin{aligned} H_k(x) &= \cfrac{1}{k}\cdot H_{k-1}(x)G(x)\\ &= \cfrac{1}{k}\cdot\cfrac{1}{k-1}\cdot H_{k-2}(x)G^2(x)\\ &=\cdots \\ &= \cfrac{1}{k}\cdot\cfrac{1}{k-1} \cdots\cfrac{1}{2}\cdot H_{1}(x)G^{k-1}(x)\\ &= \cfrac{1}{k!}G^{k}(x)\\ \end{aligned}

Similarly,

∑k≥0Hk(x)=∑k≥0Gk(x)k!=exp⁡G(x)\begin{aligned} \sum_{k\ge 0}H_k(x)=\sum_{k\ge 0}\cfrac{G^k(x)}{k!}=\exp G(x) \end{aligned}

Clearly, defining the structures as partitions into nonempty sets (g0=0g_0=0) matches the intended meaning. If the empty set is included (g0=1g_0=1), then [xn]Gk[x^n]G^k contains contributions from [xn]Gy,y>k[x^n]G^y,y>k (by choosing a constant term from at least one GG), causing overcounting and failing to give the desired quantity.

From the recursive viewpoint, a product of several EGFs can also be viewed as a knapsack-like combination: the process of combining two groups of counted objects.

In summary, the meaning of polynomial exp⁡\exp is: the generating family of sets formed by labeled elements, or the total number of ways to partition them into any number of nonempty subsets.

Permutations and circular permutations

The exponential generating function for permutations of length nn is

P^(x)=∑n≥0n!xnn!=∑n≥0xn=11−x\hat{P}(x)=\sum_{n\ge 0}\frac{n!x^n}{n!}=\sum_{n\ge 0}x^n=\frac{1}{1-x}

A circular permutation is a way to arrange 1,2,⋯ ,n1,2,\cdots,n in a ring. Rotations of the same arrangement are equivalent, but reversals are not.

The number of circular permutations of nn numbers is clearly (n−1)!(n-1)!. Therefore, the exponential generating function of circular permutations of nn numbers is

Q^(x)=∑n≥1(n−1)!xnn!=∑n≥1xnn=−ln⁡(1−x)=ln⁡(11−x)\hat{Q}(x)=\sum_{n\ge 1}\frac{(n-1)!x^n}{n!}=\sum_{n\ge 1}\frac{x^n}{n}=-\ln(1-x)=\ln\left( \frac{1}{1-x} \right)

That is, exp⁡Q^(x)=P^(x)\exp \hat{Q}(x)=\hat{P}(x). This is only a mathematical derivation, however. How can we intuitively understand why the exp⁡\exp of the EGF of circular permutations is the EGF of permutations?

A permutation is composed of several permutation cycles. For example, p=[4,3,2,5,1]p=[4,3,2,5,1] has two permutation cycles:

Figure: p1

(In other words, we draw a directed edge from pip_i to ii.)

Different permutation cycles produce different permutations. For example, if we change the second permutation cycle to

Figure: p2

the corresponding permutation becomes [5,3,2,1,4][5,3,2,1,4].

Thus, the number of permutations of length nn is the number of ways to:

  1. Divide 1,2,⋯ ,n1,2,\cdots,n into several sets.
  2. Turn each set into a permutation cycle.

The number of ways for the elements of one set to form a permutation cycle is exactly the number of circular permutations of that set. Therefore, the number of permutations of length nn is obtained by partitioning 1,2,⋯ ,n1,2,\cdots,n into several sets and multiplying the circular-permutation counts for the sets.

This is the intuitive meaning of polynomial exp⁡\exp.

More generally:

  • If the EGF of labeled spanning trees on nn vertices is F^(x)\hat{F}(x), then the EGF of labeled spanning forests on nn vertices is exp⁡F^(x)\exp \hat{F}(x)—intuitively, partition the nn vertices into several sets and multiply the number of ways for each set to form a spanning tree.

  • If the EGF of labeled undirected connected graphs on nn vertices is F^(x)\hat{F}(x), then the EGF of labeled undirected graphs on nn vertices is exp⁡F^(x)\exp \hat{F}(x), which is easy to compute:

    exp⁡F^(x)=∑n≥02(n2)xnn!\exp \hat{F}(x)=\sum_{n\ge 0}2^{\binom{n}{2}}\frac{x^n}{n!}

    Therefore, computing the former requires only one polynomial ln⁡\ln.

Next we look at some applications of exponential generating functions.

Applications

Derangements

Derangements

A derangement of length nn is a permutation satisfying pi≠ip_i\ne i.

Find the exponential generating function of the derangements.

From the perspective of permutation cycles, a derangement is a permutation with no self-loop in its cycles. In other words, it has no cycle of length 11. The EGF of the latter is

∑n≥2xnn=−ln⁡(1−x)−x\sum_{n\ge 2}\frac{x^n}{n}=-\ln\left(1-x\right)-x

Therefore, the EGF of derangements is exp⁡(−ln⁡(1−x)−x)\exp(-\ln(1-x)-x).

Fixed points

Fixed points

Problem: Count the mappings f:{1,2,⋯ ,n}→{1,2,⋯ ,n}f:\{1,2,\cdots,n\}\to \{1,2,\cdots,n\} satisfying

f∘f∘⋯∘f⏟k=f∘f∘⋯∘f⏟k−1\underbrace{f\circ f\circ\cdots\circ f}_{k}=\underbrace{f\circ f\circ\cdots\circ f}_{k-1}

nk≤2×106,1≤k≤3nk\le 2\times 10^6,1\le k\le 3.

Draw an edge from ii to f(i)f(i). The condition says that starting from any ii, after kk steps and after k−1k-1 steps we reach the same point. Thus every cycle in the functional graph is a self-loop and its depth is at most kk (the root has depth 11). Treating this functional graph as a rooted tree gives the same result. The problem therefore becomes counting forests of rooted trees on nn labeled vertices with depth at most kk.

Consider a rooted tree on nn labeled vertices with depth at most kk, and suppose its generating function is

Fk^(x)=∑n≥0fn,kxnn!\hat{F_k}(x)=\sum_{n\ge 0}f_{n,k}\frac{x^n}{n!}

To derive Fk^(x)\hat{F_k}(x) recursively, observe that a rooted tree of depth at most kk consists of several rooted trees of depth at most k−1k-1 whose roots are all connected to one new vertex. Hence

Fk^(x)=xexp⁡F^k−1(x)\hat{F_k}(x)=x\exp \hat{F}_{k-1}(x)

The answer's exponential generating function is therefore exp⁡F^k(x)\exp \hat{F}_k(x); compute its nn-th term.

Lust

Lust

You are given a sequence of nn numbers a1,a2,⋯ ,ana_1,a_2,\cdots,a_n and a variable initially equal to 00 named ss. Repeat the following operations kk times:

  • Choose an element from 1,2,⋯ ,n1,2,\cdots,n uniformly at random and call it xx.
  • Increase ss by ∏i≠xai\prod_{i\ne x}a_i.
  • Decrease axa_x by one.

After kk operations, find the expected value of ss.

1≤n≤5000,1≤k≤109,0≤ai≤1091\le n\le 5000,1\le k\le 10^9,0\le a_i\le 10^9.

Suppose that after kk operations, aia_i has decreased by bib_i. Then in fact

s=∏i=1nai−∏i=1n(ai−bi)s=\prod_{i=1}^n a_i-\prod_{i=1}^n(a_i- b_i)

Thus the problem is equivalent to, after kk operations, finding the expected value of ∏i=1n(ai−bi)\prod_{i=1}^n (a_i- b_i).

Consider the sum of ∏i=1n(ai−bi)\prod_{i=1}^n (a_i- b_i) over every sequence of choices, and divide by nkn^k at the end.

In a sequence of kk operations, the number of sequences in which ii appears bib_i times is

k!b1!b2!⋯bn!\frac{k!}{b_1!b_2!\cdots b_n!}

which resembles the coefficient in multiplication of exponential generating functions.

Let the exponential generating function associated with aja_j be

Fj(x)=∑i≥0(aj−i)xii!F_j(x)=\sum_{i\ge 0}(a_j-i)\frac{x^i}{i!}

Then the answer is

[xk]∏j=1nFj(x)[x^k]\prod_{j=1}^nF_j(x)

To compute the answer quickly, convert Fj(x)F_j(x) to closed form:

Fj(x)=∑i≥0ajxii!−∑i≥1xi(i−1)!=ajex−xex=(aj−x)ex\begin{aligned} F_j(x)&=\sum_{i\ge 0}a_j\frac{x^i}{i!}-\sum_{i\ge 1}\frac{x^i}{(i-1)!}\\ &=a_j\mathrm{e}^x-x\mathrm{e}^x\\ &=(a_j-x)\mathrm{e}^x \end{aligned}

Therefore,

∏j=1nFj(x)=enx∏j=1n(aj−x)\prod_{j=1}^nF_j(x)=\mathrm{e}^{nx}\prod_{j=1}^n(a_j-x)

Here ∏j=1n(aj−x)\prod_{j=1}^n(a_j-x) is an nn-degree polynomial, which can be computed by brute force. Suppose its expansion is ∑i=0ncixi\sum_{i=0}^nc_ix^i. Then

∏j=1nFj(x)=(∑i≥0nixii!)(∑i=0ncixi)=∑i≥0∑j=0icjxjni−jxi−j(i−j)!=∑i≥0xii!∑j=0ini−jij‾cj\begin{aligned} \prod_{j=1}^nF_j(x) &=\left(\sum_{i\ge 0} \frac{n^ix^i}{i!}\right)\left(\sum_{i=0}^nc_ix^i\right)\\ &=\sum_{i\ge 0}\sum_{j=0}^i c_jx^j\frac{n^{i-j}x^{i-j}}{(i-j)!}\\ &=\sum_{i\ge 0}\frac{x^{i}}{i!}\sum_{j=0}^i n^{i-j}i^{\underline{j}}c_j \end{aligned}

It is enough to compute the coefficient of xkx^k in this polynomial.

This content comes from OI Wiki: Exponential Generating Functions. See the original for authors and revision history. AIOJ has adapted the formatting, in-site links, and resource paths.

Content is shared under CC BY-SA 4.0 and SATA license; additional terms are governed by the original notice. Thanks to the OI Wiki authors and contributors; per the SATA terms, please visit the OI Wiki repository and star it to show your support.