def property_tactic(self, decls, proof): cut = proof.args[0] goal = decls[0] subgoal = goal_subst(goal, cut, cut.lineno) lhs = proof.args[1] if not isinstance(lhs, ia.NoneAST): fmla = il.drop_universals(cut.formula) if not il.is_exists(fmla) or len(fmla.variables) != 1: raise IvyError(proof, 'property is not existential') evar = list(fmla.variables)[0] rng = evar.sort vmap = dict((x.name, x) for x in lu.variables_ast(fmla)) used = set() args = lhs.args targs = [] for a in args: if a.name in used: raise IvyError(lhs, 'repeat parameter: {}'.format(a.name)) used.add(a.name) if a.name in vmap: v = vmap[a.name] targs.append(v) if not (il.is_topsort(a.sort) or a.sort != v.sort): raise IvyError(lhs, 'bad sort for {}'.format(a.name)) else: if il.is_topsort(a.sort): raise IvyError( lhs, 'cannot infer sort for {}'.format(a.name)) targs.append(a) for x in vmap: if x not in used: raise IvyError( lhs, '{} must be a parameter of {}'.format(x, lhs.rep)) dom = [x.sort for x in targs] sym = il.Symbol(lhs.rep, il.FuncConstSort(*(dom + [rng]))) if sym in self.stale or sym in goal_defns(goal): raise iu.IvyError(lhs, '{} is not fresh'.format(sym)) term = sym(*targs) if targs else sym fmla = lu.substitute_ast(fmla.body, {evar.name: term}) cut = clone_goal(cut, [], fmla) goal = goal_add_prem(goal, ia.ConstantDecl(sym), goal.lineno) return [goal_add_prem(goal, cut, cut.lineno)] + decls[1:] + [subgoal]
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)