Lah numbers

From Fōrmulæ wiki
Jump to: navigation, search

This page is a solution to the task Lah numbers in the Rosetta Code, written in Fōrmulæ.

Description (from Rosetta Code)

Lah numbers, sometimes referred to as Stirling numbers of the third kind, are coefficients of polynomial expansions expressing rising factorials in terms of falling factorials.

Unsigned Lah numbers count the number of ways a set of n elements can be partitioned into k non-empty linearly ordered subsets.

Lah numbers are closely related to Stirling numbers of the first & second kinds, and may be derived from them.

Lah numbers obey the identities and relations:

   L(n, 0), L(0, k) = 0 # for n, k > 0
   L(n, n) = 1
   L(n, 1) = n!
   L(n, k) =           ( n! * (n - 1)! ) / ( k! * (k - 1)! ) / (n - k)!      # For unsigned Lah numbers
     or
   L(n, k) = (-1)**n * ( n! * (n - 1)! ) / ( k! * (k - 1)! ) / (n - k)!      # For signed Lah numbers
Task
  • Write a routine (function, procedure, whatever) to find unsigned Lah numbers. There are several methods to generate unsigned Lah numbers. You are free to choose the most appropriate for your language. If your language has a built-in, or easily, publicly available library implementation, it is acceptable to use that.
  • Using the routine, generate and show here, on this page, a table (or triangle) showing the unsigned Lah numbers, L(n, k), up to L(12, 12). it is optional to show the row / column for n == 0 and k == 0. It is optional to show places where L(n, k) == 0 (when k > n).
  • If your language supports large integers, find and show here, on this page, the maximum value of L(n, k) where n == 100.
See also


Related Tasks

Solution

A single solution for signed and unsigned versions is presented. Unsigned version uses 1 as factor, signed version used -1.

LahNumbersCode01.png

Table up to L(12, 12), unsigned version:

LahNumbersOutput01a.png

Table up to L(12, 12), signed version:

LahNumbersOutput01b.png

Extra

Maximum value of L(100, k) for k ≤ 100, unsigned version:

LahNumbersSnippet02a.png

Maximum value of L(100, k) for k ≤ 100, signed version:

LahNumbersSnippet02b.png

(The result is the same that the previous one)