Search in sources :

Example 66 with Result

use of com.walmartlabs.concord.plugins.s3.Result in project java-smt by sosy-lab.

the class CVC4NativeAPITest method checkSimplePow.

/**
 * Exponents may only be natural number constants.
 */
@Test
public void checkSimplePow() {
    // x ^ 2 = 4 AND x ^ 3 = 8
    Expr two = exprMgr.mkConst(new Rational(2));
    Expr three = exprMgr.mkConst(new Rational(3));
    Expr four = exprMgr.mkConst(new Rational(4));
    Expr eight = exprMgr.mkConst(new Rational(8));
    Expr varX = exprMgr.mkVar("x", exprMgr.realType());
    Expr assertion1 = exprMgr.mkExpr(Kind.EQUAL, exprMgr.mkExpr(Kind.POW, varX, two), four);
    Expr assertion2 = exprMgr.mkExpr(Kind.EQUAL, exprMgr.mkExpr(Kind.POW, varX, three), eight);
    smtEngine.assertFormula(assertion1);
    smtEngine.assertFormula(assertion2);
    Result satCheck = smtEngine.checkSat();
    assertThat(satCheck.isSat()).isEqualTo(Sat.SAT);
}
Also used : CVC4.vectorExpr(edu.stanford.CVC4.vectorExpr) SExpr(edu.stanford.CVC4.SExpr) Expr(edu.stanford.CVC4.Expr) Rational(edu.stanford.CVC4.Rational) Result(edu.stanford.CVC4.Result) Test(org.junit.Test)

Example 67 with Result

use of com.walmartlabs.concord.plugins.s3.Result in project java-smt by sosy-lab.

the class CVC4NativeAPITest method checkSimpleLIAEqualityUnsat.

@Test
public void checkSimpleLIAEqualityUnsat() {
    Expr one = exprMgr.mkConst(new Rational(1));
    Expr assertion = exprMgr.mkExpr(Kind.EQUAL, exprMgr.mkExpr(Kind.PLUS, one, one), one);
    smtEngine.assertFormula(assertion);
    Result satCheck = smtEngine.checkSat();
    assertThat(satCheck.isSat()).isEqualTo(Sat.UNSAT);
}
Also used : CVC4.vectorExpr(edu.stanford.CVC4.vectorExpr) SExpr(edu.stanford.CVC4.SExpr) Expr(edu.stanford.CVC4.Expr) Rational(edu.stanford.CVC4.Rational) Result(edu.stanford.CVC4.Result) Test(org.junit.Test)

Example 68 with Result

use of com.walmartlabs.concord.plugins.s3.Result in project java-smt by sosy-lab.

the class CVC4NativeAPITest method checkLIAUfsSat.

@Test
public void checkLIAUfsSat() {
    // f(x) = x + 1
    // f(y) = y - 1
    // x = y -> f(x) + f(y) = x AND f(x) + f(y) = y
    Expr one = exprMgr.mkConst(new Rational(1));
    Type intType = exprMgr.integerType();
    // Type for UFs later
    Type intToInt = exprMgr.mkFunctionType(intType, intType);
    Expr xInt = exprMgr.mkVar("x", intType);
    Expr yInt = exprMgr.mkVar("y", intType);
    // declare UFs
    Expr f = exprMgr.mkVar("f", intToInt);
    // Apply UFs
    Expr fx = exprMgr.mkExpr(Kind.APPLY_UF, f, xInt);
    Expr fy = exprMgr.mkExpr(Kind.APPLY_UF, f, yInt);
    Expr plus = exprMgr.mkExpr(Kind.PLUS, fx, fy);
    Expr plusEqx = exprMgr.mkExpr(Kind.EQUAL, plus, xInt);
    Expr plusEqy = exprMgr.mkExpr(Kind.EQUAL, plus, yInt);
    Expr xEqy = exprMgr.mkExpr(Kind.EQUAL, yInt, xInt);
    Expr xEqyImplplusEqxAndy = exprMgr.mkExpr(Kind.IMPLIES, xEqy, exprMgr.mkExpr(Kind.AND, plusEqx, plusEqy));
    Expr assumptions = exprMgr.mkExpr(Kind.AND, exprMgr.mkExpr(Kind.EQUAL, fx, exprMgr.mkExpr(Kind.PLUS, xInt, one)), exprMgr.mkExpr(Kind.EQUAL, fy, exprMgr.mkExpr(Kind.MINUS, yInt, one)), xEqyImplplusEqxAndy);
    smtEngine.assertFormula(assumptions);
    Result satCheck = smtEngine.checkSat();
    assertThat(satCheck.isSat()).isEqualTo(Sat.SAT);
}
Also used : Type(edu.stanford.CVC4.Type) SortType(edu.stanford.CVC4.SortType) ArrayType(edu.stanford.CVC4.ArrayType) BitVectorType(edu.stanford.CVC4.BitVectorType) CVC4.vectorExpr(edu.stanford.CVC4.vectorExpr) SExpr(edu.stanford.CVC4.SExpr) Expr(edu.stanford.CVC4.Expr) Rational(edu.stanford.CVC4.Rational) Result(edu.stanford.CVC4.Result) Test(org.junit.Test)

Example 69 with Result

use of com.walmartlabs.concord.plugins.s3.Result in project java-smt by sosy-lab.

the class CVC4NativeAPITest method checkSimpleUnsat.

@Test
public void checkSimpleUnsat() {
    smtEngine.assertFormula(exprMgr.mkConst(false));
    Result satCheck = smtEngine.checkSat();
    assertThat(satCheck.isSat()).isEqualTo(Sat.UNSAT);
}
Also used : Result(edu.stanford.CVC4.Result) Test(org.junit.Test)

Example 70 with Result

use of com.walmartlabs.concord.plugins.s3.Result in project java-smt by sosy-lab.

the class CVC4NativeAPITest method checkQuantifierWithUf.

@SuppressWarnings("unused")
@Test
public void checkQuantifierWithUf() throws FileNotFoundException, UnsupportedEncodingException {
    Expr var = exprMgr.mkVar("var", exprMgr.integerType());
    // start with a normal, free variable!
    Expr boundVar = exprMgr.mkVar("boundVar", exprMgr.integerType());
    Expr varIsOne = exprMgr.mkExpr(Kind.EQUAL, var, exprMgr.mkConst(new Rational(1)));
    // try not to use 0 as this is the default value for CVC4 models
    Expr boundVarIsTwo = exprMgr.mkExpr(Kind.EQUAL, boundVar, exprMgr.mkConst(new Rational(2)));
    Expr boundVarIsOne = exprMgr.mkExpr(Kind.EQUAL, boundVar, exprMgr.mkConst(new Rational(1)));
    String func = "func";
    Type intType = exprMgr.integerType();
    Type ufType = exprMgr.mkFunctionType(intType, intType);
    Expr uf = exprMgr.mkVar(func, ufType);
    Expr funcAtBoundVar = exprMgr.mkExpr(uf, boundVar);
    Expr body = exprMgr.mkExpr(Kind.AND, boundVarIsTwo, exprMgr.mkExpr(Kind.EQUAL, var, funcAtBoundVar));
    // This is the bound variable used for boundVar
    Expr boundVarBound = exprMgr.mkBoundVar("boundVar", exprMgr.integerType());
    vectorExpr vec = new vectorExpr();
    vec.add(boundVarBound);
    Expr quantifiedVars = exprMgr.mkExpr(Kind.BOUND_VAR_LIST, vec);
    // Subst all boundVar variables with the bound version
    Expr bodySubst = body.substitute(boundVar, boundVarBound);
    Expr quantFormula = exprMgr.mkExpr(Kind.EXISTS, quantifiedVars, bodySubst);
    // var = 1 & boundVar = 1 & exists boundVar . ( boundVar = 2 & f(boundVar) = var )
    Expr overallFormula = exprMgr.mkExpr(Kind.AND, varIsOne, boundVarIsOne, quantFormula);
    smtEngine.assertFormula(overallFormula);
    Result satCheck = smtEngine.checkSat();
    // SAT
    assertThat(satCheck.isSat()).isEqualTo(Sat.SAT);
    // check Model
    // var = 1 & boundVar = 1 & exists boundVar . ( boundVar = 2 & f(2) = 1 )
    // It seems like CVC4 can't return quantified variables,
    // therefore we can't get a value for the uf!
    assertThat(smtEngine.getValue(var).toString()).isEqualTo("1");
    assertThat(smtEngine.getValue(boundVar).toString()).isEqualTo("1");
    assertThat(smtEngine.getValue(funcAtBoundVar).toString()).isEqualTo("1");
    assertThat(smtEngine.getValue(boundVarBound).toString()).isEqualTo("boundVar");
}
Also used : Type(edu.stanford.CVC4.Type) SortType(edu.stanford.CVC4.SortType) ArrayType(edu.stanford.CVC4.ArrayType) BitVectorType(edu.stanford.CVC4.BitVectorType) CVC4.vectorExpr(edu.stanford.CVC4.vectorExpr) SExpr(edu.stanford.CVC4.SExpr) Expr(edu.stanford.CVC4.Expr) Rational(edu.stanford.CVC4.Rational) CVC4.vectorExpr(edu.stanford.CVC4.vectorExpr) Result(edu.stanford.CVC4.Result) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)46 Result (edu.stanford.CVC4.Result)35 Expr (edu.stanford.CVC4.Expr)32 SExpr (edu.stanford.CVC4.SExpr)32 CVC4.vectorExpr (edu.stanford.CVC4.vectorExpr)31 Rational (edu.stanford.CVC4.Rational)25 Result (com.opensymphony.xwork2.Result)18 List (java.util.List)15 ArrayList (java.util.ArrayList)13 ArrayType (edu.stanford.CVC4.ArrayType)8 CompletableFuture (java.util.concurrent.CompletableFuture)8 TimeUnit (java.util.concurrent.TimeUnit)8 DataSource (jdk.incubator.sql2.DataSource)8 Result (jdk.incubator.sql2.Result)8 Session (jdk.incubator.sql2.Session)8 AfterClass (org.junit.AfterClass)8 BeforeClass (org.junit.BeforeClass)8 BitVectorType (edu.stanford.CVC4.BitVectorType)6 SortType (edu.stanford.CVC4.SortType)6 Type (edu.stanford.CVC4.Type)6