Search in sources :

Example 1 with BitVector

use of edu.stanford.CVC4.BitVector in project java-smt by sosy-lab.

the class CVC4NativeAPITest method checkBvInvalidWidthAssertion.

@Test
public void checkBvInvalidWidthAssertion() {
    Expr bvOne = exprMgr.mkConst(new BitVector(0, 1));
    Expr assertion = exprMgr.mkExpr(Kind.EQUAL, bvOne, bvOne);
    Exception e = assertThrows(edu.stanford.CVC4.Exception.class, () -> smtEngine.assertFormula(assertion));
    assertThat(e.toString()).contains("constant of size 0");
}
Also used : BitVector(edu.stanford.CVC4.BitVector) CVC4.vectorExpr(edu.stanford.CVC4.vectorExpr) SExpr(edu.stanford.CVC4.SExpr) Expr(edu.stanford.CVC4.Expr) AssumptionViolatedException(org.junit.AssumptionViolatedException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Test(org.junit.Test)

Example 2 with BitVector

use of edu.stanford.CVC4.BitVector in project java-smt by sosy-lab.

the class CVC4NativeAPITest method checkSimpleBvEqualitySat.

@Test
public void checkSimpleBvEqualitySat() {
    // 1 + 0 = 1 with bitvectors
    Expr bvOne = exprMgr.mkConst(new BitVector(16, 1));
    Expr bvZero = exprMgr.mkConst(new BitVector(16, 0));
    Expr assertion = exprMgr.mkExpr(Kind.EQUAL, exprMgr.mkExpr(Kind.BITVECTOR_PLUS, bvZero, bvOne), bvOne);
    smtEngine.assertFormula(assertion);
    Result satCheck = smtEngine.checkSat();
    assertThat(satCheck.isSat()).isEqualTo(Sat.SAT);
}
Also used : BitVector(edu.stanford.CVC4.BitVector) CVC4.vectorExpr(edu.stanford.CVC4.vectorExpr) SExpr(edu.stanford.CVC4.SExpr) Expr(edu.stanford.CVC4.Expr) Result(edu.stanford.CVC4.Result) Test(org.junit.Test)

Example 3 with BitVector

use of edu.stanford.CVC4.BitVector in project java-smt by sosy-lab.

the class CVC4NativeAPITest method checkSimpleBvEqualityUnsat.

@Test
public void checkSimpleBvEqualityUnsat() {
    // 0 + 1 = 2 UNSAT with bitvectors
    Expr bvZero = exprMgr.mkConst(new BitVector(16, 0));
    Expr bvOne = exprMgr.mkConst(new BitVector(16, 1));
    Expr bvTwo = exprMgr.mkConst(new BitVector(16, 2));
    Expr assertion = exprMgr.mkExpr(Kind.EQUAL, exprMgr.mkExpr(Kind.BITVECTOR_PLUS, bvZero, bvOne), bvTwo);
    smtEngine.assertFormula(assertion);
    Result satCheck = smtEngine.checkSat();
    assertThat(satCheck.isSat()).isEqualTo(Sat.UNSAT);
}
Also used : BitVector(edu.stanford.CVC4.BitVector) CVC4.vectorExpr(edu.stanford.CVC4.vectorExpr) SExpr(edu.stanford.CVC4.SExpr) Expr(edu.stanford.CVC4.Expr) Result(edu.stanford.CVC4.Result) Test(org.junit.Test)

Example 4 with BitVector

use of edu.stanford.CVC4.BitVector 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));
}
Also used : BitVector(edu.stanford.CVC4.BitVector) CVC4.vectorExpr(edu.stanford.CVC4.vectorExpr) SExpr(edu.stanford.CVC4.SExpr) Expr(edu.stanford.CVC4.Expr) CVC4.vectorExpr(edu.stanford.CVC4.vectorExpr) FloatingPoint(edu.stanford.CVC4.FloatingPoint) Test(org.junit.Test)

Example 5 with BitVector

use of edu.stanford.CVC4.BitVector in project java-smt by sosy-lab.

the class CVC4NativeAPITest method checkBvInvalidWidthCheckSat.

@Test
public void checkBvInvalidWidthCheckSat() {
    Expr bvOne = exprMgr.mkConst(new BitVector(0, 1));
    Expr assertion = exprMgr.mkExpr(Kind.EQUAL, bvOne, bvOne);
    Exception e = assertThrows(edu.stanford.CVC4.Exception.class, () -> smtEngine.checkSat(assertion));
    assertThat(e.toString()).contains("constant of size 0");
}
Also used : BitVector(edu.stanford.CVC4.BitVector) CVC4.vectorExpr(edu.stanford.CVC4.vectorExpr) SExpr(edu.stanford.CVC4.SExpr) Expr(edu.stanford.CVC4.Expr) AssumptionViolatedException(org.junit.AssumptionViolatedException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Test(org.junit.Test)

Aggregations

BitVector (edu.stanford.CVC4.BitVector)6 Expr (edu.stanford.CVC4.Expr)6 SExpr (edu.stanford.CVC4.SExpr)6 CVC4.vectorExpr (edu.stanford.CVC4.vectorExpr)6 Test (org.junit.Test)6 Result (edu.stanford.CVC4.Result)3 FileNotFoundException (java.io.FileNotFoundException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 AssumptionViolatedException (org.junit.AssumptionViolatedException)2 FloatingPoint (edu.stanford.CVC4.FloatingPoint)1