Search in sources :

Example 1 with FloatingPointSize

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

the class CVC4NativeAPITest method checkSimpleFPUnsat.

@Test
public void checkSimpleFPUnsat() {
    // x * y = 1/4 AND x > 0 AND y < 0
    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 zero = exprMgr.mkConst(new FloatingPoint(new FloatingPointSize(8, 24), RoundingMode.roundNearestTiesToAway, new Rational(0)));
    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);
    Expr assertion2 = exprMgr.mkExpr(Kind.FLOATINGPOINT_GT, varX, zero);
    Expr assertion3 = exprMgr.mkExpr(Kind.FLOATINGPOINT_LT, varY, zero);
    smtEngine.assertFormula(assertion1);
    smtEngine.assertFormula(assertion2);
    smtEngine.assertFormula(assertion3);
    Result satCheck = smtEngine.checkSat();
    assertThat(satCheck.isSat()).isEqualTo(Sat.UNSAT);
}
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 2 with FloatingPointSize

use of edu.stanford.CVC4.FloatingPointSize 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 3 with FloatingPointSize

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

the class CVC4FormulaCreator method parseFloatingPoint.

private Object parseFloatingPoint(Expr fpExpr) {
    Matcher matcher = FLOATING_POINT_PATTERN.matcher(fpExpr.toString());
    if (!matcher.matches()) {
        throw new NumberFormatException("Unknown floating-point format: " + fpExpr);
    }
    FloatingPoint fp = fpExpr.getConstFloatingPoint();
    FloatingPointSize fpType = fp.getT();
    long expWidth = fpType.exponentWidth();
    // without sign bit
    long mantWidth = fpType.significandWidth() - 1;
    assert matcher.group("sign").length() == 1;
    assert matcher.group("exp").length() == expWidth;
    assert matcher.group("mant").length() == mantWidth;
    String str = matcher.group("sign") + matcher.group("exp") + matcher.group("mant");
    if (expWidth == 11 && mantWidth == 52) {
        return Double.longBitsToDouble(UnsignedLong.valueOf(str, 2).longValue());
    } else if (expWidth == 8 && mantWidth == 23) {
        return Float.intBitsToFloat(UnsignedInteger.valueOf(str, 2).intValue());
    }
    // TODO to be fully correct, we would need to interpret this string
    return fpExpr.toString();
}
Also used : FloatingPointSize(edu.stanford.CVC4.FloatingPointSize) Matcher(java.util.regex.Matcher) FloatingPoint(edu.stanford.CVC4.FloatingPoint)

Aggregations

FloatingPoint (edu.stanford.CVC4.FloatingPoint)3 FloatingPointSize (edu.stanford.CVC4.FloatingPointSize)3 Expr (edu.stanford.CVC4.Expr)2 Rational (edu.stanford.CVC4.Rational)2 Result (edu.stanford.CVC4.Result)2 RoundingMode (edu.stanford.CVC4.RoundingMode)2 SExpr (edu.stanford.CVC4.SExpr)2 CVC4.vectorExpr (edu.stanford.CVC4.vectorExpr)2 Test (org.junit.Test)2 Matcher (java.util.regex.Matcher)1