The areas / V30. Combinatorics
Mathlib.Combinatorics.Colex
70 declarations and 2 deprecated aliases. Mathlib docs · Source
Colexicographic order
We define the colex order for finite sets, and give a couple of important lemmas and properties relating to it.
The colex ordering likes to avoid large values: If the biggest element of t is bigger than all
elements of s, then s < t.
In the special case of ℕ, it can be thought of as the "binary" ordering. That is, order s based
on $∑_{i ∈ s} 2^i$. It's defined here on Finset α for any linear order α.
In the context of the Kruskal-Katona theorem, we are interested in how colex behaves for sets of a
fixed size. For example, for size 3, the colex order on ℕ starts
012, 013, 023, 123, 014, 024, 124, 034, 134, 234, ...
Main statements
- Colex order properties - linearity, decidability and so on.
Finset.Colex.forall_lt_mono: ifs < tin colex, and everything intis< a, then everything insis< a. This confirms the idea that an enumeration under colex will exhaust all sets using elements< abefore allowingato be included.Finset.toColex_image_le_toColex_image: Strictly monotone functions preserve colex.Finset.geomSum_le_geomSum_iff_toColex_le_toColex: Colex for α = ℕ is the same as binary. This also proves binary expansions are unique.
See also
Related files are:
Data.List.Lex: Lexicographic order on lists.Data.Pi.Lex: Lexicographic order onΠₗ i, α i.Order.PSigma: Lexicographic order onΣ' i, α i.Order.Sigma: Lexicographic order onΣ i, α i.Order.Prod.Lex.Basic: Lexicographic order onα × β.
TODO
- Generalise
Colex.initSegso that it applies toℕ.
References
- https://github.com/b-mehta/maths-notes/blob/master/iii/mich/combinatorics.pdf
Tags
colex, colexicographic, binary
Initial segments
Colex on ℕ
The colexicographic order agrees with the order induced by interpreting a set of naturals as a
n-ary expansion.
instance Finset.Colex.instLE E0 #
{α : Type u_1} → [PartialOrder α] → LE (Colex (Finset α))
instance Finset.Colex.instPartialOrder E0 #
{α : Type u_1} → [PartialOrder α] → PartialOrder (Colex (Finset α))
theorem Finset.Colex.le_def E0 #
∀ {α : Type u_1} [inst : PartialOrder α] {s t : Colex (Finset α)},
s ≤ t ↔ ∀ ⦃a : α⦄, a ∈ ofColex s → a ∉ ofColex t → ∃ b ∈ ofColex t, b ∉ ofColex s ∧ a ≤ b
theorem Finset.Colex.toColex_le_toColex E1 #
∀ {α : Type u_1} [inst : PartialOrder α] {s t : Finset α},
toColex s ≤ toColex t ↔ ∀ ⦃a : α⦄, a ∈ s → a ∉ t → ∃ b ∈ t, b ∉ s ∧ a ≤ b
theorem Finset.Colex.toColex_lt_toColex E1 #
∀ {α : Type u_1} [inst : PartialOrder α] {s t : Finset α},
toColex s < toColex t ↔ s ≠ t ∧ ∀ ⦃a : α⦄, a ∈ s → a ∉ t → ∃ b ∈ t, b ∉ s ∧ a ≤ b
theorem Finset.Colex.toColex_mono E1 #
∀ {α : Type u_1} [inst : PartialOrder α], Monotone ⇑toColex
If s ⊆ t, then s ≤ t in the colex order. Note the converse does not hold, as inclusion does
not form a linear order.
theorem Finset.Colex.toColex_strictMono E1 #
∀ {α : Type u_1} [inst : PartialOrder α], StrictMono ⇑toColex
If s ⊂ t, then s < t in the colex order. Note the converse does not hold, as inclusion does
not form a linear order.
theorem Finset.Colex.toColex_le_toColex_of_subset E1 #
∀ {α : Type u_1} [inst : PartialOrder α] {s t : Finset α}, s ⊆ t → toColex s ≤ toColex t
If s ⊆ t, then s ≤ t in the colex order. Note the converse does not hold, as inclusion does
not form a linear order.
theorem Finset.Colex.toColex_lt_toColex_of_ssubset E1 #
∀ {α : Type u_1} [inst : PartialOrder α] {s t : Finset α}, s ⊂ t → toColex s < toColex t
If s ⊂ t, then s < t in the colex order. Note the converse does not hold, as inclusion does
not form a linear order.
instance Finset.Colex.instOrderBot E0 #
{α : Type u_1} → [inst : PartialOrder α] → OrderBot (Colex (Finset α))
theorem Finset.Colex.toColex_empty E0 #
∀ {α : Type u_1} [inst : PartialOrder α], toColex ∅ = ⊥
theorem Finset.Colex.ofColex_bot E0 #
∀ {α : Type u_1} [inst : PartialOrder α], ofColex ⊥ = ∅
theorem Finset.Colex.forall_le_mono E1 #
∀ {α : Type u_1} [inst : PartialOrder α] {s t : Finset α} {a : α},
toColex s ≤ toColex t → (∀ b ∈ t, b ≤ a) → ∀ b ∈ s, b ≤ a
If s ≤ t in colex, and all elements in t are small, then all elements in s are small.
theorem Finset.Colex.forall_lt_mono E3 #
∀ {α : Type u_1} [inst : PartialOrder α] {s t : Finset α} {a : α},
toColex s ≤ toColex t → (∀ b ∈ t, b < a) → ∀ b ∈ s, b < a
If s ≤ t in colex, and all elements in t are small, then all elements in s are small.
theorem Finset.Colex.toColex_le_singleton E1 #
∀ {α : Type u_1} [inst : PartialOrder α] {s : Finset α} {a : α},
toColex s ≤ toColex {a} ↔ ∀ b ∈ s, b ≤ a ∧ (a ∈ s → b = a)
s ≤ {a} in colex iff all elements of s are strictly less than a, except possibly a in
which case s = {a}.
theorem Finset.Colex.toColex_lt_singleton E1 #
∀ {α : Type u_1} [inst : PartialOrder α] {s : Finset α} {a : α}, toColex s < toColex {a} ↔ ∀ b ∈ s, b < a
s < {a} in colex iff all elements of s are strictly less than a.
theorem Finset.Colex.singleton_le_toColex E1 #
∀ {α : Type u_1} [inst : PartialOrder α] {s : Finset α} {a : α}, toColex {a} ≤ toColex s ↔ ∃ x ∈ s, a ≤ x
{a} ≤ s in colex iff s contains an element greater than or equal to a.
theorem Finset.Colex.singleton_le_singleton E1 #
∀ {α : Type u_1} [inst : PartialOrder α] {a b : α}, toColex {a} ≤ toColex {b} ↔ a ≤ b
Colex is an extension of the base order.
theorem Finset.Colex.singleton_lt_singleton E1 #
∀ {α : Type u_1} [inst : PartialOrder α] {a b : α}, toColex {a} < toColex {b} ↔ a < b
Colex is an extension of the base order.
theorem Finset.Colex.le_iff_sdiff_subset_lowerClosure E1 #
∀ {α : Type u_1} [inst : PartialOrder α] {s t : Colex (Finset α)},
s ≤ t ↔ ↑(ofColex s) \ ↑(ofColex t) ⊆ ↑(lowerClosure (↑(ofColex t) \ ↑(ofColex s)))
instance Finset.Colex.instDecidableLE E0 #
{α : Type u_1} → [inst : PartialOrder α] → [DecidableEq α] → [DecidableLE α] → DecidableLE (Colex (Finset α))
instance Finset.Colex.instDecidableLT E0 #
{α : Type u_1} → [inst : PartialOrder α] → [DecidableEq α] → [DecidableLE α] → DecidableLT (Colex (Finset α))
theorem Finset.Colex.toColex_sdiff_le_toColex_sdiff E1 #
∀ {α : Type u_1} [inst : PartialOrder α] {s t u : Finset α} [inst_1 : DecidableEq α],
u ⊆ s → u ⊆ t → (toColex (s \ u) ≤ toColex (t \ u) ↔ toColex s ≤ toColex t)
The colexicographic order is insensitive to removing the same elements from both sets.
theorem Finset.Colex.toColex_sdiff_lt_toColex_sdiff E1 #
∀ {α : Type u_1} [inst : PartialOrder α] {s t u : Finset α} [inst_1 : DecidableEq α],
u ⊆ s → u ⊆ t → (toColex (s \ u) < toColex (t \ u) ↔ toColex s < toColex t)
The colexicographic order is insensitive to removing the same elements from both sets.
theorem Finset.Colex.toColex_sdiff_le_toColex_sdiff' E0 #
∀ {α : Type u_1} [inst : PartialOrder α] {s t : Finset α} [inst_1 : DecidableEq α],
toColex (s \ t) ≤ toColex (t \ s) ↔ toColex s ≤ toColex t
theorem Finset.Colex.toColex_sdiff_lt_toColex_sdiff' E0 #
∀ {α : Type u_1} [inst : PartialOrder α] {s t : Finset α} [inst_1 : DecidableEq α],
toColex (s \ t) < toColex (t \ s) ↔ toColex s < toColex t
theorem Finset.Colex.cons_le_cons E0 #
∀ {α : Type u_1} [inst : PartialOrder α] {s : Finset α} {a b : α} (ha : a ∉ s) (hb : b ∉ s),
toColex (Finset.cons a s ha) ≤ toColex (Finset.cons b s hb) ↔ a ≤ b
theorem Finset.Colex.cons_lt_cons E0 #
∀ {α : Type u_1} [inst : PartialOrder α] {s : Finset α} {a b : α} (ha : a ∉ s) (hb : b ∉ s),
toColex (Finset.cons a s ha) < toColex (Finset.cons b s hb) ↔ a < b
theorem Finset.Colex.insert_le_insert E1 #
∀ {α : Type u_1} [inst : PartialOrder α] {s : Finset α} {a b : α} [inst_1 : DecidableEq α],
a ∉ s → b ∉ s → (toColex (insert a s) ≤ toColex (insert b s) ↔ a ≤ b)
theorem Finset.Colex.insert_lt_insert E1 #
∀ {α : Type u_1} [inst : PartialOrder α] {s : Finset α} {a b : α} [inst_1 : DecidableEq α],
a ∉ s → b ∉ s → (toColex (insert a s) < toColex (insert b s) ↔ a < b)
theorem Finset.Colex.erase_le_erase E1 #
∀ {α : Type u_1} [inst : PartialOrder α] {s : Finset α} {a b : α} [inst_1 : DecidableEq α],
a ∈ s → b ∈ s → (toColex (s.erase a) ≤ toColex (s.erase b) ↔ b ≤ a)
theorem Finset.Colex.erase_lt_erase E1 #
∀ {α : Type u_1} [inst : PartialOrder α] {s : Finset α} {a b : α} [inst_1 : DecidableEq α],
a ∈ s → b ∈ s → (toColex (s.erase a) < toColex (s.erase b) ↔ b < a)
instance Finset.Colex.instLinearOrder E0 #
{α : Type u_1} → [LinearOrder α] → LinearOrder (Colex (Finset α))
theorem Finset.Colex.toColex_lt_toColex_iff_exists_forall_lt E1 #
∀ {α : Type u_1} [inst : LinearOrder α] {s t : Finset α},
toColex s < toColex t ↔ ∃ a ∈ t, a ∉ s ∧ ∀ b ∈ s, b ∉ t → b < a
theorem Finset.Colex.lt_iff_exists_forall_lt E1 #
∀ {α : Type u_1} [inst : LinearOrder α] {s t : Colex (Finset α)},
s < t ↔ ∃ a ∈ ofColex t, a ∉ ofColex s ∧ ∀ b ∈ ofColex s, b ∉ ofColex t → b < a
theorem Finset.Colex.toColex_le_toColex_iff_max'_mem E1 #
∀ {α : Type u_1} [inst : LinearOrder α] {s t : Finset α},
toColex s ≤ toColex t ↔ ∀ (hst : s ≠ t), (symmDiff s t).max' ⋯ ∈ t
theorem Finset.Colex.le_iff_max'_mem E1 #
∀ {α : Type u_1} [inst : LinearOrder α] {s t : Colex (Finset α)},
s ≤ t ↔ ∀ (h : s ≠ t), (symmDiff (ofColex s) (ofColex t)).max' ⋯ ∈ ofColex t
theorem Finset.Colex.toColex_lt_toColex_iff_max'_mem E1 #
∀ {α : Type u_1} [inst : LinearOrder α] {s t : Finset α},
toColex s < toColex t ↔ ∃ (hst : s ≠ t), (symmDiff s t).max' ⋯ ∈ t
theorem Finset.Colex.lt_iff_max'_mem E1 #
∀ {α : Type u_1} [inst : LinearOrder α] {s t : Colex (Finset α)},
s < t ↔ ∃ (h : s ≠ t), (symmDiff (ofColex s) (ofColex t)).max' ⋯ ∈ ofColex t
theorem Finset.Colex.lt_iff_exists_filter_lt E1 #
∀ {α : Type u_1} [inst : LinearOrder α] {s t : Finset α},
toColex s < toColex t ↔ ∃ w ∈ t \ s, {a ∈ s | w < a} = {a ∈ t | w < a}
theorem Finset.Colex.erase_le_erase_min' E1 #
∀ {α : Type u_1} [inst : LinearOrder α] {s t : Finset α} {a : α},
toColex s ≤ toColex t → ∀ (hcard : s.card ≤ t.card) (ha : a ∈ s), toColex (s.erase a) ≤ toColex (t.erase (t.min' ⋯))
If s ≤ t in colex and #s ≤ #t, then s \ {a} ≤ t \ {min t} for any a ∈ s.
theorem Finset.Colex.toColex_image_le_toColex_image E1 #
∀ {α : Type u_1} {β : Type u_2} [inst : LinearOrder α] [inst_1 : LinearOrder β] {f : α → β} {s t : Finset α},
StrictMono f → (toColex (Finset.image f s) ≤ toColex (Finset.image f t) ↔ toColex s ≤ toColex t)
Strictly monotone functions preserve the colex ordering.
theorem Finset.Colex.toColex_image_lt_toColex_image E1 #
∀ {α : Type u_1} {β : Type u_2} [inst : LinearOrder α] [inst_1 : LinearOrder β] {f : α → β} {s t : Finset α},
StrictMono f → (toColex (Finset.image f s) < toColex (Finset.image f t) ↔ toColex s < toColex t)
Strictly monotone functions preserve the colex ordering.
theorem Finset.Colex.toColex_image_ofColex_strictMono E1 #
∀ {α : Type u_1} {β : Type u_2} [inst : LinearOrder α] [inst_1 : LinearOrder β] {f : α → β},
StrictMono f → StrictMono fun s ↦ toColex (Finset.image f (ofColex s))
instance Finset.Colex.instBoundedOrder E0 #
{α : Type u_1} → [inst : LinearOrder α] → [Fintype α] → BoundedOrder (Colex (Finset α))
theorem Finset.Colex.toColex_univ E0 #
∀ {α : Type u_1} [inst : LinearOrder α] [inst_1 : Fintype α], toColex Finset.univ = ⊤
theorem Finset.Colex.ofColex_top E0 #
∀ {α : Type u_1} [inst : LinearOrder α] [inst_1 : Fintype α], ofColex ⊤ = Finset.univ
def Finset.Colex.IsInitSeg E1 #
{α : Type u_1} → [LinearOrder α] → Finset (Finset α) → ℕ → Prop
𝒜 is an initial segment of the colexicographic order on sets of r, and that if t is below
s in colex where t has size r and s is in 𝒜, then t is also in 𝒜. In effect, 𝒜 is
downwards closed with respect to colex among sets of size r.
theorem Finset.Colex.isInitSeg_empty E0 #
∀ {α : Type u_1} [inst : LinearOrder α] {r : ℕ}, Finset.Colex.IsInitSeg ∅ r
theorem Finset.Colex.IsInitSeg.total E1 #
∀ {α : Type u_1} [inst : LinearOrder α] {𝒜₁ 𝒜₂ : Finset (Finset α)} {r : ℕ},
Finset.Colex.IsInitSeg 𝒜₁ r → Finset.Colex.IsInitSeg 𝒜₂ r → 𝒜₁ ⊆ 𝒜₂ ∨ 𝒜₂ ⊆ 𝒜₁
Initial segments are nested in some way. In particular, if they're the same size they're equal.
def Finset.Colex.initSeg E1 #
{α : Type u_1} → [LinearOrder α] → [Fintype α] → Finset α → Finset (Finset α)
The initial segment of the colexicographic order on sets with #s elements and ending at
s.
theorem Finset.Colex.mem_initSeg E0 #
∀ {α : Type u_1} [inst : LinearOrder α] {s t : Finset α} [inst_1 : Fintype α],
t ∈ Finset.Colex.initSeg s ↔ s.card = t.card ∧ toColex t ≤ toColex s
theorem Finset.Colex.mem_initSeg_self E0 #
∀ {α : Type u_1} [inst : LinearOrder α] {s : Finset α} [inst_1 : Fintype α], s ∈ Finset.Colex.initSeg s
theorem Finset.Colex.initSeg_nonempty E0 #
∀ {α : Type u_1} [inst : LinearOrder α] {s : Finset α} [inst_1 : Fintype α], (Finset.Colex.initSeg s).Nonempty
theorem Finset.Colex.isInitSeg_initSeg E1 #
∀ {α : Type u_1} [inst : LinearOrder α] {s : Finset α} [inst_1 : Fintype α],
Finset.Colex.IsInitSeg (Finset.Colex.initSeg s) s.card
theorem Finset.Colex.IsInitSeg.exists_initSeg E1 #
∀ {α : Type u_1} [inst : LinearOrder α] {𝒜 : Finset (Finset α)} {r : ℕ} [inst_1 : Fintype α],
Finset.Colex.IsInitSeg 𝒜 r → 𝒜.Nonempty → ∃ s, s.card = r ∧ 𝒜 = Finset.Colex.initSeg s
theorem Finset.Colex.isInitSeg_iff_exists_initSeg E1 #
∀ {α : Type u_1} [inst : LinearOrder α] {𝒜 : Finset (Finset α)} {r : ℕ} [inst_1 : Fintype α],
Finset.Colex.IsInitSeg 𝒜 r ∧ 𝒜.Nonempty ↔ ∃ s, s.card = r ∧ 𝒜 = Finset.Colex.initSeg s
Being a nonempty initial segment of colex is equivalent to being an initSeg.
theorem Finset.geomSum_ofColex_strictMono E1 #
∀ {n : ℕ}, 2 ≤ n → StrictMono fun s ↦ ∑ k ∈ ofColex s, n ^ k
theorem Finset.geomSum_le_geomSum_iff_toColex_le_toColex E3 #
∀ {s t : Finset ℕ} {n : ℕ}, 2 ≤ n → (∑ k ∈ s, n ^ k ≤ ∑ k ∈ t, n ^ k ↔ toColex s ≤ toColex t)
For finsets of naturals, the colexicographic order is equivalent to the order induced by the
n-ary expansion.
theorem Finset.geomSum_lt_geomSum_iff_toColex_lt_toColex E1 #
∀ {s t : Finset ℕ} {n : ℕ}, 2 ≤ n → (∑ i ∈ s, n ^ i < ∑ i ∈ t, n ^ i ↔ toColex s < toColex t)
For finsets of naturals, the colexicographic order is equivalent to the order induced by the
n-ary expansion.
theorem Finset.geomSum_injective E1 #
∀ {n : ℕ}, 2 ≤ n → Function.Injective fun s ↦ ∑ i ∈ s, n ^ i
theorem Finset.lt_geomSum_of_mem E1 #
∀ {s : Finset ℕ} {n a : ℕ}, 2 ≤ n → a ∈ s → a < ∑ i ∈ s, n ^ i
theorem Finset.toFinset_bitIndices_sum_two_pow E0 #
∀ (s : Finset ℕ), (∑ i ∈ s, 2 ^ i).bitIndices.toFinset = s
theorem Finset.sum_toFinset_bitIndices_two_pow E0 #
∀ (n : ℕ), ∑ i ∈ n.bitIndices.toFinset, 2 ^ i = n
def Finset.equivBitIndices E1 #
ℕ ≃ Finset ℕ
The equivalence between ℕ and Finset ℕ that maps ∑ i ∈ s, 2^i to s.
theorem Finset.equivBitIndices_apply E0 #
∀ (n : ℕ), Finset.equivBitIndices n = n.bitIndices.toFinset
theorem Finset.equivBitIndices_symm_apply E0 #
∀ (s : Finset ℕ), Finset.equivBitIndices.symm s = ∑ i ∈ s, 2 ^ i
def Finset.orderIsoColex E1 #
ℕ ≃o Colex (Finset ℕ)
The equivalence Nat.equivBitIndices enumerates Finset ℕ in colexicographic order.
theorem Finset.orderIsoColex_symm_apply E0 #
∀ (s : Colex (Finset ℕ)), (RelIso.symm Finset.orderIsoColex) s = Finset.equivBitIndices.symm (ofColex s)
theorem Finset.orderIsoColex_apply E0 #
∀ (n : ℕ), Finset.orderIsoColex n = toColex (Finset.equivBitIndices n)
Deprecated aliases
| Name | New name | Since |
|---|---|---|
Finset.toFinset_bitIndices_twoPowSum | Finset.toFinset_bitIndices_sum_two_pow | 2026-05-15 |
Finset.twoPowSum_toFinset_bitIndices | Finset.sum_toFinset_bitIndices_two_pow | 2026-05-15 |