使用 Z3 和 smtlib 计算具有混合值的配置/模型
如何计算属性值? 这是一个例子:
(declare-fun x () bool)
(declare-fun y () bool)
(declare-fun z () bool)
(assert (AND x (OR y z)))
这样我会得到 2 个模型:
x=true and y=true
x=true and z=true
现在,我想要的是这样的:
(declare-fun x () bool)
(declare-fun y () bool)
(declare-fun z () bool)
(declare-fun x.val () Int)
(declare-fun y.val () Int)
(declare-fun z.val () Int)
(assert (= x.val 2))
(assert (= y.val 3))
(assert (= z.val 5))
(assert (AND x (OR y z)))
(assert (> sum 6))
所以,我想得到属性总和大于 6 的模型:
x=true and z=true
也许使用数组是一种方法达到这个...
How do I calculate attributed values?
Here's an example:
(declare-fun x () bool)
(declare-fun y () bool)
(declare-fun z () bool)
(assert (AND x (OR y z)))
With this I would get 2 models:
x=true and y=true
x=true and z=true
Now, what I want is something like this:
(declare-fun x () bool)
(declare-fun y () bool)
(declare-fun z () bool)
(declare-fun x.val () Int)
(declare-fun y.val () Int)
(declare-fun z.val () Int)
(assert (= x.val 2))
(assert (= y.val 3))
(assert (= z.val 5))
(assert (AND x (OR y z)))
(assert (> sum 6))
So, I would like to get the model where the sum of the attributes is larger than 6:
x=true and z=true
Maybe working with arrays is a way to achieve this...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定我是否正确理解了你的问题。
您似乎想将一个(整数)属性关联到每个布尔变量。
因此,每个变量都是一对:一个布尔值和一个整数属性。
我假设
sum
是指分配给 true 的变量属性的总和。如果是这种情况,您可以按以下方式在 Z3 中对其进行建模:
I’m not sure if I understood your question correctly.
It seems you want to associate an (integer) attribute to each Boolean variable.
So, each variable is a pair: a Boolean value, and an integer attribute.
I’m assuming that by
sum
, you meant the sum of the attributes of the variables assigned to true.If that is the case, you can model it in Z3 in the following way:
对于三个变量,我想它会是这样的:
这里我定义了一个宏 cond_add 来在相应的条件成立时将变量添加到累加器中。
sum
被定义为考虑基于x.val
、y.val
和z.val
的条件总和关于x
、y
和z
的真值。With three variables, I imagine it would be something like:
Here I define a macro
cond_add
to add a variable to an accumulator when a corresponding condition holds. Andsum
is defined to account for conditional sum ofx.val
,y.val
andz.val
based on truth values ofx
,y
andz
.