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