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