Bit-Vector Sort
Create a bit-vector sort of a specific size:Z3_mk_bv_sort(c, sz) creates a bit-vector sort of size sz (api_bv.cpp:26)
Bit-Vector Literals
Bitwise Operations
Bitwise AND
Z3_mk_bvand (api_bv.cpp:42)
Bitwise OR
Z3_mk_bvor (api_bv.cpp:43)
Bitwise XOR
Z3_mk_bvxor (api_bv.cpp:44)
Bitwise NOT
Z3_mk_bvnot (api_bv.cpp:39)
NAND, NOR, XNOR
Additional bitwise operations:Z3_mk_bvnand, Z3_mk_bvnor, Z3_mk_bvxnor (api_bv.cpp:45-47)
Arithmetic Operations
Addition
Z3_mk_bvadd (api_bv.cpp:48)
Subtraction
Z3_mk_bvsub (api_bv.cpp:373)
Multiplication
Z3_mk_bvmul (api_bv.cpp:49)
Negation
Z3_mk_bvneg (api_bv.cpp:381)
Division and Modulo
Unsigned Division
Z3_mk_bvudiv (api_bv.cpp:50)
Signed Division
Z3_mk_bvsdiv (api_bv.cpp:51)
Unsigned Remainder
Z3_mk_bvurem (api_bv.cpp:52)
Signed Remainder and Modulo
Z3_mk_bvsrem, Z3_mk_bvsmod (api_bv.cpp:53-54)
Comparison Operations
Unsigned Comparisons
Z3_mk_bvult, Z3_mk_bvule, Z3_mk_bvugt, Z3_mk_bvuge (api_bv.cpp:55, 57, 59, 61)
Signed Comparisons
Z3_mk_bvslt, Z3_mk_bvsle, Z3_mk_bvsgt, Z3_mk_bvsge (api_bv.cpp:56, 58, 60, 62)
Bit Manipulation
Concatenation
Combine two bit-vectors:Z3_mk_concat (api_bv.cpp:63)
Extract
Extract a sub-range of bits:Z3_mk_extract(c, high, low, n) (api_bv.cpp:79)
Shift Operations
Z3_mk_bvshl, Z3_mk_bvlshr, Z3_mk_bvashr (api_bv.cpp:64-66)
Rotate
Z3_mk_rotate_left, Z3_mk_rotate_right (api_bv.cpp:106-107)
Variable rotation: Z3_mk_ext_rotate_left, Z3_mk_ext_rotate_right (api_bv.cpp:67-68)
Sign/Zero Extension
Extend bit-vectors to larger sizes:Z3_mk_zero_ext, Z3_mk_sign_ext (api_bv.cpp:102-103)
Repeat
Repeat a bit-vector pattern:Z3_mk_repeat (api_bv.cpp:104)
Conversion Operations
Bit-Vector to Integer
Z3_mk_bv2int(c, n, is_signed) (api_bv.cpp:110)
Integer to Bit-Vector
Z3_mk_int2bv (api_bv.cpp:108)
Overflow Detection
Z3 provides predicates to detect arithmetic overflow:Addition Overflow
Z3_mk_bvadd_no_overflow(c, t1, t2, is_signed) (api_bv.cpp:183)
Addition Underflow
Z3_mk_bvadd_no_underflow (api_bv.cpp:227)
Multiplication Overflow
C API:Z3_mk_bvmul_no_overflow(c, n1, n2, is_signed) (api_bv.cpp:318)
Multiplication Underflow
C API:Z3_mk_bvmul_no_underflow (api_bv.cpp:330)
Negation Overflow
Check if negation causes overflow (e.g., -128 in 8-bit signed): C API:Z3_mk_bvneg_no_overflow (api_bv.cpp:336)
Division Overflow
Check for signed division overflow: C API:Z3_mk_bvsdiv_no_overflow (api_bv.cpp:348)
Reduction Operations
Reduce AND
AND all bits together:Z3_mk_bvredand (api_bv.cpp:40)
Reduce OR
OR all bits together:Z3_mk_bvredor (api_bv.cpp:41)
Complete Example
Implementation Notes
- Bit-vectors use bit-blasting to convert to propositional logic
- Efficient for fixed-width reasoning
- All operations wrap on overflow (except when using overflow predicates)
- Supports both unsigned and signed interpretations
References
- Implementation:
src/api/api_bv.cpp - Theory plugin:
src/ast/bv_decl_plugin.h - Solver:
src/smt/theory_bv.h
