Search in sources :

Example 41 with Expr

use of com.google.api.expr.v1alpha1.Expr in project java-smt by sosy-lab.

the class CVC4QuantifiedFormulaManager method mkQuantifier.

/*
   * Makes the quantifier entered in CVC4. Note that CVC4 uses bound variables in quantified
   * formulas instead of the normal free vars. We create a bound copy for every var and substitute
   * the free var for the bound var in the body Formula. Note that CVC4 uses their internal Lists
   * for the variable list in quantifiers.
   */
@Override
public Expr mkQuantifier(Quantifier pQ, List<Expr> pVars, Expr pBody) {
    if (pVars.isEmpty()) {
        throw new IllegalArgumentException("Empty variable list for quantifier.");
    } else {
        // CVC4 uses its own lists for quantifier that may only have bound vars
        vectorExpr vec = new vectorExpr();
        Expr substBody = pBody;
        // with the same name, this is fine.
        for (Expr var : pVars) {
            Expr boundCopy = ((CVC4FormulaCreator) formulaCreator).makeBoundCopy(var);
            vec.add(boundCopy);
            substBody = substBody.substitute(var, boundCopy);
        }
        Expr quantifiedVars = exprManager.mkExpr(Kind.BOUND_VAR_LIST, vec);
        Kind quant = pQ == Quantifier.EXISTS ? Kind.EXISTS : Kind.FORALL;
        return exprManager.mkExpr(quant, quantifiedVars, substBody);
    }
}
Also used : CVC4.vectorExpr(edu.stanford.CVC4.vectorExpr) Expr(edu.stanford.CVC4.Expr) Kind(edu.stanford.CVC4.Kind) CVC4.vectorExpr(edu.stanford.CVC4.vectorExpr)

Example 42 with Expr

use of com.google.api.expr.v1alpha1.Expr 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 43 with Expr

use of com.google.api.expr.v1alpha1.Expr 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 44 with Expr

use of com.google.api.expr.v1alpha1.Expr in project bmoth by hhu-stups.

the class LiftsTest method testTargetAndCurrentCorrespond.

@Test
public void testTargetAndCurrentCorrespond() throws IOException {
    MachineNode simpleMachineWithViolation = Parser.getMachineFileAsSemanticAst(dir + "TargetAndCurrentCorrespond.mch");
    ModelCheckingResult result = ModelChecker.doModelCheck(simpleMachineWithViolation);
    assertEquals(false, result.isCorrect());
    Expr targetFloor = result.getLastState().values.get("target_floor");
    Expr currentFloor = result.getLastState().values.get("current_floor");
    assertNotEquals(targetFloor.toString(), currentFloor.toString());
}
Also used : Expr(com.microsoft.z3.Expr) MachineNode(de.bmoth.parser.ast.nodes.MachineNode) Test(org.junit.Test)

Example 45 with Expr

use of com.google.api.expr.v1alpha1.Expr in project bmoth by hhu-stups.

the class BooleanFormulaEvaluationTest method testTrueFormula.

@Test
public void testTrueFormula() throws Exception {
    String formula = "x = TRUE";
    // getting the translated z3 representation of the formula
    BoolExpr constraint = FormulaToZ3Translator.translatePredicate(formula, z3Context);
    z3Solver.add(constraint);
    Status check = z3Solver.check();
    Expr x = z3Context.mkBoolConst("x");
    assertEquals(SATISFIABLE, check);
    assertEquals(z3Context.mkTrue(), z3Solver.getModel().eval(x, true));
}
Also used : Status(com.microsoft.z3.Status) BoolExpr(com.microsoft.z3.BoolExpr) BoolExpr(com.microsoft.z3.BoolExpr) Expr(com.microsoft.z3.Expr) Test(org.junit.Test)

Aggregations

Expr (edu.stanford.CVC4.Expr)57 Test (org.junit.Test)55 CVC4.vectorExpr (edu.stanford.CVC4.vectorExpr)49 SExpr (edu.stanford.CVC4.SExpr)42 Expr (com.microsoft.z3.Expr)32 Result (edu.stanford.CVC4.Result)32 Rational (edu.stanford.CVC4.Rational)28 Expr (com.google.api.expr.v1alpha1.Expr)23 BoolExpr (com.microsoft.z3.BoolExpr)22 ArrayType (edu.stanford.CVC4.ArrayType)12 BitVectorType (edu.stanford.CVC4.BitVectorType)12 Status (com.microsoft.z3.Status)11 Type (edu.stanford.CVC4.Type)11 HashMap (java.util.HashMap)11 Test (org.junit.jupiter.api.Test)11 ParsedExpr (com.google.api.expr.v1alpha1.ParsedExpr)10 CheckedExpr (com.google.api.expr.v1alpha1.CheckedExpr)9 ArithExpr (com.microsoft.z3.ArithExpr)8 BitVecExpr (com.microsoft.z3.BitVecExpr)8 Val (org.projectnessie.cel.common.types.ref.Val)7