def join(s1, s2, relations, op): u1, c1, p1 = s1 u2, c2, p2 = s2 c1 = and_clauses(c1, diff_frame(u1, u2, relations, op)) c2 = and_clauses(c2, diff_frame(u2, u1, relations, op)) u = updated_join(u1, u2) c = or_clauses(c1, c2) p = or_clauses(p1, p2) return (u, c, p)
def join(s1,s2,relations,op): u1,c1,p1 = s1 u2,c2,p2 = s2 c1 = and_clauses(c1,diff_frame(u1,u2,relations,op)) c2 = and_clauses(c2,diff_frame(u2,u1,relations,op)) u = updated_join(u1,u2) c = or_clauses(c1,c2) p = or_clauses(p1,p2) return (u,c,p)
def join(s1, s2, op, axioms): u1, c1, p1 = s1 u2, c2, p2 = s2 df12 = diff_frame(u1, u2, op, axioms) df21 = diff_frame(u2, u1, op, axioms) c1 = and_clauses(c1, df12) c2 = and_clauses(c2, df21) p1 = and_clauses(p1, df12) p2 = and_clauses(p2, df21) u = updated_join(u1, u2) c = or_clauses(c1, c2) p = or_clauses(p1, p2) return (u, c, p)
def join(s1,s2): assert isinstance(s1,SemValue) and type(s1) is type(s2) op = s1.op u1,c1,p1 = s1.comps u2,c2,p2 = s2.comps df12 = diff_frame(u1,u2,op) df21 = diff_frame(u2,u1,op) c1 = and_clauses(c1,df12) c2 = and_clauses(c2,df21) p1 = and_clauses(p1,df12) p2 = and_clauses(p2,df21) u = updated_join(u1,u2) c = or_clauses(c1,c2) p = or_clauses(p1,p2) return type(s1)(u,c,p)
def join(s1, s2): assert isinstance(s1, SemValue) and type(s1) is type(s2) op = s1.op u1, c1, p1 = s1.comps u2, c2, p2 = s2.comps df12 = diff_frame(u1, u2, op) df21 = diff_frame(u2, u1, op) c1 = and_clauses(c1, df12) c2 = and_clauses(c2, df21) p1 = and_clauses(p1, df12) p2 = and_clauses(p2, df21) u = updated_join(u1, u2) c = or_clauses(c1, c2) p = or_clauses(p1, p2) return type(s1)(u, c, p)
def compose_updates(update1, axioms, update2): updated1, clauses1, pre1 = update1 updated2, clauses2, pre2 = update2 clauses2 = rename_distinct(clauses2, clauses1) pre2 = rename_distinct(pre2, clauses1) # print "clauses2 = {}".format(clauses2) us1 = set(updated1) us2 = set(updated2) mid = us1.intersection(us2) mid_ax = clauses_using_symbols(mid, axioms) used = used_symbols_clauses(and_clauses(clauses1, clauses2)) rn = UniqueRenamer('__m_', used) map1 = dict() map2 = dict() for v in updated1: map2[v] = new(v) for mv in mid: mvf = rename(mv, rn) map1[new(mv)] = mvf map2[mv] = mvf clauses1 = rename_clauses(clauses1, map1) new_clauses = and_clauses( clauses1, rename_clauses(and_clauses(clauses2, mid_ax), map2)) new_updated = list(us1.union(us2)) # print "pre1 before = {}".format(pre1) pre1 = and_clauses( pre1, diff_frame(updated1, updated2, None, new)) # keep track of post-state of assertion failure # print "pre1 = {}".format(pre1) new_pre = or_clauses( pre1, and_clauses(clauses1, rename_clauses(and_clauses(pre2, mid_ax), map2))) # print "new_pre = {}".format(new_pre) return (new_updated, new_clauses, new_pre)
def compose_updates(update1,axioms,update2): updated1, clauses1, pre1 = update1 updated2, clauses2, pre2 = update2 clauses2 = rename_distinct(clauses2,clauses1) pre2 = rename_distinct(pre2,clauses1) # print "clauses2 = {}".format(clauses2) us1 = set(updated1) us2 = set(updated2) mid = us1.intersection(us2) mid_ax = clauses_using_symbols(mid,axioms) used = used_symbols_clauses(and_clauses(clauses1,clauses2)) rn = UniqueRenamer('__m_',used) map1 = dict() map2 = dict() for v in updated1: map2[v] = new(v) for mv in mid: mvf = rename(mv,rn) map1[new(mv)] = mvf map2[mv] = mvf clauses1 = rename_clauses(clauses1,map1) new_clauses = and_clauses(clauses1, rename_clauses(and_clauses(clauses2,mid_ax),map2)) new_updated = list(us1.union(us2)) # print "pre1 before = {}".format(pre1) pre1 = and_clauses(pre1,diff_frame(updated1,updated2,None,new)) # keep track of post-state of assertion failure # print "pre1 = {}".format(pre1) new_pre = or_clauses(pre1,and_clauses(clauses1,rename_clauses(and_clauses(pre2,mid_ax),map2))) # print "new_pre = {}".format(new_pre) return (new_updated,new_clauses,new_pre)
def satisfy(self, axioms, _get_model_clauses=None, final_cond=None): """ Produce a state sequence if the symbolic history contains one. Returns the sort universes and a sequence of states, or None if the history is vacuous. """ if _get_model_clauses is None: _get_model_clauses = small_model_clauses # print "axioms: {}".format(axioms) # A model of the post-state embeds a valuation for each time # in the history. # print "concrete state: {}".format(self.post) # print "background: {}".format(axioms) post = and_clauses(self.post, axioms) # print "bounded check {" model = _get_model_clauses(post, final_cond=final_cond) # print "} bounded check" if model == None: # print "core = {}".format(unsat_core(post,true_clauses())) return None # we reconstruct the sub-model for each state composing the # recorded renamings in reverse order. Here "renaming" maps # symbols representing a past time onto current time skolems renaming, states, maps = {}, [], reversed(self.maps) while True: # ignore all symbols except those representing the given past time img = set(renaming[s] for s in renaming if not s.is_skolem()) ignore = lambda s: self.ignore(s, img, renaming) # get the sub-mode for the given past time as a formula if isinstance(final_cond, list): final_cond = or_clauses(*[fc.cond() for fc in final_cond]) all_clauses = and_clauses( post, final_cond) if final_cond != None else post clauses = clauses_model_to_clauses(all_clauses, ignore=ignore, model=model, numerals=use_numerals()) # map this formula into the past using inverse map clauses = rename_clauses(clauses, inverse_map(renaming)) # remove tautology equalities, TODO: not sure if this is correct here clauses = Clauses( [f for f in clauses.fmlas if not is_tautology_equality(f)], clauses.defs) states.append(clauses) try: # update the inverse map by composing it with inverse # of the next renaming (in reverse order) renaming = compose_maps(next(maps), renaming) except StopIteration: break uvs = model.universes(numerals=use_numerals()) # print "uvs: {}".format(uvs) return uvs, [pure_state(clauses) for clauses in reversed(states)]
def satisfy(self, axioms, _get_model_clauses=None, final_cond=None): """ Produce a state sequence if the symbolic history contains one. Returns the sort universes and a sequence of states, or None if the history is vacuous. """ if _get_model_clauses is None: _get_model_clauses = small_model_clauses # print "axioms: {}".format(axioms) # A model of the post-state embeds a valuation for each time # in the history. # print "concrete state: {}".format(self.post) # print "background: {}".format(axioms) post = and_clauses(self.post,axioms) # print "bounded check {" model = _get_model_clauses(post,final_cond=final_cond) # print "} bounded check" if model == None: # print "core = {}".format(unsat_core(post,true_clauses())) return None # we reconstruct the sub-model for each state composing the # recorded renamings in reverse order. Here "renaming" maps # symbols representing a past time onto current time skolems renaming,states,maps = {},[],reversed(self.maps) while True: # ignore all symbols except those representing the given past time img = set(renaming[s] for s in renaming if not s.is_skolem()) ignore = lambda s: self.ignore(s,img,renaming) # get the sub-mode for the given past time as a formula if isinstance(final_cond,list): final_cond = or_clauses(*[fc.cond() for fc in final_cond]) all_clauses = and_clauses(post,final_cond) if final_cond != None else post clauses = clauses_model_to_clauses(all_clauses,ignore = ignore, model = model, numerals=use_numerals()) # map this formula into the past using inverse map clauses = rename_clauses(clauses,inverse_map(renaming)) # remove tautology equalities, TODO: not sure if this is correct here clauses = Clauses( [f for f in clauses.fmlas if not is_tautology_equality(f)], clauses.defs ) states.append(clauses) try: # update the inverse map by composing it with inverse # of the next renaming (in reverse order) renaming = compose_maps(next(maps),renaming) except StopIteration: break uvs = model.universes(numerals=use_numerals()) # print "uvs: {}".format(uvs) return uvs, [pure_state(clauses) for clauses in reversed(states)]
def compose_updates(update1, axioms, update2): updated1, clauses1, pre1 = update1 updated2, clauses2, pre2 = update2 clauses2 = rename_distinct(clauses2, clauses1) pre2 = rename_distinct(pre2, clauses1) # print "clauses2 = {}".format(clauses2) us1 = set(updated1) us2 = set(updated2) mid = us1.intersection(us2) mid_ax = clauses_using_symbols(mid, axioms) used = used_symbols_clauses(and_clauses(clauses1, clauses2)) used.update(symbols_clauses(pre1)) used.update(symbols_clauses(pre2)) rn = UniqueRenamer('__m_', used) map1 = dict() map2 = dict() for v in updated1: map2[v] = new(v) for mv in mid: mvf = rename(mv, rn) map1[new(mv)] = mvf map2[mv] = mvf # iu.dbg('clauses1') # iu.dbg('clauses1.annot') clauses1 = rename_clauses(clauses1, map1) annot_op = lambda x, y: x.compose( y) if x is not None and y is not None else None new_clauses = and_clauses(clauses1, rename_clauses(and_clauses(clauses2, mid_ax), map2), annot_op=annot_op) new_updated = list(us1.union(us2)) # print "pre1 before = {}".format(pre1) # iu.dbg('pre1.annot') # iu.dbg('pre1') pre1 = and_clauses(pre1, diff_frame( updated1, updated2, new, axioms)) # keep track of post-state of assertion failure # print "pre1 = {}".format(pre1) temp = and_clauses(clauses1, rename_clauses(and_clauses(pre2, mid_ax), map2), annot_op=my_annot_op) # iu.dbg('temp.annot') new_pre = or_clauses(pre1, temp) # iu.dbg('new_pre.annot') # print "new_pre = {}".format(new_pre) # iu.dbg('new_clauses') # iu.dbg('new_clauses.annot') return (new_updated, new_clauses, new_pre)
def int_update(self,domain,in_scope): (updated,clauses,pre) = self.action_update(domain,in_scope) # instantiate the update axioms for u in domain.updates: updated,transrel,precond = u.get_update_axioms(updated,self) # TODO: do something with the precondition # if transrel: ## print "updated: {}".format(updated) ## print "update from axiom: %s" % transrel clauses = and_clauses(clauses,transrel) pre = or_clauses(pre,precond) ## print "update clauses: %s" % clauses res = (updated,clauses,pre) return res
def int_update(self, domain, in_scope): (updated, clauses, pre) = self.action_update(domain, in_scope) # instantiate the update axioms for u in domain.updates: updated, transrel, precond = u.get_update_axioms(updated, self) # TODO: do something with the precondition # if transrel: ## print "updated: {}".format(updated) ## print "update from axiom: %s" % transrel clauses = and_clauses(clauses, transrel) pre = or_clauses(pre, precond) ## print "update clauses: %s" % clauses res = (updated, clauses, pre) return res
def compose_updates(update1,axioms,update2): updated1, clauses1, pre1 = update1 updated2, clauses2, pre2 = update2 clauses2 = rename_distinct(clauses2,clauses1) pre2 = rename_distinct(pre2,clauses1) # print "clauses2 = {}".format(clauses2) us1 = set(updated1) us2 = set(updated2) mid = us1.intersection(us2) mid_ax = clauses_using_symbols(mid,axioms) used = used_symbols_clauses(and_clauses(clauses1,clauses2)) rn = UniqueRenamer('__m_',used) map1 = dict() map2 = dict() for v in updated1: map2[v] = new(v) for mv in mid: mvf = rename(mv,rn) map1[new(mv)] = mvf map2[mv] = mvf # iu.dbg('clauses1') # iu.dbg('clauses1.annot') clauses1 = rename_clauses(clauses1,map1) annot_op = lambda x,y: x.compose(y) if x is not None and y is not None else None new_clauses = and_clauses(clauses1, rename_clauses(and_clauses(clauses2,mid_ax),map2),annot_op=annot_op) new_updated = list(us1.union(us2)) # print "pre1 before = {}".format(pre1) # iu.dbg('pre1.annot') # iu.dbg('pre1') pre1 = and_clauses(pre1,diff_frame(updated1,updated2,None,new)) # keep track of post-state of assertion failure # print "pre1 = {}".format(pre1) temp = and_clauses(clauses1,rename_clauses(and_clauses(pre2,mid_ax),map2),annot_op=my_annot_op) # iu.dbg('temp.annot') new_pre = or_clauses(pre1,temp) # iu.dbg('new_pre.annot') # print "new_pre = {}".format(new_pre) # iu.dbg('new_clauses') # iu.dbg('new_clauses.annot') return (new_updated,new_clauses,new_pre)