Пример #1
0
def extract_pre_post_model(clauses,model,updated):
    renaming = dict((v,new(v)) for v in updated)
    ignore = lambda s: s.is_skolem() or is_new(s)
    pre_clauses = clauses_model_to_clauses(clauses,ignore = ignore,model = model,numerals=use_numerals())
    ignore = lambda s: s.is_skolem() or (not is_new(s) and s in renaming)
    post_clauses = clauses_model_to_clauses(clauses,ignore = ignore,model = model,numerals=use_numerals())
    post_clauses = rename_clauses(post_clauses,inverse_map(renaming))
    return map(remove_taut_eqs_clauses,(pre_clauses,post_clauses))
    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)]
Пример #3
0
    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)]