首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >来自z3-4.8.9-x64-ubuntu-16.04的非终止Z3Str3

来自z3-4.8.9-x64-ubuntu-16.04的非终止Z3Str3
EN

Stack Overflow用户
提问于 2021-11-18 23:22:00
回答 1查看 35关注 0票数 0

在尝试使用来自z3-4.8.9-x64-ubuntu-16.04Z3Str3时,我遇到了一个问题,特别是如果我将com.microsoft.z3.jar替换为z3-4.8.8-x64-ubuntu-16.04中的那个,我就不再有这个问题了。问题是,尽管查询很简单,但Z3进程永远不会返回结果。我注意到当我杀死我的程序时,它会返回有效的答案。当我试图在可执行文件上运行相同的查询时,我没有注意到这种行为,所以我猜使用jar文件有一些东西,我可能需要以某种方式进行调整。

这是我的代码。我使用的是Ubuntu16.04LTS和IntelliJ终极版2020.3。

非常感谢!

代码语言:javascript
复制
import com.microsoft.z3.*;
public class Z3String3Processor_reduced {
    public static void main(String[] args) {
        StringBuilder currentQuery = new StringBuilder("\n" +
                "(declare-const string0 String)\n" +
                "(assert (= (str.indexof string0 \"a\" 1) 6))\n" +
                "(check-sat)\n" +
                "(get-model)\n" +
                "\n");
        Context context1 = new Context();
        Solver solver1 = context1.mkSolver();
        Params params = context1.mkParams();
        params.add("smt.string_solver", "z3str3");
        solver1.setParameters(params);
        StringBuilder finalQuery = new StringBuilder(currentQuery.toString());

        // attempt to parse the query, if successful continue with checking satisfiability
        try {

            // throws z3 exception if malformed or unknown constant/operation
            BoolExpr[] assertions = context1.parseSMTLIB2String(finalQuery.toString(), null, null, null, null);
            solver1.add(assertions);
            // check sat, if so we can go ahead and get the model....
            if (solver1.check() == Status.SATISFIABLE) {
                System.out.println("sat");
            } else
                System.out.println("not sat");
            context1.close();
        } catch (Z3Exception e) {
            System.out.println("Z3 exception: " + e.getMessage());
        }
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-11-19 02:06:52

我不认为这与Java有任何关系。让我们提取您的查询并将其放入名为a.smt2的文件中

代码语言:javascript
复制
$ cat a.smt2
(declare-const string0 String)
(assert (= (str.indexof string0 "a" 1) 6))
(check-sat)
(get-model)

现在,如果我运行:

代码语言:javascript
复制
$ z3 a.smt2
sat
(
  (define-fun string0 () String
    "FBCADEaGaa")
)

那很好。但是如果我运行:

代码语言:javascript
复制
$ z3  smt.string_solver=z3str3 a.smt2
... does not terminate ..

所以,最重要的是,您的查询(就像它看起来那么简单)给z3str3求解器带来了困难。

我看到你已经在https://github.com/Z3Prover/z3/issues/5673上报了这是一个错误

既然默认的字符串求解器可以很好地处理查询,为什么不直接使用它呢?如果您因为其他原因而不得不使用z3str3,那么您已经发现了它不能很好地处理这个查询的情况;我不确定z3人员会倾向于修复这个问题,因为查询是由默认求解器处理得相当快的。请报告您发现的情况!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70027987

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档