简体   繁体   English

如何从Z3 smtlib2公式获取声明?

[英]How to get the declaration from a Z3 smtlib2 formula?

I would like to do incremental solving with Z3 with the C++ API. 我想使用C ++ API使用Z3进行增量求解。

There are already some old questions, 2012, about this: 2012年已经有一些关于此的旧问题:

Z3 4.0 Z3_parse_smtlib2_string Z3 4.0 Z3_parse_smtlib2_string

Z3 4.0: get complete model Z3 4.0:获取完整的模型

Z3 4.3.1 C-API parse_smtlib2_string: Where to get declarations from? Z3 4.3.1 C-API parse_smtlib2_string:从哪里获取声明?

I would like to know if there is a solution with the new Z3 versions, 4.4.2. 我想知道新的Z3版本4.4.2是否有解决方案。

Basically what I want to do it is something like this: 基本上我想做的是这样的:

char *decl = "(declare-const p0 Bool)";
char *assert = "(assert(= p0 true))";

Z3_ast ast = Z3_parse_smtlib2_string(ctx, (Z3_string)decl, 0, 0, 0, 0, 0, 0);
z3::expr eq1(ctx, ast);
solver.add(eq1);

//extract declarations from the solver, ctx or ast
...

//Parse the assert with the previous declarations
Z3_ast ast = Z3_parse_smtlib2_string(ctx, (Z3_string)assert, 0, 0, 0, num_decls, symbols, decl_list);
z3::expr eq2(ctx, ast);
solver.add(eq2);
solver.check();

But I don't know how to get the declarations. 但是我不知道如何获取声明。 I tried to use Z3_get_smtlib_num_decls, but it is only working with smtlib1, not with smtlib2. 我尝试使用Z3_get_smtlib_num_decls,但它仅与smtlib1一起使用,而不与smtlib2一起使用。

Is there a way to retrieve the declarations? 有没有办法检索声明? Will the function Z3_get_smtlib2_num_decls be implemented in the future? 将来会实现Z3_get_smtlib2_num_decls函数吗?

Thank you for your time. 感谢您的时间。

Like Nikolaj said in Z3 4.3.1 C-API parse_smtlib2_string: Where to get declarations from? 就像Nikolaj在Z3 4.3.1中所说的那样, C-API parse_smtlib2_string:从哪里获取声明? , you'll have to traverse the expressions (assertions) to collect the declarations. ,则必须遍历表达式(断言)以收集声明。 The link to the tptp example is broken, but the file comes with Z3 as examples/tptp/tptp5.cpp (see the collect_decls function). tptp示例的链接已断开,但该文件随附Z3作为examples/tptp/tptp5.cpp (请参见collect_decls函数)。

See also: Display declarations parsed from an SMT-LIB2 file 另请参阅: 显示从SMT-LIB2文件解析的声明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM