-1

I'm pretty new in Z3, but a thing that my problem could be resolved with it. I have two variables A and B and two pattern like this: pattern_1: 1010x11x pattern_2: x0x01111 where 1 and 0 are the bits zero and one, and x (dont care) cold be the bit 0 or 1. I would like to use Z3Py for check if A with the pattern_1 and B with the pattern_2 can be true at the same time. In this case if A = 10101111 and B = 10101111 than A and B cold be true ate the same time. Can anyone help me with this?? It is possible resolve this with Z3Py

Georgia
  • 43
  • 3

1 Answers1

1

revised answer after clarification

Here's one way you could represent those constraints. There is an operation called Extract that can be applied to bit-vector terms. It is defined as follows:

def Extract(high, low, a): """Create a Z3 bit-vector extraction expression."""

where high is the high bit to be extracted, low is the low bit to be extracted, and a is the bitvector. This function represents the bits of a between high and low, inclusive.

Using the Extract function you can constrain each bit of whatever term you want to check so that it matches the pattern. For example, if the seventh bit of D must be a 1, then you can write s.add(Extract(7, 7, D) == 1). Repeat this for each bit in a pattern that isn't an x.

mtrberzi
  • 215
  • 2
  • 10
  • Thanks a lot. I have one more question. You know how I could represent this vector? Because with BitVec I can't put a value and with BitVecVal I have to put a constant. How I can represent a vector with high, low and dont care ( not defined) value? I appreciate a lot your help. – Georgia Oct 28 '15 at 01:06
  • 1
    With BitVec this isn't possible just by using a single variable. Z3's type system defines the only legal values you can put into a BitVec to be 0 and 1. You would have to encode it either as individual constraints, as I explained, or as two separate BitVec variables -- one that represents whether a bit is "don't care" and one that represents which value (0 or 1) is set given that the bit isn't "don't care". – mtrberzi Oct 29 '15 at 14:01