-
-
Save delcypher/05c8711077d88231b47a353c544f79f7 to your computer and use it in GitHub Desktop.
Proof that an equality (that would be useful if true) does not hold
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
;; | |
;; Prove that | |
;; (x -y) >> 3 != ((x >> 3) - (y >> 3)) | |
;; | |
;; if x >= y | |
;; | |
;; | |
(declare-fun x () (_ BitVec 32)) | |
(declare-fun y () (_ BitVec 32)) | |
(declare-fun shift () (_ BitVec 32)) | |
(assert | |
(= | |
shift | |
(_ bv3 32) | |
) | |
) | |
(assert (bvuge x y)) | |
(assert | |
(not | |
(= | |
(bvlshr | |
(bvsub x y) | |
shift | |
) | |
(bvsub | |
(bvlshr x shift) | |
(bvlshr y shift) | |
) | |
) | |
) | |
) | |
;; Z3 responds SAT | |
;; meaning that there is a counter example | |
;; to our proposed equality. | |
(check-sat) | |
(get-model) | |
(exit) | |
;; | |
;; Prove that | |
;; (x -y) >> shift == ((x >> shift) - (y >> shift)) | |
;; | |
;; if x >= y and y is a multiple of (1 << shift). | |
;; | |
;; By adding the additional constraint on `y` it makes | |
;; the equality hold. | |
;; | |
(declare-fun x () (_ BitVec 32)) | |
(declare-fun y () (_ BitVec 32)) | |
(declare-fun shift () (_ BitVec 32)) | |
(assert | |
(= | |
shift | |
(_ bv3 32) | |
) | |
) | |
(assert | |
(= | |
(_ bv0 32) | |
(bvurem | |
y | |
(bvshl | |
(_ bv1 32) | |
shift | |
) | |
) | |
) | |
) | |
(assert (bvuge x y)) | |
(assert | |
(not | |
(= | |
(bvlshr | |
(bvsub x y) | |
shift | |
) | |
(bvsub | |
(bvlshr x shift) | |
(bvlshr y shift) | |
) | |
) | |
) | |
) | |
;; Z3 responds UNSAT | |
;; meaning that there isn't a counter example | |
;; to our proposed equality. | |
(check-sat) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example output