Пример #1
0
 def add_expr(self, e):
     """Add first-order formula."""
     # the bitblaster understands priming
     # the prefix parser treats primed bits as fresh
     # so suffice it for t to contain unprimed only
     t = self.vars
     s = bv.bitblast(e, t)
     u = sym_bdd.add_expr(s, self.bdd)
     return u
Пример #2
0
 def add_expr(self, e):
     """Add first-order formula."""
     # the bitblaster understands priming
     # the prefix parser treats primed bits as fresh
     # so suffice it for t to contain unprimed only
     t = self.vars
     s = bv.bitblast(e, t)
     u = sym_bdd.add_expr(s, self.bdd)
     return u
Пример #3
0
    def add_expr(self, e, with_ops=False):
        """Add first-order predicate.

        A predicate is a Boolean-valued formula.
        """
        assert stx.isinstance_str(e), e
        # optional because current implementation is slow
        if with_ops:
            defs = self.op
        else:
            defs = None
        s = bv.bitblast(e, vrs=self.vars, defs=defs)
        assert stx.isinstance_str(s), s  # was `e` a predicate ?
        return sym_bdd.add_expr(s, self.bdd)
Пример #4
0
    def add_expr(self, e, with_ops=False):
        """Add first-order predicate.

        A predicate is a Boolean-valued formula.
        """
        assert stx.isinstance_str(e), e
        # optional because current implementation is slow
        if with_ops:
            defs = self.op
        else:
            defs = None
        s = bv.bitblast(e, vrs=self.vars, defs=defs)
        assert stx.isinstance_str(s), s  # was `e` a predicate ?
        return sym_bdd.add_expr(s, self.bdd)
Пример #5
0
def _evaluate_result(result, memory):
    """Return integer, given a result and memory w/o variables.

    @type result: `list`
    @type memory: `list`
    """
    bdd = _bdd.BDD({'x': 0})
    n = len(memory) + 1
    mem = ' '.join(memory)
    bits = list()
    for bit in result:
        s = '$ {n} {mem} {bit}'.format(n=n, mem=mem, bit=bit)
        u = bddizer.add_expr(s, bdd)
        bits.append(u)
    bits = [b == 1 for b in bits]
    # print([int(b) for b in bits])
    j = bv.twos_complement_to_int(bits)
    return j
Пример #6
0
    def define(self, e):
        """Register operator definitions.

        The string `e` must contain definitions. Example:

        ```python
        e = '''
            a == x + y > 3
            b == z - x <= 0
            c == a /\ b
            '''
        ```

        In the future, this method may merge with `add_expr`.
        """
        assert stx.isinstance_str(e), e
        bv_defs = bv._parser.parse(e)
        defs = _parser.parse(e)
        for opdef, bv_opdef in zip(defs, bv_defs):
            assert opdef.operator == '==', opdef
            name_ast, expr_ast = opdef.operands
            _, bv_ast = bv_opdef.operands
            name = name_ast.value
            if name in self.vars:
                raise ValueError((
                    'Attempted to define operator "{name}", '
                    'but "{name}" already declared as variable: '
                    '{old}').format(
                        name=name, old=self.vars[name]))
            if name in self.op:
                raise ValueError((
                    'Attempted to redefine operator "{name}". '
                    'Previous definition as: "{old}"').format(
                        name=name, old=self.op[name]))
            s = bv_ast.flatten(
                t=self.vars, defs=self.op_bdd)
            assert stx.isinstance_str(s), s
            # sensitive point:
            #     operator expressions are stored before substitutions
            #     operator BDDs are stored after operator substitutions
            # operator definitions cannot change, so this should
            # not cause problems as currently arranged.
            self.op[name] = expr_ast.flatten()
            self.op_bdd[name] = sym_bdd.add_expr(s, self.bdd)
Пример #7
0
    def define(self, e):
        """Register operator definitions.

        The string `e` must contain definitions. Example:

        ```python
        e = '''
            a == x + y > 3
            b == z - x <= 0
            c == a /\ b
            '''
        ```

        In the future, this method may merge with `add_expr`.
        """
        assert stx.isinstance_str(e), e
        bv_defs = bv._parser.parse(e)
        defs = _parser.parse(e)
        for opdef, bv_opdef in zip(defs, bv_defs):
            assert opdef.operator == '==', opdef
            name_ast, expr_ast = opdef.operands
            _, bv_ast = bv_opdef.operands
            name = name_ast.value
            if name in self.vars:
                raise ValueError(('Attempted to define operator "{name}", '
                                  'but "{name}" already declared as variable: '
                                  '{old}').format(name=name,
                                                  old=self.vars[name]))
            if name in self.op:
                raise ValueError(('Attempted to redefine operator "{name}". '
                                  'Previous definition as: "{old}"').format(
                                      name=name, old=self.op[name]))
            s = bv_ast.flatten(t=self.vars, defs=self.op_bdd)
            assert stx.isinstance_str(s), s
            # sensitive point:
            #     operator expressions are stored before substitutions
            #     operator BDDs are stored after operator substitutions
            # operator definitions cannot change, so this should
            # not cause problems as currently arranged.
            self.op[name] = expr_ast.flatten()
            self.op_bdd[name] = sym_bdd.add_expr(s, self.bdd)
Пример #8
0
 def add_expr(self, e):
     """Add first-order formula."""
     t = self.vars
     s = bv.bitblast(e, t)
     u = sym_bdd.add_expr(s, self.bdd)
     return u
Пример #9
0
 def add_expr(self, e):
     """Add first-order formula."""
     t = self.vars
     s = bv.bitblast(e, t)
     u = sym_bdd.add_expr(s, self.bdd)
     return u
Пример #10
0
def _to_bdd(a, b, bdd):
    """For each element of `a`, append a `bdd` node to `b`."""
    for s in a:
        u = sym_bdd.add_expr(s, bdd)
        b.append(u)
Пример #11
0
def _to_bdd(a, b, bdd):
    """For each element of `a`, append a `bdd` node to `b`."""
    for s in a:
        u = sym_bdd.add_expr(s, bdd)
        b.append(u)
Пример #12
0
def _to_bdd(conjuncts, aut):
    u = Nodes.Operator('/\\', conjuncts)
    flat_expr = u.flatten(t=aut.vars)  # with defs ?
    return sym_bdd.add_expr(flat_expr, aut.bdd)