Search in sources :

Example 1 with CVC4.vectorExpr

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);
}
Also used : CVC4.vectorExpr(edu.stanford.CVC4.vectorExpr) Expr(edu.stanford.CVC4.Expr) BitvectorType(org.sosy_lab.java_smt.api.FormulaType.BitvectorType) Kind(edu.stanford.CVC4.Kind)

Example 2 with CVC4.vectorExpr

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);
}
Also used : CVC4.vectorExpr(edu.stanford.CVC4.vectorExpr)

Example 3 with CVC4.vectorExpr

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);
}
Also used : CVC4.vectorExpr(edu.stanford.CVC4.vectorExpr) Expr(edu.stanford.CVC4.Expr) BitvectorType(org.sosy_lab.java_smt.api.FormulaType.BitvectorType) Kind(edu.stanford.CVC4.Kind)

Example 4 with CVC4.vectorExpr

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);
}
Also used : FloatingPointSize(edu.stanford.CVC4.FloatingPointSize) CVC4.vectorExpr(edu.stanford.CVC4.vectorExpr) SExpr(edu.stanford.CVC4.SExpr) Expr(edu.stanford.CVC4.Expr) Rational(edu.stanford.CVC4.Rational) RoundingMode(edu.stanford.CVC4.RoundingMode) FloatingPoint(edu.stanford.CVC4.FloatingPoint) Result(edu.stanford.CVC4.Result) Test(org.junit.Test)

Example 5 with CVC4.vectorExpr

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

Aggregations

CVC4.vectorExpr (edu.stanford.CVC4.vectorExpr)17 Expr (edu.stanford.CVC4.Expr)13 SExpr (edu.stanford.CVC4.SExpr)7 Rational (edu.stanford.CVC4.Rational)6 Test (org.junit.Test)6 BitVectorType (edu.stanford.CVC4.BitVectorType)4 ArrayType (edu.stanford.CVC4.ArrayType)3 Kind (edu.stanford.CVC4.Kind)3 Result (edu.stanford.CVC4.Result)3 Type (edu.stanford.CVC4.Type)3 FloatingPoint (edu.stanford.CVC4.FloatingPoint)2 FunctionType (edu.stanford.CVC4.FunctionType)2 SmtEngine (edu.stanford.CVC4.SmtEngine)2 CVC4.vectorType (edu.stanford.CVC4.vectorType)2 BigInteger (java.math.BigInteger)2 FormulaType (org.sosy_lab.java_smt.api.FormulaType)2 ArrayFormulaType (org.sosy_lab.java_smt.api.FormulaType.ArrayFormulaType)2 BitvectorType (org.sosy_lab.java_smt.api.FormulaType.BitvectorType)2 FloatingPointType (org.sosy_lab.java_smt.api.FormulaType.FloatingPointType)2 ImmutableList (com.google.common.collect.ImmutableList)1