StirlingS2[n,m]
gives the Stirling number of the second kind
.
StirlingS2
StirlingS2[n,m]
gives the Stirling number of the second kind
.
Details
- Integer mathematical function, suitable for both symbolic and numerical manipulation.
- StirlingS2 is defined as the conversion matrix from Power of continuous calculus to FactorialPower of discrete calculus
, where
.
gives the number of ways of partitioning a set of
elements into
non‐empty subsets. »- StirlingS2 automatically threads over lists.
Examples
open all close allBasic Examples (1)
Scope (2)
StirlingS2 threads element-wise over lists:
StirlingS2[{2, 4, 6}, 2]TraditionalForm formatting:
StirlingS2[n, m]//TraditionalFormApplications (5)
Plot Stirling numbers of the second kind on a logarithmic scale:
ListPlot3D[Table[Log[Abs[StirlingS2[n, m]] + 1], {n, 60}, {m, 60}]]ArrayPlot[Mod[Table[StirlingS2[n, m], {n, 0, 100}, {m, 0, 100}], 2]]Define a recursive function for generating set partitions:
setPartitions[{x_}] := {{{x}}};
setPartitions[{r__, x_}] := Apply[Join, ReplaceList[#, {b___, {S__}, a___} | {b__} :> {b, {S, x}, a}]& /@ setPartitions[{r}]]Generate all set partitions of n elements:
n = 4;
parts = setPartitions[Range[n]]Count the number of set partitions that have 1, 2, … n disjoint subsets:
KeySort[Counts[Length /@ parts]]The Stirling number of the second kind counts the number of disjoint subsets:
StirlingS2[n, Range[n]]Closed form of derivatives of compositions with exponential functions:
D[f[Exp[z]], {z, 6}]Sum[Exp[k z] StirlingS2[6, k]Derivative[k][f][Exp[z]], {k, 6}]A fair
‐sided die is thrown
times independently. The probability that all faces appear at least once is given in terms of Stirling numbers of the second kind:
classicalOccupancyPr[n_, r_] := (r!/r^n)StirlingS2[n, r]Plot the probability for a six-sided die:
DiscretePlot[classicalOccupancyPr[n, 6], {n, 5, 24}]With[{n = 12, rep = 10 ^ 5}, Map[If[Complement[Range[6], #] === {}, 1.0, 0.0]&, RandomVariate[DiscreteUniformDistribution[{1, 6}], {rep, n}]]]//MeanclassicalOccupancyPr[12, 6]//NProperties & Relations (7)
Generate values from the ordinary generating function:
Series[BellB[12, t], {t, 0, 5}]Table[StirlingS2[12, m], {m, 5}]Generate values from the exponential generating function:
With[{n = 12},
Table[n! / m!SeriesCoefficient[Series[(E^t - 1)^m, {t, 0, n}], n], {m, 5}]]Table[StirlingS2[12, m] , {m, 5}]Stirling numbers of the second kind are effectively inverses of Stirling numbers of the first kind:
Table[Sum[StirlingS2[l, n] StirlingS1[m, l], {l, 0, Max[m, n] + 1}], {n, 0, 6}, {m, 0, 6}]//MatrixFormCalculate large Stirling numbers of the second kind using Cauchy's theorem:
With[{n = 120, m = 10, ρ = 10}, Re[-n! / m! NIntegrate[Evaluate[(Exp[x] - 1) ^ m / (x ^ (n + 1)) ρ Exp[I φ] /. x -> ρ Exp[I φ]], {φ, 0, 2Pi}]] / (I 2Pi)]StirlingS2[120, 10]//NGenerate Stirling numbers of the second kind from the commutation relation
:
s___⊗a⊗a^†⊗t___ := s⊗a^†⊗a⊗t + s⊗ta^†⊗a⊗a^†⊗a⊗a^†⊗a⊗a^†⊗a⊗a^†⊗a⊗a^†⊗aSum[StirlingS2[6, k] CircleTimes@@Flatten[{Array[a^†&, k], Array[a&, k]}], {k, 6}]The limit of finite differences of powers are Stirling numbers of the second kind:
Nest[(# /. x -> x + 1) - #&, x ^ 10, 4] / 4!% /. x -> 0StirlingS2[10, 4]Stirling numbers of the second kind are given by a partial Bell polynomial with unit arguments:
Table[BellY[n, m, Table[1, {n}]], {n, 6}, {m, 1, n}]Table[StirlingS2[n, m], {n, 6}, {m, 1, n}]Possible Issues (2)
StirlingS2 can take large values for moderate‐size arguments:
StirlingS2[1000, 500]//ShortN[%]The value at
is defined to be 1:
StirlingS2[0, 0]Neat Examples (2)
ArrayPlot[Table[Total[IntegerDigits[StirlingS2[n, m]]], {n, 36}, {m, 36}]]Determinants of a matrix with Stirling number entries:
Table[Det @ Table[(i!/(i + j)!) StirlingS2[i + j, i], {i, 0, n}, {j, 0, n}], {n, 6}]Table[2^-n (n + 1) / 2, {n, 6}]Tech Notes
Related Guides
Related Links
History
Introduced in 1988 (1.0)
Text
Wolfram Research (1988), StirlingS2, Wolfram Language function, https://reference.wolfram.com/language/ref/StirlingS2.html.
CMS
Wolfram Language. 1988. "StirlingS2." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/StirlingS2.html.
APA
Wolfram Language. (1988). StirlingS2. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/StirlingS2.html
BibTeX
@misc{reference.wolfram_2026_stirlings2, author="Wolfram Research", title="{StirlingS2}", year="1988", howpublished="\url{https://reference.wolfram.com/language/ref/StirlingS2.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_stirlings2, organization={Wolfram Research}, title={StirlingS2}, year={1988}, url={https://reference.wolfram.com/language/ref/StirlingS2.html}, note=[Accessed: 13-June-2026]}