[英]How I can to use Empty method in a List in Z3Py?
在 z3py 中,我想在 Z3py 中使用 Empty 函数(https://z3prover.github.io/api/html/z3py_8py_source.html#l09944 )
我试图让它像这样:
s = Solver()
# declare a sequence of integers
iseq = Const('iseq', SeqSort(IntSort()))
solve(Empty(iseq)!= True)
# get a model and print it:
if s.check() == sat:
print (s.model())
但我回复我“Z3Exception:传递给空的非序列、非正则表达式排序”
我也尝试 Empty(iseq) 只支持我一个空的序列,但它对我不起作用
这里发生了一些事情:
您通过s = Solver ()
声明了一个求解器对象,但随后您正在调用solve
函数。 solve
创建自己的求解器。 只需使用s.add
代替。
给定排序, Empty
创建一个序列。 你不能在iseq
上调用它。 这就是您收到的错误消息。
我猜你想说的是:声明iseq
,确保它不是空的。 您可以编写如下代码:
from z3 import *
s = Solver()
# declare a sequence of integers
iseq = Const('iseq', SeqSort(IntSort()))
# assert it's not empty
s.add (Length(iseq) != 0)
# get a model and print it:
if s.check() == sat:
print (s.model())
z3 说:
$ python a.py
[iseq = Unit(2)]
因此,它为您提供了一个模型,其中iseq
是包含数字2
的单例序列; 这不是空的,满足我们提出的约束。
下面是一个使用Empty
创建空序列的示例:
from z3 import *
s = Solver()
# Give a name to integer sequences
ISeq = SeqSort(IntSort())
# declare a sequence of integers
iseq = Const('iseq', ISeq)
# make sure it's empty!
s.add (iseq == Empty(ISeq))
# get a model and print it:
if s.check() == sat:
print (s.model())
z3 说:
[iseq = Empty(Seq(Int))]
请注意,z3py 本质上是一种函数式语言; 一旦你断言某些东西等于其他东西,你就不能修改那个值,就像在命令式语言中一样,比如 Python。 希望有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.