Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

retrieving value of an enumerated type in Z3Py

Tags:

python

z3

How do I retrieve the values of an enumerated variable v ? For example,

vTyp, (val1,val2,val3) = EnumSort('vTyp',['val1','val2','val3'])
v = Const('my variable',vTyp)

Now, given just the above variable v, how would I retrieve a list of values [val1,val2,val3] of v (where val1,val3,val3 are expressions as above) ?

I have tried [v.sort().constructor(0), ...(1), ...(2)] but the constructor method does not return an expression.

like image 217
Vu Nguyen Avatar asked Oct 06 '22 10:10

Vu Nguyen


1 Answers

The expression v.sort().constructor(0) returns a Z3 function declaration. In Z3, constants are functions with 0 arguments. To convert the declaration in a constant expression, we should use v.sort().constructor(0)().

BTW, the function is_func_decl can be used to test whether an object is a Z3 function declaration or not. The function is_expr is the equivalent for Z3 expressions.

print is_func_decl(v.sort().constructor(0))
print is_expr(v.sort().constructor(0))
print is_expr(v.sort().constructor(0)())
like image 105
Leonardo de Moura Avatar answered Oct 10 '22 02:10

Leonardo de Moura