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: add BitVec.ofFn and lemmas #1078

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

fgdorais
Copy link
Collaborator

No description provided.

@fgdorais fgdorais added the awaiting-review This PR is ready for review; the author thinks it is ready to be merged. label Dec 23, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Dec 23, 2024
@leanprover-community-bot
Copy link
Collaborator

Mathlib CI status (docs):

Batteries/Data/BitVec.lean Outdated Show resolved Hide resolved
Fin.foldr n (fun i v => v.shiftConcat (f i)) 0

/-- `ofFn f` returns the `BitVec n` whose `i`th bit is `f i` -/
abbrev ofFn (f : Fin n → Bool) : BitVec n := ofFnAux n f
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New functions creating BitVecs should have simp lemmas for toNat, toFin, and ideally also toInt.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't that need the Nat/Fin/Int functions to already exist in some way? I would probably just implement those using the BitVec version.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added Nat.ofBits and Fin.ofBits, little endian only since that's the way Nat.testBit works. I will try to think about what the right Int version should be.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding Int.ofBits would require upstreaming Int.testBit from Mathlib. Let me know if you think that's a good idea and I will get it done.

Batteries/Data/BitVec.lean Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-review This PR is ready for review; the author thinks it is ready to be merged. builds-mathlib
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants