Documentation

CslibFrontier.Foundations.Order.Changes

Change counts, piece counts, and sorted groups #

A function has at most T changes when every nondecreasing sequence has at most T adjacent positions with unequal outputs, and at most M pieces when it is constant on the level sets of a monotone rank function with values below M. Sorting a finite set by a key and splitting it into consecutive groups yields a large group on which most functions in a finite family are constant. The key may have ties, and the size bound uses natural-number division.

Main definitions #

Main results #

References #

def Cslib.ChangesAtMost {α : Type u_1} {β : Type u_2} [Preorder α] (f : α → β) (T : ℕ) :

Every nondecreasing sequence has at most T adjacent changes under f.

theorem Cslib.ChangesAtMost.mono {α : Type u_1} {β : Type u_2} [Preorder α] {f : α → β} {T T' : ℕ} (h : ChangesAtMost f T) (hT : T ≤ T') :

Increasing a change bound preserves it.

theorem Cslib.ChangesAtMost.comp {α : Type u_1} {β : Type u_2} {γ : Type u_3} [Preorder α] {f : α → β} {T : ℕ} (h : ChangesAtMost f T) (g : β → γ) :

Post-composition preserves a change bound.

theorem Cslib.ChangesAtMost.comp_monotone {α : Type u_1} {β : Type u_2} {γ : Type u_3} [Preorder α] [Preorder γ] {f : α → β} {T : ℕ} (h : ChangesAtMost f T) {g : γ → α} (hg : Monotone g) :

Monotone precomposition preserves a change bound.

theorem Cslib.ChangesAtMost.comp_antitone {α : Type u_1} {β : Type u_2} {γ : Type u_3} [Preorder α] [Preorder γ] {f : α → β} {T : ℕ} (h : ChangesAtMost f T) {g : γ → α} (hg : Antitone g) :

Antitone precomposition preserves a change bound.

theorem Cslib.ChangesAtMost.const {α : Type u_1} {β : Type u_2} [Preorder α] (b : β) :
ChangesAtMost (fun (x : α) => b) 0

A constant function has no changes.

theorem Cslib.ChangesAtMost.decide_le {α : Type u_1} [LinearOrder α] (θ : α) [DecidableRel fun (x1 x2 : α) => x1 ≤ x2] :
ChangesAtMost (fun (u : α) => decide (θ ≤ u)) 1

A threshold predicate decide (θ ≤ ·) on a linear order changes at most once.

theorem Cslib.ChangesAtMost.decide_ge {α : Type u_1} [LinearOrder α] (θ : α) [DecidableRel fun (x1 x2 : α) => x1 ≤ x2] :
ChangesAtMost (fun (u : α) => decide (u ≤ θ)) 1

A threshold predicate decide (· ≤ θ) on a linear order changes at most once: it is decide_le in the order dual, precomposed with the antitone toDual.

theorem Cslib.ChangesAtMost.pi {α : Type u_1} [Preorder α] {ι : Type u_4} [Fintype ι] {β : ι → Type u_5} {f : (i : ι) → α → β i} {T : ι → ℕ} (hf : ∀ (i : ι), ChangesAtMost (f i) (T i)) :
ChangesAtMost (fun (a : α) (i : ι) => f i a) (∑ i : ι, T i)

A tuple of functions indexed by a finite type changes at most the sum of the individual change bounds.

theorem Cslib.ChangesAtMost.finset_pi {α : Type u_1} [Preorder α] {ι : Type u_4} {s : Finset ι} {β : ι → Type u_5} {f : (i : ι) → α → β i} {T : ι → ℕ} (hf : ∀ i ∈ s, ChangesAtMost (f i) (T i)) :
ChangesAtMost (fun (a : α) (i : ↥s) => f (↑i) a) (∑ i ∈ s, T i)

A tuple of functions indexed by a finite set changes at most the sum of the individual change bounds.

def Cslib.PiecesAtMost {α : Type u_1} {β : Type u_2} [Preorder α] (Φ : α → β) (M : ℕ) :

Φ has at most M pieces when it is constant on the level sets of a monotone rank function π : α → ℕ with values below M.

theorem Cslib.PiecesAtMost.mono {α : Type u_1} {β : Type u_2} [Preorder α] {Φ : α → β} {M M' : ℕ} (h : PiecesAtMost Φ M) (hM : M ≤ M') :

Increasing a piece bound preserves it.

theorem Cslib.PiecesAtMost.comp {α : Type u_1} {β : Type u_2} {γ : Type u_3} [Preorder α] {Φ : α → β} {M : ℕ} (h : PiecesAtMost Φ M) (g : β → γ) :
PiecesAtMost (fun (t : α) => g (Φ t)) M

Post-composition preserves a piece bound.

theorem Cslib.PiecesAtMost.changesAtMost {α : Type u_1} {β : Type u_2} [Preorder α] {Φ : α → β} {M : ℕ} (h : PiecesAtMost Φ M) :
ChangesAtMost Φ (M - 1)

A function with at most M pieces changes at most M - 1 times.

theorem Cslib.ChangesAtMost.exists_sorted_group {α : Type u_1} {β : Type u_2} [LinearOrder α] {ι : Type u_4} {κ : Type u_5} (P : Finset ι) (Q : Finset κ) (key : ι → α) (Ψ : κ → α → β) {T G : ℕ} (hG : 0 < G) (hΨ : ∀ q ∈ Q, ChangesAtMost (Ψ q) T) :
∃ P' ⊆ P, ∃ Qbad ⊆ Q, P.card / G ≤ P'.card ∧ G * Qbad.card ≤ T * Q.card ∧ ∀ q ∈ Q, q ∉ Qbad → ∀ p ∈ P', ∀ p' ∈ P', Ψ q (key p) = Ψ q (key p')

Lemma 1 (sorted groups). If every Ψ q with q ∈ Q changes at most T times, there are a subset P' of P with at least ⌊|P| / G⌋ elements and a subset Qbad of Q with G |Qbad| ≤ T |Q| such that the functions p ↦ Ψ q (key p) are constant on P' for every q ∈ Q outside Qbad. In the proof, P' is one of the G consecutive groups of ⌊|P| / G⌋ elements of P sorted by key.

Alternating sequences along ordered lists #

theorem Cslib.ChangesAtMost.length_le_succ_of_isChain {α : Type u_4} {β : Type u_5} [Preorder α] {f : α → β} {T : ℕ} (hf : ChangesAtMost f T) {ts : List α} (hmono : List.IsChain (fun (x1 x2 : α) => x1 ≤ x2) ts) (halt : List.IsChain (fun (x1 x2 : β) => x1 ≠ x2) (List.map f ts)) :
ts.length ≤ T + 1

Any ordered list along which f alternates between consecutive elements has length at most T + 1 whenever ChangesAtMost f T.