Search in sources :

Example 1 with IntExpr

use of org.batfish.z3.expr.IntExpr in project batfish by batfish.

the class SimplifierTest method testSimplifyEqStaticallyFalse.

/**
 * Test that an EQ node with LHS and RHS statically determinable to be unequal simplifies to
 * FALSE.
 */
@Test
public void testSimplifyEqStaticallyFalse() {
    IntExpr i1 = new LitIntExpr(Ip.ZERO);
    IntExpr i2 = new LitIntExpr(Ip.MAX);
    EqExpr eq = new EqExpr(i1, i2);
    assertThat(simplifyBooleanExpr(eq), equalTo(FalseExpr.INSTANCE));
}
Also used : EqExpr(org.batfish.z3.expr.EqExpr) LitIntExpr(org.batfish.z3.expr.LitIntExpr) IntExpr(org.batfish.z3.expr.IntExpr) VarIntExpr(org.batfish.z3.expr.VarIntExpr) LitIntExpr(org.batfish.z3.expr.LitIntExpr) Test(org.junit.Test)

Example 2 with IntExpr

use of org.batfish.z3.expr.IntExpr in project batfish by batfish.

the class SimplifierTest method testSimplifyEqSame.

/**
 * Test that an EQ node with syntactically equal LHS and RHS simplifies to TRUE.
 */
@Test
public void testSimplifyEqSame() {
    IntExpr i1 = new VarIntExpr(BasicHeaderField.DST_IP);
    EqExpr eq = new EqExpr(i1, i1);
    assertThat(simplifyBooleanExpr(eq), equalTo(TrueExpr.INSTANCE));
}
Also used : VarIntExpr(org.batfish.z3.expr.VarIntExpr) EqExpr(org.batfish.z3.expr.EqExpr) IntExpr(org.batfish.z3.expr.IntExpr) VarIntExpr(org.batfish.z3.expr.VarIntExpr) LitIntExpr(org.batfish.z3.expr.LitIntExpr) Test(org.junit.Test)

Example 3 with IntExpr

use of org.batfish.z3.expr.IntExpr in project batfish by batfish.

the class BoolExprTransformerTest method testVisitEqExpr.

@Test
public void testVisitEqExpr() {
    IntExpr i1Batfish = newIntAtom();
    IntExpr i2Batfish = newIntAtom();
    BitVecExpr i1Z3 = toBitVecExpr(i1Batfish, _nodContext);
    BitVecExpr i2Z3 = toBitVecExpr(i2Batfish, _nodContext);
    assertThat(toBoolExpr(new EqExpr(i1Batfish, i2Batfish), _input, _nodContext), equalTo(_ctx.mkEq(i1Z3, i2Z3)));
}
Also used : BitVecExprTransformer.toBitVecExpr(org.batfish.z3.expr.visitors.BitVecExprTransformer.toBitVecExpr) BitVecExpr(com.microsoft.z3.BitVecExpr) EqExpr(org.batfish.z3.expr.EqExpr) IntExpr(org.batfish.z3.expr.IntExpr) Test(org.junit.Test)

Example 4 with IntExpr

use of org.batfish.z3.expr.IntExpr in project batfish by batfish.

the class SimplifierTest method testSimplifyEqPreserveUnalteredInstance.

/**
 * Test that an EQ node with LHS and RHS not statically determinable is unchanged by
 * simplification.
 */
@Test
public void testSimplifyEqPreserveUnalteredInstance() {
    IntExpr i1 = new VarIntExpr(BasicHeaderField.DST_IP);
    IntExpr i2 = new VarIntExpr(BasicHeaderField.SRC_IP);
    EqExpr eq = new EqExpr(i1, i2);
    assertThat(simplifyBooleanExpr(eq), sameInstance(eq));
}
Also used : VarIntExpr(org.batfish.z3.expr.VarIntExpr) EqExpr(org.batfish.z3.expr.EqExpr) IntExpr(org.batfish.z3.expr.IntExpr) VarIntExpr(org.batfish.z3.expr.VarIntExpr) LitIntExpr(org.batfish.z3.expr.LitIntExpr) Test(org.junit.Test)

Example 5 with IntExpr

use of org.batfish.z3.expr.IntExpr in project batfish by batfish.

the class Simplifier method visitEqExpr.

@Override
public BooleanExpr visitEqExpr(EqExpr eqExpr) {
    IntExpr lhs = eqExpr.getLhs();
    IntExpr rhs = eqExpr.getRhs();
    if (lhs.equals(rhs)) {
        return TrueExpr.INSTANCE;
    } else if (lhs instanceof LitIntExpr && rhs instanceof LitIntExpr) {
        return FalseExpr.INSTANCE;
    } else {
        return eqExpr;
    }
}
Also used : LitIntExpr(org.batfish.z3.expr.LitIntExpr) IntExpr(org.batfish.z3.expr.IntExpr) VarIntExpr(org.batfish.z3.expr.VarIntExpr) LitIntExpr(org.batfish.z3.expr.LitIntExpr)

Aggregations

IntExpr (org.batfish.z3.expr.IntExpr)5 EqExpr (org.batfish.z3.expr.EqExpr)4 LitIntExpr (org.batfish.z3.expr.LitIntExpr)4 VarIntExpr (org.batfish.z3.expr.VarIntExpr)4 Test (org.junit.Test)4 BitVecExpr (com.microsoft.z3.BitVecExpr)1 BitVecExprTransformer.toBitVecExpr (org.batfish.z3.expr.visitors.BitVecExprTransformer.toBitVecExpr)1