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);
}
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");
}
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);
}
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");
}
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);
}
Aggregations