-
Notifications
You must be signed in to change notification settings - Fork 465
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: proposed change to BitVec API #5200
Conversation
Mathlib CI status (docs):
|
Co-authored-by: Markus Himmel <[email protected]>
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 like the getLsb -> getLsbD rename (in fact, I've proposed this exact change before, back when bitvectors were still in now-batteries/then-std4)
src/Init/Data/BitVec/Basic.lean
Outdated
/-- | ||
Return the `i`-th least significant bit. | ||
|
||
This will be renamed `getLsb` after the existing deprecated alias is removed. | ||
-/ | ||
@[inline] def getLsb' (x : BitVec w) (i : Nat) (_ : i < w) : Bool := x.toNat.testBit i |
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 think it might make sense to bundle the proof, and have this take an i : Fin w
, akin to how List.get
does it.
IIRC, there are some places we currently have getLsb i
with i : Fin w
(relying on the Fin
to Nat
coercion). If we bundle the proof in a single Fin
argument, these call sites will just magically keep working
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.
Agreed.
This renames
BitVec.getLsb
togetLsbD
(D
for "default" value, i.e. false), and introducesgetLsb?
andgetLsb'
(which we can rename togetLsb
after a deprecation cycle).(Similarly for
getMsb
.)Also adds a
GetElem
class so we can usex[i]
andx[i]?
notation.Later, we will turn
on as a
@[simp]
lemma.This PR doesn't attempt to demonstrate the benefits, but I think both arguments are going to get easier, and this will bring the BitVec API closer in line to List/Array, etc.