use of com.acgist.snail.pojo.bean.M3u8.Type in project java-smt by sosy-lab.
the class CVC4FormulaCreator method declareUFImpl.
@Override
public Expr declareUFImpl(String pName, Type pReturnType, List<Type> pArgTypes) {
Expr exp = functionsCache.get(pName);
if (exp == null) {
vectorType args = new vectorType();
for (Type t : pArgTypes) {
args.add(t);
}
exp = exprManager.mkVar(pName, exprManager.mkFunctionType(args, pReturnType));
functionsCache.put(pName, exp);
}
return exp;
}
use of com.acgist.snail.pojo.bean.M3u8.Type in project java-smt by sosy-lab.
the class CVC4FormulaManager method dumpFormula.
@Override
public Appender dumpFormula(Expr f) {
assert getFormulaCreator().getFormulaType(f) == FormulaType.BooleanType : "Only BooleanFormulas may be dumped";
return new Appenders.AbstractAppender() {
@Override
public void appendTo(Appendable out) throws IOException {
// get all symbols
final Map<String, Expr> allVars = new LinkedHashMap<>();
creator.extractVariablesAndUFs(f, true, allVars::put);
// print all symbols
for (Map.Entry<String, Expr> entry : allVars.entrySet()) {
String name = entry.getKey();
Expr var = entry.getValue();
// escaping is stolen from SMTInterpol, lets hope this remains consistent
out.append("(declare-fun ").append(PrintTerm.quoteIdentifier(name)).append(" (");
// add function parameters
Iterable<Type> childrenTypes = Iterables.transform(var, Expr::getType);
out.append(Joiner.on(" ").join(childrenTypes));
// and return type
out.append(") ").append(var.getType().toString()).append(")\n");
}
// now add the final assert
out.append("(assert ");
// f.toStream() uses LET-expressions and is exactly what we want.
try (OutputStream stream = new OutputStream() {
@Override
public void write(int chr) throws IOException {
out.append((char) chr);
}
}) {
f.toStream(stream);
}
out.append(')');
}
};
}
use of com.acgist.snail.pojo.bean.M3u8.Type in project java-smt by sosy-lab.
the class CVC4NativeAPITest method checkLIAUfsUnsat.
@Test
public void checkLIAUfsUnsat() {
// 0 <= f(x)
// 0 <= f(y)
// f(x) + f(y) = x
// f(x) + f(y) = y
// f(x) = x + 1
// f(y) = y - 1
Expr zero = exprMgr.mkConst(new Rational(0));
Expr one = exprMgr.mkConst(new Rational(1));
Type intType = exprMgr.integerType();
// Type for UFs later
Type intToInt = exprMgr.mkFunctionType(intType, intType);
Expr xInt = exprMgr.mkVar("x", intType);
Expr yInt = exprMgr.mkVar("y", intType);
// declare UFs
Expr f = exprMgr.mkVar("f", intToInt);
// Apply UFs
Expr fx = exprMgr.mkExpr(Kind.APPLY_UF, f, xInt);
Expr fy = exprMgr.mkExpr(Kind.APPLY_UF, f, yInt);
Expr plus = exprMgr.mkExpr(Kind.PLUS, fx, fy);
// Make some assumptions
Expr assumptions1 = exprMgr.mkExpr(Kind.AND, exprMgr.mkExpr(Kind.LEQ, zero, fx), exprMgr.mkExpr(Kind.LEQ, zero, fy));
Expr assumptions2 = exprMgr.mkExpr(Kind.AND, exprMgr.mkExpr(Kind.EQUAL, fx, exprMgr.mkExpr(Kind.PLUS, xInt, one)), exprMgr.mkExpr(Kind.EQUAL, fy, exprMgr.mkExpr(Kind.MINUS, yInt, one)), exprMgr.mkExpr(Kind.EQUAL, plus, xInt), exprMgr.mkExpr(Kind.EQUAL, plus, yInt));
smtEngine.assertFormula(assumptions1);
smtEngine.assertFormula(assumptions2);
Result satCheck = smtEngine.checkSat();
assertThat(satCheck.isSat()).isEqualTo(Sat.UNSAT);
}
use of com.acgist.snail.pojo.bean.M3u8.Type in project java-smt by sosy-lab.
the class CVC4NativeAPITest method checkBooleanUFDeclaration.
@Test
public void checkBooleanUFDeclaration() {
Type boolType = exprMgr.booleanType();
Type intType = exprMgr.integerType();
// arg is bool, return is int
Type ufType = exprMgr.mkFunctionType(boolType, intType);
Expr uf = exprMgr.mkVar("fun_bi", ufType);
Expr ufTrue = exprMgr.mkExpr(uf, exprMgr.mkConst(true));
Expr ufFalse = exprMgr.mkExpr(uf, exprMgr.mkConst(false));
Expr assumptions = exprMgr.mkExpr(Kind.NOT, exprMgr.mkExpr(Kind.EQUAL, ufTrue, ufFalse));
smtEngine.assertFormula(assumptions);
Result satCheck = smtEngine.checkSat();
assertThat(satCheck.isSat()).isEqualTo(Sat.SAT);
}
use of com.acgist.snail.pojo.bean.M3u8.Type in project java-smt by sosy-lab.
the class CVC4NativeAPITest method checkUnsatCore.
@Test
public void checkUnsatCore() {
// (a & b) & (not(a OR b))
// Enable UNSAT Core first!
smtEngine.setOption("produce-unsat-cores", new SExpr(true));
Type boolType = exprMgr.booleanType();
Expr a = exprMgr.mkVar("a", boolType);
Expr b = exprMgr.mkVar("b", boolType);
Expr aAndb = exprMgr.mkExpr(Kind.AND, a, b);
Expr notaOrb = exprMgr.mkExpr(Kind.NOT, exprMgr.mkExpr(Kind.OR, a, b));
smtEngine.assertFormula(aAndb);
smtEngine.assertFormula(notaOrb);
Result satCheck = smtEngine.checkSat();
assertThat(satCheck.isSat()).isEqualTo(Sat.UNSAT);
UnsatCore unsatCore = smtEngine.getUnsatCore();
// UnsatCores are iterable
for (Expr e : unsatCore) {
assertThat(e.toString()).isIn(Arrays.asList("(not (or a b))", "(and a b)"));
}
}
Aggregations