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()
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.

1 Answer
1

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.