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.
Main declarations #
Tuple.sort: givenf : Fin n → α, produces a permutation onFin nTuple.monotone_sort:f ∘ Tuple.sort fisMonotone
If f₀ ≤ f₁ ≤ f₂ ≤ ⋯ is a sorted m-tuple of elements of α, then for any j : Fin m and
a : α we have j < #{i | fᵢ ≤ a} iff fⱼ ≤ a.
If two permutations of a tuple f are both monotone, then they are equal.
If two permutations of a tuple f are both antitone, then they are equal.
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).
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.
The permutation that sorts f is the identity if and only if f is monotone.
A permutation of a tuple f is f sorted if and only if it is monotone.
The sorted versions of a tuple f and of any permutation of f agree.
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.