Sorting algorithms on lists #
In this file we define the sorting algorithm List.insertionSort r and prove
that we have (l.insertionSort r l).Pairwise r under suitable conditions on r.
We then define List.SortedLE, List.SortedGE, List.SortedLT and List.SortedGT,
predicates which are equivalent to List.Pairwise when the relation derives from a
preorder (but which are defined in terms of the monotonicity predicates).
Insertion sort #
orderedInsert a l inserts a into l at such that
orderedInsert a l is sorted if l is.
Equations
Instances For
Alias of List.orderedInsert_cons_of_le.
An alternative definition of orderedInsert using takeWhile and dropWhile.
If l is already List.Pairwise with respect to r, then insertionSort does not change
it.
Alias of List.Pairwise.insertionSort_eq.
If l is already List.Pairwise with respect to r, then insertionSort does not change
it.
For a reflexive relation, insert then erasing is the identity.
Inserting then erasing an element that is absent is the identity.
Alias of List.erase_orderedInsert_of_notMem.
Inserting then erasing an element that is absent is the identity.
For an antisymmetric relation, erasing then inserting is the identity.
Alias of List.Pairwise.orderedInsert.
The list List.insertionSort r l is List.Pairwise with respect to r.
Alias of List.pairwise_insertionSort.
The list List.insertionSort r l is List.Pairwise with respect to r.
If c is a sorted sublist of l, then c is still a sublist of insertionSort r l.
Another statement of stability of insertion sort.
If a pair [a, b] is a sublist of l and r a b,
then [a, b] is still a sublist of insertionSort r l.
A version of insertionSort_stable which only assumes c <+~ l (instead of c <+ l), but
additionally requires IsAntisymm α r, IsTotal α r and IsTrans α r.
Another statement of stability of insertion sort.
If a pair [a, b] is a sublist of a permutation of l and a ≼ b,
then [a, b] is still a sublist of insertionSort r l.
Merge sort #
We provide some wrapper functions around the theorems for mergeSort provided in Lean,
which rather than using explicit hypotheses for transitivity and totality,
use Mathlib order typeclasses instead.
Variant of Perm.eq_of_pairwise using relation typeclasses.
Alias of List.Perm.eq_of_pairwise.
Alias of List.sublist_of_subperm_of_pairwise.
Alias of List.Pairwise.eq_of_mem_iff.
Alias of List.Pairwise.merge.
Alias of List.pairwise_mergeSort'.
Variant of pairwise_mergeSort using relation typeclasses.
The predicates List.SortedLE, List.SortedGE, List.SortedLT and List.SortedGT #
These predicates are equivalent to Monotone l.get, but they are also equivalent to
IsChain (· < ·) and Pairwise (· < ·). API is provided to move between these forms.
API has deliberately not been provided for decomposed lists to avoid unneeded API replication.
The provided API should be used to move to and from IsChain,
Pairwise or Monotone as needed. #
Alias of the forward direction of List.sortedLE_iff_monotone_get.
Alias of the reverse direction of List.sortedLE_iff_monotone_get.
Alias of the forward direction of List.sortedGE_iff_antitone_get.
Alias of the reverse direction of List.sortedGE_iff_antitone_get.
Alias of the forward direction of List.sortedLT_iff_strictMono_get.
Alias of the reverse direction of List.sortedLT_iff_strictMono_get.
Alias of the forward direction of List.sortedGT_iff_strictAnti_get.
Alias of the reverse direction of List.sortedGT_iff_strictAnti_get.
Alias of the forward direction of List.sortedLE_iff_pairwise.
Alias of the reverse direction of List.sortedLE_iff_pairwise.
Alias of the forward direction of List.sortedGE_iff_pairwise.
Alias of the reverse direction of List.sortedGE_iff_pairwise.
Alias of the reverse direction of List.sortedLT_iff_pairwise.
Alias of the forward direction of List.sortedLT_iff_pairwise.
Alias of the forward direction of List.sortedGT_iff_pairwise.
Alias of the reverse direction of List.sortedGT_iff_pairwise.
Alias of the forward direction of List.sortedLE_iff_isChain.
Alias of the reverse direction of List.sortedLE_iff_isChain.
Alias of the reverse direction of List.sortedGE_iff_isChain.
Alias of the forward direction of List.sortedGE_iff_isChain.
Alias of the reverse direction of List.sortedLT_iff_isChain.
Alias of the forward direction of List.sortedLT_iff_isChain.
Alias of the reverse direction of List.sortedGT_iff_isChain.
Alias of the forward direction of List.sortedGT_iff_isChain.
Equations
- x✝.decidableSortedLE = decidable_of_iff' (List.IsChain (fun (x1 x2 : α) => x1 ≤ x2) x✝) ⋯
Equations
- x✝.decidableSortedGE = decidable_of_iff' (List.IsChain (fun (x1 x2 : α) => x1 ≥ x2) x✝) ⋯
Equations
- x✝.decidableSortedLT = decidable_of_iff' (List.IsChain (fun (x1 x2 : α) => x1 < x2) x✝) ⋯
Equations
- x✝.decidableSortedGT = decidable_of_iff' (List.IsChain (fun (x1 x2 : α) => x1 > x2) x✝) ⋯
Alias of List.SortedLT.sortedLE.
Alias of List.SortedGT.sortedGE.
Alias of List.sortedLE_replicate.
Alias of List.sortedLT_range.
Alias of List.sortedLT_range'.
Alias of List.sortedLT_ofFn_iff.
The list List.ofFn f is strictly sorted with respect to (· ≤ ·) if and only if f is
strictly monotone.
Alias of List.sortedGT_ofFn_iff.
The list List.ofFn f is strictly sorted with respect to (· ≥ ·) if and only if f is
strictly antitone.
The list obtained from a strictly monotone tuple is sorted.
The list obtained from a strictly monotone tuple is sorted.
The list obtained from a strictly antitone tuple is sorted.
The list obtained from a strictly antitone tuple is sorted.
Alias of the reverse direction of List.sortedGE_ofFn_iff.
The list obtained from an antitone tuple is sorted.
Alias of the reverse direction of List.sortedLE_ofFn_iff.
The list obtained from a monotone tuple is sorted.
Alias of the reverse direction of List.sortedLE_reverse.
Alias of the forward direction of List.sortedLE_reverse.
Alias of the reverse direction of List.sortedGE_reverse.
Alias of the forward direction of List.sortedGE_reverse.
Alias of the reverse direction of List.sortedLT_reverse.
Alias of the forward direction of List.sortedLT_reverse.
Alias of the forward direction of List.sortedGT_reverse.
Alias of the reverse direction of List.sortedGT_reverse.
Alias of the reverse direction of List.sortedLE_map_ofDual.
Alias of the forward direction of List.sortedLE_map_ofDual.
Alias of the forward direction of List.sortedGE_map_ofDual.
Alias of the reverse direction of List.sortedGE_map_ofDual.
Alias of the reverse direction of List.sortedLT_map_ofDual.
Alias of the forward direction of List.sortedLT_map_ofDual.
Alias of the reverse direction of List.sortedGT_map_ofDual.
Alias of the forward direction of List.sortedGT_map_ofDual.
Alias of the reverse direction of List.sortedLE_map_toDual.
Alias of the forward direction of List.sortedLE_map_toDual.
Alias of the reverse direction of List.sortedGE_map_toDual.
Alias of the forward direction of List.sortedGE_map_toDual.
Alias of the forward direction of List.sortedLT_map_toDual.
Alias of the reverse direction of List.sortedLT_map_toDual.
Alias of the reverse direction of List.sortedGT_map_toDual.
Alias of the forward direction of List.sortedGT_map_toDual.
Alias of List.SortedLE.sortedLT_of_nodup.
Alias of List.SortedGE.sortedGT_of_nodup.
Alias of RelEmbedding.pairwise_listMap.
Alias of RelEmbedding.pairwise_swap_listMap.