简体   繁体   English

Z3,求解器:按smtlib2中的定义在声明堆栈上推送空级别:push(n = 1)

[英]Z3, solver: push an empty level on assertion-stack, as defined in smtlib2: push(n=1)

currently I am using Z3 with Python. 目前,我正在使用Z3和Python。 I want to create an assertion-stack, where I can push a level and pop it later. 我想创建一个断言堆栈,在其中可以推入一个级别并稍后将其弹出。 It should work exactly like any other "stack" with push- and pop-operations. 它应该与带有推入和弹出操作的任何其他“堆栈”完全一样。 Therefore the SMTLIB2-standard defines two functions "push(n)" and "pop(n)" with optional numbers n. 因此,SMTLIB2标准定义了带有可选数字n的两个函数“ push(n)”和“ pop(n)”。 In my case n would always be 1. 在我的情况下,n始终为1。

But there seems to be some strange behaviour in Z3. 但是Z3中似乎有一些奇怪的行为。 Why does following code result in "index out of bounds"? 为什么下面的代码导致“索引超出范围”?

s = Solver()
s.push()     # expected: one new level on the stack, reality: emtpy stack
s.pop(1)     # expected: stack is empty, reality: exception (index out of bounds)

If I add an assertions, Z3 works as expected. 如果添加断言,则Z3会按预期工作。

s = Solver()
s.push()
s.add(True)  # now there is one level on the stack,
s.pop(1)     # pop is successful

Even this works correct: 即使这是正确的:

s = Solver()
s.add(True)
s.push()     # now there is one level on the stack,
s.pop(1)     # pop is successful

The problem is, that I do not know, how many levels and how many assertions are created in my program. 问题是,我不知道在我的程序中创建了多少个级别和多少个断言。 It is possible, that there is no assertion at all and only one level. 有可能根本没有断言,只有一个层次。 Then the program would crash (or catch the exception). 然后程序将崩溃(或捕获异常)。 A workaround would be adding some simple formula like "True" always as a first step, but this seems ugly. 解决方法是始终将第一步添加为“ True”之类的简单公式,但这似乎很丑。

Is this a bug in Z3 or is this behaviour correct? 这是Z3中的错误还是此行为正确?

This bug has been fixed in the unstable (working-in-progress) branch. 此错误已在unstable (正在运行)分支中修复。 It will be available in the next official release. 它将在下一个正式版本中提供。 In the meantime, here are some instructions on how to compile the unstable branch. 同时, 这里有一些有关如何编译不稳定分支的说明。 The fix is also available in the nightly builds available at codeplex . 该修补程序还可以在codeplex每晚构建中找到。

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

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