如何从 Lambda 表达式中获取值?

How get a a value from a Lambda expression?

我正在 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) ) ) ) ) ) ) ) )

我可以加载它并检查是否已安装。此时我如何获得 aanother 的示例值?

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)] 

谢谢

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]]

这应该更具可读性。 (它本质上是说 aanother 都是将所有内容映射到 1 的数组;虽然有点复杂。)