Exemple #1
0
 def __init__(self, environment, logic=None):
     IdentityDagWalker.__init__(self, env=environment)
     QuantifierEliminator.__init__(self)
     self.logic = logic
     self.mgr = self.env.formula_manager
     self.enum_domain = {}
     self.instances_cache = {}
Exemple #2
0
    def normalize(self, formula):
        """ Returns the formula normalized to the current Formula Manager.

        This method is useful to contextualize a formula coming from another
        formula manager.
        E.g., f_a is defined with the FormulaManager a, and we want to obtain f_b
              that is the formula f_a expressed on the FormulaManager b :
               f_b = b.normalize(f_a)
        """
        # TODO: name clash with formula normalization
        # TODO: Move this out of the manager and into ad-hoc function
        normalizer = IdentityDagWalker(self.env)
        return normalizer.walk(formula)
Exemple #3
0
    def normalize(self, formula):
        """ Returns the formula normalized to the current Formula Manager.

        This method is useful to contextualize a formula coming from another
        formula manager.
        E.g., f_a is defined with the FormulaManager a, and we want to obtain f_b
              that is the formula f_a expressed on the FormulaManager b :
               f_b = b.normalize(f_a)
        """
        # TODO: name clash with formula normalization
        # TODO: Move this out of the manager and into ad-hoc function
        normalizer = IdentityDagWalker(self.env)
        return normalizer.walk(formula)
Exemple #4
0
        def __init__(self, environment, logic=None, algorithm='fm'):
            """Algorithm can be either 'fm' (for Fourier-Motzkin) or 'lw' (for
               Loos-Weisspfenning)"""

            IdentityDagWalker.__init__(self, env=environment)

            self.set_function(self.walk_identity, op.SYMBOL, op.REAL_CONSTANT,
                              op.BOOL_CONSTANT, op.INT_CONSTANT)

            self.logic = logic

            assert algorithm in ['fm', 'lw']
            self.algorithm = algorithm

            self.msat_config = mathsat.msat_create_default_config("QF_LRA")
            self.msat_env = mathsat.msat_create_env(self.msat_config)
            self.converter = MSatConverter(environment, self.msat_env)
            self._destroyed = False
Exemple #5
0
        def __init__(self, environment, logic=None, algorithm='fm'):
            """Algorithm can be either 'fm' (for Fourier-Motzkin) or 'lw' (for
               Loos-Weisspfenning)"""

            IdentityDagWalker.__init__(self, env=environment)

            self.set_function(self.walk_identity, op.SYMBOL, op.REAL_CONSTANT,
                              op.BOOL_CONSTANT, op.INT_CONSTANT)

            self.logic = logic

            assert algorithm in ['fm', 'lw']
            self.algorithm = algorithm

            self.msat_config = mathsat.msat_create_default_config("QF_LRA")
            self.msat_env = mathsat.msat_create_env(self.msat_config)
            self.converter = MSatConverter(environment, self.msat_env)
            self._destroyed = False
Exemple #6
0
        def __init__(self, environment, logic=None, algorithm='fm'):
            """Initialize the Quantifier Eliminator using 'fm' or 'lw'.

            fm: Fourier-Motzkin (default)
            lw: Loos-Weisspfenning
            """
            if algorithm not in ['fm', 'lw']:
                raise ValueError("Algorithm can be either 'fm' or 'lw'")
            QuantifierEliminator.__init__(self)
            IdentityDagWalker.__init__(self, env=environment)
            self.msat_config = mathsat.msat_create_default_config("QF_LRA")
            self.msat_env = MSatEnv(self.msat_config)
            mathsat.msat_destroy_config(self.msat_config)

            self.set_function(self.walk_identity, op.SYMBOL, op.REAL_CONSTANT,
                              op.BOOL_CONSTANT, op.INT_CONSTANT)
            self.logic = logic
            self.algorithm = algorithm
            self.converter = MSatConverter(environment, self.msat_env)
Exemple #7
0
    def walk_function(self, formula, args, **kwargs):
        from pysmt.typing import FunctionType
        # Separate arguments
        bool_args = []
        other_args = []
        for a in args:
            if self.get_type(a).is_bool_type():
                bool_args.append(a)
            else:
                other_args.append(a)

        if len(bool_args) == 0:
            # If no Bool Args, return as-is
            return IdentityDagWalker.walk_function(self, formula, args, **kwargs)

        # Build new function type
        rtype = formula.function_name().symbol_type().return_type
        ptype = [self.get_type(a) for a in other_args]
        if len(ptype) == 0:
            ftype = rtype
        else:
            ftype = FunctionType(rtype, ptype)

        # Base-case
        stack = []
        for i in xrange(2**len(bool_args)):
            fname = self.mgr.Symbol("%s#%i" % (formula.function_name(),i), ftype)
            if len(ptype) == 0:
                stack.append(fname)
            else:
                stack.append(self.mgr.Function(fname, tuple(other_args)))

        # Recursive case
        for b in bool_args:
            tmp = []
            while len(stack) > 0:
                lhs = stack.pop()
                rhs = stack.pop()
                # Simplify branches, if b is a constant
                if b.is_true():
                    tmp.append(lhs)
                elif b.is_false():
                    tmp.append(rhs)
                else:
                    ite = self.mgr.Ite(b, lhs, rhs)
                    tmp.append(ite)
            stack = tmp
        res = stack[0]
        return res
Exemple #8
0
 def __init__(self, env=None):
     IdentityDagWalker.__init__(self, env=env)
     self.type_normalize = self.env.type_manager.normalize
Exemple #9
0
 def __init__(self, environment, logic=None):
     IdentityDagWalker.__init__(self, env=environment)
     QuantifierEliminator.__init__(self)
     self.logic = logic
Exemple #10
0
 def __init__(self, environment):
     IdentityDagWalker.__init__(self, environment)
     self.get_type = self.env.stc.get_type
     self.mgr = self.env.formula_manager
Exemple #11
0
 def __init__(self, env=None):
     IdentityDagWalker.__init__(self, env=env)
     self.type_normalize = self.env.type_manager.normalize