Пример #1
0
def get_unstratified_funs(assumes, asserts, macros):

    vu = il.VariableUniqifier()

    def vupair(p):
        return (vu(p[0]), p[1])

    assumes = map(vupair, assumes)
    asserts = map(vupair, asserts)
    macros = map(vupair, macros)
    strat_map = create_strat_map(assumes, asserts, macros)

    #    for f,g in macros:
    #        print 'macro: {}'.format(f)

    arcs = list(get_sort_arcs(assumes + macros, asserts, strat_map))

    sccs = get_sort_sccs(arcs)
    scc_map = dict((name, idx) for idx, scc in enumerate(sccs) for name in scc)
    scc_arcs = [[] for x in sccs]

    unstrat = set()
    for ds, rng, ast in arcs:
        if scc_map[ds] == scc_map[rng]:
            scc_arcs[scc_map[ds]].append(ast)

    for y in strat_map.values():
        find(y).variables.update(y.variables)

    fun_sccs = [(x, y) for x, y in zip(sccs, scc_arcs)
                if y and any(len(n.variables) > 0 for n in x)]

    arc_map = defaultdict(list)
    for x, y, z in arcs:
        arc_map[x].append(y)
    for scc in sccs:
        for n in scc:
            for m in arc_map[n]:
                m.variables.update(n.variables)

    # print 'sccs:'
    # for scc in sccs:
    #     print [str(x) for x in scc]


#    show_strat_map(strat_map)

    bad_interpreted = set()
    for x, y in strat_map.iteritems():
        y = find(y)
        if isinstance(x, tuple) and (il.is_interpreted_symbol(x[0])
                                     or x[0].name == '='):
            if any(v in universally_quantified_variables and v.sort == x[0].
                   sort.dom[x[1]] and il.has_infinite_interpretation(v.sort)
                   for v in y.variables):
                bad_interpreted.add(x[0])

    return fun_sccs, bad_interpreted
Пример #2
0
def get_unstratified_funs(assumes,asserts,macros):

    vu = il.VariableUniqifier()
    
    def vupair(p):
        return (vu(p[0]),p[1])

    assumes = map(vupair,assumes)
    asserts = map(vupair,asserts)
    macros = map(vupair,macros)
    strat_map = create_strat_map(assumes,asserts,macros)
    
#    for f,g in macros:
#        print 'macro: {}'.format(f)


    arcs = list(get_sort_arcs(assumes+macros,asserts,strat_map))

    sccs = get_sort_sccs(arcs)
    scc_map = dict((name,idx) for idx,scc in enumerate(sccs) for name in scc)
    scc_arcs = [[] for x in sccs]

    unstrat = set()
    for ds,rng,ast in arcs:
        if scc_map[ds] == scc_map[rng]:
            scc_arcs[scc_map[ds]].append(ast)
            
    for y in strat_map.values():
        find(y).variables.update(y.variables)

    fun_sccs = [(x,y) for x,y in zip(sccs,scc_arcs)
                if y and any(len(n.variables) > 0 for n in x)]

    arc_map = defaultdict(list)
    for x,y,z in arcs:
        arc_map[x].append(y)
    for scc in sccs:
        for n in scc:
            for m in arc_map[n]:
                m.variables.update(n.variables)
    
    # print 'sccs:'
    # for scc in sccs:
    #     print [str(x) for x in scc]


#    show_strat_map(strat_map)

    bad_interpreted = set()
    for x,y in strat_map.iteritems():
        y = find(y)
        if isinstance(x,tuple) and (il.is_interpreted_symbol(x[0]) or x[0].name == '='):
            if any(v in universally_quantified_variables and 
                   v.sort == x[0].sort.dom[x[1]] and
                   il.has_infinite_interpretation(v.sort) for v in y.variables):
                bad_interpreted.add(x[0])

    return fun_sccs, bad_interpreted
Пример #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)