Search in sources :

Example 91 with Expr

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

the class CVC4NativeAPITest method checkSimpleLIRASat.

@Test
public void checkSimpleLIRASat() {
    // x + y = 8/5 AND x > 0 AND y > 0 AND x < 8/5 AND y < 8/5
    Expr zero = exprMgr.mkConst(new Rational(0));
    Expr eightFifth = exprMgr.mkConst(new Rational(8, 5));
    Expr varX = exprMgr.mkVar("x", exprMgr.realType());
    Expr varY = exprMgr.mkVar("y", exprMgr.integerType());
    Expr assertion1 = exprMgr.mkExpr(Kind.GT, varX, zero);
    Expr assertion2 = exprMgr.mkExpr(Kind.GT, varY, zero);
    Expr assertion3 = exprMgr.mkExpr(Kind.LT, varX, eightFifth);
    Expr assertion4 = exprMgr.mkExpr(Kind.LT, varY, eightFifth);
    Expr assertion5 = exprMgr.mkExpr(Kind.EQUAL, exprMgr.mkExpr(Kind.PLUS, varX, varY), eightFifth);
    smtEngine.assertFormula(assertion1);
    smtEngine.assertFormula(assertion2);
    smtEngine.assertFormula(assertion3);
    smtEngine.assertFormula(assertion4);
    smtEngine.assertFormula(assertion5);
    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 92 with Expr

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

the class CVC4NativeAPITest method checkQuantifierEliminationLIA.

@Test
public void checkQuantifierEliminationLIA() {
    // build formula: (forall x . ((x < 5) | (7 < x + y)))
    // quantifier-free equivalent: (2 < y) or (>= y 3)
    setupArrayQuant();
    Expr three = exprMgr.mkConst(new Rational(3));
    Expr five = exprMgr.mkConst(new Rational(5));
    Expr seven = exprMgr.mkConst(new Rational(7));
    Expr y = exprMgr.mkVar("y", exprMgr.integerType());
    Expr first = exprMgr.mkExpr(Kind.LT, x, five);
    Expr second = exprMgr.mkExpr(Kind.LT, seven, exprMgr.mkExpr(Kind.PLUS, x, y));
    Expr body = exprMgr.mkExpr(Kind.OR, first, second);
    Expr xBound = exprMgr.mkBoundVar("x", 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);
    Expr result = smtEngine.doQuantifierElimination(assertion, true);
    Expr resultCheck = exprMgr.mkExpr(Kind.GEQ, y, three);
    assertThat(result.toString()).isEqualTo(resultCheck.toString());
}
Also used : 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) Test(org.junit.Test)

Example 93 with Expr

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

the class CVC4NativeAPITest method checkInvalidModelGetValue.

/**
 * Note that model and getValue are seperate!
 */
@Test
public void checkInvalidModelGetValue() {
    Expr assertion = exprMgr.mkConst(false);
    Result result = smtEngine.checkSat(assertion);
    assertThat(result.isSat()).isEqualTo(Sat.UNSAT);
    Exception e = assertThrows(edu.stanford.CVC4.Exception.class, () -> smtEngine.getValue(assertion));
    assertThat(e.toString()).contains(INVALID_GETVALUE_STRING);
}
Also used : CVC4.vectorExpr(edu.stanford.CVC4.vectorExpr) SExpr(edu.stanford.CVC4.SExpr) Expr(edu.stanford.CVC4.Expr) AssumptionViolatedException(org.junit.AssumptionViolatedException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Result(edu.stanford.CVC4.Result) Test(org.junit.Test)

Example 94 with Expr

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

the class CVC4NativeAPITest method checkQuantifierExistsIncomplete.

/*
   * CVC4 fails some easy quantifier tests. To check wheter or not they really fail in CVC4 or due
   * to JavaSMT we test them in the native API.
   */
@Test
public void checkQuantifierExistsIncomplete() {
    // (not exists x . not b[x] = 0) AND (b[123] = 0) is SAT
    setupArrayQuant();
    Expr zero = exprMgr.mkConst(new Rational(0));
    Expr xBound = exprMgr.mkBoundVar("x", exprMgr.integerType());
    vectorExpr vec = new vectorExpr();
    vec.add(xBound);
    Expr quantifiedVars = exprMgr.mkExpr(Kind.BOUND_VAR_LIST, vec);
    Expr aAtxEq0s = aAtxEq0.substitute(x, xBound);
    Expr exists = exprMgr.mkExpr(Kind.EXISTS, quantifiedVars, exprMgr.mkExpr(Kind.NOT, aAtxEq0s));
    Expr notExists = exprMgr.mkExpr(Kind.NOT, exists);
    Expr select123 = exprMgr.mkExpr(Kind.SELECT, array, exprMgr.mkConst(new Rational(123)));
    Expr selectEq0 = exprMgr.mkExpr(Kind.EQUAL, select123, zero);
    Expr assertion = exprMgr.mkExpr(Kind.AND, notExists, selectEq0);
    // assertFormula has a return value, check?
    smtEngine.assertFormula(assertion);
    Result satCheck = smtEngine.checkSat();
    // CVC4 fails this test as incomplete
    assertThat(satCheck.isUnknown()).isTrue();
    assertThat(satCheck.whyUnknown()).isEqualTo(Result.UnknownExplanation.INCOMPLETE);
}
Also used : 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)

Example 95 with Expr

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

the class CVC4NativeAPITest method checkSimpleLIRAUnsat2.

@Test
public void checkSimpleLIRAUnsat2() {
    // x + y = 4 AND x * y = 4
    Expr threeHalf = exprMgr.mkConst(new Rational(3, 2));
    Expr varX = exprMgr.mkVar("x", exprMgr.integerType());
    Expr varY = exprMgr.mkVar("y", exprMgr.realType());
    Expr assertion1 = exprMgr.mkExpr(Kind.EQUAL, exprMgr.mkExpr(Kind.MULT, varX, varY), threeHalf);
    Expr assertion2 = exprMgr.mkExpr(Kind.EQUAL, exprMgr.mkExpr(Kind.PLUS, varX, varY), threeHalf);
    smtEngine.assertFormula(assertion1);
    smtEngine.assertFormula(assertion2);
    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)

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