Documentation

Mathlib.Data.Fin.Tuple.Sort

Sorting tuples by their values #

Given an n-tuple f : Fin n → α→ α where α is ordered, we may want to turn it into a sorted n-tuple. This file provides an API for doing so, with the sorted n-tuple given by f ∘ Tuple.sort f∘ Tuple.sort f.

Main declarations #

def Tuple.graph {n : } {α : Type u_1} [inst : LinearOrder α] (f : Fin nα) :
Finset (Lex (α × Fin n))

graph f produces the finset of pairs (f i, i) equipped with the lexicographic order.

Equations
def Tuple.graph.proj {n : } {α : Type u_1} [inst : LinearOrder α] {f : Fin nα} :
{ x // x Tuple.graph f }α

Given p : α ×ₗ (Fin n) := (f i, i)×ₗ (Fin n) := (f i, i) with p ∈ graph f∈ graph f, graph.proj p is defined to be f i.

Equations
@[simp]
theorem Tuple.graph.card {n : } {α : Type u_1} [inst : LinearOrder α] (f : Fin nα) :
def Tuple.graphEquiv₁ {n : } {α : Type u_1} [inst : LinearOrder α] (f : Fin nα) :
Fin n { x // x Tuple.graph f }

graphEquiv₁ f is the natural equivalence between Fin n and graph f, mapping i to (f i, i).

Equations
  • One or more equations did not get rendered due to their size.
@[simp]
theorem Tuple.proj_equiv₁' {n : } {α : Type u_1} [inst : LinearOrder α] (f : Fin nα) :
Tuple.graph.proj ↑(Tuple.graphEquiv₁ f) = f
def Tuple.graphEquiv₂ {n : } {α : Type u_1} [inst : LinearOrder α] (f : Fin nα) :
Fin n ≃o { x // x Tuple.graph f }

graphEquiv₂ f is an equivalence between Fin n and graph f that respects the order.

Equations
def Tuple.sort {n : } {α : Type u_1} [inst : LinearOrder α] (f : Fin nα) :

sort f is the permutation that orders Fin n according to the order of the outputs of f.

Equations
theorem Tuple.graphEquiv₂_apply {n : } {α : Type u_1} [inst : LinearOrder α] (f : Fin nα) (i : Fin n) :
theorem Tuple.self_comp_sort {n : } {α : Type u_1} [inst : LinearOrder α] (f : Fin nα) :
f ↑(Tuple.sort f) = Tuple.graph.proj (RelIso.toRelEmbedding (Tuple.graphEquiv₂ f)).toEmbedding
theorem Tuple.monotone_proj {n : } {α : Type u_1} [inst : LinearOrder α] (f : Fin nα) :
Monotone Tuple.graph.proj
theorem Tuple.monotone_sort {n : } {α : Type u_1} [inst : LinearOrder α] (f : Fin nα) :
theorem Tuple.unique_monotone {n : } {α : Type u_1} [inst : PartialOrder α] {f : Fin nα} {σ : Equiv.Perm (Fin n)} {τ : Equiv.Perm (Fin n)} (hfσ : Monotone (f σ)) (hfτ : Monotone (f τ)) :
f σ = f τ

If two permutations of a tuple f are both monotone, then they are equal.

theorem Tuple.eq_sort_iff' {n : } {α : Type u_1} [inst : LinearOrder α] {f : Fin nα} {σ : Equiv.Perm (Fin n)} :

A permutation σ equals sort f if and only if the map i ↦ (f (σ i), σ i)↦ (f (σ i), σ i) is strictly monotone (w.r.t. the lexicographic ordering on the target).

theorem Tuple.eq_sort_iff {n : } {α : Type u_1} [inst : LinearOrder α] {f : Fin nα} {σ : Equiv.Perm (Fin n)} :
σ = Tuple.sort f Monotone (f σ) ∀ (i j : Fin n), i < jf (σ i) = f (σ j)σ i < σ j

A permutation σ equals sort f if and only if f ∘ σ∘ σ is monotone and whenever i < j and f (σ i) = f (σ j), then σ i < σ j. This means that sort f is the lexicographically smallest permutation σ such that f ∘ σ∘ σ is monotone.

theorem Tuple.sort_eq_refl_iff_monotone {n : } {α : Type u_1} [inst : LinearOrder α] {f : Fin nα} :

The permutation that sorts f is the identity if and only if f is monotone.

theorem Tuple.comp_sort_eq_comp_iff_monotone {n : } {α : Type u_1} [inst : LinearOrder α] {f : Fin nα} {σ : Equiv.Perm (Fin n)} :
f σ = f ↑(Tuple.sort f) Monotone (f σ)

A permutation of a tuple f is f sorted if and only if it is monotone.

theorem Tuple.comp_perm_comp_sort_eq_comp_sort {n : } {α : Type u_1} [inst : LinearOrder α] {f : Fin nα} {σ : Equiv.Perm (Fin n)} :
(f σ) ↑(Tuple.sort (f σ)) = f ↑(Tuple.sort f)

The sorted versions of a tuple f and of any permutation of f agree.

theorem Tuple.antitone_pair_of_not_sorted' {n : } {α : Type u_1} [inst : LinearOrder α] {f : Fin nα} {σ : Equiv.Perm (Fin n)} (h : f σ f ↑(Tuple.sort f)) :
i j, i < j (f σ) j < (f σ) i

If a permutation f ∘ σ∘ σ of the tuple f is not the same as f ∘ sort f∘ sort f, then f ∘ σ∘ σ has a pair of strictly decreasing entries.

theorem Tuple.antitone_pair_of_not_sorted {n : } {α : Type u_1} [inst : LinearOrder α] {f : Fin nα} (h : f f ↑(Tuple.sort f)) :
i j, i < j f j < f i

If the tuple f is not the same as f ∘ sort f∘ sort f, then f has a pair of strictly decreasing entries.