def request(self, args, value0): # generate pairs (valuation, cellmap) # XX we should pass valuation and cellmap around and let subexprs unify... XX #print self, "request", value0 for valuation0 in crossiter(range(sort.size) for sort in self.sorts): #print "%s%s"%(self, valuation0) # Note: we unroll the request generators using list constructor (otherwise crossiter wont work): pairss = [list(args[i].request(value)) for (i, value) in enumerate(valuation0)] for result in crossiter(pairss): #print self, "unify: %s"%str(result) # try and unify result into single valuation, cellmap valuation, cellmap = {}, {} for _v, _c in result: valuation = unify(valuation, _v) if valuation is None: #print self, "BAD valuation", self, '\n' break cellmap = unify(cellmap, _c) if cellmap is None: #print self, "BAD cellmap", self, '\n' break if valuation is not None and cellmap is not None: cellindex = self.get_cellindex(valuation0) #print self, "valuation=%s, cellmap=%s"%(valuation, cellmap) #print self, "valuation0=%s, cellindex=%d" % (valuation0, cellindex) if not cellindex in cellmap or cellmap[cellindex] == value0: cellmap[cellindex] = value0 #print self, "--->", valuation, cellmap yield valuation, cellmap
def validate(self, cells): for func in self.funcs: func.map = func.getmap(cells) for clause in self.clauses: valuations = crossiter([range(var.sort.size) for var in clause.vars]) for valuation in valuations: # print clause.code() #print clause.code(), cells, valuation accept = clause.fastaccept(cells, *valuation) if 0: _accept = clause.accepts(valuation) assert accept == _accept if not accept: indexs = clause.refutation(cells, *valuation) refutation = list((index, cells[index]) for index in indexs) refutation.sort() if self.debug: print clause print clause.code(), ":" print ' '.join('%s = %s' % (var.name, valuation[i]) for i, var in enumerate(clause.vars)) print cells print clause.refutation_code() print refutation for func in clause.funcs: _cells = [(cell if idx in indexs else None) for idx, cell in enumerate(cells)] print func.tablestr(_cells) print return refutation # print return None
def __init__(self, theory, sorts, funcs): self.theory = theory self.sorts = sorts self.funcs = funcs self.sizeiter = crossiter([s.sizes for s in sorts])
else: return repr(self) if __name__ == "__main__": import sys name = sys.argv[1] exec open(name) for arg in sys.argv[2:]: if "=" in arg: key, val = arg.split("=") val = int(val) globals()[key].sizes = [val] for sizes in crossiter([s.sizes for s in sorts]): print # set the size of each sort for idx, size in enumerate(sizes): sorts[idx].size = size print "%s.size = %s" % (sorts[idx], size) # print [s.size for s in sorts] interps = [Interpretation(func) for func in funcs] positions = MultiSearch(interps) count = 0 for position in positions: accept = True
def domain(self): items = list(crossiter(range(sort.size) for sort in self.sorts)) return items