def myeval(self, expr, pred=None): assert Miscs.is_expr(expr), expr if pred is None: return [trace.myeval(expr) for trace in self] else: return any(pred(trace.myeval(expr)) for trace in self)
def _infer(self, loc, template, uks, exprs, dtraces, inps): assert isinstance(loc, str) and loc, loc assert Miscs.is_expr(template), template assert isinstance(uks, list), uks assert isinstance(exprs, set) and exprs, exprs assert isinstance(dtraces, DTraces) and dtraces, dtraces assert isinstance(inps, Inps) and inps, inps cache = set() eqts = set() # results exprs = list(exprs) new_cexs = [] curIter = 0 while True: curIter += 1 mlog.debug("{}, iter {} infer using {} exprs".format( loc, curIter, len(exprs))) new_eqts = Miscs.solve_eqts(exprs, uks, template) unchecks = [eqt for eqt in new_eqts if eqt not in cache] if not unchecks: mlog.debug("{}: no new results -- break".format(loc)) break mlog.debug('{}: {} candidates:\n{}'.format( loc, len(new_eqts), '\n'.join(map(str, new_eqts)))) mlog.debug("{}: check {} unchecked ({} candidates)".format( loc, len(unchecks), len(new_eqts))) dinvs = DInvs.mk(loc, Invs(list(map(data.inv.eqt.Eqt, unchecks)))) cexs, dinvs = self.check(dinvs, None) if cexs: new_cexs.append(cexs) [eqts.add(inv) for inv in dinvs[loc] if not inv.is_disproved] [cache.add(inv.inv) for inv in dinvs[loc] if inv.stat is not None] if loc not in cexs: mlog.debug("{}: no disproved candidates -- break".format(loc)) break cexs = Traces.extract(cexs[loc]) cexs = cexs.padzeros(set(self.inv_decls[loc].names)) exprs_ = cexs.instantiate(template, None) mlog.debug("{}: {} new cex exprs".format(loc, len(exprs_))) exprs.extend(exprs_) return eqts, new_cexs
def get_postconds(cls, eqt): assert Miscs.is_expr(eqt), eqt assert eqt.operator() == operator.eq, eqt # tCtr symbols = [ s for s in Miscs.get_vars(eqt) if settings.CTR_VAR in str(s) ] if not symbols: return assert len(symbols) == 1, \ "should only have 1 tCtr symbol: {}, {}".format( symbols, settings.CTR_VAR) postconds = sage.all.solve(eqt, symbols[0]) return postconds if len(postconds) >= 1 else None
def instantiate(self, term, ntraces): assert Miscs.is_expr(term), term assert ntraces is None or ntraces >= 1, ntraces if ntraces is None: for t in self.mydicts: exprs = set(term.subs(t) for t in self.mydicts) else: ntracesExtra = ntraces * settings.TRACE_MULTIPLIER exprs = set() for t in self.mydicts: expr = term.subs(t) if expr not in exprs: exprs.add(expr) if len(exprs) >= ntracesExtra: break # instead of doing this, can find out the # 0's in traces # the more 0's , the better exprs = sorted(exprs, key=lambda expr: len(Miscs.get_vars(expr))) exprs = set(exprs[:ntraces]) return exprs
def __init__(self, poly): assert Miscs.is_expr(poly), poly super().__init__(poly)
def myeval(self, expr): assert Miscs.is_expr(expr), expr rs = expr.subs(self.mydict) return rs