diff --git a/java-backend/src/main/java/org/kframework/backend/java/symbolic/KILtoSMTLib.java b/java-backend/src/main/java/org/kframework/backend/java/symbolic/KILtoSMTLib.java index 4e6b40deb7..922f1f6e67 100644 --- a/java-backend/src/main/java/org/kframework/backend/java/symbolic/KILtoSMTLib.java +++ b/java-backend/src/main/java/org/kframework/backend/java/symbolic/KILtoSMTLib.java @@ -195,9 +195,9 @@ public static String translateImplication( sb.append(leftTransformer.getConstantDeclarations(Sets.difference( Sets.union(leftTransformer.variables(), rightTransformer.variables()), rightHandSideOnlyVariables))); - sb.append("(assert (and "); + sb.append("(assert "); sb.append(leftExpression); - sb.append(" (not "); + sb.append(")\n(check-sat)\n(assert (not "); rightHandSideOnlyVariables = Sets.intersection( rightTransformer.variables(), rightHandSideOnlyVariables); @@ -210,7 +210,7 @@ public static String translateImplication( if (!rightHandSideOnlyVariables.isEmpty()) { sb.append(")"); } - sb.append(")))"); + sb.append("))"); return sb.toString(); } diff --git a/java-backend/src/main/java/org/kframework/backend/java/symbolic/SMTOperations.java b/java-backend/src/main/java/org/kframework/backend/java/symbolic/SMTOperations.java index 661c8a5168..22611eb90b 100644 --- a/java-backend/src/main/java/org/kframework/backend/java/symbolic/SMTOperations.java +++ b/java-backend/src/main/java/org/kframework/backend/java/symbolic/SMTOperations.java @@ -63,7 +63,7 @@ public boolean impliesSMT( Set rightOnlyVariables) { if (smtOptions.smt == SMTSolver.Z3) { try { - return z3.isUnsat( + return z3.isImplication( KILtoSMTLib.translateImplication(left, right, rightOnlyVariables), smtOptions.z3ImplTimeout); } catch (UnsupportedOperationException | SMTTranslationFailure e) { diff --git a/java-backend/src/main/java/org/kframework/backend/java/util/Z3Wrapper.java b/java-backend/src/main/java/org/kframework/backend/java/util/Z3Wrapper.java index b7ff2f665e..3aaa3d2227 100644 --- a/java-backend/src/main/java/org/kframework/backend/java/util/Z3Wrapper.java +++ b/java-backend/src/main/java/org/kframework/backend/java/util/Z3Wrapper.java @@ -49,7 +49,15 @@ public Z3Wrapper( public synchronized boolean isUnsat(String query, int timeout) { if (options.z3Executable) { - return checkQueryWithExternalProcess(query, timeout); + return checkQueryWithExternalProcess(query, 0, timeout); + } else { + return checkQueryWithLibrary(query, timeout); + } + } + + public synchronized boolean isImplication(String query, int timeout) { + if (options.z3Executable) { + return checkQueryWithExternalProcess(query, 1, timeout); } else { return checkQueryWithLibrary(query, timeout); } @@ -76,7 +84,7 @@ private boolean checkQueryWithLibrary(String query, int timeout) { return result; } - private boolean checkQueryWithExternalProcess(String query, int timeout) { + private boolean checkQueryWithExternalProcess(String query, int intermediateCheckSatCalls, int timeout) { String result = ""; try { for (int i = 0; i < Z3_RESTART_LIMIT; i++) { @@ -94,6 +102,16 @@ private boolean checkQueryWithExternalProcess(String query, int timeout) { z3Process.getInputStream())); input.write(SMT_PRELUDE + query + "(check-sat)\n"); input.flush(); + input.close(); + for (int ignores = 0; ignores < intermediateCheckSatCalls; ++ignores) { + result = output.readLine(); + if (result == null) { + break; + } + if (globalOptions.debug && !Z3_QUERY_RESULTS.contains(result)) { + break; + } + } result = output.readLine(); z3Process.destroy(); if (result != null) {