Search in sources :

Example 26 with Type

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;
}
Also used : FloatingPointType(org.sosy_lab.java_smt.api.FormulaType.FloatingPointType) CVC4.vectorType(edu.stanford.CVC4.vectorType) Type(edu.stanford.CVC4.Type) BitVectorType(edu.stanford.CVC4.BitVectorType) FormulaType(org.sosy_lab.java_smt.api.FormulaType) ArrayFormulaType(org.sosy_lab.java_smt.api.FormulaType.ArrayFormulaType) ArrayType(edu.stanford.CVC4.ArrayType) FunctionType(edu.stanford.CVC4.FunctionType) CVC4.vectorExpr(edu.stanford.CVC4.vectorExpr) Expr(edu.stanford.CVC4.Expr) CVC4.vectorType(edu.stanford.CVC4.vectorType)

Example 27 with Type

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(')');
        }
    };
}
Also used : Type(edu.stanford.CVC4.Type) FormulaType(org.sosy_lab.java_smt.api.FormulaType) Expr(edu.stanford.CVC4.Expr) OutputStream(java.io.OutputStream) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 28 with Type

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);
}
Also used : Type(edu.stanford.CVC4.Type) SortType(edu.stanford.CVC4.SortType) ArrayType(edu.stanford.CVC4.ArrayType) BitVectorType(edu.stanford.CVC4.BitVectorType) CVC4.vectorExpr(edu.stanford.CVC4.vectorExpr) SExpr(edu.stanford.CVC4.SExpr) Expr(edu.stanford.CVC4.Expr) Rational(edu.stanford.CVC4.Rational) Result(edu.stanford.CVC4.Result) Test(org.junit.Test)

Example 29 with Type

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);
}
Also used : Type(edu.stanford.CVC4.Type) SortType(edu.stanford.CVC4.SortType) ArrayType(edu.stanford.CVC4.ArrayType) BitVectorType(edu.stanford.CVC4.BitVectorType) CVC4.vectorExpr(edu.stanford.CVC4.vectorExpr) SExpr(edu.stanford.CVC4.SExpr) Expr(edu.stanford.CVC4.Expr) Result(edu.stanford.CVC4.Result) Test(org.junit.Test)

Example 30 with Type

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)"));
    }
}
Also used : Type(edu.stanford.CVC4.Type) SortType(edu.stanford.CVC4.SortType) ArrayType(edu.stanford.CVC4.ArrayType) BitVectorType(edu.stanford.CVC4.BitVectorType) UnsatCore(edu.stanford.CVC4.UnsatCore) CVC4.vectorExpr(edu.stanford.CVC4.vectorExpr) SExpr(edu.stanford.CVC4.SExpr) Expr(edu.stanford.CVC4.Expr) SExpr(edu.stanford.CVC4.SExpr) Result(edu.stanford.CVC4.Result) Test(org.junit.Test)

Aggregations

Type (com.google.api.expr.v1alpha1.Type)30 Test (org.junit.Test)16 Type (edu.stanford.CVC4.Type)14 Type (com.google.spanner.v1.Type)12 ArrayType (edu.stanford.CVC4.ArrayType)11 BitVectorType (edu.stanford.CVC4.BitVectorType)11 Expr (edu.stanford.CVC4.Expr)11 MapType (com.google.api.expr.v1alpha1.Type.MapType)10 Type (org.apache.xbean.asm9.Type)10 ByteString (com.google.protobuf.ByteString)9 CVC4.vectorExpr (edu.stanford.CVC4.vectorExpr)9 ArrayList (java.util.ArrayList)9 CheckedExpr (com.google.api.expr.v1alpha1.CheckedExpr)8 FieldType (org.projectnessie.cel.common.types.ref.FieldType)8 FormulaType (org.sosy_lab.java_smt.api.FormulaType)8 ListValue (com.google.protobuf.ListValue)7 ExecuteSqlRequest (com.google.spanner.v1.ExecuteSqlRequest)7 CheckerEnv.dynElementType (org.projectnessie.cel.checker.CheckerEnv.dynElementType)7 CheckerEnv.getObjectWellKnownType (org.projectnessie.cel.checker.CheckerEnv.getObjectWellKnownType)7 CheckerEnv.isObjectWellKnownType (org.projectnessie.cel.checker.CheckerEnv.isObjectWellKnownType)7