The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V30. Combinatorics

Mathlib.Combinatorics.Enumerative.DoubleCounting

27 declarations. Mathlib docs · Source

Double counting

This file gathers a few double counting arguments.

Bipartite graphs

In a bipartite graph (considered as a relation r : α → β → Prop), we can bound the number of edges between s : Finset α and t : Finset β by the minimum/maximum of edges over all a ∈ s times the size of s. Similarly for t. Combining those two yields inequalities between the sizes of s and t.

  • bipartiteBelow: s.bipartiteBelow r b are the elements of s below b w.r.t. r. Its size is the number of edges of b in s.
  • bipartiteAbove: t.bipartite_Above r a are the elements of t above a w.r.t. r. Its size is the number of edges of a in t.
  • card_mul_le_card_mul, card_mul_le_card_mul': Double counting the edges of a bipartite graph from below and from above.
  • card_mul_eq_card_mul: Equality combination of the previous.

Implementation notes

For the formulation of double-counting arguments where a bipartite graph is considered as a bipartite simple graph G : SimpleGraph V, see Mathlib/Combinatorics/SimpleGraph/Bipartite.lean.

Bipartite graph

theorem Finset.bipartiteAbove.congr_simp E1 #

∀ {α : Type u_2} {β : Type u_3} (r r_1 : α → β → Prop),
  r = r_1 →
    ∀ (t t_1 : Finset β),
      t = t_1 →
        ∀ (a a_1 : α),
          a = a_1 →
            ∀ {inst : DecidablePred (r a)} [inst_1 : DecidablePred (r_1 a_1)],
              Finset.bipartiteAbove r t a = Finset.bipartiteAbove r_1 t_1 a_1

theorem Finset.bipartiteBelow.congr_simp E1 #

∀ {α : Type u_2} {β : Type u_3} (r r_1 : α → β → Prop),
  r = r_1 →
    ∀ (s s_1 : Finset α),
      s = s_1 →
        ∀ (b b_1 : β),
          b = b_1 →
            ∀ {inst : (a : α) → Decidable (r a b)} [inst_1 : (a : α) → Decidable (r_1 a b_1)],
              Finset.bipartiteBelow r s b = Finset.bipartiteBelow r_1 s_1 b_1

def Finset.bipartiteBelow E1 #

{α : Type u_2} → {β : Type u_3} → (r : α → β → Prop) → Finset α → (b : β) → [(a : α) → Decidable (r a b)] → Finset α

Elements of s which are "below" b according to relation r.

def Finset.bipartiteAbove E1 #

{α : Type u_2} → {β : Type u_3} → (r : α → β → Prop) → Finset β → (a : α) → [DecidablePred (r a)] → Finset β

Elements of t which are "above" a according to relation r.

theorem Finset.bipartiteBelow_swap E1 #

∀ {α : Type u_2} {β : Type u_3} (r : α → β → Prop) (t : Finset β) (a : α) [inst : DecidablePred (r a)],
  Finset.bipartiteBelow (Function.swap r) t a = Finset.bipartiteAbove r t a

theorem Finset.bipartiteAbove_swap E1 #

∀ {α : Type u_2} {β : Type u_3} (r : α → β → Prop) (s : Finset α) (b : β) [inst : (a : α) → Decidable (r a b)],
  Finset.bipartiteAbove (Function.swap r) s b = Finset.bipartiteBelow r s b

theorem Finset.coe_bipartiteBelow E0 #

∀ {α : Type u_2} {β : Type u_3} (r : α → β → Prop) (s : Finset α) (b : β) [inst : (a : α) → Decidable (r a b)],
  ↑(Finset.bipartiteBelow r s b) = {a | a ∈ s ∧ r a b}

theorem Finset.coe_bipartiteAbove E0 #

∀ {α : Type u_2} {β : Type u_3} (r : α → β → Prop) (t : Finset β) (a : α) [inst : DecidablePred (r a)],
  ↑(Finset.bipartiteAbove r t a) = {b | b ∈ t ∧ r a b}

theorem Finset.mem_bipartiteBelow E0 #

∀ {α : Type u_2} {β : Type u_3} (r : α → β → Prop) {s : Finset α} {b : β} [inst : (a : α) → Decidable (r a b)] {a : α},
  a ∈ Finset.bipartiteBelow r s b ↔ a ∈ s ∧ r a b

theorem Finset.mem_bipartiteAbove E0 #

∀ {α : Type u_2} {β : Type u_3} (r : α → β → Prop) {t : Finset β} {a : α} [inst : DecidablePred (r a)] {b : β},
  b ∈ Finset.bipartiteAbove r t a ↔ b ∈ t ∧ r a b

theorem Finset.sum_sum_bipartiteAbove_eq_sum_sum_bipartiteBelow E1 #

∀ {R : Type u_1} {α : Type u_2} {β : Type u_3} (r : α → β → Prop) {s : Finset α} {t : Finset β} [inst : AddCommMonoid R]
  (f : α → β → R) [inst_1 : (a : α) → (b : β) → Decidable (r a b)],
  ∑ a ∈ s, ∑ b ∈ Finset.bipartiteAbove r t a, f a b = ∑ b ∈ t, ∑ a ∈ Finset.bipartiteBelow r s b, f a b

theorem Finset.prod_prod_bipartiteAbove_eq_prod_prod_bipartiteBelow E1 #

∀ {R : Type u_1} {α : Type u_2} {β : Type u_3} (r : α → β → Prop) {s : Finset α} {t : Finset β} [inst : CommMonoid R]
  (f : α → β → R) [inst_1 : (a : α) → (b : β) → Decidable (r a b)],
  ∏ a ∈ s, ∏ b ∈ Finset.bipartiteAbove r t a, f a b = ∏ b ∈ t, ∏ a ∈ Finset.bipartiteBelow r s b, f a b

theorem Finset.sum_card_bipartiteAbove_eq_sum_card_bipartiteBelow E1 #

∀ {α : Type u_2} {β : Type u_3} (r : α → β → Prop) {s : Finset α} {t : Finset β}
  [inst : (a : α) → (b : β) → Decidable (r a b)],
  ∑ a ∈ s, (Finset.bipartiteAbove r t a).card = ∑ b ∈ t, (Finset.bipartiteBelow r s b).card

theorem Finset.card_nsmul_le_card_nsmul E1 #

∀ {R : Type u_1} {α : Type u_2} {β : Type u_3} (r : α → β → Prop) {s : Finset α} {t : Finset β} [inst : Semiring R]
  [inst_1 : PartialOrder R] [IsOrderedRing R] {m n : R} [inst_3 : (a : α) → (b : β) → Decidable (r a b)],
  (∀ a ∈ s, m ≤ ↑(Finset.bipartiteAbove r t a).card) →
    (∀ b ∈ t, ↑(Finset.bipartiteBelow r s b).card ≤ n) → s.card • m ≤ t.card • n

Double counting argument.

Considering r as a bipartite graph, the LHS is a lower bound on the number of edges while the RHS is an upper bound.

theorem Finset.card_nsmul_le_card_nsmul' E1 #

∀ {R : Type u_1} {α : Type u_2} {β : Type u_3} (r : α → β → Prop) {s : Finset α} {t : Finset β} [inst : Semiring R]
  [inst_1 : PartialOrder R] [IsOrderedRing R] {m n : R} [inst_3 : (a : α) → (b : β) → Decidable (r a b)],
  (∀ b ∈ t, n ≤ ↑(Finset.bipartiteBelow r s b).card) →
    (∀ a ∈ s, ↑(Finset.bipartiteAbove r t a).card ≤ m) → t.card • n ≤ s.card • m

Double counting argument.

Considering r as a bipartite graph, the LHS is a lower bound on the number of edges while the RHS is an upper bound.

theorem Finset.card_nsmul_lt_card_nsmul_of_lt_of_le E1 #

∀ {R : Type u_1} {α : Type u_2} {β : Type u_3} [inst : Semiring R] [inst_1 : PartialOrder R] [IsStrictOrderedRing R]
  (r : α → β → Prop) {s : Finset α} {t : Finset β} {m n : R} [inst_3 : (a : α) → (b : β) → Decidable (r a b)],
  s.Nonempty →
    (∀ a ∈ s, m < ↑(Finset.bipartiteAbove r t a).card) →
      (∀ b ∈ t, ↑(Finset.bipartiteBelow r s b).card ≤ n) → s.card • m < t.card • n

Double counting argument.

Considering r as a bipartite graph, the LHS is a strict lower bound on the number of edges while the RHS is an upper bound.

theorem Finset.card_nsmul_lt_card_nsmul_of_le_of_lt E1 #

∀ {R : Type u_1} {α : Type u_2} {β : Type u_3} [inst : Semiring R] [inst_1 : PartialOrder R] [IsStrictOrderedRing R]
  (r : α → β → Prop) {s : Finset α} {t : Finset β} {m n : R} [inst_3 : (a : α) → (b : β) → Decidable (r a b)],
  t.Nonempty →
    (∀ a ∈ s, m ≤ ↑(Finset.bipartiteAbove r t a).card) →
      (∀ b ∈ t, ↑(Finset.bipartiteBelow r s b).card < n) → s.card • m < t.card • n

Double counting argument.

Considering r as a bipartite graph, the LHS is a lower bound on the number of edges while the RHS is a strict upper bound.

theorem Finset.card_nsmul_lt_card_nsmul_of_lt_of_le' E1 #

∀ {R : Type u_1} {α : Type u_2} {β : Type u_3} [inst : Semiring R] [inst_1 : PartialOrder R] [IsStrictOrderedRing R]
  (r : α → β → Prop) {s : Finset α} {t : Finset β} {m n : R} [inst_3 : (a : α) → (b : β) → Decidable (r a b)],
  t.Nonempty →
    (∀ b ∈ t, n < ↑(Finset.bipartiteBelow r s b).card) →
      (∀ a ∈ s, ↑(Finset.bipartiteAbove r t a).card ≤ m) → t.card • n < s.card • m

Double counting argument.

Considering r as a bipartite graph, the LHS is a strict lower bound on the number of edges while the RHS is an upper bound.

theorem Finset.card_nsmul_lt_card_nsmul_of_le_of_lt' E1 #

∀ {R : Type u_1} {α : Type u_2} {β : Type u_3} [inst : Semiring R] [inst_1 : PartialOrder R] [IsStrictOrderedRing R]
  (r : α → β → Prop) {s : Finset α} {t : Finset β} {m n : R} [inst_3 : (a : α) → (b : β) → Decidable (r a b)],
  s.Nonempty →
    (∀ b ∈ t, n ≤ ↑(Finset.bipartiteBelow r s b).card) →
      (∀ a ∈ s, ↑(Finset.bipartiteAbove r t a).card < m) → t.card • n < s.card • m

Double counting argument.

Considering r as a bipartite graph, the LHS is a lower bound on the number of edges while the RHS is a strict upper bound.

theorem Finset.card_mul_le_card_mul E1 #

∀ {α : Type u_2} {β : Type u_3} (r : α → β → Prop) {s : Finset α} {t : Finset β} {m n : ℕ}
  [inst : (a : α) → (b : β) → Decidable (r a b)],
  (∀ a ∈ s, m ≤ (Finset.bipartiteAbove r t a).card) →
    (∀ b ∈ t, (Finset.bipartiteBelow r s b).card ≤ n) → s.card * m ≤ t.card * n

Double counting argument.

Considering r as a bipartite graph, the LHS is a lower bound on the number of edges while the RHS is an upper bound.

theorem Finset.card_mul_le_card_mul' E1 #

∀ {α : Type u_2} {β : Type u_3} (r : α → β → Prop) {s : Finset α} {t : Finset β} {m n : ℕ}
  [inst : (a : α) → (b : β) → Decidable (r a b)],
  (∀ b ∈ t, n ≤ (Finset.bipartiteBelow r s b).card) →
    (∀ a ∈ s, (Finset.bipartiteAbove r t a).card ≤ m) → t.card * n ≤ s.card * m

theorem Finset.card_mul_eq_card_mul E1 #

∀ {α : Type u_2} {β : Type u_3} (r : α → β → Prop) {s : Finset α} {t : Finset β} {m n : ℕ}
  [inst : (a : α) → (b : β) → Decidable (r a b)],
  (∀ a ∈ s, (Finset.bipartiteAbove r t a).card = m) →
    (∀ b ∈ t, (Finset.bipartiteBelow r s b).card = n) → s.card * m = t.card * n

theorem Finset.card_le_card_of_forall_subsingleton E1 #

∀ {α : Type u_2} {β : Type u_3} (r : α → β → Prop) {s : Finset α} {t : Finset β},
  (∀ a ∈ s, ∃ b ∈ t, r a b) → (∀ b ∈ t, {a | a ∈ s ∧ r a b}.Subsingleton) → s.card ≤ t.card

theorem Finset.card_le_card_of_forall_subsingleton' E1 #

∀ {α : Type u_2} {β : Type u_3} (r : α → β → Prop) {s : Finset α} {t : Finset β},
  (∀ b ∈ t, ∃ a ∈ s, r a b) → (∀ a ∈ s, {b | b ∈ t ∧ r a b}.Subsingleton) → t.card ≤ s.card

theorem Finset.sum_card_eq_sum_biUnion_card E1 #

∀ {α : Type u_2} {β : Type u_3} [inst : Fintype α] [inst_1 : DecidableEq α] [inst_2 : DecidableEq β] (B : α → Finset β)
  (s : Finset α), ∑ j ∈ s, (B j).card = ∑ x ∈ s.biUnion B, {j | j ∈ s ∧ x ∈ B j}.card

Given a finite collection of finite subsets $B_1, \ldots, B_k$ and, for every $x \in \bigcup_i B_i$, let $C_x$ be the set of indices of the $B_i$'s that contain $x$. Then, $\sum_i |B_i| = \sum_x |C_x|$.

theorem Fintype.card_le_card_of_leftTotal_unique E1 #

∀ {α : Type u_2} {β : Type u_3} [inst : Fintype α] [inst_1 : Fintype β] {r : α → β → Prop},
  Relator.LeftTotal r → Relator.LeftUnique r → Fintype.card α ≤ Fintype.card β

theorem Fintype.card_le_card_of_rightTotal_unique E1 #

∀ {α : Type u_2} {β : Type u_3} [inst : Fintype α] [inst_1 : Fintype β] {r : α → β → Prop},
  Relator.RightTotal r → Relator.RightUnique r → Fintype.card β ≤ Fintype.card α