use of edu.stanford.CVC4.SmtEngine in project java-smt by sosy-lab.
the class CVC4NativeAPITest method createEnvironment.
@Before
public void createEnvironment() {
exprMgr = new ExprManager();
smtEngine = new SmtEngine(exprMgr);
// Set the logic
smtEngine.setLogic("ALL");
// options
smtEngine.setOption("produce-models", new SExpr(true));
smtEngine.setOption("finite-model-find", new SExpr(true));
smtEngine.setOption("sets-ext", new SExpr(true));
smtEngine.setOption("output-language", new SExpr("smt2"));
}
use of edu.stanford.CVC4.SmtEngine in project java-smt by sosy-lab.
the class CVC4QuantifiedFormulaManager method eliminateQuantifiers.
/*
* (non-Javadoc) CVC4s quantifier support is dependent on the options used.
* Without any options it tends to run infenitly on many theories or examples.
* There are 2 options improving this: full-saturate-quant and sygus-inst.
* full-saturate-quant is activated in JavaSMT per default.
* You can try combinations of them, or just one if a query is not solveable.
* More info on full-saturate-quant: Enables "enumerative instantiation",
* see: https://homepage.divms.uiowa.edu/~ajreynol/tacas18.pdf
* More info on sygus-inst: Enables syntax-guided instantiation,
* see https://homepage.divms.uiowa.edu/~ajreynol/tacas21.pdf
* This approach tends to work well when the quantified formula involves
* theories (e.g. strings) where more traditional quantifier instantiation
* heuristics do not apply.
* This applies to CVC4 and CVC5!
*/
@Override
protected Expr eliminateQuantifiers(Expr pExtractInfo) throws SolverException, InterruptedException {
SmtEngine smtEngine = new SmtEngine(exprManager);
Expr eliminated = pExtractInfo;
// unexpected logic is used.
try {
eliminated = smtEngine.doQuantifierElimination(pExtractInfo, true);
} catch (RuntimeException e) {
// quantifier elimination failed, simply return the input
}
// We don't delete it in the prover.close(), is there a reason for that?
smtEngine.delete();
return eliminated;
}
use of edu.stanford.CVC4.SmtEngine in project java-smt by sosy-lab.
the class CVC4TheoremProver method isUnsat.
@Override
@SuppressWarnings("try")
public boolean isUnsat() throws InterruptedException, SolverException {
Preconditions.checkState(!closed);
closeAllModels();
changedSinceLastSatQuery = false;
if (!incremental) {
for (Expr expr : getAssertedExpressions()) {
smtEngine.assertFormula(importExpr(expr));
}
}
Result result;
try (ShutdownHook hook = new ShutdownHook(shutdownNotifier, smtEngine::interrupt)) {
shutdownNotifier.shutdownIfNecessary();
result = smtEngine.checkSat();
}
shutdownNotifier.shutdownIfNecessary();
return convertSatResult(result);
}
use of edu.stanford.CVC4.SmtEngine in project java-smt by sosy-lab.
the class CVC4NativeAPITest method checkInterruptBehaviour.
/**
* CVC4 does not support Array quantifier elimination. This is expected to fail! But it runs
* endlessly. So we can check interruption on it.
*/
@Test
public void checkInterruptBehaviour() {
setupArrayQuant();
Expr body = exprMgr.mkExpr(Kind.OR, aAtxEq0, aAtxEq1);
Expr xBound = exprMgr.mkBoundVar("x_b", exprMgr.integerType());
vectorExpr vec = new vectorExpr();
vec.add(xBound);
Expr quantifiedVars = exprMgr.mkExpr(Kind.BOUND_VAR_LIST, vec);
Expr bodySubst = body.substitute(x, xBound);
Expr assertion = exprMgr.mkExpr(Kind.FORALL, quantifiedVars, bodySubst);
Thread t = new Thread(() -> {
try {
// 1 is not enough!
Thread.sleep(10);
smtEngine.interrupt();
} catch (InterruptedException pE) {
throw new UnsupportedOperationException("Unexpected interrupt");
}
});
t.start();
// According to the API of CVC4 this should either throw a UnsafeInterruptedException if the
// SMTEngine is running or ModalException if the SMTEngine is not running. But it does not, it
// returns the input, but not in a way that its equal to the input.
Expr result = smtEngine.doQuantifierElimination(assertion, true);
String resultString = "(forall ((x_b Int)) (let ((_let_0 (select a x_b))) (or (= _let_0 0) (= _let_0 1))) )";
assertThat(result.toString()).isEqualTo(resultString);
}
use of edu.stanford.CVC4.SmtEngine in project java-smt by sosy-lab.
the class CVC4SolverContext method create.
public static SolverContext create(LogManager pLogger, ShutdownNotifier pShutdownNotifier, int randomSeed, NonLinearArithmetic pNonLinearArithmetic, FloatingPointRoundingMode pFloatingPointRoundingMode, Consumer<String> pLoader) {
pLoader.accept("cvc4jni");
// ExprManager is the central class for creating expressions/terms/formulae.
ExprManager exprManager = new ExprManager();
CVC4FormulaCreator creator = new CVC4FormulaCreator(exprManager);
// set common options.
// temporary SmtEngine instance, until ExprManager.getOptions() works without SegFault.
SmtEngine smtEngine = new SmtEngine(exprManager);
smtEngine.setOption("output-language", new SExpr("smt2"));
smtEngine.setOption("random-seed", new SExpr(randomSeed));
// Set Strings option to enable all String features (such as lessOrEquals)
smtEngine.setOption("strings-exp", new SExpr(true));
// smtEngine.delete();
// Create managers
CVC4UFManager functionTheory = new CVC4UFManager(creator);
CVC4BooleanFormulaManager booleanTheory = new CVC4BooleanFormulaManager(creator);
CVC4IntegerFormulaManager integerTheory = new CVC4IntegerFormulaManager(creator, pNonLinearArithmetic);
CVC4RationalFormulaManager rationalTheory = new CVC4RationalFormulaManager(creator, pNonLinearArithmetic);
CVC4BitvectorFormulaManager bitvectorTheory = new CVC4BitvectorFormulaManager(creator, booleanTheory);
CVC4FloatingPointFormulaManager fpTheory;
if (Configuration.isBuiltWithSymFPU()) {
fpTheory = new CVC4FloatingPointFormulaManager(creator, pFloatingPointRoundingMode);
} else {
fpTheory = null;
pLogger.log(Level.INFO, "CVC4 was built without support for FloatingPoint theory");
// throw new AssertionError("CVC4 was built without support for FloatingPoint theory");
}
CVC4QuantifiedFormulaManager qfTheory = new CVC4QuantifiedFormulaManager(creator);
CVC4ArrayFormulaManager arrayTheory = new CVC4ArrayFormulaManager(creator);
CVC4SLFormulaManager slTheory = new CVC4SLFormulaManager(creator);
CVC4StringFormulaManager strTheory = new CVC4StringFormulaManager(creator);
CVC4FormulaManager manager = new CVC4FormulaManager(creator, functionTheory, booleanTheory, integerTheory, rationalTheory, bitvectorTheory, fpTheory, qfTheory, arrayTheory, slTheory, strTheory);
return new CVC4SolverContext(creator, manager, pShutdownNotifier, randomSeed);
}
Aggregations