[英]Z3, solver: push an empty level on assertion-stack, as defined in smtlib2: push(n=1)
目前,我正在使用Z3和Python。 我想創建一個斷言堆棧,在其中可以推入一個級別並稍后將其彈出。 它應該與帶有推入和彈出操作的任何其他“堆棧”完全一樣。 因此,SMTLIB2標准定義了帶有可選數字n的兩個函數“ push(n)”和“ pop(n)”。 在我的情況下,n始終為1。
但是Z3中似乎有一些奇怪的行為。 為什么下面的代碼導致“索引超出范圍”?
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)
如果添加斷言,則Z3會按預期工作。
s = Solver()
s.push()
s.add(True) # now there is one level on the stack,
s.pop(1) # pop is successful
即使這是正確的:
s = Solver()
s.add(True)
s.push() # now there is one level on the stack,
s.pop(1) # pop is successful
問題是,我不知道在我的程序中創建了多少個級別和多少個斷言。 有可能根本沒有斷言,只有一個層次。 然后程序將崩潰(或捕獲異常)。 解決方法是始終將第一步添加為“ True”之類的簡單公式,但這似乎很丑。
這是Z3中的錯誤還是此行為正確?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.