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