我正在尝试使用Java API学习Z3,因为没有文档,我一直在看C API文档,但是直到现在我仍然找不到如何使用一些基本功能的清晰示例.
我正在尝试编码此Z3代码(在在线版本中有效)
;general options for getting values when sat
(set-option :produce-models true)
(set-option :produce-assignments true)
;declaring new sorts
(declare-sort Task)
(declare-sort User)
;function for assign an specific user
(declare-fun assignUser (Task) User)
;creating a relation between a task and a usert
(declare-fun TaskUser (Task User) Bool)
;stablishing order
(declare-fun mustPrecede (Task Task) Bool)
(assert(forall((t Task)) (not (mustPrecede t t))))
(assert(forall((t1 Task)(t2 Task)(t3 Task)) (implies (and (mustPrecede t1 t2)(mustPrecede t2 t3)) (mustPrecede t1 t3))))
;asserting that all task must have one assigned user
(assert(forall((t Task)(u User)) (TaskUser t u)))
;asserting that all task must have one assigned user
;(assert(forall((t1 Task)(t2 Task)) (not(= (assignUser t1) (assignUser t2)))))
到现在为止,我只是设法声明未解释的排序,并按如下方式声明我的函数
HashMap<String, String> cfg = new HashMap<String, String>();
cfg.put("proof", "true");
cfg.put("auto-config", "false");
Context ctx = new Context(cfg);
//cfg.put("model", "true");
Sort USER = ctx.mkUninterpretedSort("USER");
Sort TASK = ctx.mkUninterpretedSort("TASK");
FuncDecl assignUser = ctx.mkFuncDecl("assignUser", TASK, USER);
FuncDecl TaskUser = ctx.mkFuncDecl("TaskUser", new Sort[] { TASK, USER }, ctx.mkBoolSort());
FuncDecl mustPrecede = ctx.mkFuncDecl("mustPrecede", new Sort[]{TASK,TASK}, ctx.mkBoolSort());
但我找不到表达的例子
(assert(forall((t Task)) (not (mustPrecede t t))))
(assert(forall((t1 Task)(t2 Task)(t3 Task)) (implies (and (mustPrecede t1 t2) (mustPrecede t2 t3)) (mustPrecede t1 t3))))
;asserting that all task must have one assigned user
(assert(forall((t Task)(u User)) (TaskUser t u)))
;asserting that all task must have one assigned user
;(assert(forall((t1 Task)(t2 Task)) (not(= (assignUser t1) (assignUser t2)))))
有人可以帮我吗?用Java API表示此assert-foralls的方法是什么?
解决方法:
Z3代码中的示例包含一组带有各种Java调用的示例:
https://z3.codeplex.com/SourceControl/latest#examples/java/JavaExample.java
它们包括建立和检查量化公式.