Skip to content

Commit a79e105

Browse files
authored
Merge pull request #542 from sosy-lab/add_mathsat5_extended_parsing
Allow Mathsat to use its extended dumping method (allowing let-expressions and quantifier dumping) with new options
2 parents 92e6afb + ddd061c commit a79e105

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

src/org/sosy_lab/java_smt/solvers/mathsat5/Mathsat5FormulaManager.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import static org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5NativeApi.msat_make_copy_from;
1414
import static org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5NativeApi.msat_simplify;
1515
import static org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5NativeApi.msat_to_smtlib2;
16+
import static org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5NativeApi.msat_to_smtlib2_ext;
1617

1718
import com.google.common.collect.Collections2;
1819
import com.google.common.primitives.Longs;
@@ -26,6 +27,9 @@
2627

2728
final class Mathsat5FormulaManager extends AbstractFormulaManager<Long, Long, Long, Long> {
2829

30+
private final boolean dumpExtendedOutput;
31+
private final boolean dumpLetExpressions;
32+
2933
@SuppressWarnings("checkstyle:parameternumber")
3034
Mathsat5FormulaManager(
3135
Mathsat5FormulaCreator creator,
@@ -36,7 +40,9 @@ final class Mathsat5FormulaManager extends AbstractFormulaManager<Long, Long, Lo
3640
Mathsat5BitvectorFormulaManager pBitpreciseManager,
3741
Mathsat5FloatingPointFormulaManager pFloatingPointManager,
3842
Mathsat5ArrayFormulaManager pArrayManager,
39-
Mathsat5EnumerationFormulaManager pEnumerationManager) {
43+
Mathsat5EnumerationFormulaManager pEnumerationManager,
44+
boolean pDumpExtendedOutput,
45+
boolean pDumpLetExpressions) {
4046
super(
4147
creator,
4248
pFunctionManager,
@@ -50,6 +56,8 @@ final class Mathsat5FormulaManager extends AbstractFormulaManager<Long, Long, Lo
5056
null,
5157
null,
5258
pEnumerationManager);
59+
dumpLetExpressions = pDumpLetExpressions;
60+
dumpExtendedOutput = pDumpExtendedOutput;
5361
}
5462

5563
static long getMsatTerm(Formula pT) {
@@ -69,7 +77,16 @@ public Long parseImpl(String pS) throws IllegalArgumentException {
6977
public String dumpFormulaImpl(final Long f) {
7078
assert getFormulaCreator().getFormulaType(f) == FormulaType.BooleanType
7179
: "Only BooleanFormulas may be dumped";
72-
return msat_to_smtlib2(getEnvironment(), f);
80+
81+
if (dumpExtendedOutput) {
82+
// msat_to_smtlib2_ext() can export quantified formulas created in MathSAT5 (which it can't
83+
// solve). Can generate let-expressions instead of define-fun bindings.
84+
return msat_to_smtlib2_ext(getFormulaCreator().getEnv(), f, "", dumpLetExpressions ? 0 : 1);
85+
} else {
86+
// msat_to_smtlib2() generates `.def_...` expressions, which are disliked by some solvers
87+
// (due to the . being a SMTLIB2 reserved symbol at the beginning of definitions)
88+
return msat_to_smtlib2(getEnvironment(), f);
89+
}
7390
}
7491

7592
@Override

src/org/sosy_lab/java_smt/solvers/mathsat5/Mathsat5SolverContext.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,26 @@ private static final class Mathsat5Settings {
6060
+ "Format is 'key1=value1,key2=value2'")
6161
private String furtherOptions = "";
6262

63+
@Option(
64+
secure = true,
65+
description =
66+
"If enabled, SMTLIB2 output of MathSAT5 will be generated using the extended dumping "
67+
+ "function msat_to_smtlib2_ext(), instead of the regular dumping "
68+
+ "function msat_to_smtlib2(). This extended dump might allow the exporting of "
69+
+ "features to SMTLIB2 that can't be solved using MathSAT5, e.g. quantified "
70+
+ "formulas. "
71+
+ "The output will contain define-fun based bindings instead of "
72+
+ "let-expressions per default. If you want to use let bindings, enable option "
73+
+ "solver.mathsat5.dumpSMTLIB2LetExpressions as well.")
74+
private boolean useExtendedSMTLIB2Output = false;
75+
76+
@Option(
77+
secure = true,
78+
description =
79+
"If used together with solver.mathsat5.useExtendedSMTLIB2Output, SMTLIB2 output will "
80+
+ "contain let-bindings instead of define-fun based bindings.")
81+
private boolean dumpSMTLIB2LetExpressions = false;
82+
6383
@Option(secure = true, description = "Load less stable optimizing version of mathsat5 solver.")
6484
boolean loadOptimathsat5 = false;
6585

@@ -206,7 +226,9 @@ public static Mathsat5SolverContext create(
206226
bitvectorTheory,
207227
floatingPointTheory,
208228
arrayTheory,
209-
enumerationTheory);
229+
enumerationTheory,
230+
settings.useExtendedSMTLIB2Output,
231+
settings.dumpSMTLIB2LetExpressions);
210232
return new Mathsat5SolverContext(
211233
logger, msatConf, settings, randomSeed, pShutdownNotifier, manager, creator);
212234
}

0 commit comments

Comments
 (0)