-
Notifications
You must be signed in to change notification settings - Fork 462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: List.mergeSort #5092
feat: List.mergeSort #5092
Conversation
I am really trying hard to resist the temptation to state the result that "forgetting it is sorted" and "stable merge sort" form a Galois connection between sorted lists and lists, with the |
This PR will need to wait for me to verify that #5088 doesn't have any bad performance implications. |
Mathlib CI status (docs):
|
This is expected to break Mathlib as there is a (non-tail-recursive, non-stable) implementation of |
The statements of stability follow those used for `mergeSort` in leanprover/lean4#5092. Co-authored-by: Matthew Ballard <[email protected]>
The statements of stability follow those used for `mergeSort` in leanprover/lean4#5092. Co-authored-by: Matthew Ballard <[email protected]>
Defines
mergeSort
, a naive stable merge sort algorithm, replaces it via a@[csimp]
lemma with something faster at runtime, and proves the following results:mergeSort_sorted
:mergeSort
produces a sorted list.mergeSort_perm
:mergeSort
is a permutation of the input list.mergeSort_of_sorted
:mergeSort
does not change a sorted list.mergeSort_cons
: provesmergeSort le (x :: xs) = l₁ ++ x :: l₂
for somel₁, l₂
so that
mergeSort le xs = l₁ ++ l₂
, and noa ∈ l₁
satisfiesle a x
.mergeSort_stable
: ifc
is a sorted sublist ofl
, thenc
is still a sublist ofmergeSort le l
.