Stirling numbers of the first kind
This page is a solution to the task Stirling numbers of the first kind in the Rosetta Code, written in Fōrmulæ.
Description (from Rosetta Code)
Stirling numbers of the first kind, or Stirling cycle numbers, count permutations according to their number
of cycles (counting fixed points as cycles of length one). They may be defined directly to be the number of permutations of n elements with k disjoint cycles. Stirling numbers of the first kind express coefficients of polynomial expansions of falling or rising factorials. Depending on the application, Stirling numbers of the first kind may be "signed" or "unsigned". Signed Stirling numbers of the first kind arise when the polynomial expansion is expressed in terms of falling factorials; unsigned when expressed in terms of rising factorials. The only substantial difference is that, for signed Stirling numbers of the first kind, values of S1(n, k) are negative when n + k is odd. Stirling numbers of the first kind follow the simple identities: S1(0, 0) = 1 S1(n, 0) = 0 if n > 0 S1(n, k) = 0 if k > n S1(n, k) = S1(n - 1, k - 1) + (n - 1) * S1(n - 1, k) # For unsigned or S1(n, k) = S1(n - 1, k - 1) - (n - 1) * S1(n - 1, k) # For signed
|
Solution
A single solution for signed and unsigned versions is presented. Unsigned version uses 1 as factor, signed version used -1.
Recursive
Table for unsigned version:
Table for unsigned version:
Non recursive
A faster, non recursive version is presented:
Table for unsigned version:
(The result is the same as recursive version)
Table for signed version:
(The result is the same as recursive version)
Extra
For unsigned version:
For signed version: