def testfunc(mod): # for testing/ debugging ns = logic.UninterpretedSort("node") ids = logic.UninterpretedSort('id') n1 = logic.Var('Node0', ns) n2 = logic.Var('Node1', ns) ineq = logic.Not(logic.Eq(n2, n1)) leadsorts = [ns, logic.BooleanSort()] leadfunc = logic.Const("leader", logic.FunctionSort(*leadsorts)) idsorts = [ns, logic.UninterpretedSort("id")] idfunc = logic.Const("idn", logic.FunctionSort(*idsorts)) lesorts = [ids, ids, logic.BooleanSort()] lefunc = logic.Const('le', logic.FunctionSort(*lesorts)) leadterm = logic.Apply(leadfunc, *[n1]) leterm = logic.Apply( lefunc, *[logic.Apply(idfunc, *[n1]), logic.Apply(idfunc, *[n2])]) fmla = logic.Not(logic.And(*[ineq, leadterm, leterm])) candInv, coincide = Clauses([fmla]), false_clauses() print "<plearn> CandInv", candInv for actname in sorted(mod.public_actions): spos, sneg = samplePos(mod, candInv, coincide, actname), sampleNeg(mod, candInv, actname) spos, sneg = Sample(spos, '1'), Sample(sneg, '0') if hasattr(spos, 'interp'): print "<plearn> + interp: ", spos.interp spos.displaySample() if hasattr(sneg, 'interp'): print "<plearn> - interp: ", sneg.interp sneg.displaySample() exit(0)
def emit_action(a): if isinstance(a, ia.AssignAction): vars = [ (x if isinstance(x, lg.Variable) else lg.Variable('$V' + str(idx))) for x, idx in enumerate(a.args[0].args) ] emit(' ' + a.args[0].rep.name + ' ::= ') rhs = a.args[1] if len(vars) != 0: cond = lg.And( *[lg.Eq(v, w) for v, w in zip(vars, a.args[0].args) if v != w]) rhs = lg.Ite(cond, rhs, lg.Apply(a.func, vars)) emit_expr(rhs) elif isinstance(a, ia.Sequence): emit('(') first = True for x in a.args: if not first: emit(';\n') emit_action(x) first = False emit(')') elif isinstance(a, ia.IfAction): emit('(PL.pterm.ite ') emit_expr(a.args[0]) emit_action(a.args[1]) if len(a.args) > 2: emit_action(a.args[1]) else: emit('PL.pterm.skip') else: raise iu.IvyError(a, 'action not supported yet')
def predToivyFmla(pred): if isinstance(pred, Function): sorts, terms = [], [] for arg in pred.args: term = predToivyFmla(arg) terms.append(term) sorts.append(term.sort) sorts.append(pred.ivysort()) func = logic.Const(pred.name, logic.FunctionSort(*sorts)) return logic.Apply(func, *terms) elif isinstance(pred, Var): # Var in feature set is universally quantified return logic.Var(pred.name, pred.ivysort()) elif isinstance(pred, Equality): t1, t2 = predToivyFmla(pred.args[0]), predToivyFmla(pred.args[1]) return logic.Eq(t1, t2) elif isinstance(pred, Const): assert False, "Const object are not supported yet" assert False, "Can't Convert {} to ivy formula".format(pred)
def Atom(rel, args): return Equals( *args) if rel == equals else lg.Apply(rel, *args) if args else rel