Search code examples
z3smtbitvector

Z3 bitvector operations


How does one use the 'repeat' and 'rotate_left' bitvector operations?

More generally, where can I find detailed documentation of bitvector operations in the SMT2 scripting format used by Z3?

Everything I find seems to just go to tutorials, or broken links:
https://github.com/Z3Prover/z3/wiki/Documentation
http://research.microsoft.com/en-us/um/redmond/projects/z3/old/documentation.html

Trying to understand "repeat", "rotate_left", and "rotate_right" by guessing has been frustating. I cannot figure out how to use them. For example

(display (repeat #b01))
(display (repeat #b01 3))
(display (repeat 3))
(display (rotate_left #b0001 2))

gives

"repeat expects one non-zero integer parameter"
"repeat expects one argument"
"operator is applied to arguments of the wrong sort"
"rotate left expects one argument"

Where is the documentation? Hoping they didn't explain because all of this is standard, I also looked at smt-lib.org but that doesn't list these details either. So frustrating.


Solution

  • In addition to dejvuth's answer:

    The SMT language is well documented (see smt-lib.org), for this particular issue the FixedSizeBitVectors theory and the QF_BV logic definition are relevant. The latter contains the definition for repeat:

    ((_ repeat i) (_ BitVec m) (_ BitVec i*m))
    - ((_ repeat i) x) means concatenate i copies of x
    

    Apart from those, David Cok wrote an excellent SMT2 tutorial.

    The names of functions in the Z3 API is the same as in SMT2 where syntax permits, in this case prefixed with Z3_mk_ to indicate that they are functions that construct Z3 expressions.