Skip to main content
The bit-vector theory provides reasoning about fixed-width integers with operations like those found in hardware and low-level programming. Bit-vectors support both unsigned and signed interpretations.

Bit-Vector Sort

Create a bit-vector sort of a specific size:
C API: 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

C API: Z3_mk_bvand (api_bv.cpp:42)

Bitwise OR

C API: Z3_mk_bvor (api_bv.cpp:43)

Bitwise XOR

C API: Z3_mk_bvxor (api_bv.cpp:44)

Bitwise NOT

C API: Z3_mk_bvnot (api_bv.cpp:39)

NAND, NOR, XNOR

Additional bitwise operations:
C API: Z3_mk_bvnand, Z3_mk_bvnor, Z3_mk_bvxnor (api_bv.cpp:45-47)

Arithmetic Operations

Addition

C API: Z3_mk_bvadd (api_bv.cpp:48)

Subtraction

C API: Z3_mk_bvsub (api_bv.cpp:373)

Multiplication

C API: Z3_mk_bvmul (api_bv.cpp:49)

Negation

C API: Z3_mk_bvneg (api_bv.cpp:381)

Division and Modulo

Unsigned Division

C API: Z3_mk_bvudiv (api_bv.cpp:50)

Signed Division

C API: Z3_mk_bvsdiv (api_bv.cpp:51)

Unsigned Remainder

C API: Z3_mk_bvurem (api_bv.cpp:52)

Signed Remainder and Modulo

C API: Z3_mk_bvsrem, Z3_mk_bvsmod (api_bv.cpp:53-54)

Comparison Operations

Unsigned Comparisons

C API: Z3_mk_bvult, Z3_mk_bvule, Z3_mk_bvugt, Z3_mk_bvuge (api_bv.cpp:55, 57, 59, 61)

Signed Comparisons

C API: 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:
C API: Z3_mk_concat (api_bv.cpp:63)

Extract

Extract a sub-range of bits:
C API: Z3_mk_extract(c, high, low, n) (api_bv.cpp:79)

Shift Operations

C API: Z3_mk_bvshl, Z3_mk_bvlshr, Z3_mk_bvashr (api_bv.cpp:64-66)

Rotate

C API: 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:
C API: Z3_mk_zero_ext, Z3_mk_sign_ext (api_bv.cpp:102-103)

Repeat

Repeat a bit-vector pattern:
C API: Z3_mk_repeat (api_bv.cpp:104)

Conversion Operations

Bit-Vector to Integer

C API: Z3_mk_bv2int(c, n, is_signed) (api_bv.cpp:110)

Integer to Bit-Vector

C API: Z3_mk_int2bv (api_bv.cpp:108)

Overflow Detection

Z3 provides predicates to detect arithmetic overflow:

Addition Overflow

C API: Z3_mk_bvadd_no_overflow(c, t1, t2, is_signed) (api_bv.cpp:183)

Addition Underflow

C API: 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:
C API: Z3_mk_bvredand (api_bv.cpp:40)

Reduce OR

OR all bits together:
C API: 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