-
Notifications
You must be signed in to change notification settings - Fork 451
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: rm partial / bounds checks in Array.qsort #3933
Conversation
!bench |
Here are the benchmark results for commit 228efff. |
Mathlib CI status (docs):
|
!bench |
Here are the benchmark results for commit 28c305a. Benchmark Metric Change
============================================
- stdlib instructions 2.0% (371.8 σ)
- stdlib task-clock 1.3% (11.5 σ)
- stdlib type checking 9.0% (11.0 σ)
- stdlib wall-clock 8.0% (86.5 σ) |
Do you know why this gets the |
if h : lo < hi.1 then | ||
let ⟨as, mid, (_ : lo ≤ mid), _⟩ := | ||
qpartition as lt ⟨lo, Nat.lt_trans h hi.2⟩ hi (Nat.le_of_lt h) | ||
let as := sort as lo ⟨mid - 1, by omega⟩ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessarily relevant for this PR, but one simple improvement to quicksort (as explained in the Sedgewick paper) is to recurse on the smallest subproblem first. This ensures a stack depth of O(log n)
because the other call will be in tail position.
The proof is actually suspiciously slow (the definition of This code is slightly suboptimal, in that |
!bench |
(The version that was previously benched had a sharing bug. Unsure if that is related to the stdlib slowdown.) |
Here are the benchmark results for commit 824a7fe. Benchmark Metric Change
===========================================
- stdlib type checking 4.6% (17.2 σ)
- stdlib wall-clock 3.8% (23.5 σ) |
Marking draft pending further benchmarking (build time and run time) |
Oh, sorry, I missed this, and did it independently. (Additionally, using Vector to clean up a bit.) I also have most of proof that the result is sorted, on a branch. |
With
omega
in core, it is now more feasible to perform the necessary proofs to eliminate thepartial
fromArray.qsort
, as well as the many uses ofArray.get!
andArray.swap!
. (This is also a perfect example of the kind of code that would benefit from the proposedVector
API.)I wrote this code over a year ago, but the stance regarding proofs in lean core has shifted so I think this is now more likely to be accepted. This is in any case blocking some proofs in Std which are built on top of uses of Array.qsort.