Skip to content

Conversation

@fgdorais
Copy link
Collaborator

This PR adds functions for calculating digit representation in any base. Both little-endian and big-endian versions are provided.

@fgdorais fgdorais added the WIP work in progress label Jun 26, 2025
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jun 26, 2025
Comment on lines +181 to +183
@[simp]
theorem ofDigitsBE_reverse_eq_ofDigitsLE {l : List (Fin base)} :
ofDigitsBE l.reverse = ofDigitsLE l := by
Copy link
Member

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.

Copy link
Collaborator Author

@fgdorais fgdorais Jun 26, 2025

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 csimp to make an efficient implementation of the LE version.
  • The BE version has an obvious use case that decimal numbers are in BE format.

Copy link
Collaborator Author

@fgdorais fgdorais Jun 26, 2025

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.

@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added the merge-conflict This PR has merge conflicts with the `main` branch which must be resolved by the author. label Jul 19, 2025
@linesthatinterlace
Copy link
Contributor

linesthatinterlace commented Sep 30, 2025

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.

@linesthatinterlace
Copy link
Contributor

(Mathlib has Nat.bits, which modulo finTwoEquiv is the same as this.)

@fgdorais
Copy link
Collaborator Author

Good reminders! This PR is on hiatus until I find time to rethink the overall design.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-conflict This PR has merge conflicts with the `main` branch which must be resolved by the author. WIP work in progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants