-
Notifications
You must be signed in to change notification settings - Fork 131
feat: add Nat.Digits
#1293
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
base: main
Are you sure you want to change the base?
feat: add Nat.Digits
#1293
Conversation
| @[simp] | ||
| theorem ofDigitsBE_reverse_eq_ofDigitsLE {l : List (Fin base)} : | ||
| ofDigitsBE l.reverse = ofDigitsLE l := by |
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.
I claim that because of this there really is no point having both versions of the function.
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.
There is:
- The LE version has an obvious user-friendly recursion pattern but is highly inefficient. (Stack overflow happens before 7000 digits.)
- The BE version is not user-friendly but it is naturally tail-recursive.
- The BE version is used via
csimpto make an efficient implementation of the LE version. - The BE version has an obvious use case that decimal numbers are in BE format.
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.
The names used here don't conflict with Mathlib at all. The expected blend-in is to use toDigitsLE (once csimp implemented as the reverse of toDigitsBE) as a more efficient replacement for Mathlib's digitsAux, the whole thing should be invisible to Mathlib users.
|
You might want to consider that #799 ought to be compatible with this. I am sure there's a lemma like this in Mathlib somewhere but I can't find it. |
|
(Mathlib has Nat.bits, which modulo |
|
Good reminders! This PR is on hiatus until I find time to rethink the overall design. |
This PR adds functions for calculating digit representation in any base. Both little-endian and big-endian versions are provided.