Search in sources :

Example 6 with BoolExpr

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

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

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

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

Example 10 with BoolExpr

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

the class QuantifiedFormulaEvaluationTest method testFailUniversalExistentialFormula.

@Test
public void testFailUniversalExistentialFormula() {
    String formula = "#(y).(y:NATURAL & !(x).(x=y))";
    // getting the translated z3 representation of the formula
    BoolExpr constraint = translatePredicate(formula, z3Context);
    z3Solver.add(constraint);
    Status check = z3Solver.check();
    assertEquals(Status.UNSATISFIABLE, check);
}
Also used : Status(com.microsoft.z3.Status) BoolExpr(com.microsoft.z3.BoolExpr) Test(org.junit.Test)

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