Search in sources :

Example 1 with SmtEngine

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"));
}
Also used : ExprManager(edu.stanford.CVC4.ExprManager) SmtEngine(edu.stanford.CVC4.SmtEngine) SExpr(edu.stanford.CVC4.SExpr) Before(org.junit.Before)

Example 2 with SmtEngine

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;
}
Also used : SmtEngine(edu.stanford.CVC4.SmtEngine) CVC4.vectorExpr(edu.stanford.CVC4.vectorExpr) Expr(edu.stanford.CVC4.Expr)

Example 3 with SmtEngine

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);
}
Also used : SExpr(edu.stanford.CVC4.SExpr) Expr(edu.stanford.CVC4.Expr) ShutdownHook(org.sosy_lab.java_smt.basicimpl.ShutdownHook) Result(edu.stanford.CVC4.Result)

Example 4 with SmtEngine

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);
}
Also used : CVC4.vectorExpr(edu.stanford.CVC4.vectorExpr) SExpr(edu.stanford.CVC4.SExpr) Expr(edu.stanford.CVC4.Expr) CVC4.vectorExpr(edu.stanford.CVC4.vectorExpr) Test(org.junit.Test)

Example 5 with SmtEngine

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);
}
Also used : SmtEngine(edu.stanford.CVC4.SmtEngine) ExprManager(edu.stanford.CVC4.ExprManager) SExpr(edu.stanford.CVC4.SExpr)

Aggregations

SExpr (edu.stanford.CVC4.SExpr)4 SmtEngine (edu.stanford.CVC4.SmtEngine)4 Expr (edu.stanford.CVC4.Expr)3 ExprManager (edu.stanford.CVC4.ExprManager)2 CVC4.vectorExpr (edu.stanford.CVC4.vectorExpr)2 Result (edu.stanford.CVC4.Result)1 Before (org.junit.Before)1 Test (org.junit.Test)1 ShutdownHook (org.sosy_lab.java_smt.basicimpl.ShutdownHook)1