Search in sources :

Example 21 with Expr

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

the class CVC4NativeAPITest method checkArraySat.

@Test
public void checkArraySat() {
    // ((x = 123) & (select(arr, 5) = 123)) => ((select(arr, 5) = x) & (x = 123))
    Expr five = exprMgr.mkConst(new Rational(5));
    Expr oneTwoThree = exprMgr.mkConst(new Rational(123));
    Expr xInt = exprMgr.mkVar("x_int", exprMgr.integerType());
    ArrayType arrayType = exprMgr.mkArrayType(exprMgr.integerType(), exprMgr.integerType());
    Expr arr = exprMgr.mkVar("arr", arrayType);
    Expr xEq123 = exprMgr.mkExpr(Kind.EQUAL, xInt, oneTwoThree);
    Expr selAat5Eq123 = exprMgr.mkExpr(Kind.EQUAL, exprMgr.mkExpr(Kind.SELECT, arr, five), oneTwoThree);
    Expr selAat5EqX = exprMgr.mkExpr(Kind.EQUAL, exprMgr.mkExpr(Kind.SELECT, arr, five), xInt);
    Expr leftAnd = exprMgr.mkExpr(Kind.AND, xEq123, selAat5Eq123);
    Expr rightAnd = exprMgr.mkExpr(Kind.AND, xEq123, selAat5EqX);
    Expr impl = exprMgr.mkExpr(Kind.IMPLIES, leftAnd, rightAnd);
    smtEngine.assertFormula(impl);
    Result satCheck = smtEngine.checkSat();
    assertThat(satCheck.isSat()).isEqualTo(Sat.SAT);
}
Also used : ArrayType(edu.stanford.CVC4.ArrayType) 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 22 with Expr

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

the class CVC4NativeAPITest method checkInvalidTypeOperationsCheckSat.

/**
 * It does not matter if you take an int or array or bv here, all result in the same error.
 */
@Test
public void checkInvalidTypeOperationsCheckSat() {
    BitVectorType bvType = exprMgr.mkBitVectorType(16);
    Expr bvVar = exprMgr.mkVar("bla", bvType);
    Expr assertion = exprMgr.mkExpr(Kind.AND, bvVar, bvVar);
    Exception e = assertThrows(edu.stanford.CVC4.Exception.class, () -> smtEngine.checkSat(assertion));
    assertThat(e.toString()).contains("expecting a Boolean subexpression");
}
Also used : CVC4.vectorExpr(edu.stanford.CVC4.vectorExpr) SExpr(edu.stanford.CVC4.SExpr) Expr(edu.stanford.CVC4.Expr) BitVectorType(edu.stanford.CVC4.BitVectorType) AssumptionViolatedException(org.junit.AssumptionViolatedException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Test(org.junit.Test)

Example 23 with Expr

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

the class CVC4NativeAPITest method checkSimpleLRAUnsat2.

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

Example 24 with Expr

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

the class CVC4NativeAPITest method checkLIAModel.

@Test
public void checkLIAModel() {
    // 1 + 2 = var
    // it follows that var = 3
    Expr one = exprMgr.mkConst(new Rational(1));
    Expr two = exprMgr.mkConst(new Rational(2));
    Expr var = exprMgr.mkVar(exprMgr.integerType());
    Expr assertion = exprMgr.mkExpr(Kind.EQUAL, exprMgr.mkExpr(Kind.PLUS, one, two), var);
    Result result = smtEngine.checkSat(assertion);
    assertThat(result.isSat()).isEqualTo(Sat.SAT);
    Expr assertionValue = smtEngine.getValue(assertion);
    assertThat(assertionValue.toString()).isEqualTo("true");
    assertThat(smtEngine.getValue(var).toString()).isEqualTo("3");
}
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 25 with Expr

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

the class CVC4NativeAPITest method checkSimpleLRASat.

@Test
public void checkSimpleLRASat() {
    // x * y = 8/5 AND x < 4/5
    Expr fourFifth = exprMgr.mkConst(new Rational(4, 5));
    Expr eightFifth = exprMgr.mkConst(new Rational(8, 5));
    Expr varX = exprMgr.mkVar("x", exprMgr.realType());
    Expr varY = exprMgr.mkVar("y", exprMgr.realType());
    Expr assertion1 = exprMgr.mkExpr(Kind.EQUAL, exprMgr.mkExpr(Kind.NONLINEAR_MULT, varX, varY), eightFifth);
    Expr assertion2 = exprMgr.mkExpr(Kind.LT, varX, fourFifth);
    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)

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