def rename_vars_no_clash(fmlas1, fmlas2): """ Rename the free variables in formula list fmlas1 so they occur nowhere in fmlas2, avoiding capture """ uvs = lu.used_variables(*fmlas2) uvs = lu.union(uvs, lu.bound_variables(*fmlas1)) rn = iu.UniqueRenamer('', (v.name for v in uvs)) vs = lu.free_variables(*fmlas1) vmap = dict((v, Variable(rn(v.name), v.sort)) for v in vs) return [lu.substitute(f, vmap) for f in fmlas1]
def avoid_capture_problem(prob, match): """ Rename a match problem to avoid capture when applying a match""" mrv = match_rhs_vars(match) matchnames = set(x.name for x in match_rhs_vars(match)) used = set(matchnames) used.update(x.name for x in goal_defns(prob.schema)) used.update(v.name for v in goal_free(prob.schema) if il.is_variable(v)) rn = iu.UniqueRenamer(used=used) cmatch = dict((v, v.rename(rn)) for v in prob.freesyms if v.name in matchnames and v not in match) rename_problem(cmatch, prob)
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
def fresh_label(goals): rn = iu.UniqueRenamer(used=[x.name for x in goals]) return ia.Atom(rn(), [])
def __init__(self): self.rn = iu.UniqueRenamer()
def __init__(self,method_name,modifies,outparams): self.rn = iu.UniqueRenamer(method_name + ':tmp',{}) self.local_renamer = iu.UniqueRenamer('loc:' + method_name + ':',{}) self.modifies = modifies self.outparams = outparams self.name = 'method_context'