-
Notifications
You must be signed in to change notification settings - Fork 439
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 reverse
definition, getLsbD_reverse, getMsbD_reverse, reverse_append, reverse_replicate
and Nat.mod_sub_eq_sub_mod
#6476
base: master
Are you sure you want to change the base?
Conversation
Mathlib CI status (docs):
|
@@ -669,4 +669,11 @@ def ofBoolListLE : (bs : List Bool) → BitVec bs.length | |||
| [] => 0#0 | |||
| b :: bs => concat (ofBoolListLE bs) b | |||
|
|||
/- ### reverse -/ | |||
|
|||
/-- Reverse of a Bitvec. We treat BitVec as lists of bools. -/ |
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.
/-- Reverse of a Bitvec. We treat BitVec as lists of bools. -/ | |
/-- Reverse the bits in a bitvector. -/ |
We generally phrase a docstring for a function as an action/verb rather than just the result/noun.
I also wouldn't mention that we treat a bitvector as a list of bools, that's the "expected" interpretation of a bitvector (list of bools is more or less the same as a "vector of bits").
I guess you're referring here to the fact that the implementation is more in the style of a List.reverse
versus other definitions that rely on the Nat-based internal encoding. That kind of comment feels more appropriate as a local comment rather than a docstring, but even then, I'm not sure it needs mentioning; it's clear from the code already.
/- ### reverse -/ | ||
|
||
/-- Reverse of a Bitvec. We treat BitVec as lists of bools. -/ | ||
def reverse : (w : Nat) → BitVec w → BitVec w |
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.
def reverse : (w : Nat) → BitVec w → BitVec w | |
def reverse : {w : Nat} → BitVec w → BitVec w |
w
can be inferred from the bitvector arg, and can thus be implicit
· simp only [hi, decide_true, show w - 1 - i < w by omega, Bool.true_and] | ||
congr; omega | ||
· simp [hi, show i ≥ w by omega] | ||
|
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'm missing a msb_reverse
specialization
This PR defines
reverse
for bitvectors and implements a first subset of theorems (getLsbD_reverse, getMsbD_reverse, reverse_append, reverse_replicate
) and an additional theorem necessary for one of the proofs (Nat.mod_sub_eq_sub_mod
).The main objective is to simplify the proofs in #6326. I sadly could not find a way to avoid adding
Nat.mod_sub_eq_sub_mod
, any suggestion in this direction would be greatly helpful.