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