Skip to content
This repository was archived by the owner on Feb 1, 2020. It is now read-only.

Commit 31fb4e0

Browse files
bmmooremsaxena2
authored andcommitted
Add (check-sat) to preprocess context before proving goal
1 parent 77a83f5 commit 31fb4e0

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

java-backend/src/main/java/org/kframework/backend/java/symbolic/KILtoSMTLib.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ public static String translateImplication(
195195
sb.append(leftTransformer.getConstantDeclarations(Sets.difference(
196196
Sets.union(leftTransformer.variables(), rightTransformer.variables()),
197197
rightHandSideOnlyVariables)));
198-
sb.append("(assert (and ");
198+
sb.append("(assert ");
199199
sb.append(leftExpression);
200-
sb.append(" (not ");
200+
sb.append(")\n(check-sat)\n(assert (not ");
201201
rightHandSideOnlyVariables = Sets.intersection(
202202
rightTransformer.variables(),
203203
rightHandSideOnlyVariables);
@@ -210,7 +210,7 @@ public static String translateImplication(
210210
if (!rightHandSideOnlyVariables.isEmpty()) {
211211
sb.append(")");
212212
}
213-
sb.append(")))");
213+
sb.append("))");
214214
return sb.toString();
215215
}
216216

java-backend/src/main/java/org/kframework/backend/java/symbolic/SMTOperations.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public boolean impliesSMT(
6363
Set<Variable> rightOnlyVariables) {
6464
if (smtOptions.smt == SMTSolver.Z3) {
6565
try {
66-
return z3.isUnsat(
66+
return z3.isImplication(
6767
KILtoSMTLib.translateImplication(left, right, rightOnlyVariables),
6868
smtOptions.z3ImplTimeout);
6969
} catch (UnsupportedOperationException | SMTTranslationFailure e) {

java-backend/src/main/java/org/kframework/backend/java/util/Z3Wrapper.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,15 @@ public Z3Wrapper(
4949

5050
public synchronized boolean isUnsat(String query, int timeout) {
5151
if (options.z3Executable) {
52-
return checkQueryWithExternalProcess(query, timeout);
52+
return checkQueryWithExternalProcess(query, 0, timeout);
53+
} else {
54+
return checkQueryWithLibrary(query, timeout);
55+
}
56+
}
57+
58+
public synchronized boolean isImplication(String query, int timeout) {
59+
if (options.z3Executable) {
60+
return checkQueryWithExternalProcess(query, 1, timeout);
5361
} else {
5462
return checkQueryWithLibrary(query, timeout);
5563
}
@@ -76,7 +84,7 @@ private boolean checkQueryWithLibrary(String query, int timeout) {
7684
return result;
7785
}
7886

79-
private boolean checkQueryWithExternalProcess(String query, int timeout) {
87+
private boolean checkQueryWithExternalProcess(String query, int intermediateCheckSatCalls, int timeout) {
8088
String result = "";
8189
try {
8290
for (int i = 0; i < Z3_RESTART_LIMIT; i++) {
@@ -94,6 +102,16 @@ private boolean checkQueryWithExternalProcess(String query, int timeout) {
94102
z3Process.getInputStream()));
95103
input.write(SMT_PRELUDE + query + "(check-sat)\n");
96104
input.flush();
105+
input.close();
106+
for (int ignores = 0; ignores < intermediateCheckSatCalls; ++ignores) {
107+
result = output.readLine();
108+
if (result == null) {
109+
break;
110+
}
111+
if (globalOptions.debug && !Z3_QUERY_RESULTS.contains(result)) {
112+
break;
113+
}
114+
}
97115
result = output.readLine();
98116
z3Process.destroy();
99117
if (result != null) {

0 commit comments

Comments
 (0)