The areas / V30. Combinatorics
Mathlib.Combinatorics.Enumerative.Stirling
27 declarations. Mathlib docs · Source
Stirling Numbers
This file defines Stirling numbers of the first and second kinds, proves their fundamental recurrence relations, and establishes some of their key properties and identities.
The Stirling numbers of the first kind
The unsigned Stirling numbers of the first kind, represent the number of ways
to partition n distinct elements into k non-empty cycles.
The Stirling numbers of the second kind
The Stirling numbers of the second kind, represent the number of ways to partition
n distinct elements into k non-empty subsets.
Main definitions
Nat.stirlingFirst: the number of ways to partitionndistinct elements intoknon-empty cycles, defined by the recursive relationship it satisfies.Nat.stirlingSecond: the number of ways to partitionndistinct elements intoknon-empty subsets, defined by the recursive relationship it satisfies.
Main results
Nat.pow_eq_sum_stirlingSecond_mul_descFactorial: every powern ^ kis a linear combination of the descending factorialsNat.descFactorialwith the Stirling numbers of the second kind as coefficients.
References
- [Knuth, The Art of Computer Programming, Volume 1, §1.2.6][knuth1997]
theorem Nat.stirlingFirst.match_1.congr_eq_4 E1 #
∀ (motive : ℕ → ℕ → Sort u_1) (x x_1 : ℕ) (h_1 : Unit → motive 0 0) (h_2 : (n : ℕ) → motive 0 n.succ)
(h_3 : (n : ℕ) → motive n.succ 0) (h_4 : (n k : ℕ) → motive n.succ k.succ) (n k : ℕ),
x = n.succ →
x_1 = k.succ →
(match x, x_1 with
| 0, 0 => h_1 ()
| 0, n.succ => h_2 n
| n.succ, 0 => h_3 n
| n.succ, k.succ => h_4 n k) ≍
h_4 n k
theorem Nat.stirlingFirst.match_1.congr_eq_2 E1 #
∀ (motive : ℕ → ℕ → Sort u_1) (x x_1 : ℕ) (h_1 : Unit → motive 0 0) (h_2 : (n : ℕ) → motive 0 n.succ)
(h_3 : (n : ℕ) → motive n.succ 0) (h_4 : (n k : ℕ) → motive n.succ k.succ) (n : ℕ),
x = 0 →
x_1 = n.succ →
(match x, x_1 with
| 0, 0 => h_1 ()
| 0, n.succ => h_2 n
| n.succ, 0 => h_3 n
| n.succ, k.succ => h_4 n k) ≍
h_2 n
theorem Nat.stirlingFirst.match_1.congr_eq_3 E1 #
∀ (motive : ℕ → ℕ → Sort u_1) (x x_1 : ℕ) (h_1 : Unit → motive 0 0) (h_2 : (n : ℕ) → motive 0 n.succ)
(h_3 : (n : ℕ) → motive n.succ 0) (h_4 : (n k : ℕ) → motive n.succ k.succ) (n : ℕ),
x = n.succ →
x_1 = 0 →
(match x, x_1 with
| 0, 0 => h_1 ()
| 0, n.succ => h_2 n
| n.succ, 0 => h_3 n
| n.succ, k.succ => h_4 n k) ≍
h_3 n
theorem Nat.stirlingFirst.match_1.congr_eq_1 E1 #
∀ (motive : ℕ → ℕ → Sort u_1) (x x_1 : ℕ) (h_1 : Unit → motive 0 0) (h_2 : (n : ℕ) → motive 0 n.succ)
(h_3 : (n : ℕ) → motive n.succ 0) (h_4 : (n k : ℕ) → motive n.succ k.succ),
x = 0 →
x_1 = 0 →
(match x, x_1 with
| 0, 0 => h_1 ()
| 0, n.succ => h_2 n
| n.succ, 0 => h_3 n
| n.succ, k.succ => h_4 n k) ≍
h_1 ()
def Nat.stirlingFirst E3 #
ℕ → ℕ → ℕ
Nat.stirlingFirst n k is the (unsigned) Stirling number of the first kind,
counting the number of permutations of n elements with exactly k disjoint cycles.
theorem Nat.stirlingFirst_zero E0 #
Nat.stirlingFirst 0 0 = 1
theorem Nat.stirlingFirst_zero_succ E0 #
∀ (k : ℕ), Nat.stirlingFirst 0 k.succ = 0
theorem Nat.stirlingFirst_succ_zero E0 #
∀ (n : ℕ), n.succ.stirlingFirst 0 = 0
theorem Nat.stirlingFirst_succ_left E1 #
∀ (n k : ℕ), k ≠ 0 → (n + 1).stirlingFirst k = n * n.stirlingFirst k + n.stirlingFirst (k - 1)
theorem Nat.stirlingFirst_succ_right E1 #
∀ (n k : ℕ), n ≠ 0 → n.stirlingFirst (k + 1) = (n - 1) * (n - 1).stirlingFirst (k + 1) + (n - 1).stirlingFirst k
theorem Nat.stirlingFirst_succ_succ E1 #
∀ (n k : ℕ), (n + 1).stirlingFirst (k + 1) = n * n.stirlingFirst (k + 1) + n.stirlingFirst k
theorem Nat.stirlingFirst_eq_zero_of_lt E1 #
∀ {n k : ℕ}, n < k → n.stirlingFirst k = 0
theorem Nat.stirlingFirst_self E1 #
∀ (n : ℕ), n.stirlingFirst n = 1
theorem Nat.stirlingFirst_succ_self_left E1 #
∀ (n : ℕ), (n + 1).stirlingFirst n = (n + 1).choose 2
theorem Nat.stirlingFirst_one_right E1 #
∀ (n : ℕ), (n + 1).stirlingFirst 1 = n.factorial
def Nat.stirlingSecond E3 #
ℕ → ℕ → ℕ
Nat.stirlingSecond n k is the Stirling number of the second kind,
counting the number of ways to partition a set of n elements into k nonempty subsets.
theorem Nat.stirlingSecond_zero E0 #
Nat.stirlingSecond 0 0 = 1
theorem Nat.stirlingSecond_zero_succ E0 #
∀ (k : ℕ), Nat.stirlingSecond 0 k.succ = 0
theorem Nat.stirlingSecond_succ_zero E0 #
∀ (n : ℕ), n.succ.stirlingSecond 0 = 0
theorem Nat.stirlingSecond_succ_left E1 #
∀ (n k : ℕ), k ≠ 0 → (n + 1).stirlingSecond k = k * n.stirlingSecond k + n.stirlingSecond (k - 1)
theorem Nat.stirlingSecond_succ_right E1 #
∀ (n k : ℕ), n ≠ 0 → n.stirlingSecond (k + 1) = (k + 1) * (n - 1).stirlingSecond (k + 1) + (n - 1).stirlingSecond k
theorem Nat.stirlingSecond_succ_succ E1 #
∀ (n k : ℕ), (n + 1).stirlingSecond (k + 1) = (k + 1) * n.stirlingSecond (k + 1) + n.stirlingSecond k
theorem Nat.stirlingSecond_eq_zero_of_lt E1 #
∀ {n k : ℕ}, n < k → n.stirlingSecond k = 0
theorem Nat.stirlingSecond_self E1 #
∀ (n : ℕ), n.stirlingSecond n = 1
theorem Nat.stirlingSecond_one_right E1 #
∀ (n : ℕ), (n + 1).stirlingSecond 1 = 1
theorem Nat.stirlingSecond_succ_self_left E1 #
∀ (n : ℕ), (n + 1).stirlingSecond n = (n + 1).choose 2
theorem Nat.pow_eq_sum_stirlingSecond_mul_descFactorial E3 #
∀ (n k : ℕ), n ^ k = ∑ j ∈ Finset.range (k + 1), k.stirlingSecond j * n.descFactorial j
Every power n ^ k is a linear combination of the descending factorials n.descFactorial j
with the Stirling numbers of the second kind stirlingSecond k j as coefficients.