Beispiel #1
0
def get_sort_arcs(assumes, asserts):
    for sym in il.all_symbols():
        name = sym.name
        sort = sym.sort
        rng = sort.rng
        if il.is_uninterpreted_sort(rng):
            for ds in sort.dom:
                if il.is_uninterpreted_sort(ds):
                    yield (ds, rng, sym)

    for fmla, ast in assumes + asserts:
        for a in get_qa_arcs(fmla, ast, True, list(lu.free_variables(fmla))):
            yield a

    for fmla, ast in asserts:
        for a in get_qa_arcs(fmla, ast, False, []):
            yield a
Beispiel #2
0
def get_sort_arcs(assumes, asserts):
    for sym in il.all_symbols():
        name = sym.name
        sort = sym.sort
        rng = sort.rng
        if il.is_uninterpreted_sort(rng):
            for ds in sort.dom:
                if il.is_uninterpreted_sort(ds):
                    yield (ds, rng, sym)

    for fmla, ast in assumes + asserts:
        for a in get_qa_arcs(fmla, ast, True, list(lu.free_variables(fmla))):
            yield a

    for fmla, ast in asserts:
        for a in get_qa_arcs(fmla, ast, False, []):
            yield a
Beispiel #3
0
def create_strat_map(assumes, asserts, macros):
    """ Given a list of assumptions, assertions and macros, compute
    the stratification graph. The difference between assumes and
    asserts is that the free variables in assumes are treated as
    universally quantified, while the asserts are treated as
    negated.

    Each argument is a list of pairs `(fmla,ast)` where `fmla` is the
    formula and `ast` an ast giving the origin of the formula.

    """

    global universally_quantified_variables
    global strat_map
    global arcs

    # Gather all the formulas in the VC.

    all_fmlas = [(il.close_formula(x), y) for x, y in assumes]
    all_fmlas.extend((il.Not(x), y) for x, y in asserts)
    all_fmlas.extend(macros)

    # Get the universally quantified variables. The free variables of
    # asserts and macros won't count as universal. We keep track of the
    # line numbers of these variables for error messages.

    universally_quantified_variables = dict()
    for fmla, lf in all_fmlas:
        for v in il.universal_variables([fmla]):
            if (il.is_uninterpreted_sort(v.sort)
                    or il.has_infinite_interpretation(v.sort)):
                universally_quantified_variables[v] = lf

    # print 'universally_quantified_variables : {}'.format([str(v) for v in universally_quantified_variables])

    # Create an empty graph.

    strat_map = defaultdict(UFNode)
    arcs = []

    # Handle macros, as described above.

    create_macro_maps(assumes, asserts, macros)

    # Simulate the Skolem functions that would be generated by AE alternations.

    for fmla, ast in all_fmlas:
        make_skolems(fmla, ast, True, [])

    # Construct the stratification graph by calling `map_fmla` on all
    # of the formulas in the VC. We don't include the macro definitions
    # here, because these are 'inlined' by `map_fmla`.

    for pair in assumes + asserts:
        map_fmla(pair[1].lineno, pair[0], 0)
    def get_selected_conjecture(self):
        """
        Return a positive universal conjecture based on the selected facts.

        The result is a Clauses object
        """
        from logic_util import used_constants, free_variables, substitute
        from ivy_logic_utils import negate, Clauses, simplify_clauses

        facts = self.get_active_facts()
        assert len(free_variables(
            *
            facts)) == 0, "conjecture would contain existential quantifiers..."
        sig_symbols = frozenset(il.sig.symbols.values())
        facts_consts = used_constants(*facts)
        subs = {}
        rn = iu.VariableGenerator()
        for c in sorted(facts_consts, key=lambda c: c.name):
            if c.is_numeral() and il.is_uninterpreted_sort(c.sort):
                #                prefix = str(c.sort)[:2].upper() + c.name
                subs[c] = lg.Var(rn(c.sort.name), c.sort)

        literals = [negate(substitute(f, subs)) for f in facts]
        result = Clauses([lg.Or(*literals)])
        result = simplify_clauses(result)

        # now rename again to get a pretty clause, since some
        # variables have been eliminated by simplify_clauses
        # assert len(result.fmlas) == 1
        # clause = result.fmlas[0]
        # subs = {}
        # count = defaultdict(int)
        # for c in free_variables(clause):
        #     prefix = str(c.sort)[0].upper()
        #     count[prefix] += 1
        #     subs[c] = lg.Var(prefix + str(count[prefix]), c.sort)
        # result = Clauses([substitute(clause, subs)])

        # change to negation of conjunction rather than disjunction
        assert len(result.fmlas) == 1
        if type(result.fmlas[0]) is lg.Or:
            result = Clauses(
                [lg.Not(lg.And(*(negate(lit) for lit in result.fmlas[0])))])

        return result
Beispiel #5
0
    def get_selected_conjecture(self):
        """
        Return a positive universal conjecture based on the selected facts.

        The result is a Clauses object
        """
        from logic_util import used_constants, free_variables, substitute
        from ivy_logic_utils import negate, Clauses, simplify_clauses

        facts = self.get_active_facts()
        assert len(free_variables(*facts)) == 0, "conjecture would contain existential quantifiers..."
        sig_symbols = frozenset(il.sig.symbols.values())
        facts_consts = used_constants(*facts)
        subs = {}
        rn = iu.UniqueRenamer()
        for c in sorted(facts_consts, key=lambda c: c.name):
            if c.is_numeral() and il.is_uninterpreted_sort(c.sort):
                prefix = str(c.sort)[:2].upper() + str(c)
                subs[c] = lg.Var(rn(prefix), c.sort)

        literals = [negate(substitute(f, subs)) for f in facts]
        result = Clauses([lg.Or(*literals)])
        result = simplify_clauses(result)

        # now rename again to get a pretty clause, since some
        # variables have been eliminated by simplify_clauses
        # assert len(result.fmlas) == 1
        # clause = result.fmlas[0]
        # subs = {}
        # count = defaultdict(int)
        # for c in free_variables(clause):
        #     prefix = str(c.sort)[0].upper()
        #     count[prefix] += 1
        #     subs[c] = lg.Var(prefix + str(count[prefix]), c.sort)
        # result = Clauses([substitute(clause, subs)])

        # change to negation of conjunction rather than disjunction
        assert len(result.fmlas) == 1
        if type(result.fmlas[0]) is lg.Or:
            result = Clauses([lg.Not(lg.And(*(negate(lit) for lit in result.fmlas[0])))])

        return result