-
Notifications
You must be signed in to change notification settings - Fork 423
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: BitVec.(not_sshiftRight, not_sshiftRight_not, getMsb_not, msb_not) #5492
Conversation
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.
LGTM
Mathlib CI status (docs):
|
src/Init/Data/BitVec/Lemmas.lean
Outdated
@@ -949,6 +949,13 @@ theorem not_not {b : BitVec w} : ~~~(~~~b) = b := by | |||
ext i | |||
simp | |||
|
|||
@[simp] theorem getMsb_not {x : BitVec w} : | |||
(~~~x).getMsbD i = (decide (i < w) && !(x.getMsbD i)) := by | |||
by_cases h : i < w <;> simp [getMsbD, h] ; 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.
This proof is a bit unstructured, the <;> simp
solves one of the two goals produced by by_cases
and then the ; omega
only handles the last remaining goal. Usually we do these kinds of proofs like this:
@[simp] theorem not_append {x : BitVec w} {y : BitVec v} : ~~~ (x ++ y) = (~~~ x) ++ (~~~ y) := by
ext i
simp only [getLsbD_not, getLsbD_append, cond_eq_if]
split
· simp_all
· simp_all; omega
this is important for proof stability and being able to debug quicker proofs if they ever end up breaking in some way. For example if one of the simp
happens to not be powerful enough anymore omega
would be thrown at potentially another goal and you'd get a message about it not being able to solve the goal + an open goal still existing etc.
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.
Looks good apart from the small style issue!
thanks a lot! I changed the style of the theorem to make it more similar to the one you sent, not sure it's correct style-wise |
src/Init/Data/BitVec/Lemmas.lean
Outdated
(~~~x).getMsbD i = (decide (i < w) && !(x.getMsbD i)) := by | ||
simp only [getMsbD] | ||
by_cases h : i < w | ||
· simp_all; 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.
You can use just simp [h]
here. simp_all
is a more powerful tool. It basically goes through all hypothesis h_x
and does simp [all_hyps_except h_x] at h_x
until a fixpoint.
Mathlib CI status (docs):
|
Mathlib CI status (docs):
|
No description provided.