Python z3.BoolVal() Examples

The following are 11 code examples of z3.BoolVal(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module z3 , or try the search function .
Example #1
Source File: solver.py    From tea-lang with Apache License 2.0 6 votes vote down vote up
def query(self):  # May want to change this....
        global __property_to_function__

        self._populate_properties()  # Apply to specific instance of variables
        # if self.__query__ is None:
        conj = []
        for p in self._properties:  # combines Test and Var-specific properties
            # p.__z3__ = uninterpreted function
            # p.__var__ = instantiated z3 BoolVal
            # Add the uf, and interpret the uf as always ==ing the instantiated BoolVal
            # conj += [p.__z3__, p.__z3__ == p.__var__]
            conj += [p.__z3__]

            # Add property to property to function map
            __property_to_function__[p.__z3__] = p.property.function

        return conj
        # self.__query__ = query
        # return self.__query__ 
Example #2
Source File: solver.py    From cozy with Apache License 2.0 5 votes vote down vote up
def __init__(self, z3ctx, z3solver):
        self.ctx = z3ctx
        self.solver = z3solver
        self.int_zero = z3.IntVal(0, self.ctx)
        self.int_one  = z3.IntVal(1, self.ctx)
        self.true = z3.BoolVal(True, self.ctx)
        self.false = z3.BoolVal(False, self.ctx)
        assert to_bool(self.true) is True
        assert to_bool(self.false) is False
        assert to_bool(self.int_zero) is None 
Example #3
Source File: solver.py    From cozy with Apache License 2.0 5 votes vote down vote up
def distinct(self, t, *values):
        if len(values) <= 1:
            return z3.BoolVal(True, self.ctx)
        return self.all(
            self.distinct(t, values[1:]),
            *[self.neg(self.eq(t, values[0], v1, {})) for v1 in values[1:]]) 
Example #4
Source File: solver.py    From cozy with Apache License 2.0 5 votes vote down vote up
def visit_EBool(self, b, env):
        return z3.BoolVal(b.val, self.ctx) 
Example #5
Source File: solver.py    From cozy with Apache License 2.0 5 votes vote down vote up
def visit_bool(self, e, env):
        return z3.BoolVal(e, self.ctx) 
Example #6
Source File: backend_z3.py    From claripy with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def BoolV(self, ast): #pylint:disable=unused-argument
        # TODO: Here the checks performed by the high level API are mandatory before calling the low level API
        #       So we can keep the high level API call here
        return z3.BoolVal(ast.args[0], ctx=self._context) 
Example #7
Source File: backend_z3.py    From claripy with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def _is_false(self, e, extra_constraints=(), solver=None, model_callback=None):
        return z3.simplify(e).eq(z3.BoolVal(False, ctx=self._context)) 
Example #8
Source File: backend_z3.py    From claripy with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def _is_true(self, e, extra_constraints=(), solver=None, model_callback=None):
        return z3.simplify(e).eq(z3.BoolVal(True, ctx=self._context)) 
Example #9
Source File: z3.py    From pysmt with Apache License 2.0 5 votes vote down vote up
def walk_bool_constant(self, formula, **kwargs):
        _t = z3.BoolVal(formula.constant_value(), ctx=self.ctx)
        z3term = _t.as_ast()
        z3.Z3_inc_ref(self.ctx.ref(), z3term)
        return z3term 
Example #10
Source File: z3_extra_util.py    From teether with Apache License 2.0 5 votes vote down vote up
def simplify_non_const_hashes(expr, sha_ids):
    while True:
        expr = z3.simplify(expr, expand_select_store=True)
        sha_subst = get_sha_subst_non_recursive(expr, sha_ids)
        if not sha_subst:
            break
        expr = z3.substitute(expr, [(s, z3.BoolVal(False)) for s in sha_subst])
    return expr 
Example #11
Source File: mlil_ast.py    From f-ing-around-with-binaryninja with MIT License 4 votes vote down vote up
def generate_reaching_constraints(self):
        visitor = ConditionVisitor(self.view)

        for (
            (start, end),
            reaching_condition,
        ) in self.reaching_conditions.items():
            or_exprs = []

            for condition in reaching_condition:
                and_exprs = []

                for edge in condition:
                    if edge.type == BranchType.UnconditionalBranch:
                        continue

                    if edge.type == BranchType.TrueBranch:
                        condition = edge.source[-1].condition
                        if (
                            condition.operation
                            == MediumLevelILOperation.MLIL_VAR
                        ):
                            condition = self.function.get_ssa_var_definition(
                                edge.source[-1].ssa_form.condition.src
                            ).src
                        and_exprs.append(visitor.simplify(condition))

                    elif edge.type == BranchType.FalseBranch:
                        condition = edge.source[-1].condition
                        if (
                            condition.operation
                            == MediumLevelILOperation.MLIL_VAR
                        ):
                            condition = self.function.get_ssa_var_definition(
                                edge.source[-1].ssa_form.condition.src
                            ).src
                        and_exprs += Tactic("ctx-solver-simplify")(
                            Not(visitor.simplify(condition))
                        )[0]

                if and_exprs != []:
                    or_exprs.append(And(*and_exprs))

            if or_exprs:
                or_exprs = Tactic("ctx-solver-simplify")(Or(*or_exprs))[0]
                reaching_constraint = (
                    And(*or_exprs)
                    if len(or_exprs) > 1
                    else or_exprs[0]
                    if len(or_exprs)
                    else BoolVal(True)
                )
                self._reaching_constraints[(start, end)] = reaching_constraint