5

I am new to z3py and was going through the Z3 API in Python, but couldn't figure out how to define an array of bitvectors.

I want something like:

DOT__mem[16] = BitVec('DOT__mem[16]', 8)

but this syntax didn't work, even on the practice panel in the tutorial.

Can someone help with the correct syntax?

David Cain
  • 16,484
  • 14
  • 65
  • 75
Sharad
  • 445
  • 6
  • 20

1 Answers1

7

The following examples illustrate how to create a "vector" (Python list) of Z3 Bit-Vectors. The example is also available online at rise4fun.

# Create a Bitvector of size 8
a = BitVec('a', 8)

# Create a "vector" (list) with 16 Bit-vectors of size 8
DomVect = [ BitVec('DomVect_%s' % i, 8) for i in range(16) ]
print DomVect
print DomVect[15]

def BitVecVector(prefix, sz, N):
  """Create a vector with N Bit-Vectors of size sz"""
  return [ BitVec('%s__%s' % (prefix, i), sz) for i in range(N) ]

# The function BitVecVector is similar to the functions IntVector and RealVector in Z3Py.

# Create a vector with 32 Bit-vectors of size 8. 
print BitVecVector("A", 8, 32)
Leonardo de Moura
  • 21,065
  • 2
  • 47
  • 53
  • Can we create a function which takes an `integer/bitvecotr` as argument and returns a "BitVecVector"? What `sort` we need to use for a "BitVecVector"? Thanks – Shafiul Nov 20 '15 at 03:46