Esempio n. 1
0
def decompose_action_app(state2,expr):
    assert is_action_app(expr)
    action = eval_action(expr.rep)
    state1 = eval_state(expr.args[0])
    comps = action.decompose(state1.value,state2.value)
    bg = state1.domain.background_theory(state1.in_scope)
    for pre,acts,post in comps:
        print "pre core: {} ".format(unsat_core(and_clauses(pre[1],bg),true_clauses()))
        print "post core: {} ".format(unsat_core(and_clauses(post[1],bg),true_clauses()))
        upds = [act.update(state1.domain,state1.in_scope) for act in acts]
        h = History(pre)
#        print "h.post: {}".format(h.post)
        for upd in upds:
#            print "upd: {}".format(upd)
            h = h.forward_step(bg,upd)
#            print "h.post: {}".format(h.post)
        h = h.assume(post)
#        print "h.post: {}".format(h.post)
        bmc_res = h.satisfy(bg)
        if bmc_res == None:
            continue
        universe,path = bmc_res
        states = []
        for i,value in enumerate(path):
#            print "core: {} ".format(unsat_core(and_clauses(value[1],bg),true_clauses()))
            state = new_state(value)
            if i != 0:
                state.expr = action_app(acts[i-1],states[-1])
                state.update = upds[i-1]
                state.pred = states[-1]
            state.label = None
            state.universe = universe
            states.append(state)
        return state
    return None
Esempio n. 2
0
def get_core(state,clause):
        """ Check whether a clause is implied by a state. If so,
        return a core (a subset of clauses in the state that implies
        clause) else return None. Clause is assumed to be ground.
        """
        state_clauses = state.clauses
        clauses1 = and_clauses(state_clauses,state.domain.background_theory(state.in_scope))
        clauses2 = [[~lit] for lit in clause]
        return unsat_core(clauses1,clauses2)    
Esempio n. 3
0
def get_core(state,clause):
        """ Check whether a clause is implied by a state. If so,
        return a core (a subset of clauses in the state that implies
        clause) else return None. Clause is assumed to be ground.
        """
        state_clauses = state.clauses
        clauses1 = and_clauses(state_clauses,state.domain.background_theory(state.in_scope))
        clauses2 = [[~lit] for lit in clause]
        return unsat_core(clauses1,clauses2)    
Esempio n. 4
0
def interpolant(clauses1,clauses2,axioms,interpreted):
#    print "interpolant clauses1={} clauses2={}".format(clauses1,clauses2)
#    print "axioms = {}".format(axioms)
    foo = and_clauses(clauses1,axioms)
    clauses2 = simplify_clauses(clauses2)
    core = unsat_core(clauses2,foo)
    if core == None:
        return None
#    print "core: %s" % core
    return core, interp_from_unsat_core(clauses2,foo,core,interpreted)
Esempio n. 5
0
def decompose_action_app(state2, expr):
    assert is_action_app(expr)
    action = eval_action(expr.rep)
    state1 = eval_state(expr.args[0])
    comps = action.decompose(state1.value, state2.value)
    bg = state1.domain.background_theory(state1.in_scope)
    for pre, acts, post in comps:
        print "pre core: {} ".format(
            unsat_core(and_clauses(pre[1], bg), true_clauses()))
        print "post core: {} ".format(
            unsat_core(and_clauses(post[1], bg), true_clauses()))
        upds = [act.update(state1.domain, state1.in_scope) for act in acts]
        h = History(pre)
        #        print "h.post: {}".format(h.post)
        for upd in upds:
            #            print "upd: {}".format(upd)
            h = h.forward_step(bg, upd)


#            print "h.post: {}".format(h.post)
        h = h.assume(post)
        #        print "h.post: {}".format(h.post)
        bmc_res = h.satisfy(bg)
        if bmc_res == None:
            continue
        universe, path = bmc_res
        states = []
        for i, value in enumerate(path):
            #            print "core: {} ".format(unsat_core(and_clauses(value[1],bg),true_clauses()))
            state = new_state(value)
            if i != 0:
                state.expr = action_app(acts[i - 1], states[-1])
                state.update = upds[i - 1]
                state.pred = states[-1]
            state.label = None
            state.universe = universe
            states.append(state)
        return state
    return None
Esempio n. 6
0
    def minimize_conjecture(self, button=None, bound=None):
        import ivy_transrel
        import ivy_solver
        from proof import ProofGoal
        from ivy_logic_utils import Clauses, and_clauses, dual_clauses, used_symbols_clauses, negate
        from ivy_solver import unsat_core
        from logic_util import free_variables, substitute

        if self.bmc_conjecture(bound=bound):
            # found a BMC counter-example
            return

        with self.ui_parent.run_context():
            step_action = im.module.actions['ext']

            n_steps = self.current_bound

            ag = self.parent.new_ag()
            with ag.context as ac:
                post = ac.new_state(ag.init_cond)
            if 'initialize' in im.module.actions:
                init_action = im.module.actions['initialize']
                post = ag.execute(init_action, None, None, 'initialize')
            for n in range(n_steps):
                post = ag.execute(step_action, None, None, 'ext')
            axioms = im.module.background_theory()
            post_clauses = and_clauses(post.clauses, axioms)

            used_names = (
                frozenset(x.name for x in il.sig.symbols.values()) |
                frozenset(x.name for x in used_symbols_clauses(post_clauses))
            )
            facts = self.get_active_facts()
            assert not any(
                c.is_skolem() and c.name in used_names for c in lu.used_constants(*facts)
            )
            core = unsat_core(Clauses(facts), post_clauses)
            if core is None:
                core = Clauses([]) ## can happen if we are proving true
#            assert core is not None, "bmc_conjecture returned False but unsat core is None"
            core_formulas = frozenset(core.fmlas)
            self.set_facts([fact for fact in facts if fact in core_formulas])
            self.highlight_selected_facts()
            self.ui_parent.text_dialog("BMC found the following possible conjecture:",
                                       str(self.get_selected_conjecture()))
Esempio n. 7
0
    def minimize_conjecture(self, button=None, bound=None):
        import ivy_transrel
        import ivy_solver
        from proof import ProofGoal
        from ivy_logic_utils import Clauses, and_clauses, dual_clauses, used_symbols_clauses, negate
        from ivy_solver import unsat_core
        from logic_util import free_variables, substitute

        if self.bmc_conjecture(bound=bound):
            # found a BMC counter-example
            return

        with self.ui_parent.run_context():
            step_action = im.module.actions['ext']

            n_steps = self.current_bound

            ag = self.parent.new_ag()
            with ag.context as ac:
                post = ac.new_state(ag.init_cond)
            if 'initialize' in im.module.actions:
                init_action = im.module.actions['initialize']
                post = ag.execute(init_action, None, None, 'initialize')
            for n in range(n_steps):
                post = ag.execute(step_action, None, None, 'ext')
            axioms = im.module.background_theory()
            post_clauses = and_clauses(post.clauses, axioms)

            used_names = (frozenset(x.name for x in il.sig.symbols.values())
                          | frozenset(
                              x.name
                              for x in used_symbols_clauses(post_clauses)))
            facts = self.get_active_facts()
            assert not any(c.is_skolem() and c.name in used_names
                           for c in lu.used_constants(*facts))
            core = unsat_core(Clauses(facts), post_clauses)
            if core is None:
                core = Clauses([])  ## can happen if we are proving true
#            assert core is not None, "bmc_conjecture returned False but unsat core is None"
            core_formulas = frozenset(core.fmlas)
            self.set_facts([fact for fact in facts if fact in core_formulas])
            self.highlight_selected_facts()
            self.ui_parent.text_dialog(
                "BMC found the following possible conjecture:",
                str(self.get_selected_conjecture()))