def subactions(self) : if isinstance(self.args[0],ivy_ast.Some): ps = list(self.args[0].params()) fmla = self.args[0].fmla() vs = [Variable('V{}'.format(idx),x.sort) for idx,x in enumerate(ps)] subst = dict((c,v) for c,v in zip(ps,vs)) sfmla = substitute_constants_ast(fmla,subst) if isinstance(self.args[0],ivy_ast.SomeMinMax): idx = self.args[0].index() if idx not in ps: ltsym = Symbol('<',RelationSort([idx.sort,idx.sort])) operator = lambda x,y: Not(ltsym(x,y)) ivar = substitute_constants_ast(idx,subst) comp = operator(ivar,idx) if isinstance(self.args[0],ivy_ast.SomeMin) else operator(idx,ivar) fmla = And(fmla,Implies(sfmla,comp)) else : leqsym = Symbol('<=',RelationSort([idx.sort,idx.sort])) operator = lambda x,y: And(leqsym(x,y),Not(Equals(x,y))) ivar = next(v for p,v in zip(ps,vs) if p == idx) comp = operator(ivar,idx) if isinstance(self.args[0],ivy_ast.SomeMin) else operator(idx,ivar) fmla = And(fmla,Not(And(sfmla,comp))) if_part = LocalAction(*(ps+[Sequence(AssumeAction(fmla),self.args[1])])) else_action = self.args[2] if len(self.args) >= 3 else Sequence() else_part = Sequence(AssumeAction(Not(sfmla)),else_action) # iu.dbg('if_part') # iu.dbg('else_part') else: if not is_boolean(self.args[0]): raise IvyError(self,'condition must be boolean') if_part = Sequence(AssumeAction(self.args[0]),self.args[1]) else_action = self.args[2] if len(self.args) >= 3 else Sequence() else_part = Sequence(AssumeAction(dual_formula(self.args[0])),else_action) return if_part,else_part
def apply_mixin(decl, action1, action2): assert hasattr(action1, 'lineno') assert hasattr(action2, 'lineno') name1, name2 = (a.relname for a in decl.args) if len(action1.formal_params) != len(action2.formal_params): raise IvyError( decl, "mixin {} has wrong number of input parameters for {}".format( name1, name2)) if len(action1.formal_returns) != len(action2.formal_returns): raise IvyError( decl, "mixin {} has wrong number of output parameters for {}".format( name1, name2)) formals1, formals2 = (a.formal_params + a.formal_returns for a in (action1, action2)) for x, y in zip(formals1, formals2): if x.sort != y.sort: raise IvyError( decl, "parameter {} of mixin {} has wrong sort".format( str(x), name1)) subst = dict(zip(formals1, formals2)) action1_renamed = substitute_constants_ast(action1, subst) # print "action1_renamed: {}".format(action1_renamed) if isinstance(decl, MixinAfterDef): res = concat_actions(action2, action1_renamed) else: res = concat_actions(action1_renamed, action2) res.lineno = action1.lineno res.formal_params = action2.formal_params res.formal_returns = action2.formal_returns return res
def apply_actuals(self, domain, pvars, v): actual_params = self.args[0].args actual_returns = self.args[1:] # formal_params = [s.prefix('_') for s in v.formal_params] # rename to prevent capture # formal_returns = [s.prefix('_') for s in v.formal_returns] # rename to prevent capture # subst = dict(zip(v.formal_params+v.formal_returns, formal_params+formal_returns)) vocab = list(symbols_asts(actual_params + actual_returns)) subst = distinct_obj_renaming(v.formal_params + v.formal_returns, vocab) # print "apply_actuals: subst: {}".format(subst) formal_params = [subst[s] for s in v.formal_params] # rename to prevent capture formal_returns = [subst[s] for s in v.formal_returns] # rename to prevent capture v = substitute_constants_ast(v, subst) # print "formal_params: {}".format(formal_params) # print "formal_returns: {}".format(formal_returns) # print "substituted called action: {}".format(v) if len(formal_params) != len(actual_params): raise IvyError(self, "wrong number of input parameters") if len(formal_returns) != len(actual_returns): raise IvyError(self, "wrong number of output parameters") for x, y in zip(formal_params, actual_params): if x.sort != y.sort: raise IvyError(self, "value for input parameter {} has wrong sort".format(x)) for x, y in zip(formal_returns, actual_returns): if x.sort != y.sort: raise IvyError(self, "value for output parameter {} has wrong sort".format(x)) input_asgns = [AssignAction(x, y) for x, y in zip(formal_params, actual_params)] output_asgns = [AssignAction(y, x) for x, y in zip(formal_returns, actual_returns)] res = Sequence(*(input_asgns + [v] + output_asgns)) # print "with parameter assigns: {}".format(res) res = res.int_update(domain, pvars) # print "call update: {}".format(res) res = hide(formal_params + formal_returns, res) # print "after hide: {}".format(res) return res
def get_cond(self): if isinstance(self.args[0],ivy_ast.Some): ps = list(self.args[0].params()) fmla = self.args[0].fmla() vs = [Variable('V{}'.format(idx),x.sort) for idx,x in enumerate(ps)] subst = dict((c,v) for c,v in zip(ps,vs)) sfmla = substitute_constants_ast(fmla,subst) return Exists(vs,sfmla) else: return self.args[0]
def instantiate_non_epr(non_epr,ground_terms): theory = [] if ground_terms != None: matched = set() for term in ground_terms: if term.rep in non_epr and term not in matched: ldf,cnst = non_epr[term.rep] subst = dict((v,t) for v,t in zip(ldf.formula.args[0].args,term.args) if not isinstance(v,il.Variable)) inst = lu.substitute_constants_ast(cnst,subst) theory.append(inst) # iu.dbg('inst') matched.add(term) return lu.Clauses(theory)
def apply_actuals(self, domain, pvars, v): assert hasattr(v, 'formal_params'), v actual_params = self.args[0].args actual_returns = self.args[1:] # formal_params = [s.prefix('_') for s in v.formal_params] # rename to prevent capture # formal_returns = [s.prefix('_') for s in v.formal_returns] # rename to prevent capture # subst = dict(zip(v.formal_params+v.formal_returns, formal_params+formal_returns)) vocab = list(symbols_asts(actual_params + actual_returns)) subst = distinct_obj_renaming(v.formal_params + v.formal_returns, vocab) for s, t in list(subst.iteritems()): subst[old(s)] = old(t) # print "apply_actuals: subst: {}".format(subst) formal_params = [subst[s] for s in v.formal_params] # rename to prevent capture formal_returns = [subst[s] for s in v.formal_returns ] # rename to prevent capture v = substitute_constants_ast(v, subst) # print "formal_params: {}".format(formal_params) # print "formal_returns: {}".format(formal_returns) # print "substituted called action: {}".format(v) if len(formal_params) != len(actual_params): raise IvyError(self, "wrong number of input parameters") if len(formal_returns) != len(actual_returns): raise IvyError(self, "wrong number of output parameters") for x, y in zip(formal_params, actual_params): if x.sort != y.sort and not domain.is_variant(x.sort, y.sort): raise IvyError( self, "value for input parameter {} has wrong sort".format(x)) for x, y in zip(formal_returns, actual_returns): if x.sort != y.sort and not domain.is_variant(y.sort, x.sort): raise IvyError( self, "value for output parameter {} has wrong sort".format(x)) input_asgns = [ AssignAction(x, y) for x, y in zip(formal_params, actual_params) ] output_asgns = [ AssignAction(y, x) for x, y in zip(formal_returns, actual_returns) ] res = Sequence(*(input_asgns + [BindOldsAction(v)] + output_asgns)) res = res.int_update(domain, pvars) # print "call update: {}".format(res) res = hide(formal_params + formal_returns, res) # print "after hide: {}".format(res) return res
def mixin_before(decl,action1,action2): name1,name2 = (a.relname for a in decl.args) if len(action1.formal_params) != len(action2.formal_params): raise IvyError(decl,"mixin {} has wrong number of input parameters for {}".format(name1,name2)) if len(action1.formal_returns) != 0: raise IvyError(decl,"mixin {} must not have return parameters") for x,y in zip(action1.formal_params,action2.formal_params): if x.sort != y.sort: raise IvyError(decl,"parameter {} of mixin {} has wrong sort".format(str(x),name1)) subst = dict(zip(action1.formal_params,action2.formal_params)) action1_renamed = substitute_constants_ast(action1,subst) # print "action1_renamed: {}".format(action1_renamed) res = Sequence(action1_renamed,action2) res.formal_params = action2.formal_params res.formal_returns = action2.formal_returns return res
def mixin_before(decl, action1, action2): name1, name2 = (a.relname for a in decl.args) if len(action1.formal_params) != len(action2.formal_params): raise IvyError( decl, "mixin {} has wrong number of input parameters for {}".format( name1, name2)) if len(action1.formal_returns) != 0: raise IvyError(decl, "mixin {} must not have return parameters") for x, y in zip(action1.formal_params, action2.formal_params): if x.sort != y.sort: raise IvyError( decl, "parameter {} of mixin {} has wrong sort".format( str(x), name1)) subst = dict(zip(action1.formal_params, action2.formal_params)) action1_renamed = substitute_constants_ast(action1, subst) # print "action1_renamed: {}".format(action1_renamed) res = Sequence(action1_renamed, action2) res.formal_params = action2.formal_params res.formal_returns = action2.formal_returns return res
def apply_mixin(decl,action1,action2): assert hasattr(action1,'lineno') assert hasattr(action2,'lineno') name1,name2 = (a.relname for a in decl.args) if len(action1.formal_params) != len(action2.formal_params): raise IvyError(decl,"mixin {} has wrong number of input parameters for {}".format(name1,name2)) if len(action1.formal_returns) != len(action2.formal_returns): raise IvyError(decl,"mixin {} has wrong number of output parameters for {}".format(name1,name2)) formals1,formals2 = (a.formal_params + a.formal_returns for a in (action1,action2)) for x,y in zip(formals1,formals2): if x.sort != y.sort: raise IvyError(decl,"parameter {} of mixin {} has wrong sort".format(str(x),name1)) subst = dict(zip(formals1,formals2)) action1_renamed = substitute_constants_ast(action1,subst) # print "action1_renamed: {}".format(action1_renamed) if isinstance(decl,MixinAfterDef): res = Sequence(action2,action1_renamed) else: res = Sequence(action1_renamed,action2) res.lineno = action1.lineno res.formal_params = action2.formal_params res.formal_returns = action2.formal_returns return res
def loop_action(action, mod): subst = dict((p, ivy_logic.Variable('Y' + p.name, p.sort)) for p in action.formal_params) action = lu.substitute_constants_ast(action, subst) ia.type_check_action(action, mod) # make sure all is legal return action