{
  "id": "generating-function",
  "title": "Generating Function",
  "lang": "en",
  "source_lang": "en",
  "summary": "A generating function encodes a sequence as coefficients of a series, enabling algebraic and analytic methods to solve counting problems, recurrences, and probability calculations.",
  "category": "mathematics",
  "subcategory": "discrete-logic",
  "type": "concept",
  "aliases": [
    "Generating series"
  ],
  "generated_at": "2026-10-04",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/generating-function/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/generating-function/",
      "json": "https://aiwiki.page/zh/generating-function.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "A generating function is a mathematical expression that represents a sequence by placing its terms in the coefficients of a series. The most common form associates a sequence \\(a_0,a_1,a_2,\\ldots\\) with the power series \\(A(z)=\\sum_{n\\ge0}a_nz^n\\). Operations on this single expression translate into operations on the sequence, making generating functions important tools in combinatorics, probability theory, and the analysis of algorithms. Depending on the purpose, the series can be treated as a purely formal algebraic object or as a convergent function. (aofa.cs.princeton.edu)"
    },
    {
      "heading": "Definition and interpretation",
      "text": "The ordinary generating function (OGF) of a sequence is\n\n\\[A(z)=\\sum_{n=0}^{\\infty}a_nz^n.\\]\n\nThe notation \\([z^n]A(z)\\) means “the coefficient of \\(z^n\\) in \\(A(z)\\),” so that \\([z^n]A(z)=a_n\\). For a counting sequence, the exponent records an object's size and the coefficient records how many objects have that size. A finite sequence gives a polynomial, with subsequent coefficients understood to be zero. (aofa.cs.princeton.edu)\n\nFor example, the sequence \\(1,1,1,\\ldots\\) has generating function\n\n\\[1+z+z^2+\\cdots=\\frac{1}{1-z},\\]\n\nusing the geometric series identity. Likewise,\n\n\\[\\sum_{n\\ge0}nz^n=\\frac{z}{(1-z)^2}.\\]\n\nThese compact expressions retain every coefficient of the original sequences. (aofa.cs.princeton.edu)\n\nFormal and analytic viewpoints\n\nA formal power series is specified by its coefficients, without requiring numerical convergence. Equality means coefficient-by-coefficient equality. Over a field, a formal series has a multiplicative inverse precisely when its constant coefficient is nonzero. Thus \\(1/(1-z)\\) is meaningful formally, independently of whether a numerical value is assigned to \\(z\\). (math.cmu.edu)\n\nThe distinction matters for rapidly growing sequences. The series\n\n\\[\\sum_{n\\ge0}n!z^n\\]\n\nhas radius of convergence zero, but remains a valid formal generating function. If a series does converge near zero, methods of complex analysis become available, including coefficient extraction through contour integration and estimates based on singularities. (math.cmu.edu)"
    },
    {
      "heading": "Algebraic operations",
      "text": "Let \\(A(z)=\\sum a_nz^n\\) and \\(B(z)=\\sum b_nz^n\\). Their operations have direct coefficient interpretations:\n\nOperation | Coefficient interpretation\n\\(A(z)+B(z)\\) | Termwise addition: \\(a_n+b_n\\)\n\\(z^rA(z)\\), \\(r\\ge0\\) | Shift by \\(r\\) positions, inserting initial zeros\n\\(A(z)B(z)\\) | \\(\\displaystyle c_n=\\sum_{k=0}^{n}a_kb_{n-k}\\)\n\\(zA'(z)\\) | Weight the \\(n\\)-th term by \\(n\\)\n\\(\\displaystyle A(z)/(1-z)\\) | Partial sums: \\(\\displaystyle s_n=\\sum_{k=0}^{n}a_k\\)\n\nMultiplication therefore implements discrete convolution, while taking a derivative implements index-dependent weighting. These rules explain why relations involving sums and shifts often become simpler equations for generating functions. (math.cmu.edu)"
    },
    {
      "heading": "Main types",
      "text": "Exponential generating functions\n\nThe exponential generating function (EGF) of a sequence is\n\n\\[E(z)=\\sum_{n\\ge0}a_n\\frac{z^n}{n!}, \\qquad a_n=n![z^n]E(z),\\]\n\nwhere \\(n!\\) is the factorial. For the constant sequence \\(a_n=1\\), the EGF is the exponential function \\(e^z\\), rather than \\(1/(1-z)\\). (aofa.cs.princeton.edu)\n\nEGFs are especially useful for counting structures on distinct labels. Their product encodes\n\n\\[c_n=\\sum_{k=0}^{n}\\binom{n}{k}a_kb_{n-k}.\\]\n\nThe binomial coefficient chooses which \\(k\\) labels belong to the first component. This distinguishes labelled products from ordinary products, which do not include that allocation factor. (aofa.cs.princeton.edu)\n\nMultivariate generating functions\n\nA generating function can record several parameters:\n\n\\[A(z,u)=\\sum_{n,k\\ge0}a_{n,k}z^nu^k.\\]\n\nHere \\(z\\) might mark size and \\(u\\) a secondary statistic, such as the number of leaves in a tree. When the substitution is well-defined, \\(A(z,1)\\) counts objects by size alone. Differentiating with respect to \\(u\\) weights objects by their secondary statistic, allowing averages and higher moments to be recovered. (ac.cs.princeton.edu)\n\nOther generating series\n\nOther coefficient encodings suit different operations. A Dirichlet generating series,\n\n\\[D(s)=\\sum_{n\\ge1}\\frac{a_n}{n^s},\\]\n\nis useful in number theory because multiplication combines indices through divisors rather than addition:\n\n\\[c_n=\\sum_{d\\mid n}a_db_{n/d}.\\]\n\nChoosing a generating series is therefore partly a choice of which sequence operations should become multiplication, differentiation, or another simple transformation. (math.cmu.edu)"
    },
    {
      "heading": "Solving recurrence relations",
      "text": "Generating functions turn many recurrence relations into algebraic or differential equations. The usual procedure is to multiply the recurrence by \\(z^n\\), sum over its valid indices, account for initial terms, and solve the resulting equation. (aofa.cs.princeton.edu)\n\nFor the Fibonacci sequence, take\n\n\\[F_0=0,\\qquad F_1=1,\\qquad F_n=F_{n-1}+F_{n-2}\\quad(n\\ge2).\\]\n\nWriting \\(F(z)=\\sum_{n\\ge0}F_nz^n\\) gives\n\n\\[F(z)-z=zF(z)+z^2F(z),\\]\n\nhence\n\n\\[F(z)=\\frac{z}{1-z-z^2}.\\]\n\nFactoring the denominator and expanding its partial fractions yields an explicit expression for \\(F_n\\). The initial conditions are essential: the recurrence alone does not determine the numerator. (math.mit.edu)"
    },
    {
      "heading": "Counting combinatorial structures",
      "text": "Generating functions express ways of building objects. Disjoint alternatives correspond to addition; ordered pairs of components, with sizes added, correspond to multiplication. If \\(A(z)\\) counts components and \\(A(0)=0\\), arbitrary finite sequences of components have generating function\n\n\\[1+A(z)+A(z)^2+\\cdots=\\frac{1}{1-A(z)}.\\]\n\nThe condition excludes zero-size components, which could otherwise produce infinitely many sequences of a fixed size. (aofa.cs.princeton.edu)\n\nA classical example is the Catalan numbers, which count ordered full binary trees by their number of internal nodes. A tree is either a single leaf or an internal root with two subtrees, giving\n\n\\[C(z)=1+zC(z)^2.\\]\n\nSelecting the solution with constant coefficient \\(1\\) gives\n\n\\[C(z)=\\frac{1-\\sqrt{1-4z}}{2z}, \\qquad C_n=\\frac{1}{n+1}\\binom{2n}{n}.\\]\n\nThe first coefficients are \\(1,1,2,5,14,\\ldots\\). This illustrates how a recursive structural description becomes an equation and then a counting formula. (aofa.cs.princeton.edu)"
    },
    {
      "heading": "Probability generating functions",
      "text": "For a random variable \\(X\\) taking nonnegative integer values, its probability generating function is\n\n\\[G_X(z)=\\mathbb E[z^X] =\\sum_{n\\ge0}\\Pr(X=n)z^n.\\]\n\nIts coefficients form the probability mass function. For a binomial distribution with parameters \\(m\\) and \\(p\\),\n\n\\[G_X(z)=(1-p+pz)^m.\\]\n\nThe coefficient of \\(z^k\\) is the probability of exactly \\(k\\) successes. (math.mit.edu)\n\nDifferentiation generates factorial moments:\n\n\\[G_X^{(r)}(1^-) =\\mathbb E[X(X-1)\\cdots(X-r+1)].\\]\n\nWhen the relevant moments are finite, the mean and variance follow from\n\n\\[\\mathbb E[X]=G_X'(1^-),\\]\n\n\\[\\operatorname{Var}(X) =G_X''(1^-)+G_X'(1^-)-\\bigl(G_X'(1^-)\\bigr)^2.\\]\n\nGenerating-function representations also support exact inference for some discrete probabilistic models. (math.cmu.edu)"
    },
    {
      "heading": "Analytic methods and limitations",
      "text": "Analytic combinatorics connects structural counting equations with analytic properties of their generating functions. Singularities can determine both exponential growth and polynomial corrections in the coefficients. For example, the square-root singularity in the Catalan generating function leads to\n\n\\[C_n\\sim\\frac{4^n}{\\sqrt{\\pi}\\,n^{3/2}}.\\]\n\nHere \\(\\sim\\) means that the ratio of the two expressions tends to \\(1\\). General singularity-transfer results require appropriate analyticity conditions; knowing only the radius of convergence is not enough to determine a full asymptotic formula. (aofa.cs.princeton.edu)\n\nEncoding a sequence does not guarantee an easily usable closed form. An equation for its generating function may be harder to solve than the original recurrence, and extracting coefficients can remain difficult. Formal manipulations also do not automatically justify numerical substitutions or analytic arguments: convergence must be established separately. The usefulness of the method depends on matching the series type and its operations to the structure of the problem. (math.cmu.edu)\n\nThe modern subject combines formal series algebra, combinatorial construction rules, and complex-analytic estimates. Herbert S. Wilf's generatingfunctionology, first published in 1990, presents these techniques through sequence and counting problems; Philippe Flajolet and Robert Sedgewick's Analytic Combinatorics develops the systematic connection between combinatorial specifications and asymptotic analysis. (www2.math.upenn.edu)"
    }
  ],
  "links": [
    "power-series",
    "combinatorics",
    "probability",
    "algorithm",
    "mathematical-function",
    "polynomial",
    "geometric-series",
    "field-mathematics",
    "complex-analysis",
    "convolution",
    "derivative",
    "factorial",
    "exponential-function",
    "binomial-coefficient",
    "number-theory",
    "recurrence-relation",
    "differential-equation",
    "fibonacci-sequence",
    "catalan-number",
    "random-variable",
    "probability-generating-function",
    "probability-mass-function",
    "binomial-distribution",
    "expected-value",
    "variance"
  ],
  "sources": [
    {
      "title": "Generating Functions",
      "url": "https://aofa.cs.princeton.edu/30gf/"
    },
    {
      "title": "Generating Function Notes",
      "url": "https://math.mit.edu/~djk/18.310/Lecture-Notes/generating_function_notes.pdf"
    },
    {
      "title": "generatingfunctionology",
      "url": "https://www.math.cmu.edu/~af1p/Teaching/Combinatorics/Slides/Notes/gfology.pdf"
    },
    {
      "title": "Generating Functions lecture slides",
      "url": "https://aofa.cs.princeton.edu/online/slides/AA03-GFs.pdf"
    },
    {
      "title": "Analytic Combinatorics",
      "url": "https://aofa.cs.princeton.edu/50ac/"
    },
    {
      "title": "Analytic Combinatorics — Philippe Flajolet and Robert Sedgewick",
      "url": "https://ac.cs.princeton.edu/home/"
    },
    {
      "title": "Exact Bayesian Inference on Discrete Models via Probability Generating Functions: A Probabilistic Programming Approach",
      "url": "https://arxiv.org/abs/2305.17058"
    },
    {
      "title": "Download generatingfunctionology",
      "url": "https://www2.math.upenn.edu/~wilf/DownldGF.html"
    }
  ],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}