Search in sources :

Example 81 with BoolExpr

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

the class Z3ContextJob method getSolverInput.

protected BoolExpr getSolverInput(Expr answer, NodProgram program, boolean negate) {
    BoolExpr solverInput;
    if (answer.getArgs().length > 0) {
        Map<String, BitVecExpr> variablesAsConsts = program.getNodContext().getVariablesAsConsts();
        List<BitVecExpr> reversedVars = Lists.reverse(program.getNodContext().getVariableNames().stream().filter(name -> !TransformationHeaderField.transformationHeaderFieldNames.contains(name)).map(variablesAsConsts::get).collect(Collectors.toList()));
        Expr substitutedAnswer = answer.substituteVars(reversedVars.toArray(new Expr[] {}));
        solverInput = (BoolExpr) substitutedAnswer;
    } else {
        solverInput = (BoolExpr) answer;
    }
    if (negate) {
        solverInput = program.getNodContext().getContext().mkNot(solverInput);
    }
    return solverInput;
}
Also used : Arrays(java.util.Arrays) FuncDecl(com.microsoft.z3.FuncDecl) IpProtocol(org.batfish.datamodel.IpProtocol) ImmutableMap(com.google.common.collect.ImmutableMap) BatfishJob(org.batfish.job.BatfishJob) Context(com.microsoft.z3.Context) BitVecExpr(com.microsoft.z3.BitVecExpr) BatfishException(org.batfish.common.BatfishException) Streams(com.google.common.collect.Streams) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) State(org.batfish.datamodel.State) Fixedpoint(com.microsoft.z3.Fixedpoint) Settings(org.batfish.config.Settings) Flow(org.batfish.datamodel.Flow) List(java.util.List) BatfishJobResult(org.batfish.job.BatfishJobResult) Lists(com.google.common.collect.Lists) Params(com.microsoft.z3.Params) Map(java.util.Map) BoolExpr(com.microsoft.z3.BoolExpr) Expr(com.microsoft.z3.Expr) Status(com.microsoft.z3.Status) Ip(org.batfish.datamodel.Ip) BoolExpr(com.microsoft.z3.BoolExpr) BitVecExpr(com.microsoft.z3.BitVecExpr) BitVecExpr(com.microsoft.z3.BitVecExpr) BoolExpr(com.microsoft.z3.BoolExpr) Expr(com.microsoft.z3.Expr)

Example 82 with BoolExpr

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

the class BoolExprTransformerTest method testVisitAndExpr.

@Test
public void testVisitAndExpr() {
    BooleanExpr p1Batfish = newBooleanAtom();
    BooleanExpr p2Batfish = newBooleanAtom();
    BoolExpr p1Z3 = toBoolExpr(p1Batfish, _input, _nodContext);
    BoolExpr p2Z3 = toBoolExpr(p2Batfish, _input, _nodContext);
    assertThat(toBoolExpr(new AndExpr(of(p1Batfish, p2Batfish)), _input, _nodContext), equalTo(_ctx.mkAnd(p1Z3, p2Z3)));
}
Also used : AndExpr(org.batfish.z3.expr.AndExpr) BoolExpr(com.microsoft.z3.BoolExpr) BoolExprTransformer.toBoolExpr(org.batfish.z3.expr.visitors.BoolExprTransformer.toBoolExpr) BooleanExpr(org.batfish.z3.expr.BooleanExpr) Test(org.junit.Test)

Example 83 with BoolExpr

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

the class BoolExprTransformerTest method testVisitOrExpr.

@Test
public void testVisitOrExpr() {
    BooleanExpr p1Batfish = newBooleanAtom();
    BooleanExpr p2Batfish = newBooleanAtom();
    BoolExpr p1Z3 = toBoolExpr(p1Batfish, _input, _nodContext);
    BoolExpr p2Z3 = toBoolExpr(p2Batfish, _input, _nodContext);
    assertThat(toBoolExpr(new OrExpr(of(p1Batfish, p2Batfish)), _input, _nodContext), equalTo(_ctx.mkOr(p1Z3, p2Z3)));
}
Also used : BoolExpr(com.microsoft.z3.BoolExpr) BoolExprTransformer.toBoolExpr(org.batfish.z3.expr.visitors.BoolExprTransformer.toBoolExpr) BooleanExpr(org.batfish.z3.expr.BooleanExpr) OrExpr(org.batfish.z3.expr.OrExpr) Test(org.junit.Test)

Example 84 with BoolExpr

use of com.microsoft.z3.BoolExpr 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 85 with BoolExpr

use of com.microsoft.z3.BoolExpr in project Dat3M by hernanponcedeleon.

the class ARM method encode.

public static BoolExpr encode(Program program, Context ctx) throws Z3Exception {
    Set<Event> events = program.getEvents().stream().filter(e -> e instanceof MemEvent).collect(Collectors.toSet());
    Set<Event> eventsL = program.getEvents().stream().filter(e -> e instanceof MemEvent || e instanceof Local).collect(Collectors.toSet());
    BoolExpr enc = satUnion("co", "fr", events, ctx);
    enc = ctx.mkAnd(enc, satUnion("com", "(co+fr)", "rf", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("poloc", "com", events, ctx));
    enc = ctx.mkAnd(enc, satTransFixPoint("idd", eventsL, ctx));
    enc = ctx.mkAnd(enc, satIntersection("data", "idd^+", "RW", events, ctx));
    enc = ctx.mkAnd(enc, satEmpty("addr", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("dp", "addr", "data", events, ctx));
    enc = ctx.mkAnd(enc, satComp("fre", "rfe", events, ctx));
    enc = ctx.mkAnd(enc, satComp("coe", "rfe", events, ctx));
    enc = ctx.mkAnd(enc, satIntersection("rdw", "poloc", "(fre;rfe)", events, ctx));
    enc = ctx.mkAnd(enc, satIntersection("detour", "poloc", "(coe;rfe)", events, ctx));
    // Base case for program order
    enc = ctx.mkAnd(enc, satUnion("dp", "rdw", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("ii0", "(dp+rdw)", "rfi", events, ctx));
    enc = ctx.mkAnd(enc, satEmpty("ic0", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("ci0", "ctrlisb", "detour", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("dp", "ctrl", events, ctx));
    enc = ctx.mkAnd(enc, satComp("addr", "po", events, ctx));
    enc = ctx.mkAnd(enc, satARMPPO(events, ctx));
    enc = ctx.mkAnd(enc, satUnion("cc0", "(dp+ctrl)", "(addr;po)", events, ctx));
    enc = ctx.mkAnd(enc, satIntersection("RR", "ii", events, ctx));
    enc = ctx.mkAnd(enc, satIntersection("RW", "ic", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("po-arm", "(RR&ii)", "(RW&ic)", events, ctx));
    // Happens before
    enc = ctx.mkAnd(enc, satUnion("po-arm", "rfe", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("hb-arm", "(po-arm+rfe)", "ish", events, ctx));
    // Prop-base
    enc = ctx.mkAnd(enc, satComp("rfe", "ish", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("ish", "(rfe;ish)", events, ctx));
    enc = ctx.mkAnd(enc, satTransRef("hb-arm", events, ctx));
    enc = ctx.mkAnd(enc, satComp("prop-base", "(ish+(rfe;ish))", "(hb-arm)*", events, ctx));
    // Propagation for ARM
    enc = ctx.mkAnd(enc, satTransRef("com", events, ctx));
    enc = ctx.mkAnd(enc, satTransRef("prop-base", events, ctx));
    enc = ctx.mkAnd(enc, satComp("(com)*", "(prop-base)*", events, ctx));
    enc = ctx.mkAnd(enc, satComp("((com)*;(prop-base)*)", "ish", events, ctx));
    enc = ctx.mkAnd(enc, satComp("(((com)*;(prop-base)*);ish)", "(hb-arm)*", events, ctx));
    enc = ctx.mkAnd(enc, satIntersection("WW", "prop-base", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("prop", "(WW&prop-base)", "((((com)*;(prop-base)*);ish);(hb-arm)*)", events, ctx));
    enc = ctx.mkAnd(enc, satComp("fre", "prop", events, ctx));
    enc = ctx.mkAnd(enc, satComp("(fre;prop)", "(hb-arm)*", events, ctx));
    enc = ctx.mkAnd(enc, satUnion("co", "prop", events, ctx));
    return enc;
}
Also used : EncodingsCAT.satTransFixPoint(dartagnan.wmm.EncodingsCAT.satTransFixPoint) EncodingsCAT.satCycle(dartagnan.wmm.EncodingsCAT.satCycle) EncodingsCAT.satTransRef(dartagnan.wmm.EncodingsCAT.satTransRef) Event(dartagnan.program.Event) Context(com.microsoft.z3.Context) Set(java.util.Set) Utils(dartagnan.utils.Utils) Collectors(java.util.stream.Collectors) Utils.intCount(dartagnan.utils.Utils.intCount) EncodingsCAT.satEmpty(dartagnan.wmm.EncodingsCAT.satEmpty) EncodingsCAT.satUnion(dartagnan.wmm.EncodingsCAT.satUnion) EncodingsCAT.satComp(dartagnan.wmm.EncodingsCAT.satComp) EncodingsCAT.satIrref(dartagnan.wmm.EncodingsCAT.satIrref) EncodingsCAT.satCycleDef(dartagnan.wmm.EncodingsCAT.satCycleDef) EncodingsCAT.satAcyclic(dartagnan.wmm.EncodingsCAT.satAcyclic) Local(dartagnan.program.Local) MemEvent(dartagnan.program.MemEvent) BoolExpr(com.microsoft.z3.BoolExpr) Z3Exception(com.microsoft.z3.Z3Exception) Program(dartagnan.program.Program) Utils.edge(dartagnan.utils.Utils.edge) EncodingsCAT.satIntersection(dartagnan.wmm.EncodingsCAT.satIntersection) BoolExpr(com.microsoft.z3.BoolExpr) MemEvent(dartagnan.program.MemEvent) Event(dartagnan.program.Event) MemEvent(dartagnan.program.MemEvent) Local(dartagnan.program.Local)

Aggregations

BoolExpr (com.microsoft.z3.BoolExpr)141 Status (com.microsoft.z3.Status)55 Test (org.junit.Test)51 ArithExpr (com.microsoft.z3.ArithExpr)27 GraphEdge (org.batfish.symbolic.GraphEdge)25 Context (com.microsoft.z3.Context)24 HashMap (java.util.HashMap)22 Expr (com.microsoft.z3.Expr)21 Set (java.util.Set)20 Collectors (java.util.stream.Collectors)18 BitVecExpr (com.microsoft.z3.BitVecExpr)17 Event (dartagnan.program.Event)17 MemEvent (dartagnan.program.MemEvent)17 Program (dartagnan.program.Program)16 Map (java.util.Map)16 Local (dartagnan.program.Local)15 ArrayList (java.util.ArrayList)15 BatfishException (org.batfish.common.BatfishException)14 Graph (org.batfish.symbolic.Graph)14 com.microsoft.z3 (com.microsoft.z3)12