Mathlib.Data.Nat.Choose.Basic
63 declarations. Mathlib docs · Source
Binomial coefficients
This file defines binomial coefficients and proves simple lemmas (i.e. those not
requiring more imports).
For the lemma that n.choose k counts the k-element-subsets of an n-element set,
see Finset.card_powersetCard in Mathlib/Data/Finset/Powerset.lean.
Main definition and results
Nat.choose: binomial coefficients, defined inductivelyNat.choose_eq_factorial_div_factorial: a proof thatchoose n k = n! / (k! * (n - k)!)Nat.choose_symm: symmetry of binomial coefficientsNat.choose_le_succ_of_lt_half_left:choose n kis increasing for small values ofkNat.choose_le_middle:choose n ris maximised whenrisn/2Nat.descFactorial_eq_factorial_mul_choose: Relates binomial coefficients to the descending factorial. This is used to proveNat.choose_le_powand variants. We provide similar statements for the ascending factorial.Nat.multichoose: whereaschoosecounts combinations,multichoosecounts multicombinations. The fact that this is indeed the correct counting function for multisets is proved inSym.card_sym_eq_multichooseinData.Sym.Card.Nat.multichoose_eq: a proof thatmultichoose n k = (n + k - 1).choose k. This is central to the "stars and bars" technique in informal mathematics, where we switch between counting multisets of sizekover an alphabet of sizento counting strings ofkelements ("stars") separated byn-1dividers ("bars"). SeeData.Sym.Cardfor more detail.
Tags
binomial coefficient, combination, multicombination, stars and bars
Inequalities
Inequalities about increasing the first argument
Multichoose
Whereas choose n k is the number of subsets of cardinality k from a type of cardinality n,
multichoose n k is the number of multisets of cardinality k from a type of cardinality n.
Alternatively, whereas choose n k counts the number of combinations,
i.e. ways to select k items (up to permutation) from n items without replacement,
multichoose n k counts the number of multicombinations,
i.e. ways to select k items (up to permutation) from n items with replacement.
Note that multichoose is not the multinomial coefficient, although it can be computed
in terms of multinomial coefficients. For details see https://mathworld.wolfram.com/Multichoose.html
theorem Nat.choose.match_1.congr_eq_2 E1 #
∀ (motive : ℕ → ℕ → Sort u_1) (x x_1 : ℕ) (h_1 : (x : ℕ) → motive x 0) (h_2 : (n : ℕ) → motive 0 n.succ)
(h_3 : (n k : ℕ) → motive n.succ k.succ) (n : ℕ),
x = 0 →
x_1 = n.succ →
(match x, x_1 with
| x, 0 => h_1 x
| 0, n.succ => h_2 n
| n.succ, k.succ => h_3 n k) ≍
h_2 n
theorem Nat.choose.match_1.congr_eq_1 E1 #
∀ (motive : ℕ → ℕ → Sort u_1) (x x_1 : ℕ) (h_1 : (x : ℕ) → motive x 0) (h_2 : (n : ℕ) → motive 0 n.succ)
(h_3 : (n k : ℕ) → motive n.succ k.succ) (x_2 : ℕ),
x = x_2 →
x_1 = 0 →
(match x, x_1 with
| x, 0 => h_1 x
| 0, n.succ => h_2 n
| n.succ, k.succ => h_3 n k) ≍
h_1 x_2
theorem Nat.choose.match_1.congr_eq_3 E1 #
∀ (motive : ℕ → ℕ → Sort u_1) (x x_1 : ℕ) (h_1 : (x : ℕ) → motive x 0) (h_2 : (n : ℕ) → motive 0 n.succ)
(h_3 : (n k : ℕ) → motive n.succ k.succ) (n k : ℕ),
x = n.succ →
x_1 = k.succ →
(match x, x_1 with
| x, 0 => h_1 x
| 0, n.succ => h_2 n
| n.succ, k.succ => h_3 n k) ≍
h_3 n k
def Nat.choose E3 #
ℕ → ℕ → ℕ
choose n k is the number of k-element subsets in an n-element set. Also known as binomial
coefficients. For the fact that this is the number of k-element-subsets of an n-element
set, see Finset.card_powersetCard.
theorem Nat.choose_zero_right E0 #
∀ (n : ℕ), n.choose 0 = 1
theorem Nat.choose_zero_succ E0 #
∀ (k : ℕ), Nat.choose 0 k.succ = 0
theorem Nat.choose_succ_succ E1 #
∀ (n k : ℕ), n.succ.choose k.succ = n.choose k + n.choose k.succ
theorem Nat.choose_succ_succ' E1 #
∀ (n k : ℕ), (n + 1).choose (k + 1) = n.choose k + n.choose (k + 1)
theorem Nat.choose_succ_left E1 #
∀ (n k : ℕ), 0 < k → (n + 1).choose k = n.choose (k - 1) + n.choose k
theorem Nat.choose_succ_right E1 #
∀ (n k : ℕ), 0 < n → n.choose (k + 1) = (n - 1).choose k + (n - 1).choose (k + 1)
theorem Nat.choose_eq_choose_pred_add E1 #
∀ {n k : ℕ}, 0 < n → 0 < k → n.choose k = (n - 1).choose (k - 1) + (n - 1).choose k
theorem Nat.choose_eq_zero_of_lt E1 #
∀ {n k : ℕ}, n < k → n.choose k = 0
theorem Nat.choose_self E0 #
∀ (n : ℕ), n.choose n = 1
theorem Nat.choose_succ_self E0 #
∀ (n : ℕ), n.choose n.succ = 0
theorem Nat.choose_one_right E0 #
∀ (n : ℕ), n.choose 1 = n
theorem Nat.triangle_succ E1 #
∀ (n : ℕ), (n + 1) * (n + 1 - 1) / 2 = n * (n - 1) / 2 + n
theorem Nat.choose_two_right E1 #
∀ (n : ℕ), n.choose 2 = n * (n - 1) / 2
choose n 2 is the n-th triangle number.
theorem Nat.choose_pos E1 #
∀ {n k : ℕ}, k ≤ n → 0 < n.choose k
theorem Nat.choose_eq_zero_iff E0 #
∀ {n k : ℕ}, n.choose k = 0 ↔ n < k
theorem Nat.choose_ne_zero_iff E0 #
∀ {n k : ℕ}, n.choose k ≠ 0 ↔ k ≤ n
theorem Nat.choose_ne_zero E1 #
∀ {n k : ℕ}, k ≤ n → n.choose k ≠ 0
theorem Nat.add_one_mul_choose_eq E0 #
∀ (n k : ℕ), (n + 1) * n.choose k = (n + 1).choose (k + 1) * (k + 1)
theorem Nat.choose_mul_factorial_mul_factorial E1 #
∀ {n k : ℕ}, k ≤ n → n.choose k * k.factorial * (n - k).factorial = n.factorial
theorem Nat.choose_mul E1 #
∀ {n k s : ℕ}, s ≤ k → n.choose k * k.choose s = n.choose s * (n - s).choose (k - s)
theorem Nat.choose_eq_factorial_div_factorial E1 #
∀ {n k : ℕ}, k ≤ n → n.choose k = n.factorial / (k.factorial * (n - k).factorial)
theorem Nat.add_choose E1 #
∀ (i j : ℕ), (i + j).choose j = (i + j).factorial / (i.factorial * j.factorial)
theorem Nat.add_choose_mul_factorial_mul_factorial E1 #
∀ (i j : ℕ), (i + j).choose j * i.factorial * j.factorial = (i + j).factorial
theorem Nat.factorial_mul_factorial_dvd_factorial E1 #
∀ {n k : ℕ}, k ≤ n → k.factorial * (n - k).factorial ∣ n.factorial
theorem Nat.factorial_mul_factorial_dvd_factorial_add E1 #
∀ (i j : ℕ), i.factorial * j.factorial ∣ (i + j).factorial
theorem Nat.choose_symm E0 #
∀ {n k : ℕ}, k ≤ n → n.choose (n - k) = n.choose k
theorem Nat.choose_symm_of_eq_add E1 #
∀ {n a b : ℕ}, n = a + b → n.choose a = n.choose b
theorem Nat.choose_symm_add E1 #
∀ {a b : ℕ}, (a + b).choose a = (a + b).choose b
theorem Nat.choose_symm_half E1 #
∀ (m : ℕ), (2 * m + 1).choose (m + 1) = (2 * m + 1).choose m
theorem Nat.choose_succ_right_eq E0 #
∀ (n k : ℕ), n.choose (k + 1) * (k + 1) = n.choose k * (n - k)
theorem Nat.choose_succ_self_right E0 #
∀ (n : ℕ), (n + 1).choose n = n + 1
theorem Nat.choose_mul_succ_eq E0 #
∀ (n k : ℕ), n.choose k * (n + 1) = (n + 1).choose k * (n + 1 - k)
theorem Nat.choose_mul_add E1 #
∀ {m n : ℕ}, n ≠ 0 → (m * n + n).choose n = (m + 1) * (m * n + n - 1).choose (n - 1)
theorem Nat.choose_mul_right E1 #
∀ {m n : ℕ}, n ≠ 0 → (m * n).choose n = m * (m * n - 1).choose (n - 1)
theorem Nat.ascFactorial_eq_factorial_mul_choose E1 #
∀ (n k : ℕ), (n + 1).ascFactorial k = k.factorial * (n + k).choose k
theorem Nat.ascFactorial_eq_factorial_mul_choose' E1 #
∀ (n k : ℕ), n.ascFactorial k = k.factorial * (n + k - 1).choose k
theorem Nat.factorial_dvd_ascFactorial E1 #
∀ (n k : ℕ), k.factorial ∣ n.ascFactorial k
theorem Nat.choose_eq_asc_factorial_div_factorial E1 #
∀ (n k : ℕ), (n + k).choose k = (n + 1).ascFactorial k / k.factorial
theorem Nat.choose_eq_asc_factorial_div_factorial' E1 #
∀ (n k : ℕ), (n + k - 1).choose k = n.ascFactorial k / k.factorial
theorem Nat.descFactorial_eq_factorial_mul_choose E1 #
∀ (n k : ℕ), n.descFactorial k = k.factorial * n.choose k
theorem Nat.factorial_dvd_descFactorial E1 #
∀ (n k : ℕ), k.factorial ∣ n.descFactorial k
theorem Nat.choose_eq_descFactorial_div_factorial E1 #
∀ (n k : ℕ), n.choose k = n.descFactorial k / k.factorial
def Nat.fast_choose E1 #
ℕ → ℕ → ℕ
A faster implementation of choose, to be used during bytecode evaluation
and in compiled code.
theorem Nat.choose_eq_fast_choose E1 #
Nat.choose = Nat.fast_choose
theorem Nat.choose_le_succ_of_lt_half_left E1 #
∀ {r n : ℕ}, r < n / 2 → n.choose r ≤ n.choose (r + 1)
Show that Nat.choose is increasing for small values of the right argument.
theorem Nat.choose_le_middle E1 #
∀ (r n : ℕ), n.choose r ≤ n.choose (n / 2)
choose n r is maximised when r is n/2.
theorem Nat.choose_le_succ E1 #
∀ (a c : ℕ), a.choose c ≤ a.succ.choose c
theorem Nat.choose_le_add E1 #
∀ (a b c : ℕ), a.choose c ≤ (a + b).choose c
theorem Nat.choose_le_choose E1 #
∀ {a b : ℕ} (c : ℕ), a ≤ b → a.choose c ≤ b.choose c
theorem Nat.choose_mono E1 #
∀ (b : ℕ), Monotone fun a ↦ a.choose b
theorem Nat.choose_eq_one_iff E0 #
∀ {n k : ℕ}, n.choose k = 1 ↔ k = 0 ∨ n = k
def Nat.multichoose E1 #
ℕ → ℕ → ℕ
multichoose n k is the number of multisets of cardinality k from a type of cardinality n.
theorem Nat.multichoose_zero_right E0 #
∀ (n : ℕ), n.multichoose 0 = 1
theorem Nat.multichoose_zero_succ E0 #
∀ (k : ℕ), Nat.multichoose 0 (k + 1) = 0
theorem Nat.multichoose_succ_succ E1 #
∀ (n k : ℕ), (n + 1).multichoose (k + 1) = n.multichoose (k + 1) + (n + 1).multichoose k
theorem Nat.multichoose_one E0 #
∀ (k : ℕ), Nat.multichoose 1 k = 1
theorem Nat.multichoose_two E0 #
∀ (k : ℕ), Nat.multichoose 2 k = k + 1
theorem Nat.multichoose_one_right E0 #
∀ (n : ℕ), n.multichoose 1 = n
theorem Nat.multichoose_eq E0 #
∀ (n k : ℕ), n.multichoose k = (n + k - 1).choose k