-
Notifications
You must be signed in to change notification settings - Fork 0
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: shiftRight bitblasting theorems #11
Conversation
185f53b
to
ffaa328
Compare
This did not lead to a clean PR? Maybe update origin/master and merge origin/master? |
ffaa328
to
80e05d8
Compare
@tobiasgrosser clean now. |
src/Init/Data/BitVec/Bitblast.lean
Outdated
theorem ushiftRight_eq' (x : BitVec w) (y : BitVec w₂) : | ||
x >>> y = x >>> y.toNat := by rfl |
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 ushiftRight_eq' (x : BitVec w) (y : BitVec w₂) : | |
x >>> y = x >>> y.toNat := by rfl | |
theorem ushiftRight_eq' (x : BitVec w₁) (y : BitVec w₂) : | |
x >>> y = x >>> y.toNat := by rfl |
src/Init/Data/BitVec/Bitblast.lean
Outdated
theorem getLsb_ushiftRight' (x : BitVec w) (y : BitVec w₂) (i : Nat) : | ||
(x >>> y).getLsb i = x.getLsb (y.toNat + i) := by |
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 getLsb_ushiftRight' (x : BitVec w) (y : BitVec w₂) (i : Nat) : | |
(x >>> y).getLsb i = x.getLsb (y.toNat + i) := by | |
theorem getLsb_ushiftRight' (x : BitVec w₁) (y : BitVec w₂) (i : Nat) : | |
(x >>> y).getLsb i = x.getLsb (y.toNat + i) := by |
src/Init/Data/BitVec/Bitblast.lean
Outdated
theorem shiftRight_eq_shiftRight_rec (x : BitVec ℘) (y : BitVec w₂) : | ||
x >>> y = ushiftRight_rec x y (w₂ - 1) := by |
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 shiftRight_eq_shiftRight_rec (x : BitVec ℘) (y : BitVec w₂) : | |
x >>> y = ushiftRight_rec x y (w₂ - 1) := by | |
theorem shiftRight_eq_shiftRight_rec (x : BitVec w₁) (y : BitVec w₂) : | |
x >>> y = ushiftRight_rec x y (w₂ - 1) := by |
def sshiftRightRec (x : BitVec w) (y : BitVec w₂) (n : Nat) : BitVec w := | ||
let shiftAmt := (y &&& (twoPow w₂ n)) |
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 sshiftRightRec (x : BitVec w) (y : BitVec w₂) (n : Nat) : BitVec w := | |
let shiftAmt := (y &&& (twoPow w₂ n)) | |
def sshiftRightRec (x : BitVec w₁) (y : BitVec w₂) (n : Nat) : BitVec w₁ := | |
let shiftAmt := (y &&& (twoPow w₂ n)) |
theorem sshiftRightRec_zero_eq (x : BitVec w) (y : BitVec w₂) : | ||
sshiftRightRec x y 0 = x.sshiftRight' (y &&& 1#w₂) := by |
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 sshiftRightRec_zero_eq (x : BitVec w) (y : BitVec w₂) : | |
sshiftRightRec x y 0 = x.sshiftRight' (y &&& 1#w₂) := by | |
theorem sshiftRightRec_zero_eq (x : BitVec w₁) (y : BitVec w₂) : | |
sshiftRightRec x y 0 = x.sshiftRight' (y &&& 1#w₂) := by |
theorem sshiftRightRec_succ_eq (x : BitVec w) (y : BitVec w₂) (n : Nat) : | ||
sshiftRightRec x y (n + 1) = (sshiftRightRec x y n).sshiftRight' (y &&& twoPow w₂ (n + 1)) := by |
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 sshiftRightRec_succ_eq (x : BitVec w) (y : BitVec w₂) (n : Nat) : | |
sshiftRightRec x y (n + 1) = (sshiftRightRec x y n).sshiftRight' (y &&& twoPow w₂ (n + 1)) := by | |
theorem sshiftRightRec_succ_eq (x : BitVec w₁) (y : BitVec w₂) (n : Nat) : | |
sshiftRightRec x y (n + 1) = (sshiftRightRec x y n).sshiftRight' (y &&& twoPow w₂ (n + 1)) := by |
theorem sshiftRight_or_eq_sshiftRight_sshiftRight_of_and_eq_zero {x : BitVec w} {y z : BitVec w₂} | ||
(h : y &&& z = 0#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.
theorem sshiftRight_or_eq_sshiftRight_sshiftRight_of_and_eq_zero {x : BitVec w} {y z : BitVec w₂} | |
(h : y &&& z = 0#w₂) : | |
theorem sshiftRight_or_eq_sshiftRight_sshiftRight_of_and_eq_zero {x : BitVec w₁} {y z : BitVec w₂} | |
(h : y &&& z = 0#w₂) : |
simp [sshiftRight', ← add_eq_or_of_and_eq_zero _ _ h, | ||
toNat_add_of_and_eq_zero h, sshiftRight'_add] |
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.
simp [sshiftRight', ← add_eq_or_of_and_eq_zero _ _ h, | |
toNat_add_of_and_eq_zero h, sshiftRight'_add] | |
simp [sshiftRight', ← add_eq_or_of_and_eq_zero _ _ h, | |
toNat_add_of_and_eq_zero h, sshiftRight'_add] |
src/Init/Data/BitVec/Bitblast.lean
Outdated
theorem ushiftRight_or_eq_ushiftRight_ushiftRight_of_and_eq_zero {x : BitVec w} {y z : BitVec w₂} | ||
(h : y &&& z = 0#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.
theorem ushiftRight_or_eq_ushiftRight_ushiftRight_of_and_eq_zero {x : BitVec w} {y z : BitVec w₂} | |
(h : y &&& z = 0#w₂) : | |
theorem ushiftRight_or_eq_ushiftRight_ushiftRight_of_and_eq_zero {x : BitVec w₁} {y z : BitVec w₂} | |
(h : y &&& z = 0#w₂) : |
src/Init/Data/BitVec/Bitblast.lean
Outdated
(ushiftRight_rec x y n) >>> (y &&& twoPow w₂ (n + 1)) := by | ||
simp [ushiftRight_rec] | ||
|
||
theorem ushiftRight_eq' (x : BitVec w) (y : 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.
I am not a fan, but in the previous PR we marked this as simp, no?
The PR message states that there are still open TODOs. Is this up-to-date? |
a7c33b0
to
30a350a
Compare
30a350a
to
d222874
Compare
ushiftRight_rec x y n = x >>> (y.truncate (n + 1)).zeroExtend w₂ := by | ||
induction n generalizing x y |
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.
ushiftRight_rec x y n = x >>> (y.truncate (n + 1)).zeroExtend w₂ := by | |
induction n generalizing x y | |
ushiftRight_rec x y n = x >>> (y.truncate (n + 1)).zeroExtend w₂ := by | |
induction n generalizing x y |
sshiftRightRec x y n = x.sshiftRight' ((y.truncate (n + 1)).zeroExtend w₂) := by | ||
induction n generalizing x y |
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.
sshiftRightRec x y n = x.sshiftRight' ((y.truncate (n + 1)).zeroExtend w₂) := by | |
induction n generalizing x y | |
sshiftRightRec x y n = x.sshiftRight' ((y.truncate (n + 1)).zeroExtend w₂) := by | |
induction n generalizing x y |
These were merged in leanprover#4872 and leanprover#4889. |
These theorems allow us to bitblast arithmetic and logical shift rights. The TODOS are yet to be addressed.