Skip to content
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

Merged
merged 24 commits into from
Aug 20, 2024
Merged

feat: List.mergeSort #5092

merged 24 commits into from
Aug 20, 2024

Conversation

kim-em
Copy link
Collaborator

@kim-em kim-em commented Aug 19, 2024

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: proves mergeSort le (x :: xs) = l₁ ++ x :: l₂ for some l₁, l₂
    so that mergeSort le xs = l₁ ++ l₂, and no a ∈ l₁ satisfies le a x.
  • mergeSort_stable: if c is a sorted sublist of l, then c is still a sublist of mergeSort le l.

@kim-em kim-em requested a review from digama0 as a code owner August 19, 2024 10:44
@kim-em
Copy link
Collaborator Author

kim-em commented Aug 19, 2024

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 <+ (sublist) partial order.

@kim-em
Copy link
Collaborator Author

kim-em commented Aug 19, 2024

This PR will need to wait for me to verify that #5088 doesn't have any bad performance implications.

@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Aug 19, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Aug 19, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Aug 19, 2024
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added the breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan label Aug 19, 2024
@leanprover-community-mathlib4-bot
Copy link
Collaborator

leanprover-community-mathlib4-bot commented Aug 19, 2024

Mathlib CI status (docs):

@kim-em
Copy link
Collaborator Author

kim-em commented Aug 20, 2024

This is expected to break Mathlib as there is a (non-tail-recursive, non-stable) implementation of mergeSort there. I'll clean it up after this is merged.

leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Aug 20, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Aug 20, 2024
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc August 20, 2024 01:53 Inactive
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Aug 20, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Aug 20, 2024
@kim-em kim-em added this pull request to the merge queue Aug 20, 2024
Merged via the queue into master with commit 4aa74d9 Aug 20, 2024
15 checks passed
@kim-em kim-em deleted the mergesort branch August 20, 2024 12:41
mathlib-bors bot pushed a commit to leanprover-community/mathlib4 that referenced this pull request Sep 29, 2024
The statements of stability follow those used for `mergeSort` in leanprover/lean4#5092.



Co-authored-by: Matthew Ballard <[email protected]>
fbarroero pushed a commit to leanprover-community/mathlib4 that referenced this pull request Oct 2, 2024
The statements of stability follow those used for `mergeSort` in leanprover/lean4#5092.



Co-authored-by: Matthew Ballard <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants