如何在Z3中建模构造?
给定这样的结构:
struct MyStruct {
uint[10] a;
uint b;
bool c;
};
Mystruct m;
我的问题是如何使用 z3
来建模变量 m
?一个简单的解决方案是将 m
拆分为多个变量:ma、mb、mc
。但是,它是不可扩展的(在我看来)。 z3
支持更好的解决方案吗?谢谢!
我正在尝试在 z3 中建模结构!
Given a struct like this:
struct MyStruct {
uint[10] a;
uint b;
bool c;
};
Mystruct m;
My problem is how to model variable m
using z3
? a trivial solution is to split m
into multiple variables: m.a, m.b, m.c
. However, it is not extensible (in my opinion). Are there any better solution supported by z3
? thanks!
I am trying to model struct in z3 !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 SMTLib 中执行此操作的标准方法是使用数据类型。请参阅 https://smtlib.cs.uiowa.edu/papers/smt-lib-reference-v2.6-r2021-05-12.pdf。这是该文档中的“对”示例:
请注意,上面是参数化的,即它允许您创建具有不同类型的对。您可以将其单态化:
并使用标签
a
/b
/c
等来添加您自己的具有所需类型的字段。详细信息请参见 SMTLib 文档。如果您使用的是更高级别的 API(例如 Haskell、Python、Scala 的 API)等;他们可能会提供更简单的方法来做到这一点;你需要检查他们自己的文档。特别是,如果您使用的是 z3py,请参阅 https://ericpony.github .io/z3py-tutorial/advanced-examples.htm,标题为“数据类型”的部分。
请注意,SMTLib/z3 结构甚至可以是递归的,即字段可以包含您定义的类型的值。您甚至可以创建相互递归的数据类型。看来您在这里不需要这些设施,但相同的机制应该适合您。
The standard way to do this in SMTLib is to use datatypes. See Section 4.2.3 of https://smtlib.cs.uiowa.edu/papers/smt-lib-reference-v2.6-r2021-05-12.pdf. Here's the "pair" example from that document:
Note that the above is parametric, i.e., it allows you to create pairs with differing types in them. You can monomorphize it:
and use the tags
a
/b
/c
etc. to add your own fields with the types you want. See the SMTLib document for details.If you are using a higher-level API (like that from Haskell, Python, Scala) etc; they might provide easier ways to do the same; you need to check their own documentation. In particular, if you're using z3py, See https://ericpony.github.io/z3py-tutorial/advanced-examples.htm, in the section titled "Datatypes."
Note that SMTLib/z3 structs can even be recursive, i.e., the fields can contain values of type that you are defining. You can even make mutually recursive datatypes. It seems you do not need those facility here, but the same mechanism should work for you just fine.