use of com.google.api.expr.v1alpha1.Expr in project java-smt by sosy-lab.
the class CVC4NativeAPITest method checkSimpleEqualityUnsat.
@Test
public void checkSimpleEqualityUnsat() {
Expr zero = exprMgr.mkConst(new Rational(0));
Expr one = exprMgr.mkConst(new Rational(1));
Expr assertion = exprMgr.mkExpr(Kind.EQUAL, zero, one);
smtEngine.assertFormula(assertion);
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 checkSimpleFPSat.
/**
* Do not ever try to use decimals in a new Rational that has only a 0 as decimal. This will
* SIGSEV CVC4!
*/
@Test
public void checkSimpleFPSat() {
// x * y = 1/4
RoundingMode rm = RoundingMode.roundNearestTiesToAway;
Expr rmExpr = exprMgr.mkConst(rm);
Expr oneFourth = exprMgr.mkConst(new FloatingPoint(new FloatingPointSize(8, 24), rm, new Rational(1, 4)));
Expr varX = exprMgr.mkVar("x", exprMgr.mkFloatingPointType(8, 24));
Expr varY = exprMgr.mkVar("y", exprMgr.mkFloatingPointType(8, 24));
Expr assertion1 = exprMgr.mkExpr(Kind.FLOATINGPOINT_EQ, exprMgr.mkExpr(Kind.FLOATINGPOINT_MULT, rmExpr, varX, varY), oneFourth);
smtEngine.assertFormula(assertion1);
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 checkQuantifierEliminationBV.
/**
* CVC4 does not support Bv quantifier elim. This is expected to fail!
*/
@Test
public void checkQuantifierEliminationBV() {
// build formula: exists y : bv[2]. x * y = 1
// quantifier-free equivalent: x = 1 | x = 3
// or extract_0_0 x = 1
int width = 2;
Expr xBv = exprMgr.mkVar("x_bv", exprMgr.mkBitVectorType(width));
Expr yBv = exprMgr.mkVar("y_bv", exprMgr.mkBitVectorType(width));
Expr body = exprMgr.mkExpr(Kind.EQUAL, exprMgr.mkExpr(Kind.MULT, xBv, yBv), exprMgr.mkConst(new BitVector(1)));
Expr xBound = exprMgr.mkBoundVar("y_bv", exprMgr.mkBitVectorType(width));
vectorExpr vec = new vectorExpr();
vec.add(xBound);
Expr quantifiedVars = exprMgr.mkExpr(Kind.BOUND_VAR_LIST, vec);
Expr bodySubst = body.substitute(yBv, xBound);
Expr assertion = exprMgr.mkExpr(Kind.EXISTS, quantifiedVars, bodySubst);
assertThrows(RuntimeException.class, () -> smtEngine.doQuantifierElimination(assertion, true));
}
use of com.google.api.expr.v1alpha1.Expr in project java-smt by sosy-lab.
the class CVC4NativeAPITest method checkUnsatCore.
@Test
public void checkUnsatCore() {
// (a & b) & (not(a OR b))
// Enable UNSAT Core first!
smtEngine.setOption("produce-unsat-cores", new SExpr(true));
Type boolType = exprMgr.booleanType();
Expr a = exprMgr.mkVar("a", boolType);
Expr b = exprMgr.mkVar("b", boolType);
Expr aAndb = exprMgr.mkExpr(Kind.AND, a, b);
Expr notaOrb = exprMgr.mkExpr(Kind.NOT, exprMgr.mkExpr(Kind.OR, a, b));
smtEngine.assertFormula(aAndb);
smtEngine.assertFormula(notaOrb);
Result satCheck = smtEngine.checkSat();
assertThat(satCheck.isSat()).isEqualTo(Sat.UNSAT);
UnsatCore unsatCore = smtEngine.getUnsatCore();
// UnsatCores are iterable
for (Expr e : unsatCore) {
assertThat(e.toString()).isIn(Arrays.asList("(not (or a b))", "(and a b)"));
}
}
use of com.google.api.expr.v1alpha1.Expr in project java-smt by sosy-lab.
the class CVC4NumeralFormulaManager method consistsOfNumerals.
/**
* Check whether the current term is numeric and the value of a term is determined by only
* numerals, i.e. no variable is contained. This method should check as precisely as possible the
* situations in which CVC4 supports arithmetic operations like multiplications.
*
* <p>Example: TRUE for "1", "2+3", "ite(x,2,3) and FALSE for "x", "x+2", "ite(1=2,x,0)"
*/
boolean consistsOfNumerals(Expr val) {
Set<Expr> finished = new HashSet<>();
Deque<Expr> waitlist = new ArrayDeque<>();
waitlist.add(val);
while (!waitlist.isEmpty()) {
Expr e = waitlist.pop();
if (!finished.add(e)) {
continue;
}
if (isNumeral(e)) {
// true, skip and check others
} else if (NUMERIC_FUNCTIONS.contains(e.getKind())) {
Iterables.addAll(waitlist, e);
} else if (ITE.equals(e.getKind())) {
// ignore condition, just use the if- and then-case
waitlist.add(e.getChild(1));
waitlist.add(e.getChild(2));
} else {
return false;
}
}
return true;
}
Aggregations