def sort_infer(term): res = concretize_sorts(term) for x in chain(lu.used_variables(res),lu.used_constants(res)): if lg.contains_topsort(x.sort) or lg.is_polymorphic(x.sort): raise IvyError(None,"cannot infer sort of {} in {}".format(x,term)) # print "sort_infer: res = {!r}".format(res) return res
def sort_infer(term): res = concretize_sorts(term) for x in chain(lu.used_variables(res),lu.used_constants(res)): if lg.contains_topsort(x.sort) or lg.is_polymorphic(x.sort): raise IvyError(None,"cannot infer sort of {}".format(x)) # print "sort_infer: res = {!r}".format(res) return res
def is_segregated(fmla): fmla = drop_existentials(fmla) vs = lu.used_variables(fmla) apps = list(t for t in subterms(fmla) if isinstance(t,lg.Apply) and lu.used_variables(t)) byname = iu.partition(apps,lambda self:self.func.name) for name,terms in byname.iteritems(): pat = seg_var_pat(terms[0]) pvs = set(x for x in pat if x != None) if pvs != vs: reason_text = "{} is not segrated (not all variables appear)".format(name) return False for t in terms[1:]: if seg_var_pat(t) != pat: reason_text = "{} is not segrated (variable positions differ)".format(name) return False return True
def check_concretely_sorted(term,no_error=False,unsorted_var_names=()): for x in chain(lu.used_variables(term),lu.used_constants(term)): if lg.contains_topsort(x.sort) or lg.is_polymorphic(x.sort): if x.name not in unsorted_var_names: if no_error: raise lg.SortError raise IvyError(None,"cannot infer sort of {} in {}".format(x,repr(term)))
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 check_concretely_sorted(term, no_error=False, unsorted_var_names=()): for x in chain(lu.used_variables(term), lu.used_constants(term)): if lg.contains_topsort(x.sort) or lg.is_polymorphic(x.sort): if x.name not in unsorted_var_names: if no_error: raise lg.SortError raise IvyError( None, "cannot infer sort of {} in {}".format(x, repr(term)))
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]