Stirling Numbers Calculator
First Kind · Second Kind · Bell Numbers · Triangular Tables
Compute S(n,k) (set partitions), s(n,k) (permutation cycles), and B(n) (Bell numbers) with full recurrence steps and triangular tables.
Quick Examples
Recurrence Relations Used
S(n,k) = k·S(n-1,k) + S(n-1,k-1)
S(0,0)=1 S(n,0)=0 S(0,k)=0
s(n,k) = (n-1)·s(n-1,k) + s(n-1,k-1)
s(0,0)=1 s(n,0)=0 s(0,k)=0
2nd KindStep-by-Step Recurrence for S(n,k)
| n \ k | k cols |
|---|
1st KindStep-by-Step Recurrence for s(n,k)
| n \ k | k cols |
|---|
2nd KindStirling Numbers S(n,k) — Triangle
Number of ways to partition n elements into k non-empty subsets.
1st KindStirling Numbers s(n,k) — Triangle
Number of permutations of n elements with exactly k cycles.
BellBell Numbers B(0) through B(n)
| n | B(n) | = Sum S(n,k) | Meaning |
|---|
Bell Triangle (Aitken's Array)
Each row starts with the last element of the previous row. Each subsequent element is the sum of the element to its left and the element directly above that left element. The first element of each row is a Bell number.
Bell Number Formulas
B(n+1) = ∑k=0n C(n,k) · B(k) (recurrence via binomial)
B(0)=1, B(1)=1, B(2)=2, B(3)=5, B(4)=15, B(5)=52, B(6)=203
What Are Stirling Numbers?
Stirling numbers are two families of integers introduced by the Scottish mathematician James Stirling (1692–1770) in his 1730 work Methodus Differentialis. They arise naturally in combinatorics, probability, and analysis, and appear in formulas connecting ordinary powers to falling factorials and vice versa. Today, Stirling numbers are fundamental objects in enumerative combinatorics and appear in the study of permutations, set partitions, generating functions, and probability distributions.
Stirling Numbers of the Second Kind — S(n, k)
The Stirling number of the second kind S(n, k) (also written {n choose k} with curly braces, or sometimes denoted S(n,k)) counts the number of ways to partition a set of n distinct elements into k non-empty, unordered subsets. These subsets are unordered, meaning the partition {1,2},{3,4} is the same as {3,4},{1,2}.
The key recurrence is:
S(n,k) = k · S(n-1,k) + S(n-1,k-1)
The combinatorial proof: given the n-th element, it either joins one of the k existing blocks (k choices — hence k·S(n-1,k)) or forms its own new singleton block (S(n-1,k-1)). Base cases are S(0,0)=1 and S(n,0)=S(0,k)=0 for n,k > 0.
Small Values of S(n,k)
| n \ k | 0 | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|---|
| 0 | 1 | 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 | 0 | 0 | 0 |
| 2 | 0 | 1 | 1 | 0 | 0 | 0 |
| 3 | 0 | 1 | 3 | 1 | 0 | 0 |
| 4 | 0 | 1 | 7 | 6 | 1 | 0 |
| 5 | 0 | 1 | 15 | 25 | 10 | 1 |
Stirling Numbers of the First Kind — s(n, k)
The unsigned Stirling number of the first kind s(n, k) counts the number of permutations of n elements that have exactly k disjoint cycles. For example, the permutation (1 2 3)(4 5) of {1,2,3,4,5} has 2 cycles, so it is counted in s(5,2).
The recurrence is:
s(n,k) = (n-1) · s(n-1,k) + s(n-1,k-1)
Here, the n-th element either extends one of the (n-1) existing elements in a cycle by inserting itself after it ((n-1)·s(n-1,k) ways), or forms its own new 1-cycle (s(n-1,k-1) ways). The signed Stirling numbers of the first kind are ⌊n k⌋ = (-1)^(n-k) · s(n,k) and appear in the expansion of falling factorials.
Bell Numbers — B(n)
Bell numbers B(n) count the total number of partitions of an n-element set, summing across all possible numbers of blocks:
B(n) = S(n,0) + S(n,1) + ··· + S(n,n)
Bell numbers grow super-exponentially. The sequence begins: B(0)=1, B(1)=1, B(2)=2, B(3)=5, B(4)=15, B(5)=52, B(6)=203, B(7)=877, B(8)=4140, B(9)=21147, B(10)=115975. They satisfy the recurrence B(n+1) = ∑k=0n C(n,k)·B(k).
Connections to Falling Factorials and Binomial Coefficients
One of the most elegant relationships in combinatorics is the connection between ordinary powers and falling factorials via Stirling numbers:
- 2nd kind: xn = ∑k=0n S(n,k) · x(k), where x(k) = x(x-1)···(x-k+1) is the falling factorial.
- 1st kind: x(n) = ∑k=0n s(n,k) · xk (unsigned, with appropriate signs for the signed version).
- S(n,k) relates to binomial coefficients via: S(n,k) = (1/k!) ∑j=0k (-1)k-j C(k,j) jn.
Applications in Probability and Combinatorics
- Set Partitions: S(n,k) directly counts the number of ways to cluster n objects into k groups — a problem appearing in machine learning, chemistry (molecular bond configurations), and database theory.
- Moments and Cumulants: The moments of a Poisson distribution with parameter λ are expressed via Bell polynomials built from Stirling numbers.
- Occupancy Problems: The probability that n randomly thrown balls fill exactly k of m urns involves S(n,k) in its formula.
- Permutation Statistics: s(n,k) counts permutations by cycle structure, directly relevant to random permutation theory and card shuffle analysis.
- Generating Functions: The ordinary generating function for S(n,k) in n is xk/((1-x)(1-2x)···(1-kx)). Bell numbers have the exponential generating function e^(e^x - 1).
James Stirling — Historical Background
James Stirling was born in Garden, Stirlingshire, Scotland in 1692. He studied at Oxford and later worked in Venice before returning to Scotland. His masterwork Methodus Differentialis (1730) systematically studied differences and series of factorial form, where the Stirling numbers first appeared explicitly. Stirling is also famous for Stirling's approximation: n! ≈ √(2πn) · (n/e)n, which provides an accurate estimate of factorial growth and is used throughout probability, statistical mechanics, and information theory.