-
Notifications
You must be signed in to change notification settings - Fork 260
Implement version of Data.Nat.Binary.fromℕ that runs in O(log n) #1405
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
Conversation
|
Instead of using well-founded recursion, you can use the number itself to prove termination. I have found this to be much quicker in practice. (and it doesn't require as many dependencies) I also have proofs that the fast version is the same as the slow, if that is of any help: https://oisdk.github.io/agda-playground/Data.Binary.Conversion.Fast.Properties.html |
1a76ba4 to
a0d4e9b
Compare
a0d4e9b to
c05cb79
Compare
MatthewDaggitt
left a comment
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.
@Taneb thanks for the PR! You'll also need to update all the relevant proofs as well which may prove to be a bit harder given the increase in complexity. @oisdk's version does look a lot neater with less dependencies and the former might be a significant advantage when it comes to proving properties about it...
|
I'm not a huge fan of @oisdk's version, but if I'm being honest with myself, about 70% of that is "I didn't come up with it". |
Definitely an admirable goal! Though fair warning I suspect it's going to pretty messy 😄 We probably want the best code in the standard library though so just a heads up that if you continue with this definition, I probably won't merge the results in! Not a problem of course, but I thought I should give you an explicit heads up 👍 |
|
Okay, closing this PR. However, I've opened an issue #1468 to keep track of the problem. |
This makes the dependency footprint of this module a fair bit heavier I'm afraid.
I'll add a changelog entry after the 1.5 release to avoid rebasing difficulties.
I tested this with a little program that prints 10000000 round-tripped through
ℕᵇ. With the old one, this took 1.5s, with the new version 0.002s.