【发布时间】:2018-06-04 16:25:21
【问题描述】:
我正在尝试收集公式中的所有变量(Z3py 中的量化公式)。一个小例子
w, x, y, z = Bools('w x y z')
fml = And( ForAll(x, ForAll(y, And(x, y))), ForAll(z, ForAll(w, And(z, w))) )
varSet = traverse( fml )
我用来遍历的代码是
def traverse(e):
r = set()
def collect(e):
if is_quantifier(e):
# Lets assume there is only one type of quantifier
if e.is_forall():
collect(e.body())
else:
if ( is_and(e) ):
n = e.num_args()
for i in range(n):
collect( e.arg(i) )
if ( is_or(e) ):
n = e.num_args()
for i in range(n):
collect( e.arg(i) )
if ( is_not(e) ):
collect( e.arg(0) )
if ( is_var(e) ):
r.add( e )
collect(e)
return r
我得到:set([Var(0), Var(1)])。据我了解,这是由于 Z3 使用了De Bruijn index。是否可以避免这种情况并获得所需的集合:set([Var(0), Var(1), Var(2), Var(3)])。
【问题讨论】:
标签: z3 z3py quantifiers