【发布时间】:2013-04-02 07:35:34
【问题描述】:
我想在 Z3 中查看 C-API Z3_mk_forall_const() 的示例。
我正在尝试编码 -
(define-fun max_integ ((x Int) (y Int)) Int
(ite (< x y) y x))
我尝试了以下,但我得到了type error
#include <stdio.h>
#include <stdlib.h>
#include <z3.h>
void error_handler(Z3_context c, Z3_error_code e)
{
printf("Error code: %d\n", e);
printf("Error msg : %s\n", Z3_get_error_msg(e));
exit(0);
}
Z3_context mk_context_custom(Z3_config cfg, Z3_error_handler err)
{
Z3_context ctx;
Z3_set_param_value(cfg, "MODEL", "true");
ctx = Z3_mk_context(cfg);
Z3_set_error_handler(ctx, err);
return ctx;
}
Z3_context mk_context()
{
Z3_config cfg;
Z3_context ctx;
cfg = Z3_mk_config();
ctx = mk_context_custom(cfg, error_handler);
Z3_del_config(cfg);
return ctx;
}
Z3_ast mk_var(Z3_context ctx, const char * name, Z3_sort ty)
{
Z3_symbol s = Z3_mk_string_symbol(ctx, name);
return Z3_mk_const(ctx, s, ty);
}
Z3_ast mk_int_var(Z3_context ctx, const char * name)
{
Z3_sort ty = Z3_mk_int_sort(ctx);
return mk_var(ctx, name, ty);
}
int main()
{
Z3_context ctx;
Z3_func_decl f;
Z3_sort int_sort;
Z3_symbol f_name;
Z3_ast xVar, yVar;
Z3_app bound[2];
Z3_ast implication;
Z3_sort f_domain[2];
// Make context.
ctx = mk_context();
int_sort = Z3_mk_int_sort(ctx);
f_name = Z3_mk_string_symbol(ctx, "max_integer");
f_domain[0] = int_sort;
f_domain[1] = int_sort;
f = Z3_mk_func_decl(ctx, f_name, 2, f_domain, int_sort);
xVar = mk_int_var(ctx, "x");
yVar = mk_int_var(ctx, "y");
bound[0] = (Z3_app)xVar;
bound[1] = (Z3_app)yVar;
implication = Z3_mk_ite(ctx, Z3_mk_lt(ctx, xVar, yVar), xVar, yVar);
Z3_mk_forall_const(ctx, 0, 2, bound, 0, 0, implication);
// Delete the context.
Z3_del_context(ctx);
return 0;
}
【问题讨论】:
-
This question 可能会有所帮助。
-
不能用正则常量来表示量化子句中的绑定变量,需要制作绑定变量。请参阅 API 中的 z3_mk_bound。
-
感谢您的回答。我以前读过这篇文章,但这对我来说有点混乱。我试图在我的代码中实现它,但我没有成功编译代码。
-
在我的代码中我有
xVar = Z3_mk_bound(ctx, 0, int_sort);yVar = Z3_mk_bound(ctx, 1, int_sort);但它不起作用。 -
我还检查了 2 个来源 1. Z3 API for
Z3_mk_forall_const和 2. this link,都说我们可以在绑定参数中使用 const 变量。