简体   繁体   English

在Z3Py中检索枚举类型的值

[英]retrieving value of an enumerated type in Z3Py

How do I retrieve the values of an enumerated variable v ? 如何检索枚举变量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) ? 现在, 给定上述变量v ,我将如何检索值的列表[val1,val2,val3]v (其中val1,val3,val3是表达如上)?

I have tried [v.sort().constructor(0), ...(1), ...(2)] but the constructor method does not return an expression. 我试过[v.sort().constructor(0), ...(1), ...(2)]但是构造函数方法没有返回表达式。

The expression v.sort().constructor(0) returns a Z3 function declaration. 表达式v.sort().constructor(0)返回Z3函数声明。 In Z3, constants are functions with 0 arguments. 在Z3中,常量是具有0个参数的函数。 To convert the declaration in a constant expression, we should use v.sort().constructor(0)() . 要在常量表达式中转换声明,我们应该使用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. 顺便说一句,函数is_func_decl可用于测试对象是否是Z3函数声明。 The function is_expr is the equivalent for Z3 expressions. 函数is_expr与Z3表达式等效。

print is_func_decl(v.sort().constructor(0))
print is_expr(v.sort().constructor(0))
print is_expr(v.sort().constructor(0)())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM