【问题标题】:Adding assertions to Z3 after loading in smt2 file with C++ API使用 C++ API 加载 smt2 文件后向 Z3 添加断言
【发布时间】: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


    【解决方案1】:

    这是一个非常“特定于 z3 实现”的问题。如果您在此处向开发人员提交票证,您可能会得到更好的回应:https://github.com/Z3Prover/z3/issues

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-27
    • 2017-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多