Documentation

Mathlib.Data.Nat.Choose.Basic

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 #

Tags #

binomial coefficient, combination, multicombination, stars and bars

def Nat.choose :
ℕ → ℕ → ℕ

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.

Equations
Instances For
    @[simp]
    theorem Nat.choose_zero_right (n : ℕ) :
    n.choose 0 = 1
    @[simp]
    theorem Nat.choose_zero_succ (k : ℕ) :
    choose 0 k.succ = 0
    theorem Nat.choose_succ_succ' (n k : ℕ) :
    (n + 1).choose (k + 1) = n.choose k + n.choose (k + 1)
    theorem Nat.choose_succ_left (n k : ℕ) (hk : 0 < k) :
    (n + 1).choose k = n.choose (k - 1) + n.choose k
    theorem Nat.choose_succ_right (n k : ℕ) (hn : 0 < n) :
    n.choose (k + 1) = (n - 1).choose k + (n - 1).choose (k + 1)
    theorem Nat.choose_eq_choose_pred_add {n k : ℕ} (hn : 0 < n) (hk : 0 < k) :
    n.choose k = (n - 1).choose (k - 1) + (n - 1).choose k
    theorem Nat.choose_eq_zero_of_lt {n k : ℕ} :
    n < k → n.choose k = 0
    @[simp]
    theorem Nat.choose_self (n : ℕ) :
    n.choose n = 1
    @[simp]
    theorem Nat.choose_succ_self (n : ℕ) :
    n.choose n.succ = 0
    @[simp]
    theorem Nat.choose_one_right (n : ℕ) :
    n.choose 1 = n
    theorem Nat.triangle_succ (n : ℕ) :
    (n + 1) * (n + 1 - 1) / 2 = n * (n - 1) / 2 + n
    theorem Nat.choose_two_right (n : ℕ) :
    n.choose 2 = n * (n - 1) / 2

    choose n 2 is the n-th triangle number.

    theorem Nat.choose_pos {n k : ℕ} :
    k ≤ n → 0 < n.choose k
    theorem Nat.choose_eq_zero_iff {n k : ℕ} :
    n.choose k = 0 ↔ n < k
    theorem Nat.choose_ne_zero_iff {n k : ℕ} :
    n.choose k ≠ 0 ↔ k ≤ n
    theorem Nat.choose_ne_zero {n k : ℕ} (h : k ≤ n) :
    n.choose k ≠ 0
    theorem Nat.add_one_mul_choose_eq (n k : ℕ) :
    (n + 1) * n.choose k = (n + 1).choose (k + 1) * (k + 1)
    theorem Nat.choose_mul {n k s : ℕ} (hsk : s ≤ k) :
    n.choose k * k.choose s = n.choose s * (n - s).choose (k - s)
    theorem Nat.add_choose (i j : ℕ) :
    (i + j).choose j = (i + j).factorial / (i.factorial * j.factorial)
    @[simp]
    theorem Nat.choose_symm {n k : ℕ} (hk : k ≤ n) :
    n.choose (n - k) = n.choose k
    theorem Nat.choose_symm_of_eq_add {n a b : ℕ} (h : n = a + b) :
    n.choose a = n.choose b
    theorem Nat.choose_symm_add {a b : ℕ} :
    (a + b).choose a = (a + b).choose b
    theorem Nat.choose_symm_half (m : ℕ) :
    (2 * m + 1).choose (m + 1) = (2 * m + 1).choose m
    theorem Nat.choose_succ_right_eq (n k : ℕ) :
    n.choose (k + 1) * (k + 1) = n.choose k * (n - k)
    @[simp]
    theorem Nat.choose_succ_self_right (n : ℕ) :
    (n + 1).choose n = n + 1
    theorem Nat.choose_mul_succ_eq (n k : ℕ) :
    n.choose k * (n + 1) = (n + 1).choose k * (n + 1 - k)
    theorem Nat.choose_mul_add {m n : ℕ} (hn : n ≠ 0) :
    (m * n + n).choose n = (m + 1) * (m * n + n - 1).choose (n - 1)
    theorem Nat.choose_mul_right {m n : ℕ} (hn : n ≠ 0) :
    (m * n).choose n = m * (m * n - 1).choose (n - 1)
    def Nat.fast_choose (n k : ℕ) :

    A faster implementation of choose, to be used during bytecode evaluation and in compiled code.

    Equations
    Instances For

      Inequalities #

      theorem Nat.choose_le_succ_of_lt_half_left {r n : ℕ} (h : 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 (r n : ℕ) :
      n.choose r ≤ n.choose (n / 2)

      choose n r is maximised when r is n/2.

      Inequalities about increasing the first argument #

      theorem Nat.choose_le_add (a b c : ℕ) :
      a.choose c ≤ (a + b).choose c
      theorem Nat.choose_le_choose {a b : ℕ} (c : ℕ) (h : a ≤ b) :
      a.choose c ≤ b.choose c
      theorem Nat.choose_mono (b : ℕ) :
      Monotone fun (a : ℕ) => a.choose b
      theorem Nat.choose_eq_one_iff {n k : ℕ} :
      n.choose k = 1 ↔ k = 0 ∨ n = k

      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

      @[irreducible]
      def Nat.multichoose :
      ℕ → ℕ → ℕ

      multichoose n k is the number of multisets of cardinality k from a type of cardinality n.

      Equations
      Instances For
        @[simp]
        @[simp]
        theorem Nat.multichoose_zero_succ (k : ℕ) :
        multichoose 0 (k + 1) = 0
        theorem Nat.multichoose_succ_succ (n k : ℕ) :
        (n + 1).multichoose (k + 1) = n.multichoose (k + 1) + (n + 1).multichoose k
        @[simp]
        theorem Nat.multichoose_one (k : ℕ) :
        @[simp]
        theorem Nat.multichoose_two (k : ℕ) :
        multichoose 2 k = k + 1
        @[simp]
        theorem Nat.multichoose_eq (n k : ℕ) :
        n.multichoose k = (n + k - 1).choose k