简体   繁体   中英

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

currently I am using Z3 with 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. In my case n would always be 1.

But there seems to be some strange behaviour in 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.

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.

Is this a bug in Z3 or is this behaviour correct?

This bug has been fixed in the unstable (working-in-progress) branch. 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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