mathlib documentation

combinatorics.pigeonhole

Pigeonhole principles

Given pigeons (possibly infinitely many) in pigeonholes, the pigeonhole principle states that, if there are more pigeons than pigeonholes, then there is a pigeonhole with two or more pigeons.

There are a few variations on this statement, and the conclusion can be made stronger depending on how many pigeons you know you might have.

The basic statements of the pigeonhole principle appear in the following locations:

This module gives access to these pigeonhole principles along with 20 more. The versions vary by:

Lemma names follow mathlib convention (e.g., finset.exists_lt_sum_fiber_of_maps_to_of_nsmul_lt_sum); "pigeonhole principle" is mentioned in the docstrings instead of the names.

See also

Tags

pigeonhole principle

The pigeonhole principles on finsets, pigeons counted by weight

In this section we prove the following version of the pigeonhole principle: if the total weight of a finite set of pigeons is greater than n •ℕ b, and they are sorted into n pigeonholes, then for some pigeonhole, the total weight of the pigeons in this pigeonhole is greateer than b, and a few variations of this theorem.

The principle is formalized in the following way, see finset.exists_lt_sum_fiber_of_maps_to_of_nsmul_lt_sum: if f : α → β is a function which maps all elements of s : finset α to t : finset β and card t •ℕ b < ∑ x in s, w x, where w : α → M is a weight function taking values in a linear_ordered_cancel_add_comm_monoid, then for some y ∈ t, the sum of the weights of all x ∈ s such that f x = y is greater than b.

There are a few bits we can change in this theorem:

We can do all these variations independently, so we have eight versions of the theorem.

Strict inequality versions

theorem finset.exists_lt_sum_fiber_of_maps_to_of_nsmul_lt_sum {α : Type u} {β : Type v} {M : Type w} [linear_ordered_cancel_add_comm_monoid M] [decidable_eq β] {s : finset α} {t : finset β} {f : α → β} {w : α → M} {b : M} (hf : ∀ (a : α), a sf a t) (hb : t.card •ℕ b < ∑ (x : α) in s, w x) :
∃ (y : β) (H : y t), b < ∑ (x : α) in finset.filter (λ (x : α), f x = y) s, w x

The pigeonhole principle for finitely many pigeons counted by weight, strict inequality version: if the total weight of a finite set of pigeons is greater than n •ℕ b, and they are sorted into n pigeonholes, then for some pigeonhole, the total weight of the pigeons in this pigeonhole is greater than b.

theorem finset.exists_sum_fiber_lt_of_maps_to_of_sum_lt_nsmul {α : Type u} {β : Type v} {M : Type w} [linear_ordered_cancel_add_comm_monoid M] [decidable_eq β] {s : finset α} {t : finset β} {f : α → β} {w : α → M} {b : M} (hf : ∀ (a : α), a sf a t) (hb : ∑ (x : α) in s, w x < t.card •ℕ b) :
∃ (y : β) (H : y t), ∑ (x : α) in finset.filter (λ (x : α), f x = y) s, w x < b

The pigeonhole principle for finitely many pigeons counted by weight, strict inequality version: if the total weight of a finite set of pigeons is less than n •ℕ b, and they are sorted into n pigeonholes, then for some pigeonhole, the total weight of the pigeons in this pigeonhole is less than b.

theorem finset.exists_lt_sum_fiber_of_sum_fiber_nonpos_of_nsmul_lt_sum {α : Type u} {β : Type v} {M : Type w} [linear_ordered_cancel_add_comm_monoid M] [decidable_eq β] {s : finset α} {t : finset β} {f : α → β} {w : α → M} {b : M} (ht : ∀ (y : β), y t∑ (x : α) in finset.filter (λ (x : α), f x = y) s, w x 0) (hb : t.card •ℕ b < ∑ (x : α) in s, w x) :
∃ (y : β) (H : y t), b < ∑ (x : α) in finset.filter (λ (x : α), f x = y) s, w x

The pigeonhole principle for finitely many pigeons counted by weight, strict inequality version: if the total weight of a finite set of pigeons is greater than n •ℕ b, they are sorted into some pigeonholes, and for all but n pigeonholes the total weight of the pigeons there is nonpositive, then for at least one of these n pigeonholes, the total weight of the pigeons in this pigeonhole is greater than b.

theorem finset.exists_sum_fiber_lt_of_sum_fiber_nonneg_of_sum_lt_nsmul {α : Type u} {β : Type v} {M : Type w} [linear_ordered_cancel_add_comm_monoid M] [decidable_eq β] {s : finset α} {t : finset β} {f : α → β} {w : α → M} {b : M} (ht : ∀ (y : β), y t0 ∑ (x : α) in finset.filter (λ (x : α), f x = y) s, w x) (hb : ∑ (x : α) in s, w x < t.card •ℕ b) :
∃ (y : β) (H : y t), ∑ (x : α) in finset.filter (λ (x : α), f x = y) s, w x < b

The pigeonhole principle for finitely many pigeons counted by weight, strict inequality version: if the total weight of a finite set of pigeons is less than n •ℕ b, they are sorted into some pigeonholes, and for all but n pigeonholes the total weight of the pigeons there is nonnegative, then for at least one of these n pigeonholes, the total weight of the pigeons in this pigeonhole is less than b.

Non-strict inequality versions

theorem finset.exists_le_sum_fiber_of_maps_to_of_nsmul_le_sum {α : Type u} {β : Type v} {M : Type w} [linear_ordered_cancel_add_comm_monoid M] [decidable_eq β] {s : finset α} {t : finset β} {f : α → β} {w : α → M} {b : M} (hf : ∀ (a : α), a sf a t) (ht : t.nonempty) (hb : t.card •ℕ b ∑ (x : α) in s, w x) :
∃ (y : β) (H : y t), b ∑ (x : α) in finset.filter (λ (x : α), f x = y) s, w x

The pigeonhole principle for finitely many pigeons counted by weight, non-strict inequality version: if the total weight of a finite set of pigeons is greater than or equal to n •ℕ b, and they are sorted into n > 0 pigeonholes, then for some pigeonhole, the total weight of the pigeons in this pigeonhole is greater than or equal to b.

theorem finset.exists_sum_fiber_le_of_maps_to_of_sum_le_nsmul {α : Type u} {β : Type v} {M : Type w} [linear_ordered_cancel_add_comm_monoid M] [decidable_eq β] {s : finset α} {t : finset β} {f : α → β} {w : α → M} {b : M} (hf : ∀ (a : α), a sf a t) (ht : t.nonempty) (hb : ∑ (x : α) in s, w x t.card •ℕ b) :
∃ (y : β) (H : y t), ∑ (x : α) in finset.filter (λ (x : α), f x = y) s, w x b

The pigeonhole principle for finitely many pigeons counted by weight, non-strict inequality version: if the total weight of a finite set of pigeons is less than or equal to n •ℕ b, and they are sorted into n > 0 pigeonholes, then for some pigeonhole, the total weight of the pigeons in this pigeonhole is less than or equal to b.

theorem finset.exists_le_sum_fiber_of_sum_fiber_nonpos_of_nsmul_le_sum {α : Type u} {β : Type v} {M : Type w} [linear_ordered_cancel_add_comm_monoid M] [decidable_eq β] {s : finset α} {t : finset β} {f : α → β} {w : α → M} {b : M} (hf : ∀ (y : β), y t∑ (x : α) in finset.filter (λ (x : α), f x = y) s, w x 0) (ht : t.nonempty) (hb : t.card •ℕ b ∑ (x : α) in s, w x) :
∃ (y : β) (H : y t), b ∑ (x : α) in finset.filter (λ (x : α), f x = y) s, w x

The pigeonhole principle for finitely many pigeons counted by weight, non-strict inequality version: if the total weight of a finite set of pigeons is greater than or equal to n •ℕ b, they are sorted into some pigeonholes, and for all but n > 0 pigeonholes the total weight of the pigeons there is nonpositive, then for at least one of these n pigeonholes, the total weight of the pigeons in this pigeonhole is greater than or equal to b.

theorem finset.exists_sum_fiber_le_of_sum_fiber_nonneg_of_sum_le_nsmul {α : Type u} {β : Type v} {M : Type w} [linear_ordered_cancel_add_comm_monoid M] [decidable_eq β] {s : finset α} {t : finset β} {f : α → β} {w : α → M} {b : M} (hf : ∀ (y : β), y t0 ∑ (x : α) in finset.filter (λ (x : α), f x = y) s, w x) (ht : t.nonempty) (hb : ∑ (x : α) in s, w x t.card •ℕ b) :
∃ (y : β) (H : y t), ∑ (x : α) in finset.filter (λ (x : α), f x = y) s, w x b

The pigeonhole principle for finitely many pigeons counted by weight, non-strict inequality version: if the total weight of a finite set of pigeons is less than or equal to n •ℕ b, they are sorted into some pigeonholes, and for all but n > 0 pigeonholes the total weight of the pigeons there is nonnegative, then for at least one of these n pigeonholes, the total weight of the pigeons in this pigeonhole is less than or equal to b.

The pigeonhole principles on finsets, pigeons counted by heads

In this section we formalize a few versions of the following pigeonhole principle: there is a pigeonhole with at least as many pigeons as the ceiling of the average number of pigeons across all pigeonholes.

First, we can use strict or non-strict inequalities. While the versions with non-strict inequalities are weaker than those with strict inequalities, sometimes it might be more convenient to apply the weaker version. Second, we can either state that there exists a pigeonhole with at least n pigeons, or state that there exists a pigeonhole with at most n pigeons. In the latter case we do not need the assumption ∀ a ∈ s, f a ∈ t.

So, we prove four theorems: finset.exists_lt_card_fiber_of_maps_to_of_mul_lt_card, finset.exists_le_card_fiber_of_maps_to_of_mul_le_card, finset.exists_card_fiber_lt_of_card_lt_mul, and finset.exists_card_fiber_le_of_card_le_mul.

theorem finset.exists_lt_card_fiber_of_mul_lt_card_of_maps_to {α : Type u} {β : Type v} [decidable_eq β] {s : finset α} {t : finset β} {f : α → β} {n : } (hf : ∀ (a : α), a sf a t) (hn : (t.card) * n < s.card) :
∃ (y : β) (H : y t), n < (finset.filter (λ (x : α), f x = y) s).card

The pigeonhole principle for finitely many pigeons counted by heads: there is a pigeonhole with at least as many pigeons as the ceiling of the average number of pigeons across all pigeonholes. ("The maximum is at least the mean" specialized to integers.)

More formally, given a function between finite sets s and t and a natural number n such that card t * n < card s, there exists y ∈ t such that its preimage in s has more than n elements.

theorem finset.exists_card_fiber_lt_of_card_lt_mul {α : Type u} {β : Type v} [decidable_eq β] {s : finset α} {t : finset β} {f : α → β} {n : } (hn : s.card < (t.card) * n) :
∃ (y : β) (H : y t), (finset.filter (λ (x : α), f x = y) s).card < n

The pigeonhole principle for finitely many pigeons counted by heads: there is a pigeonhole with at most as many pigeons as the floor of the average number of pigeons across all pigeonholes. ("The minimum is at most the mean" specialized to integers.)

More formally, given a function f, a finite sets s in its domain, a finite set t in its codomain, and a natural number n such that card s < card t * n, there exists y ∈ t such that its preimage in s has less than n elements.

theorem finset.exists_le_card_fiber_of_mul_le_card_of_maps_to {α : Type u} {β : Type v} [decidable_eq β] {s : finset α} {t : finset β} {f : α → β} {n : } (hf : ∀ (a : α), a sf a t) (ht : t.nonempty) (hn : (t.card) * n s.card) :
∃ (y : β) (H : y t), n (finset.filter (λ (x : α), f x = y) s).card

The pigeonhole principle for finitely many pigeons counted by heads: given a function between finite sets s and t and a natural number n such that card t * n ≤ card s, there exists y ∈ t such that its preimage in s has at least n elements. See also finset.exists_lt_card_fiber_of_mul_lt_card_of_maps_to for a stronger statement.

theorem finset.exists_card_fiber_le_of_card_le_mul {α : Type u} {β : Type v} [decidable_eq β] {s : finset α} {t : finset β} {f : α → β} {n : } (ht : t.nonempty) (hn : s.card (t.card) * n) :
∃ (y : β) (H : y t), (finset.filter (λ (x : α), f x = y) s).card n

The pigeonhole principle for finitely many pigeons counted by heads: given a function f, a finite sets s in its domain, a finite set t in its codomain, and a natural number n such that card s ≤ card t * n, there exists y ∈ t such that its preimage in s has no more than n elements. See also finset.exists_card_fiber_lt_of_card_lt_mul for a stronger statement.

The pigeonhole principles on fintypess, pigeons counted by weight

In this section we specialize theorems from the previous section to the special case of functions between fintypes and s = univ, t = univ. In this case the assumption ∀ x ∈ s, f x ∈ t always holds, so we have four theorems instead of eight.

theorem fintype.exists_lt_sum_fiber_of_nsmul_lt_sum {α : Type u} {β : Type v} {M : Type w} [linear_ordered_cancel_add_comm_monoid M] [decidable_eq β] [fintype α] [fintype β] (f : α → β) {w : α → M} {b : M} (hb : fintype.card β •ℕ b < ∑ (x : α), w x) :
∃ (y : β), b < ∑ (x : α) in finset.filter (λ (x : α), f x = y) finset.univ, w x

The pigeonhole principle for finitely many pigeons of different weights, strict inequality version: there is a pigeonhole with the total weight of pigeons in it greater than b provided that the total number of pigeonholes times b is less than the total weight of all pigeons.

theorem fintype.exists_le_sum_fiber_of_nsmul_le_sum {α : Type u} {β : Type v} {M : Type w} [linear_ordered_cancel_add_comm_monoid M] [decidable_eq β] [fintype α] [fintype β] (f : α → β) {w : α → M} {b : M} [nonempty β] (hb : fintype.card β •ℕ b ∑ (x : α), w x) :
∃ (y : β), b ∑ (x : α) in finset.filter (λ (x : α), f x = y) finset.univ, w x

The pigeonhole principle for finitely many pigeons of different weights, non-strict inequality version: there is a pigeonhole with the total weight of pigeons in it greater than or equal to b provided that the total number of pigeonholes times b is less than or equal to the total weight of all pigeons.

theorem fintype.exists_sum_fiber_lt_of_sum_lt_nsmul {α : Type u} {β : Type v} {M : Type w} [linear_ordered_cancel_add_comm_monoid M] [decidable_eq β] [fintype α] [fintype β] (f : α → β) {w : α → M} {b : M} (hb : ∑ (x : α), w x < fintype.card β •ℕ b) :
∃ (y : β), ∑ (x : α) in finset.filter (λ (x : α), f x = y) finset.univ, w x < b

The pigeonhole principle for finitely many pigeons of different weights, strict inequality version: there is a pigeonhole with the total weight of pigeons in it less than b provided that the total number of pigeonholes times b is greater than the total weight of all pigeons.

theorem fintype.exists_sum_fiber_le_of_sum_le_nsmul {α : Type u} {β : Type v} {M : Type w} [linear_ordered_cancel_add_comm_monoid M] [decidable_eq β] [fintype α] [fintype β] (f : α → β) {w : α → M} {b : M} [nonempty β] (hb : ∑ (x : α), w x fintype.card β •ℕ b) :
∃ (y : β), ∑ (x : α) in finset.filter (λ (x : α), f x = y) finset.univ, w x b

The pigeonhole principle for finitely many pigeons of different weights, non-strict inequality version: there is a pigeonhole with the total weight of pigeons in it less than or equal to b provided that the total number of pigeonholes times b is greater than or equal to the total weight of all pigeons.

theorem fintype.exists_lt_card_fiber_of_mul_lt_card {α : Type u} {β : Type v} [decidable_eq β] [fintype α] [fintype β] (f : α → β) {n : } (hn : (fintype.card β) * n < fintype.card α) :
∃ (y : β), n < (finset.filter (λ (x : α), f x = y) finset.univ).card

The strong pigeonhole principle for finitely many pigeons and pigeonholes. There is a pigeonhole with at least as many pigeons as the ceiling of the average number of pigeons across all pigeonholes. ("The maximum is at least the mean" specialized to integers.)

More formally, given a function f between finite types α and β and a number n such that card β * n < card α, there exists an element y : β such that its preimage has more than n elements.

theorem fintype.exists_card_fiber_lt_of_card_lt_mul {α : Type u} {β : Type v} [decidable_eq β] [fintype α] [fintype β] (f : α → β) {n : } (hn : fintype.card α < (fintype.card β) * n) :
∃ (y : β), (finset.filter (λ (x : α), f x = y) finset.univ).card < n

The strong pigeonhole principle for finitely many pigeons and pigeonholes. There is a pigeonhole with at most as many pigeons as the floor of the average number of pigeons across all pigeonholes. ("The minimum is at most the mean" specialized to integers.)

More formally, given a function f between finite types α and β and a number n such that card α < card β * n, there exists an element y : β such that its preimage has less than n elements.

theorem fintype.exists_le_card_fiber_of_mul_le_card {α : Type u} {β : Type v} [decidable_eq β] [fintype α] [fintype β] (f : α → β) {n : } [nonempty β] (hn : (fintype.card β) * n fintype.card α) :
∃ (y : β), n (finset.filter (λ (x : α), f x = y) finset.univ).card

The strong pigeonhole principle for finitely many pigeons and pigeonholes. Given a function f between finite types α and β and a number n such that card β * n ≤ card α, there exists an element y : β such that its preimage has at least n elements. See also fintype.exists_lt_card_fiber_of_mul_lt_card for a stronger statement.

theorem fintype.exists_card_fiber_le_of_card_le_mul {α : Type u} {β : Type v} [decidable_eq β] [fintype α] [fintype β] (f : α → β) {n : } [nonempty β] (hn : fintype.card α (fintype.card β) * n) :
∃ (y : β), (finset.filter (λ (x : α), f x = y) finset.univ).card n

The strong pigeonhole principle for finitely many pigeons and pigeonholes. Given a function f between finite types α and β and a number n such that card α ≤ card β * n, there exists an element y : β such that its preimage has at most n elements. See also fintype.exists_card_fiber_lt_of_card_lt_mul for a stronger statement.