【发布时间】:2017-04-04 16:57:26
【问题描述】:
我正在尝试使用适用于 z3 (v4.5.1) 的 C++/C API 加载 smt2 文件,然后使用该 API 添加断言,以及在 smt2 文件中声明的数据类型和函数。
这是我将文件加载到求解器中的示例:
solver loadBackgroundTheoryFile(context& c, string filename) {
Z3_ast ast = Z3_parse_smtlib2_file(c, filename.c_str(), 0, 0, 0, 0, 0, 0);
Z3_solver c_solver;
expr e(c, ast);
solver s(c);
s.add(e);
return s;
}
int main() {
context g;
solver s = loadBackgroundTheoryFile(g, "family.smt2");
std::cout << s << std::endl;
// Here it shows that the solver has all the contents of the family.smt2 file
return 0;
}
那么我如何使用 smt2 文件中定义的内容,使用 C 或 C++ API? (如果可能的话)。我想使用 smt2 文件中定义的函数和数据类型进行更多断言,获取模型,然后进行评估。如果有人感兴趣,这里是 smt2 文件的内容:
;(declare-sort Person)
(declare-datatypes () ((Person (person (name String)))))
(declare-fun related (Person Person) Bool)
(declare-fun father (Person Person) Bool)
(declare-fun sibling (Person Person) Bool)
; related symetric
(assert
(forall ((p Person) (q Person))
(=> (related p q)
(related q p))))
; related transitive
(assert
(forall ((p Person) (q Person) (j Person))
(=> (and (related p q) (related q j))
(related p j))))
; the father of a person is related to that person
(assert
(forall ((p Person) (q Person))
(=> (father p q)
(related p q))))
; for all people, there exists another person that is their father
(assert
(forall ((p Person))
(exists ((q Person)) (father q p))))
; sibling symetric
(assert
(forall ((p Person) (q Person))
(=> (sibling p q) (sibling q p))))
; siblings have the same father
(assert
(forall ((p Person) (q Person) (j Person))
(=> (and (sibling p q) (father j p))
(father j q))))
(declare-fun get-father (Person) Person)
; here we use a double implication to define the behavior of get-father
(assert
(forall ((p Person) (q Person))
(= (father q p) (= (get-father p) q))))
【问题讨论】:
标签: z3