forked from leanprover/lean4
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: fix BitVec.abs, prove toInt produces the expected value.
The previous definition of `abs` was incorrect when only the msb was `1` and all other bits were `0`. For example, consider bit-width 3: ``` 100 -- 4#3 ``` If we compute `-x`, i.e. `!x + 1`, we get: ``` 011 +001 --- 100 ``` We recover `4#3` once again. The semantically correct implementation can use `BitVec.slt`, and we can prove the equivalence to the bit-fiddling hack: ``` // https://math.stackexchange.com/q/2565736/261373 int iabs(int a) { int t = a >> 31; a = (a^t) - t; return a; } ``` written in lean, this is: ``` def BitVec.abs' (x : BitVec w) : let t := x >> (w - 1) (x ^^^ t) - t ```
- Loading branch information
Showing
4 changed files
with
89 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters