解析SMT-LIB2字符串使用现有上下文声明上下文、字符串、声明、SMT

2023-09-07 09:03:58 作者:日不落.

我有.NET API中创建的现有Z3 4.1范围内,有许多函数声明,排序声明,假设断言,等等。

I have an existing Z3 4.1 context created in the .NET API, with many function declarations, sort declarations, assumptions asserted, etc.

什么是解析使用所有现有的宣言在这方面的SMT-LIB2字符串,最彻底的方法?具体来说,有没有办法来迭代在上下文中的所有声明?我没有看到任何上下文的方法,让我来访问的声明。

What is the cleanest way to parse an SMT-LIB2 string using all the existing declarations in this context? Specifically, is there a way to iterate over all the declarations in a context? I did not see any methods in Context that would allow me to access the declarations.

目前,我做了以下内容:

Currently, I am doing the following:

Context z3 = new Context();

// ... declare sorts, add declarations (parsing other input files), add assertions, to z3 context

List<FuncDecl> decls = new List<FuncDecl>();
List<Symbol> names = new List<Symbol>();
string pstr; // smtlib2 string to be parsed populated elsewhere

// ... populate decls and names by iterating over my internal data structures with references to these declarations

BoolExpr prop = z3.ParseSMTLIB2String(pstr, null, null, names.ToArray(), decls.ToArray());

有没有办法让所有这些声明并从Z3环境本身的符号名?他们都已经在Z3对象声明。我宁愿做这种方式比遍历我的内部数据结构。

Is there a way to get all these declarations and symbol names from the z3 context itself? They all have already been declared in the z3 object. I would rather do it this way than iterate over my internal data structures.

我可能已经错过了,但我没有看到任何将让我在API中做到这一点。我成像相似,可通过Solver.Assertions断言公式的数组的东西。

I may have missed it, but I didn't see anything that would let me do this in the API. I'm imaging something similar to the array of asserted formulas available via Solver.Assertions.

推荐答案

您的解决方案看起来是正确的。该decls和名称可以收集他们第一次发生,而不是改造他们为每个呼叫,这将摆脱迭代过内部数据结构为每一个​​电话。需要注意的是,如果你正在多方呼吁,Z3,采用SMT解析器可能不是最有效的解决方案;如果可能的话,我会建议构建一个字符串Z3 EX pressions,而不是直接(在这种情况下,符号的表很可能是必要的,也是)。

Your solution looks correct. The decls and names could be collected the first time they occur instead of reconstructing them for each call, which would get rid of the iteration over internal data structures for every call. Note that, if you are making many calls to Z3, using the SMT parser may not be the most efficient solution; If possible, I would recommend constructing Z3 expressions directly instead of strings (in which case a table of symbols would likely be necessary as well).