Search in sources :

Example 11 with Expr

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

the class StateTest method testStateEquals3.

@Test
public void testStateEquals3() throws Exception {
    HashMap<String, Expr> map = new HashMap<>();
    map.put("x", z3Context.mkInt(11));
    State state = new State(map);
    assertEquals(state, state);
    assertNotEquals(state, new Object());
}
Also used : Expr(com.microsoft.z3.Expr) HashMap(java.util.HashMap) State(de.bmoth.modelchecker.State) Test(org.junit.Test)

Example 12 with Expr

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

the class BooleanFormulaEvaluationTest method testFalseFormula.

@Test
public void testFalseFormula() throws Exception {
    String formula = "x = FALSE";
    // getting the translated z3 representation of the formula
    BoolExpr constraint = FormulaToZ3Translator.translatePredicate(formula, z3Context);
    z3Solver.add(constraint);
    Status check = z3Solver.check();
    Expr x = z3Context.mkBoolConst("x");
    assertEquals(SATISFIABLE, check);
    assertEquals(z3Context.mkFalse(), z3Solver.getModel().eval(x, true));
}
Also used : Status(com.microsoft.z3.Status) BoolExpr(com.microsoft.z3.BoolExpr) BoolExpr(com.microsoft.z3.BoolExpr) Expr(com.microsoft.z3.Expr) Test(org.junit.Test)

Example 13 with Expr

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

the class BooleanFormulaEvaluationTest method testImplication.

@Test
public void testImplication() throws Exception {
    String formula = "1=1 => x";
    // getting the translated z3 representation of the formula
    BoolExpr constraint = FormulaToZ3Translator.translatePredicate(formula, z3Context);
    z3Solver.add(constraint);
    Status check = z3Solver.check();
    Expr x = z3Context.mkBoolConst("x");
    assertEquals(SATISFIABLE, check);
    assertEquals(z3Context.mkBool(true), z3Solver.getModel().eval(x, true));
}
Also used : Status(com.microsoft.z3.Status) BoolExpr(com.microsoft.z3.BoolExpr) BoolExpr(com.microsoft.z3.BoolExpr) Expr(com.microsoft.z3.Expr) Test(org.junit.Test)

Example 14 with Expr

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

the class BooleanFormulaEvaluationTest method testTrueFormula.

@Test
public void testTrueFormula() throws Exception {
    String formula = "x = TRUE";
    // getting the translated z3 representation of the formula
    BoolExpr constraint = FormulaToZ3Translator.translatePredicate(formula, z3Context);
    z3Solver.add(constraint);
    Status check = z3Solver.check();
    Expr x = z3Context.mkBoolConst("x");
    assertEquals(SATISFIABLE, check);
    assertEquals(z3Context.mkTrue(), z3Solver.getModel().eval(x, true));
}
Also used : Status(com.microsoft.z3.Status) BoolExpr(com.microsoft.z3.BoolExpr) BoolExpr(com.microsoft.z3.BoolExpr) Expr(com.microsoft.z3.Expr) Test(org.junit.Test)

Example 15 with Expr

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

the class MachineToZ3Translator method getDistinctVars.

public BoolExpr getDistinctVars(int from, int to) {
    if (tuple == null) {
        Expr[] variables = getVariables().stream().map(this::getVariable).toArray(Expr[]::new);
        Symbol[] symbols = Arrays.stream(variables).map(var -> var.getFuncDecl().getName()).toArray(Symbol[]::new);
        Sort[] sorts = Arrays.stream(variables).map(Expr::getSort).toArray(Sort[]::new);
        tuple = z3Context.mkTupleSort(z3Context.mkSymbol("tuple"), symbols, sorts);
    }
    Expr[] distinct = new Expr[to - from + 1];
    for (int v = from, i = 0; v <= to; v++, i++) {
        int finalV = v;
        Expr[] vector = getVariables().stream().map(var -> getPrimedVariable(var, new TranslationOptions(finalV))).toArray(Expr[]::new);
        distinct[i] = tuple.mkDecl().apply(vector);
    }
    return z3Context.mkDistinct(distinct);
}
Also used : SubstitutionOptions(de.bmoth.backend.SubstitutionOptions) java.util(java.util) com.microsoft.z3(com.microsoft.z3) PRIMED_0(de.bmoth.backend.TranslationOptions.PRIMED_0) UNPRIMED(de.bmoth.backend.TranslationOptions.UNPRIMED) de.bmoth.parser.ast.nodes(de.bmoth.parser.ast.nodes) SubstitutionVisitor(de.bmoth.parser.ast.visitors.SubstitutionVisitor) Streams(com.google.common.collect.Streams) Collectors(java.util.stream.Collectors) TranslationOptions(de.bmoth.backend.TranslationOptions) TranslationOptions(de.bmoth.backend.TranslationOptions)

Aggregations

BoolExpr (com.microsoft.z3.BoolExpr)28 Expr (com.microsoft.z3.Expr)27 Test (org.junit.Test)19 HashMap (java.util.HashMap)12 Status (com.microsoft.z3.Status)11 BitVecExpr (com.microsoft.z3.BitVecExpr)10 ArithExpr (com.microsoft.z3.ArithExpr)8 CommunityVar (org.batfish.symbolic.CommunityVar)6 State (de.bmoth.modelchecker.State)5 Ip (org.batfish.datamodel.Ip)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Map (java.util.Map)4 BatfishException (org.batfish.common.BatfishException)4 Prefix (org.batfish.datamodel.Prefix)4 BooleanExpr (org.batfish.datamodel.routing_policy.expr.BooleanExpr)4 Protocol (org.batfish.symbolic.Protocol)4 HashSet (java.util.HashSet)3 Collectors (java.util.stream.Collectors)3 MatchProtocol (org.batfish.datamodel.routing_policy.expr.MatchProtocol)3