{
  "id": "stirling-numbers",
  "title": "Stirling Numbers",
  "lang": "en",
  "source_lang": "en",
  "summary": "Stirling numbers are two families of integers that count permutations by cycles and set partitions by blocks, and connect ordinary powers with factorial powers.",
  "category": "mathematics",
  "subcategory": "discrete-logic",
  "type": "concept",
  "aliases": [
    "Stirling numbers of the first and second kinds"
  ],
  "generated_at": "2026-11-05",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/stirling-numbers/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/stirling-numbers/",
      "json": "https://aiwiki.page/zh/stirling-numbers.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "Stirling numbers are two closely related families of integers in combinatorics. Stirling numbers of the first kind count permutations according to their number of cycles, while Stirling numbers of the second kind count partitions of a set into a specified number of nonempty blocks. Algebraically, they are the coefficients that convert between ordinary powers and factorial powers. They occur in enumeration, finite differences, probability theory, and the manipulation of polynomial expressions.\n\nThe numbers are named after the Scottish mathematician James Stirling, who studied them in his 1730 work Methodus Differentialis. Although they share his name with Stirling’s approximation for factorials, they are distinct mathematical objects."
    },
    {
      "heading": "Definitions and notation",
      "text": "For nonnegative integers \\(n\\) and \\(k\\), the unsigned Stirling number of the first kind\n\n\\[\\left[{n\\atop k}\\right]\\]\n\nis the number of permutations of an \\(n\\)-element set having exactly \\(k\\) cycles in their disjoint-cycle decomposition. It is also commonly written \\(c(n,k)\\).\n\nThe Stirling number of the second kind\n\n\\[\\left\\{{n\\atop k}\\right\\}\\]\n\nis the number of partitions of an \\(n\\)-element set into exactly \\(k\\) nonempty, unordered blocks. It is also commonly written \\(S(n,k)\\).\n\nThe signed Stirling number of the first kind is\n\n\\[s(n,k)=(-1)^{n-k}\\left[{n\\atop k}\\right].\\]\n\nNotation varies across sources: in particular, “Stirling number of the first kind” may mean either the signed or the unsigned version. The convention must therefore be specified.\n\nThe boundary values are\n\n\\[\\left[{0\\atop0}\\right] = \\left\\{{0\\atop0}\\right\\} =1,\\]\n\nand, for \\(n>0\\),\n\n\\[\\left[{n\\atop0}\\right] = \\left\\{{n\\atop0}\\right\\} =0.\\]\n\nBoth families are zero when \\(k>n\\). The value at \\((0,0)\\) records the unique empty permutation and the unique partition of the empty set into no blocks."
    },
    {
      "heading": "Combinatorial interpretations",
      "text": "First kind: permutations by cycles\n\nA cycle describes a circular arrangement of distinct elements. Cyclic rotations represent the same cycle: for example, \\((1\\,2\\,3)\\), \\((2\\,3\\,1)\\), and \\((3\\,1\\,2)\\) are identical as permutations. The order in which disjoint cycles are listed also does not matter.\n\nFor a three-element set, the permutations are distributed as follows:\n\n- Two have one cycle: \\((1\\,2\\,3)\\) and \\((1\\,3\\,2)\\).\n- Three have two cycles: \\((1\\,2)(3)\\), \\((1\\,3)(2)\\), and \\((2\\,3)(1)\\).\n- One has three cycles: \\((1)(2)(3)\\).\n\nThus,\n\n\\[\\left[{3\\atop1}\\right]=2,\\qquad \\left[{3\\atop2}\\right]=3,\\qquad \\left[{3\\atop3}\\right]=1.\\]\n\nSumming over all possible cycle counts gives the total number of permutations:\n\n\\[\\sum_{k=0}^{n}\\left[{n\\atop k}\\right]=n!,\\]\n\nwhere \\(n!\\) denotes the factorial.\n\nSecond kind: partitions into blocks\n\nA set partition divides a set into disjoint nonempty subsets whose union is the original set. Neither the order of the blocks nor the order of elements within a block matters.\n\nFor example,\n\n\\[\\left\\{{3\\atop2}\\right\\}=3,\\]\n\nbecause the partitions of \\(\\{1,2,3\\}\\) into two blocks are\n\n\\[\\{\\{1\\},\\{2,3\\}\\},\\qquad \\{\\{2\\},\\{1,3\\}\\},\\qquad \\{\\{3\\},\\{1,2\\}\\}.\\]\n\nThe two kinds are related by\n\n\\[\\left[{n\\atop k}\\right] = \\sum_{\\pi}\\prod_{B\\in\\pi}(|B|-1)!,\\]\n\nwhere the sum runs over all partitions \\(\\pi\\) into \\(k\\) blocks. Each block \\(B\\) can be arranged as a cycle in \\((|B|-1)!\\) ways. The first kind therefore counts partitions whose blocks carry cyclic orderings."
    },
    {
      "heading": "Recurrence relations",
      "text": "Both families satisfy triangular recurrence relations.\n\nFor the unsigned first kind,\n\n\\[\\left[{n\\atop k}\\right] = \\left[{n-1\\atop k-1}\\right] +(n-1)\\left[{n-1\\atop k}\\right], \\qquad n\\ge1.\\]\n\nTo see this, distinguish one element, labeled \\(n\\). It either forms a singleton cycle, leaving \\(k-1\\) cycles on the other elements, or is inserted immediately after one of the \\(n-1\\) elements in an existing cycle.\n\nFor the signed first kind, the corresponding relation is\n\n\\[s(n,k)=s(n-1,k-1)-(n-1)s(n-1,k).\\]\n\nFor the second kind,\n\n\\[\\left\\{{n\\atop k}\\right\\} = \\left\\{{n-1\\atop k-1}\\right\\} +k\\left\\{{n-1\\atop k}\\right\\}, \\qquad n\\ge1.\\]\n\nHere the distinguished element either forms its own block or joins one of the \\(k\\) existing blocks.\n\nThe first few rows are:\n\n\\(n\\) | Unsigned first kind, \\(k=0,\\ldots,n\\) | Second kind, \\(k=0,\\ldots,n\\)\n0 | 1 | 1\n1 | 0, 1 | 0, 1\n2 | 0, 1, 1 | 0, 1, 1\n3 | 0, 2, 3, 1 | 0, 1, 3, 1\n4 | 0, 6, 11, 6, 1 | 0, 1, 7, 6, 1\n5 | 0, 24, 50, 35, 10, 1 | 0, 1, 15, 25, 10, 1\n\nUseful special values include\n\n\\[\\left[{n\\atop1}\\right]=(n-1)!, \\qquad \\left\\{{n\\atop1}\\right\\}=1 \\quad(n\\ge1),\\]\n\nand\n\n\\[\\left[{n\\atop n}\\right] = \\left\\{{n\\atop n}\\right\\}=1.\\]\n\nImmediately below the diagonal, both families equal a binomial coefficient:\n\n\\[\\left[{n\\atop n-1}\\right] = \\left\\{{n\\atop n-1}\\right\\} = \\binom n2 \\quad(n\\ge2).\\]"
    },
    {
      "heading": "Factorial powers and change of basis",
      "text": "Define the falling and rising factorial powers by\n\n\\[x^{\\underline n}=x(x-1)\\cdots(x-n+1),\\]\n\n\\[x^{\\overline n}=x(x+1)\\cdots(x+n-1),\\]\n\nwith both expressions equal to \\(1\\) when \\(n=0\\).\n\nStirling numbers are characterized by the polynomial identities\n\n\\[x^{\\underline n} = \\sum_{k=0}^{n}s(n,k)x^k,\\]\n\n\\[x^{\\overline n} = \\sum_{k=0}^{n}\\left[{n\\atop k}\\right]x^k,\\]\n\nand\n\n\\[x^n = \\sum_{k=0}^{n} \\left\\{{n\\atop k}\\right\\}x^{\\underline k}.\\]\n\nFor example,\n\n\\[x^{\\underline3}=x^3-3x^2+2x,\\]\n\nwhereas\n\n\\[x^3=x^{\\underline3}+3x^{\\underline2}+x^{\\underline1}.\\]\n\nThus ordinary powers and falling factorials form two bases of the polynomial vector space, with the signed first-kind and second-kind numbers supplying inverse changes of basis.\n\nFor any fixed degree bound \\(N\\), the lower-triangular matrices\n\n\\[A=(s(n,k))_{0\\le n,k\\le N}, \\qquad B=\\left(\\left\\{{n\\atop k}\\right\\}\\right)_{0\\le n,k\\le N}\\]\n\nsatisfy \\(AB=BA=I\\). Equivalently,\n\n\\[\\sum_{j=k}^{n}s(n,j)\\left\\{{j\\atop k}\\right\\} =\\delta_{n,k},\\]\n\n\\[\\sum_{j=k}^{n}\\left\\{{n\\atop j}\\right\\}s(j,k) =\\delta_{n,k},\\]\n\nwhere \\(\\delta_{n,k}\\) is \\(1\\) when \\(n=k\\) and \\(0\\) otherwise.\n\nThis gives Stirling inversion: sequences related by\n\n\\[b_n=\\sum_{k=0}^{n}\\left\\{{n\\atop k}\\right\\}a_k\\]\n\ncan be recovered through\n\n\\[a_n=\\sum_{k=0}^{n}s(n,k)b_k.\\]"
    },
    {
      "heading": "Explicit formulas and generating functions",
      "text": "An explicit formula for the second kind\n\nThe inclusion–exclusion principle gives\n\n\\[\\left\\{{n\\atop k}\\right\\} = \\frac1{k!} \\sum_{j=0}^{k} (-1)^{k-j}\\binom kj j^n.\\]\n\nIndeed, \\(k!\\left\\{{n\\atop k}\\right\\}\\) counts surjective functions from an \\(n\\)-element set onto a \\(k\\)-element labeled set. Inclusion–exclusion removes functions that omit one or more target elements; division by \\(k!\\) forgets the labels of the resulting blocks. For the boundary case \\(n=k=0\\), the formula uses the combinatorial convention \\(0^0=1\\).\n\nExponential generating functions\n\nFor fixed \\(k\\), the exponential generating functions are\n\n\\[\\sum_{n=k}^{\\infty} \\left\\{{n\\atop k}\\right\\}\\frac{z^n}{n!} = \\frac{(e^z-1)^k}{k!},\\]\n\n\\[\\sum_{n=k}^{\\infty} \\left[{n\\atop k}\\right]\\frac{z^n}{n!} = \\frac{[-\\log(1-z)]^k}{k!},\\]\n\nand\n\n\\[\\sum_{n=k}^{\\infty}s(n,k)\\frac{z^n}{n!} = \\frac{[\\log(1+z)]^k}{k!}.\\]\n\nThese identities hold as formal power series; the logarithmic expressions also have their usual analytic interpretations near \\(z=0\\).\n\nThe bivariate versions include\n\n\\[\\sum_{n=0}^{\\infty}\\sum_{k=0}^{n} \\left\\{{n\\atop k}\\right\\}u^k\\frac{z^n}{n!} = \\exp\\!\\bigl(u(e^z-1)\\bigr),\\]\n\nand\n\n\\[\\sum_{n=0}^{\\infty}\\sum_{k=0}^{n} \\left[{n\\atop k}\\right]u^k\\frac{z^n}{n!} = (1-z)^{-u}.\\]\n\nFor fixed \\(k\\), the second-kind numbers also have the ordinary generating function\n\n\\[\\sum_{n=k}^{\\infty} \\left\\{{n\\atop k}\\right\\}z^n = \\frac{z^k}{(1-z)(1-2z)\\cdots(1-kz)}.\\]"
    },
    {
      "heading": "Applications",
      "text": "Bell numbers and counting functions\n\nThe total number of partitions of an \\(n\\)-element set is the Bell number\n\n\\[B_n=\\sum_{k=0}^{n}\\left\\{{n\\atop k}\\right\\}.\\]\n\nIts exponential generating function is\n\n\\[\\sum_{n=0}^{\\infty}B_n\\frac{z^n}{n!} = \\exp(e^z-1).\\]\n\nMore generally,\n\n\\[m^n = \\sum_{k=0}^{n} \\left\\{{n\\atop k}\\right\\}m^{\\underline k}\\]\n\ncounts functions from an \\(n\\)-element set to an \\(m\\)-element set by the number \\(k\\) of values actually used. First partition the domain into nonempty fibers, then assign distinct target values to those fibers.\n\nMoments in probability\n\nFor a random variable \\(X\\), ordinary moments and factorial moments are connected by\n\n\\[\\mathbb E[X^n] = \\sum_{k=0}^{n} \\left\\{{n\\atop k}\\right\\} \\mathbb E[X^{\\underline k}],\\]\n\nand\n\n\\[\\mathbb E[X^{\\underline n}] = \\sum_{k=0}^{n}s(n,k)\\mathbb E[X^k],\\]\n\nwhenever the relevant expectations exist.\n\nIf \\(X\\) has a Poisson distribution with parameter \\(\\lambda\\), then\n\n\\[\\mathbb E[X^{\\underline k}]=\\lambda^k,\\]\n\nso\n\n\\[\\mathbb E[X^n] = \\sum_{k=0}^{n}\\left\\{{n\\atop k}\\right\\}\\lambda^k.\\]\n\nAt \\(\\lambda=1\\), the \\(n\\)th ordinary moment is \\(B_n\\).\n\nIf a permutation of \\(n\\) elements is chosen uniformly, its number of cycles \\(C_n\\) has distribution\n\n\\[\\Pr(C_n=k)=\\frac{\\left[{n\\atop k}\\right]}{n!}.\\]\n\nFor \\(n\\ge1\\), its probability generating function is\n\n\\[\\mathbb E[t^{C_n}] = \\frac{t(t+1)\\cdots(t+n-1)}{n!},\\]\n\nfrom which\n\n\\[\\mathbb E[C_n]=\\sum_{j=1}^{n}\\frac1j\\]\n\nfollows.\n\nFinite differences\n\nFor the forward-difference operator\n\n\\[\\Delta f(x)=f(x+1)-f(x),\\]\n\nfalling factorials obey\n\n\\[\\Delta x^{\\underline k} = k x^{\\underline{k-1}}.\\]\n\nThis parallels the action of the derivative on ordinary powers. Consequently,\n\n\\[\\left.\\Delta^k(x^n)\\right|_{x=0} = k!\\left\\{{n\\atop k}\\right\\}.\\]\n\nStirling numbers therefore connect power-basis calculations with finite-difference methods and polynomial interpolation."
    },
    {
      "heading": "Computation and numerical considerations",
      "text": "The triangular recurrences provide a direct method for exact computation. Computing every entry through row \\(n\\) requires \\(O(n^2)\\) arithmetic operations. If only one row is needed, storage can be reduced to \\(O(n)\\) integers by updating a single array from right to left.\n\nThese are arithmetic-operation bounds, not bit-complexity bounds: the entries grow rapidly, so the cost of integer arithmetic increases with \\(n\\).\n\nThe alternating explicit formula for the second kind is useful symbolically, but its large intermediate terms can undergo severe cancellation in floating-point arithmetic. Exact integer recurrence calculations avoid this problem when exact values are required. Approximation formulas must also specify the relationship between \\(n\\) and \\(k\\): the regime of fixed \\(k\\) differs substantially from one in which \\(k\\) grows with \\(n\\)."
    }
  ],
  "links": [
    "integer",
    "combinatorics",
    "permutation",
    "set-partition",
    "probability",
    "empty-set",
    "factorial",
    "recurrence-relation",
    "binomial-coefficient",
    "polynomial",
    "basis-linear-algebra",
    "vector-space",
    "matrix",
    "inclusion-exclusion-principle",
    "surjective-function",
    "generating-function",
    "power-series",
    "bell-number",
    "random-variable",
    "expected-value",
    "poisson-distribution",
    "derivative",
    "interpolation",
    "floating-point-arithmetic"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}