Search in sources :

Example 71 with Context

use of com.microsoft.z3.Context in project batfish by batfish.

the class BoolExprTransformer method visitBasicRuleStatement.

@Override
public BoolExpr visitBasicRuleStatement(BasicRuleStatement basicRuleStatement) {
    Context ctx = _nodContext.getContext();
    ImmutableList.Builder<BoolExpr> preconditions = ImmutableList.<BoolExpr>builder().add(toBoolExpr(basicRuleStatement.getPreconditionStateIndependentConstraints(), _input, _nodContext));
    basicRuleStatement.getPreconditionStates().stream().map(preconditionState -> toBoolExpr(preconditionState, _input, _nodContext)).forEach(preconditions::add);
    return ctx.mkImplies(ctx.mkAnd(preconditions.build().stream().toArray(BoolExpr[]::new)), toBoolExpr(basicRuleStatement.getPostconditionState(), _input, _nodContext));
}
Also used : Context(com.microsoft.z3.Context) NodContext(org.batfish.z3.NodContext) Statement(org.batfish.z3.expr.Statement) Arrays(java.util.Arrays) PrefixMatchExpr(org.batfish.z3.expr.PrefixMatchExpr) TransformationHeaderField(org.batfish.z3.TransformationHeaderField) OrExpr(org.batfish.z3.expr.OrExpr) TrueExpr(org.batfish.z3.expr.TrueExpr) Context(com.microsoft.z3.Context) SynthesizerInput(org.batfish.z3.SynthesizerInput) TransformationRuleStatement(org.batfish.z3.expr.TransformationRuleStatement) GenericStatementVisitor(org.batfish.z3.expr.GenericStatementVisitor) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) BoolExpr(com.microsoft.z3.BoolExpr) StateExpr(org.batfish.z3.expr.StateExpr) HeaderSpaceMatchExpr(org.batfish.z3.expr.HeaderSpaceMatchExpr) Parameterizer(org.batfish.z3.state.visitors.Parameterizer) IfExpr(org.batfish.z3.expr.IfExpr) BooleanExpr(org.batfish.z3.expr.BooleanExpr) FalseExpr(org.batfish.z3.expr.FalseExpr) ImmutableMap(com.google.common.collect.ImmutableMap) IpSpaceMatchExpr(org.batfish.z3.expr.IpSpaceMatchExpr) IfThenElse(org.batfish.z3.expr.IfThenElse) Set(java.util.Set) NotExpr(org.batfish.z3.expr.NotExpr) Comment(org.batfish.z3.expr.Comment) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) SaneExpr(org.batfish.z3.expr.SaneExpr) AndExpr(org.batfish.z3.expr.AndExpr) NodContext(org.batfish.z3.NodContext) CurrentIsOriginalExpr(org.batfish.z3.expr.CurrentIsOriginalExpr) EqExpr(org.batfish.z3.expr.EqExpr) Expr(com.microsoft.z3.Expr) QueryStatement(org.batfish.z3.expr.QueryStatement) RangeMatchExpr(org.batfish.z3.expr.RangeMatchExpr) Type(org.batfish.z3.state.StateParameter.Type) BoolExpr(com.microsoft.z3.BoolExpr) ImmutableList(com.google.common.collect.ImmutableList)

Example 72 with Context

use of com.microsoft.z3.Context in project bmoth by hhu-stups.

the class Issue59Test method testIssue59JustInvariant.

@Test
public void testIssue59JustInvariant() {
    Context ctx = new Context();
    Solver s = ctx.mkSolver();
    String formula = "x**2 = x*x & #x.({x} \\/ {1,2} = {1,2})";
    BoolExpr combinedConstraint = translatePredicate(formula, ctx);
    s.add(combinedConstraint);
    Status check = s.check();
    assertEquals(Status.SATISFIABLE, check);
}
Also used : Context(com.microsoft.z3.Context) Status(com.microsoft.z3.Status) BoolExpr(com.microsoft.z3.BoolExpr) Solver(com.microsoft.z3.Solver) Test(org.junit.Test)

Example 73 with Context

use of com.microsoft.z3.Context in project bmoth by hhu-stups.

the class Issue59Test method testIssue59JustInvariant2.

@Test
public void testIssue59JustInvariant2() {
    Context ctx = new Context();
    Solver s = ctx.mkSolver();
    String formula = "x**2 = x*x";
    BoolExpr combinedConstraint = translatePredicate(formula, ctx);
    s.add(combinedConstraint);
    Status check = s.check();
    assertEquals(Status.SATISFIABLE, check);
}
Also used : Context(com.microsoft.z3.Context) Status(com.microsoft.z3.Status) BoolExpr(com.microsoft.z3.BoolExpr) Solver(com.microsoft.z3.Solver) Test(org.junit.Test)

Example 74 with Context

use of com.microsoft.z3.Context in project bmoth by hhu-stups.

the class Z3SolverFactory method getZ3Solver.

static Solver getZ3Solver(Context ctx) {
    Solver solver = ctx.mkSolver();
    Params params = ctx.mkParams();
    params.add("timeout", BMothPreferences.getIntPreference(BMothPreferences.IntPreference.Z3_TIMEOUT));
    solver.setParameters(params);
    return solver;
}
Also used : Solver(com.microsoft.z3.Solver) Params(com.microsoft.z3.Params)

Example 75 with Context

use of com.microsoft.z3.Context in project bmoth by hhu-stups.

the class Z3TypeInference method getZ3Sort.

public Sort getZ3Sort(Z3Type t, Context z3Context) {
    if (t instanceof Z3BasicType) {
        switch(((Z3BasicType) t).kind) {
            case INTEGER:
                return z3Context.getIntSort();
            case BOOL:
                return z3Context.getBoolSort();
            default:
                break;
        }
    } else if (t instanceof Z3SetType) {
        Sort subSort = getZ3Sort(((Z3SetType) t).subtype, z3Context);
        return z3Context.mkSetSort(subSort);
    } else if (t instanceof Z3CoupleType) {
        Z3CoupleType couple = (Z3CoupleType) t;
        Sort left = getZ3Sort(couple.left, z3Context);
        Sort right = getZ3Sort(couple.right, z3Context);
        Sort[] subSorts = new Sort[2];
        subSorts[0] = left;
        subSorts[1] = right;
        return z3Context.mkTupleSort(z3Context.mkSymbol("couple"), new Symbol[] { z3Context.mkSymbol("left"), z3Context.mkSymbol("right") }, subSorts);
    } else if (t instanceof Z3SequenceType) {
        Sort subSort = getZ3Sort(((Z3SequenceType) t).subtype, z3Context);
        Sort intType = z3Context.getIntSort();
        Sort[] subSorts = new Sort[2];
        subSorts[0] = z3Context.mkArraySort(intType, subSort);
        subSorts[1] = intType;
        return z3Context.mkTupleSort(z3Context.mkSymbol("sequence"), new Symbol[] { z3Context.mkSymbol("array"), z3Context.mkSymbol("size") }, subSorts);
    } else if (t instanceof Z3DeferredType) {
        return z3Context.mkUninterpretedSort(((Z3DeferredType) t).name);
    } else if (t instanceof Z3EnumeratedSetType) {
        List<String> elements = ((Z3EnumeratedSetType) t).elements;
        String[] array = elements.toArray(new String[elements.size()]);
        return z3Context.mkEnumSort(((Z3EnumeratedSetType) t).name, array);
    }
    throw new AssertionError("Missing Type Conversion: " + t.getClass());
}
Also used : Symbol(com.microsoft.z3.Symbol) Sort(com.microsoft.z3.Sort) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Context (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context)58 Context (com.microsoft.z3.Context)36 CoreException (org.eclipse.core.runtime.CoreException)34 BoolExpr (com.microsoft.z3.BoolExpr)31 Test (org.junit.Test)24 List (java.util.List)21 Event (dartagnan.program.Event)19 MemEvent (dartagnan.program.MemEvent)19 Program (dartagnan.program.Program)19 IOException (java.io.IOException)19 Set (java.util.Set)19 Collectors (java.util.stream.Collectors)19 ServerInstance (org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance)17 Context (org.kie.workbench.common.dmn.api.definition.v1_1.Context)17 Local (dartagnan.program.Local)16 HashMap (java.util.HashMap)16 Map (java.util.Map)15 Solver (com.microsoft.z3.Solver)14 Init (dartagnan.program.Init)14 File (java.io.File)14