Esempio n. 1
0
def compile_match(proof, prob, decl):
    """ Compiles match in a proof. Only the symbols in
    freesyms may be used in the match."""

    schema = prob.schema
    matches = compile_match_list(proof, schema, decl)
    matches = [
        compile_one_match(m.lhs(), m.rhs(), prob.freesyms, prob.constants)
        for m in matches
    ]
    res = merge_matches(*matches)
    return res

    freesyms = prob.freesyms
    res = dict()
    for m in proof.match():
        if il.is_app(m.lhs()):
            res[m.defines()] = il.Lambda(m.lhs().args, m.rhs())
        else:
            res[m.lhs()] = m.rhs()
    # iu.dbg('freesyms')
    # freesyms = apply_match_freesyms(res,freesyms)
    # iu.dbg('freesyms')
    # for sym in res:
    #     if sym not in freesyms:
    #         raise ProofError(proof,'{} is not a premise of schema {}'.format(repr(sym),schemaname))
    return res
Esempio n. 2
0
def extract_terms(inst,terms):
    """ Returns a lambda term t such that t(terms) = inst and
    terms do not occur in t. vars is a list of distinct variables
    of same types as terms that are not free in inst. """

    vars = make_distinct_vars([t.sort for t in terms], inst)
    def rec(inst):
        for term,var in zip(terms,vars):
            if term == inst:
                return var
        return inst.clone(map(rec,inst.args))
    return il.Lambda(vars,rec(inst))
Esempio n. 3
0
def compile_match(proof, prob, schemaname):
    """ Compiles match in a proof. Only the symbols in
    freesyms may be used in the match."""

    match = proof.match()
    freesyms = prob.freesyms
    res = dict()
    for m in proof.match():
        if il.is_app(m.lhs()):
            res[m.defines()] = il.Lambda(m.lhs().args, m.rhs())
        else:
            res[m.lhs()] = m.rhs()
    # iu.dbg('freesyms')
    # freesyms = apply_match_freesyms(res,freesyms)
    # iu.dbg('freesyms')
    # for sym in res:
    #     if sym not in freesyms:
    #         raise ProofError(proof,'{} is not a premise of schema {}'.format(repr(sym),schemaname))
    return res
Esempio n. 4
0
def parameterize_schema(sorts,schema):
    """ Add initial parameters to all the free symbols in a schema.

    Takes a list of sorts and an ia.SchemaBody. """

    vars = make_distinct_vars(sorts,goal_conc(schema))
    match = {}
    prems = []
    for prem in goal_prems(schema):
        if isinstance(prem,ia.ConstantDecl):
            sym = prem.args[0]
            vs2 = [il.Variable('X'+str(i),y) for i,y in enumerate(sym.sort.dom)]
            sym2 = sym.resort(il.FuncConstSort(*(sorts + list(sym.sort.dom) + [sym.sort.rng])))
            match[sym] = il.Lambda(vs2,sym2(*(vars+vs2)))
            prems.append(ia.ConstantDecl(sym2))
        else:
            prems.append(prem)
    conc = apply_match(match,goal_conc(schema))
    return clone_goal(schema,prems,conc)