【发布时间】:2017-01-29 05:27:10
【问题描述】:
我需要使用 C++ 实现 Z3 的集合理论,系统应该像这样工作: 1. 使用C++构建支持常用集合操作的约束系统;
- 以 smtlib2 格式添加额外的约束,我在这里使用 这个 API 在 C 中将字符串转换为 expr:Z3_parse_smtlib2_string
对于集合论,我从 Leonardo 在这篇文章中的原始答案开始: Defining a Theory of Sets with Z3/SMT-LIB2
我尝试了http://rise4fun.com/Z3/DWYC 中的编码,并且在rise4fun 中一切正常。但是,我在将编码转换为 C++ 代码时遇到了一些麻烦,并且在 Z3 中找不到任何用于 C++ 的设置 API。 有什么例子吗?
然后我发现 z3_api.h 包含了为 c 设置的 API。于是我写了一个非常简单的代码sn-p,它似乎可以工作:
//https://github.com/Z3Prover/z3/blob/master/examples/c/test_capi.c#L105
Z3_context c = mk_context();
Z3_solver s = mk_solver(c);
Z3_sort ty = Z3_mk_int_sort(c);
Z3_ast emp = Z3_mk_empty_set(c, ty);
Z3_ast s1 = Z3_mk_empty_set(c, ty);
Z3_ast s2 = Z3_mk_empty_set(c, ty);
Z3_ast one = Z3_mk_int(c, 1, ty);
Z3_ast two = Z3_mk_int(c, 2, ty);
Z3_ast three = Z3_mk_int(c, 3, ty);
s1 = Z3_mk_set_add(c, s1, one);
s1 = Z3_mk_set_add(c, s1, two);
s2 = Z3_mk_set_add(c, s2, three);
Z3_ast intersect_array[2];
intersect_array[0] = s1;
intersect_array[1] = s2;
Z3_ast s3 = Z3_mk_set_intersect(c, 2, intersect_array);
Z3_ast assert1 = Z3_mk_eq(c, s3, emp);
Z3_solver_assert(c, s,assert1);
check(c, s, Z3_L_TRUE);
如果我使用 z3::context 初始化 Z3_context 对象,代码将在调用“Z3_mk_set_intersect”时引发“分段错误”错误。
context ctx;
Z3_context c = ctx.operator _Z3_context *();
我想对字符串元素执行一些设置操作,但我不知道如何将它集成到我的 C++ 代码中,因为我还在 C++ 中创建了自己的 z3:context。如何在 C++ 中直接执行集合操作?
谢谢,
【问题讨论】: