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