[英]How to define a function in Z3 java API?
我正在學習在匹配案例中運行類似的代碼,用於匹配運輸卡車( https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/nbjorner- nuz.pdf ) in JAVA API. 有一個定義最大function的代碼:
(define-fun imax ((a Int) (b Int)) Int (if (> a b) a b))
我將其翻譯成 Java:
public static ArithExpr maxFunc(ArithExpr a, ArithExpr b)
{
Context ctx = new Context();
ArithExpr result = (ArithExpr) ctx.mkITE(ctx.mkGe(a, b), a, b);
return result;
}
並嘗試以同樣的方式使用它(以下只是一個演示)
ArithExpr per1 = maxFunc(X0101, maxFunc(X0201, maxFunc(X0301, maxFunc(X0401, X0501))));
BoolExpr minPer1 = ctx.mkEq(per1, constant0);
o.AssertSoft(minPer1,1 , "a");
以上代碼存在錯誤:
Exception in thread "main" com.microsoft.z3.Z3Exception: Context mismatch
錯誤指的是function正文:
ArithExpr result = (ArithExpr) ctx.mkITE(ctx.mkGe(a, b), a, b);
我對在 JAVA 中構造 z3 function 肯定有疑問。Z3 Java API 是否存在特殊的 function 形式? 如何修復function?
“上下文不匹配”意味着您正在嘗試同時使用來自多個上下文的表達式,這是不受支持的。 而不是Context ctx = new Context();
, 請確保您使用的上下文與您在程序的 rest 中使用的上下文相同。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.