我正在用python尝试z3。我有以下模型:
(set-option :produce-models true)
(set-logic QF_AUFBV )
(declare-fun a () (Array (_ BitVec 32) (_ BitVec 8) ) )
(declare-fun another () (Array (_ BitVec 32) (_ BitVec 8) ) )
(assert (and (= false (= (_ bv77 32) (concat (select a (_ bv3 32) ) (concat (select a (_ bv2 32) ) (concat (select a (_ bv1 32) ) (select a (_ bv0 32) ) ) ) ) ) ) (= false (= (_ bv12 32) (concat (select another (_ bv3 32) ) (concat (select another (_ bv2 32) ) (concat (select another (_ bv1 32) ) (select another (_ bv0 32) ) ) ) ) ) ) ) )
我可以加载它并检查它是否坐好。此时,如何获得a
和another
的示例值?
import z3
s = z3.Solver()
s.from_file("first.smt")
"""
s
[And(False ==
(77 == Concat(a[3], Concat(a[2], Concat(a[1], a[0])))),
False ==
(12 ==
Concat(another[3],
Concat(another[2],
Concat(another[1], another[0])))))]
"""
s.check()
"""
sat
"""
m = s.model()
m
[a = Lambda(k!0, 1), another = Lambda(k!0, 1)]
谢谢
答案 0 :(得分:1)
Z3默认情况下为数组生成Lambda
抽象;这很有用,但很难看到模型中发生了什么。我建议通过在您的python程序中添加以下行来将其关闭:
z3.set_param('model_compress', False)
import z3
之后,您应该立即执行此操作。
这样,如果您在程序中打印模型,则会得到:
>>> m
[a = [3 -> 1, else -> 1],
another = [1 -> 1, else -> 1],
k!0 = [3 -> 1, else -> 1],
k!1 = [1 -> 1, else -> 1]]
应该更具可读性。 (本质上说a
和another
都是将所有内容都映射为1的数组;尽管有点费解。)