Использование "для всех" с неинтерпретируемыми видами JAVA API

Я пытаюсь изучить Z3, используя java 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))))) 

Может ли кто-нибудь помочь мне с этим, пожалуйста? Какой способ выразить эти утверждения-запросы с помощью API Java?

2 ответа

В качестве примеров в коде Z3 представлен набор примеров с различными вызовами Java:

https://z3.codeplex.com/SourceControl/latest

Они включают построение и проверку количественных формул.

//creating uninterpreted sorts for function declaration
Sort User = ctx.mkUninterpretedSort("User");
Sort Task = ctx.mkUninterpretedSort("Task");
//function declaration
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());

//task for using in quatifiers
Expr task = ctx.mkConst("t", ctx.mkUninterpretedSort(ctx.mkSymbol("Task")));

// creating (assert(forall((t Task)) (not (mustPrecede t t))))
//just one task is needed
Sort[] Tasks = new Sort[1];
Tasks[0] =ctx.mkUninterpretedSort(ctx.mkSymbol("Task"));
//setting the name for the task
Symbol[] namess = new Symbol[1];
namess[0] =  ctx.mkSymbol("t");
//Creating a map between mustPrecede and  its two parameters
Expr mtt = ctx.mkApp(mustPrecede, task,task);
//acreating not
Expr body = ctx.mkNot((BoolExpr)mtt);

Expr mustPrecedett = ctx.mkForall(Tasks, namess, body, 1, null, null,
ctx.mkSymbol("Q1"), ctx.mkSymbol("skid1"));

System.out.println("Quantifier mustPrecedett: " + mustPrecedett.toString());

//creating (assert(forall((t1 Task)(t2 Task)(t3 Task)) (implies (and (mustPrecede t1 t2)(mustPrecede t2 t3)) (mustPrecede t1 t3))))

//tree taks will be neede
Sort[] tTask = new Sort[3];
tTask[0] =ctx.mkUninterpretedSort(ctx.mkSymbol("Task"));
tTask[1] =ctx.mkUninterpretedSort(ctx.mkSymbol("Task"));
tTask[2] =ctx.mkUninterpretedSort(ctx.mkSymbol("Task"));

//setting the names for the tasks
Symbol[] Tnames = new Symbol[3];
Tnames[0] =  ctx.mkSymbol("t1");
Tnames[1] =  ctx.mkSymbol("t2");
Tnames[2] =  ctx.mkSymbol("t3");

//creating tree diferent tasks for the relations
Expr t1 = ctx.mkConst("t1", ctx.mkUninterpretedSort(ctx.mkSymbol("Task")));
Expr t2 = ctx.mkConst("t2", ctx.mkUninterpretedSort(ctx.mkSymbol("Task")));
Expr t3 = ctx.mkConst("t3", ctx.mkUninterpretedSort(ctx.mkSymbol("Task")));
//creating mappins
Expr mt1t2 = ctx.mkApp(mustPrecede, t1,t2);
Expr mt2t3 = ctx.mkApp(mustPrecede, t2,t3);
Expr mt1t3 = ctx.mkApp(mustPrecede, t1,t3);
//Creating the relation between them        
Expr tbody2= ctx.mkImplies(ctx.mkAnd((BoolExpr)mt1t2,(BoolExpr) mt2t3), (BoolExpr) mt1t3);  
//building quatifier
Expr tra = ctx.mkForall(tTask, Tnames, tbody2, 1, null, null,ctx.mkSymbol("Q1"), ctx.mkSymbol("skid1"));

System.out.println("Quantifier tra: " + tra.toString());



//creating (assert(forall((t Task)(u User)) (TaskUser t u)))
//one user and one task
Sort[] userTask = new Sort[2];
userTask[0] =ctx.mkUninterpretedSort(ctx.mkSymbol("Task"));
userTask[1] =ctx.mkUninterpretedSort(ctx.mkSymbol("User"));
//setting names
Symbol[] userNames = new Symbol[2];
userNames[0] =  ctx.mkSymbol("t");
userNames[1] =  ctx.mkSymbol("u");
//creating one cost for the user        
Expr user = ctx.mkConst("u", ctx.mkUninterpretedSort(ctx.mkSymbol("User")));
//creating the relation between them and TaskUser funct
Expr uTask = ctx.mkApp(TaskUser, task,user);
//building quatificar
Expr userTaskExpr = ctx.mkForall(userTask, userNames, uTask, 1, null, null,ctx.mkSymbol("Q1"), ctx.mkSymbol("skid1"));

System.out.println("Quantifier userTaskExpr: " + userTaskExpr.toString());
Другие вопросы по тегам