-
Notifications
You must be signed in to change notification settings - Fork 459
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: complete BitVec.[getMsbD|getLsbD|msb]
for shifts
#5604
Conversation
Co-authored-by: Tobias Grosser <[email protected]>
Co-authored-by: Tobias Grosser <[email protected]>
Co-authored-by: Tobias Grosser <[email protected]>
Co-authored-by: Tobias Grosser <[email protected]>
Co-authored-by: Tobias Grosser <[email protected]>
Co-authored-by: Tobias Grosser <[email protected]>
Co-authored-by: Tobias Grosser <[email protected]>
BitVec.(getMsbD_sshiftRight, getLsbD_sshiftRight', getMsbD_sshiftRight', getMsbD_ushiftRight, msb_shiftLeft, msb_ushiftRight, msb_sshiftRight')
and rename sshiftRight_msb_eq_msb
to msb_sshiftRight
BitVec.(getMsbD_sshiftRight, getLsbD_sshiftRight', getMsbD_sshiftRight', getMsbD_ushiftRight, msb_shiftLeft, msb_ushiftRight, msb_sshiftRight')
and deprecated sshiftRight_msb_eq_msb
to msb_sshiftRight
Mathlib CI status (docs):
|
Co-authored-by: Tobias Grosser <[email protected]>
Also, I feel you can have a slightly shorter title, e.g., |
BitVec.(getMsbD_sshiftRight, getLsbD_sshiftRight', getMsbD_sshiftRight', getMsbD_ushiftRight, msb_shiftLeft, msb_ushiftRight, msb_sshiftRight')
and deprecated sshiftRight_msb_eq_msb
to msb_sshiftRight
BitVec.[getMsbD|getLsbD|msb]
for shifts
src/Init/Data/BitVec/Lemmas.lean
Outdated
all_goals (simp [h, h₁, h₂, h₃, h₄]; try congr; try omega) | ||
simp_all |
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 am afraid this simp is non-terminal, so you may want to turn it into a simp only. You can try to be strategic and only include the minimal set of theorems needed to get it through.
Also, do you really need a simp_all at the end?
I am having some trouble refactoring the proofs of |
src/Init/Data/BitVec/Lemmas.lean
Outdated
by_cases h : i < w | ||
<;> by_cases h₁ : i < n | ||
<;> by_cases h₂ : i - n < w | ||
all_goals (simp only [h, decide_False, ushiftRight_eq, getLsbD_ushiftRight, Bool.false_and, h₁, |
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 looks fairly aggressive, and wonder if there are higher-level lemmas to be extracted here.
src/Init/Data/BitVec/Lemmas.lean
Outdated
theorem getMsbD_ushiftRight {w} {x : BitVec w} {i n : Nat} : | ||
getMsbD (x.ushiftRight n) i = (decide (i < w) && if i < n then false else getMsbD x (i - n)) := by | ||
simp only [getMsbD, ushiftRight_eq, getLsbD_ushiftRight, Bool.if_false_left] | ||
by_cases h : i < w | ||
<;> by_cases h₁ : i < n | ||
<;> by_cases h₂ : i - n < w | ||
<;> simp (discharger := omega) [h, h₁, h₂] | ||
congr; 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.
theorem getMsbD_ushiftRight {w} {x : BitVec w} {i n : Nat} : | |
getMsbD (x.ushiftRight n) i = (decide (i < w) && if i < n then false else getMsbD x (i - n)) := by | |
simp only [getMsbD, ushiftRight_eq, getLsbD_ushiftRight, Bool.if_false_left] | |
by_cases h : i < w | |
<;> by_cases h₁ : i < n | |
<;> by_cases h₂ : i - n < w | |
<;> simp (discharger := omega) [h, h₁, h₂] | |
congr; omega | |
theorem getMsbD_ushiftRight {x : BitVec w} {i n : Nat} : | |
getMsbD (x.ushiftRight n) i = (decide (i < w) && if i < n then false else getMsbD x (i - n)) := by | |
simp only [getMsbD, Bool.if_false_left] | |
by_cases h : i < n | |
· simp [getLsbD_ge, show w ≤ (n + (w - 1 - i)) by omega] | |
omega | |
· by_cases h₁ : i < w <;> by_cases h₂ : i - n < w | |
· simp only [h, , h₁, h₂, ushiftRight_eq, getLsbD_ushiftRight] | |
congr | |
omega | |
all_goals (simp [h, h₁, h₂]; try 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.
Maybe you can refactor the other cases in similar ways?
I changed the proof |
Co-authored-by: Tobias Grosser <[email protected]>
No description provided.