mathlib3 documentation

data.fin.tuple.sort

Sorting tuples by their values #

THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.

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.

Main declarations #

def tuple.graph {n : } {α : Type u_1} [linear_order α] (f : 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} [linear_order α] {f : fin n α} :

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

Equations
@[simp]
theorem tuple.graph.card {n : } {α : Type u_1} [linear_order α] (f : fin n α) :
def tuple.graph_equiv₁ {n : } {α : Type u_1} [linear_order α] (f : fin n α) :

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

Equations
@[simp]
theorem tuple.proj_equiv₁' {n : } {α : Type u_1} [linear_order α] (f : fin n α) :
def tuple.graph_equiv₂ {n : } {α : Type u_1} [linear_order α] (f : fin n α) :

graph_equiv₂ f is an equivalence between fin n and graph f that respects the order.

Equations
def tuple.sort {n : } {α : Type u_1} [linear_order α] (f : fin n α) :

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

Equations
theorem tuple.graph_equiv₂_apply {n : } {α : Type u_1} [linear_order α] (f : fin n α) (i : fin n) :
theorem tuple.monotone_proj {n : } {α : Type u_1} [linear_order α] (f : fin n α) :
theorem tuple.monotone_sort {n : } {α : Type u_1} [linear_order α] (f : fin n α) :
theorem tuple.unique_monotone {n : } {α : Type u_1} [partial_order α] {f : 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} [linear_order α] {f : fin n α} {σ : equiv.perm (fin n)} :

A permutation σ equals sort f if and only if the map 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} [linear_order α] {f : fin n α} {σ : equiv.perm (fin n)} :
σ = tuple.sort f monotone (f σ) (i j : fin n), i < j f (σ 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} [linear_order α] {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} [linear_order α] {f : fin n α} {σ : equiv.perm (fin n)} :

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} [linear_order α] {f : fin n α} {σ : equiv.perm (fin n)} :

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} [linear_order α] {f : fin n α} {σ : equiv.perm (fin n)} (h : f σ f (tuple.sort f)) :
(i j : fin n), i < j (f σ) j < (f σ) i

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

theorem tuple.antitone_pair_of_not_sorted {n : } {α : Type u_1} [linear_order α] {f : fin n α} (h : f f (tuple.sort f)) :
(i j : fin n), i < j f j < f i

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