def interp_from_unsat_core(clauses1, clauses2, core, interpreted):
    used_syms = used_symbols_clauses(core)
    vars = used_variables_clauses(core)
    if vars:
        #        print "interpolant would require skolem constants"
        return None
    core_consts = used_constants_clauses(core)
    clauses2_consts = used_constants_clauses(clauses2)
    #    print "interp_from_unsat_core core_consts = {}".format(map(str,core_consts))
    #    print "interp_from_unsat_core clauses2_consts = {}".format(map(str,clauses2_consts))
    renaming = dict()
    i = 0
    for v in core_consts:
        if v not in clauses2_consts or v.is_skolem(
        ):  # and v not in interpreted:
            renaming[v] = Variable('V' + str(i), Constant(v).get_sort())
            i += 1


#    print "interp_from_unsat_core core = {}".format(core)
#    print "interp_from_unsat_core renaming = {}".format(renaming)
    renamed_core = substitute_constants_clauses(core, renaming)
    #    print "interp_from_unsat_core renamed_core = {}".format(renamed_core)
    res = simplify_clauses(
        Clauses([Or(*[negate(c) for c in renamed_core.fmlas])]))
    #    print "interp_from_unsat_core res = {}".format(res)
    return res
示例#2
0
def clauses_model_to_clauses(clauses1,
                             ignore=None,
                             implied=None,
                             model=None,
                             numerals=False):
    """ Return a model of clauses1 or None. Model is represented by a
    clause set that uniquely characterizes it. The function "ignore", if
    provided, returns true for symbols that should be ignored in the
    model (tyipically skolems).
    """
    ##    print "clauses_model_to_clauses clauses1 = {}".format(clauses1)
    h = model_if_none(clauses1, implied, model)
    ignore = ignore if ignore != None else lambda x: False
    res = model_facts(h, ignore, clauses1)
    # if using numerals, replace the universe elements with them
    if numerals:
        m = dict((c.rep, ivy_logic.Constant(c.rep.rename(lambda s: str(i))))
                 for s in h.sorts()
                 for i, c in enumerate(h.sorted_sort_universe(s)))
    # else, existentially quantify the names of the universe elements
    else:
        m = dict((c.rep, ivy_logic.Constant(c.rep.prefix('__')))
                 for s in h.sorts() for c in h.sort_universe(s))
    res = substitute_constants_clauses(res, m)
    #    print "clauses_model_to_clauses res = {}".format(res)
    return res
示例#3
0
def clauses_model_to_diagram(clauses1,ignore = None, implied = None,model = None,axioms=None,weaken=True,numerals=True):
    """ Return a diagram of a model of clauses1 or None.  The function "ignore", if
    provided, returns true for symbols that should be ignored in the
    diagram.
    """
#    print "clauses_model_to_diagram clauses1 = {}".format(clauses1)
    if axioms == None:
        axioms = true_clauses()
    h = model_if_none(and_clauses(clauses1,axioms),implied,model)
    ignore = ignore if ignore != None else lambda x: False
    res = model_facts(h,(lambda x: False),clauses1,upclose=True) # why not pass axioms?
#    print "clauses_model_to_diagram res = {}".format(res)
    # find representative elements
    # find representatives of universe elements
    if numerals:
        reps = numeral_assign(res,h)
    else:
        reps = dict()
        for c in used_constants_clauses(clauses1):
    #        print "constant: {}".format(c)
            mc = get_model_constant(h.model,ivy_logic.Constant(c))
    #        print "value: {}".format(mc)
            if mc.rep not in reps or reps[mc.rep].rep.is_skolem() and not c.is_skolem():
                reps[mc.rep] = ivy_logic.Constant(c)
        for s in h.sorts():
            for e in h.sort_universe(s):
                if e.rep not in reps:
                    reps[e.rep] = e.rep.skolem()()
#    print "clauses_model_to_diagram reps = {}".format(reps)
    # filter out clauses using universe elements without reps
#    res = [cls for cls in res if all(c in reps for c in used_constants_clause(cls))]
    # replace universe elements with their reps
#    print "clauses_model_to_diagram res = {}".format(res)
    res = substitute_constants_clauses(res,reps)
    # filter defined skolems
    # this caused a bug in the leader example. the generated diagram did not satisfy clauses1
    res.fmlas = [f for f in res.fmlas if not any((x.is_skolem() and x in clauses1.defidx) for x in used_symbols_ast(f))]
#    print "clauses_model_to_diagram res = {}".format(res)
    uc = Clauses([[ivy_logic._eq_lit(ivy_logic.Variable('X',c.get_sort()),reps[c.rep])
                   for c in h.sort_universe(s)] for s in h.sorts()])
#    print "clauses_model_to_diagram uc = {}".format(uc)

    #    uc = true_clauses()
    if weaken:
        res = unsat_core(res,and_clauses(uc,axioms),clauses1) # implied not used here
#    print "clauses_model_to_diagram res = {}".format(res)

#    print "foo = {}".format(unsat_core(and_clauses(uc,axioms),true_clauses(),clauses1))

    # filter out non-rep skolems
    repset = set(c.rep for e,c in reps.iteritems())
#    print "clauses_model_to_diagram repset = {}".format(repset)
    ign = lambda x,ignore=ignore: (ignore(x) and not x in repset)
    res = Clauses([cl for cl in res.fmlas if not any(ign(c) for c in used_symbols_ast(cl))])
#    print "clauses_model_to_diagram res = {}".format(res)
    return res
示例#4
0
def clauses_model_to_clauses(clauses1,ignore = None, implied = None,model = None, numerals=False):
    """ Return a model of clauses1 or None. Model is represented by a
    clause set that uniquely characterizes it. The function "ignore", if
    provided, returns true for symbols that should be ignored in the
    model (tyipically skolems).
    """
##    print "clauses_model_to_clauses clauses1 = {}".format(clauses1)
    h = model_if_none(clauses1,implied,model)
    ignore = ignore if ignore != None else lambda x: False
    res = model_facts(h,ignore,clauses1)
    # if using numerals, replace the universe elements with them
    if numerals:
        m = dict((c.rep,ivy_logic.Constant(c.rep.rename(lambda s:str(i))))
             for s in h.sorts() for i,c in enumerate(h.sorted_sort_universe(s)))
    # else, existentially quantify the names of the universe elements
    else:
        m = dict((c.rep,ivy_logic.Constant(c.rep.prefix('__')))
                 for s in h.sorts() for c in h.sort_universe(s))
    res = substitute_constants_clauses(res,m)
#    print "clauses_model_to_clauses res = {}".format(res)
    return res
示例#5
0
文件: ivy_transrel.py 项目: odedp/ivy
def interp_from_unsat_core(clauses1,clauses2,core,interpreted):
    used_syms = used_symbols_clauses(core)
    vars = used_variables_clauses(core)
    if vars:
#        print "interpolant would require skolem constants"
        return None
    core_consts = used_constants_clauses(core)
    clauses2_consts = used_constants_clauses(clauses2)
#    print "interp_from_unsat_core core_consts = {}".format(map(str,core_consts))
#    print "interp_from_unsat_core clauses2_consts = {}".format(map(str,clauses2_consts))
    renaming = dict()
    i = 0
    for v in core_consts:
        if v not in clauses2_consts or v.is_skolem(): # and v not in interpreted:
            renaming[v] = Variable('V' + str(i),Constant(v).get_sort())
            i += 1
#    print "interp_from_unsat_core core = {}".format(core)
#    print "interp_from_unsat_core renaming = {}".format(renaming)
    renamed_core = substitute_constants_clauses(core,renaming)
#    print "interp_from_unsat_core renamed_core = {}".format(renamed_core)
    res = simplify_clauses(Clauses([Or(*[negate(c) for c in renamed_core.fmlas])]))
#    print "interp_from_unsat_core res = {}".format(res)
    return res
示例#6
0
def clauses_model_to_diagram(clauses1,
                             ignore=None,
                             implied=None,
                             model=None,
                             axioms=None,
                             weaken=True):
    """ Return a diagram of a model of clauses1 or None.  The function "ignore", if
    provided, returns true for symbols that should be ignored in the
    diagram.
    """
    print "clauses_model_to_diagram clauses1 = {}".format(clauses1)
    if axioms == None:
        axioms = true_clauses
    h = model_if_none(and_clauses(clauses1, axioms), implied, model)
    ignore = ignore if ignore != None else lambda x: False
    res = model_facts(h, (lambda x: False), clauses1,
                      upclose=True)  # why not pass axioms?
    print "clauses_model_to_diagram res = {}".format(res)
    # find representative elements
    # find representatives of universe elements
    reps = dict()
    for c in used_constants_clauses(clauses1):
        #        print "constant: {}".format(c)
        mc = get_model_constant(h.model, ivy_logic.Constant(c))
        #        print "value: {}".format(mc)
        if mc.rep not in reps or reps[
                mc.rep].rep.is_skolem() and not c.is_skolem():
            reps[mc.rep] = ivy_logic.Constant(c)
    for s in h.sorts():
        for e in h.sort_universe(s):
            if e.rep not in reps:
                reps[e.rep] = e.rep.skolem()()
    print "clauses_model_to_diagram reps = {}".format(reps)
    # filter out clauses using universe elements without reps
    #    res = [cls for cls in res if all(c in reps for c in used_constants_clause(cls))]
    # replace universe elements with their reps
    print "clauses_model_to_diagram res = {}".format(res)
    res = substitute_constants_clauses(res, reps)
    # filter defined skolems
    # this caused a bug in the leader example. the generated diagram did not satisfy clauses1
    res.fmlas = [
        f for f in res.fmlas
        if not any((x.is_skolem() and x in clauses1.defidx)
                   for x in used_symbols_ast(f))
    ]
    print "clauses_model_to_diagram res = {}".format(res)
    uc = Clauses([[
        ivy_logic._eq_lit(ivy_logic.Variable('X', c.get_sort()), reps[c.rep])
        for c in h.sort_universe(s)
    ] for s in h.sorts()])
    print "clauses_model_to_diagram uc = {}".format(uc)

    #    uc = true_clauses()
    if weaken:
        res = unsat_core(res, and_clauses(uc, axioms),
                         clauses1)  # implied not used here
    print "clauses_model_to_diagram res = {}".format(res)

    #    print "foo = {}".format(unsat_core(and_clauses(uc,axioms),true_clauses(),clauses1))

    # filter out non-rep skolems
    repset = set(c.rep for e, c in reps.iteritems())
    print "clauses_model_to_diagram repset = {}".format(repset)
    ign = lambda x, ignore=ignore: (ignore(x) and not x in repset)
    res = Clauses([
        cl for cl in res.fmlas
        if not any(ign(c) for c in used_symbols_ast(cl))
    ])
    print "clauses_model_to_diagram res = {}".format(res)
    return res