use of edu.stanford.CVC4.vectorExpr in project java-smt by sosy-lab.
the class CVC4BitvectorFormulaManager method divide.
@Override
protected Expr divide(Expr numerator, Expr denumerator, boolean signed) {
final Kind operator = signed ? Kind.BITVECTOR_SDIV : Kind.BITVECTOR_UDIV;
final Expr division = exprManager.mkExpr(operator, numerator, denumerator);
// CVC4 does not align with SMTLIB standard when it comes to divide-by-zero.
// For divide-by-zero, we compute the result as: return "1" with the opposite
// sign than the numerator.
final int bitsize = ((BitvectorType) formulaCreator.getFormulaType(numerator)).getSize();
final Expr zero = makeBitvectorImpl(bitsize, 0);
final Expr one = makeBitvectorImpl(bitsize, 1);
// all bits equal "1"
final Expr maxValue = makeBitvectorImpl(bitsize, -1);
return exprManager.mkExpr(Kind.ITE, exprManager.mkExpr(Kind.EQUAL, denumerator, zero), exprManager.mkExpr(Kind.ITE, lessThan(numerator, zero, signed), one, maxValue), division);
}
use of edu.stanford.CVC4.vectorExpr in project java-smt by sosy-lab.
the class CVC4BitvectorFormulaManager method distinctImpl.
@Override
protected Expr distinctImpl(List<Expr> pParam) {
vectorExpr param = new vectorExpr();
pParam.forEach(param::add);
return exprManager.mkExpr(Kind.DISTINCT, param);
}
use of edu.stanford.CVC4.vectorExpr in project java-smt by sosy-lab.
the class CVC4BitvectorFormulaManager method modulo.
@Override
protected Expr modulo(Expr numerator, Expr denumerator, boolean signed) {
final Kind operator = signed ? Kind.BITVECTOR_SREM : Kind.BITVECTOR_UREM;
final Expr remainder = exprManager.mkExpr(operator, numerator, denumerator);
// CVC4 does not align with SMTLIB standard when it comes to modulo-by-zero.
// For modulo-by-zero, we compute the result as: "return the numerator".
final int bitsize = ((BitvectorType) formulaCreator.getFormulaType(numerator)).getSize();
final Expr zero = makeBitvectorImpl(bitsize, 0);
return exprManager.mkExpr(Kind.ITE, exprManager.mkExpr(Kind.EQUAL, denumerator, zero), numerator, remainder);
}
use of edu.stanford.CVC4.vectorExpr 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 edu.stanford.CVC4.vectorExpr 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));
}
Aggregations