コード例 #1
0
    def __init__(self, theory, constrains, title='', prompt=''):
        self.theory = theory
        self.constrains = list(constrains)
        self.s = z3.Solver()
        self.s.add(clauses_to_z3(self.theory))
        self.alits = [
            z3.Const('__core_aux{}'.format(n), z3.BoolSort())
            for n, c in enumerate(self.constrains)
        ]
        for a, c in zip(self.alits, self.constrains):
            self.s.add(z3.Or(z3.Not(a), ivy_solver.formula_to_z3(c)))
        options = OrderedDict(
            (str(c), n) for n, c in enumerate(self.constrains))
        self.select = widgets.SelectMultiple(options=options, value=[])
        self.prompt = widgets.Latex(prompt)
        self.result = widgets.Latex('')
        self.check_button = widgets.Button(description='Check SAT')
        self.check_button.on_click(self.check)

        super(UserSelectCore, self).__init__(title, [
            self.prompt,
            self.select,
            self.check_button,
            self.result,
        ])
コード例 #2
0
ファイル: iupdr.py プロジェクト: simudream/ivy
    def __init__(self, theory, constrains, title="", prompt=""):
        self.theory = theory
        self.constrains = list(constrains)
        self.s = z3.Solver()
        self.s.add(clauses_to_z3(self.theory))
        self.alits = [z3.Const("__core_aux{}".format(n), z3.BoolSort()) for n, c in enumerate(self.constrains)]
        for a, c in zip(self.alits, self.constrains):
            self.s.add(z3.Or(z3.Not(a), ivy_solver.formula_to_z3(c)))
        options = OrderedDict((str(c), n) for n, c in enumerate(self.constrains))
        self.select = widgets.SelectMultiple(options=options, value=[])
        self.prompt = widgets.Latex(prompt)
        self.result = widgets.Latex("")
        self.check_button = widgets.Button(description="Check SAT")
        self.check_button.on_click(self.check)

        super(UserSelectCore, self).__init__(title, [self.prompt, self.select, self.check_button, self.result])
コード例 #3
0
ファイル: ivy_updr.py プロジェクト: asyaf/ivy
    # globals are the inflexible symbols
    gsyms = [ns(sym) for sym in inflex]

    print "lsyms = {}".format(lsyms)
    print "gsyms = {}".format(gsyms)

    init = state.clauses
    init = forward_clauses(init, inflex)
    print "init = {}".format(init)

    error = forward_clauses(error, inflex)
    print "error = {}".format(error)

    axioms += forward_clauses(axioms, inflex)

    init_z3 = sv.clauses_to_z3(init)
    print "init_z3 = {}".format(init_z3)
    for a in updates:
        print lu.simplify_clauses(a[1])
    rho_z3 = z3.Or(
        *[sv.clauses_to_z3(lu.simplify_clauses(a[1])) for a in updates])
    print "rho_z3 = {}".format(rho_z3)
    bad_z3 = sv.clauses_to_z3(error)
    print "bad_z3 = {}".format(bad_z3)
    background_z3 = sv.clauses_to_z3(axioms)
    print "background_z3 = {}".format(background_z3)
    #relations_z3 = [ns(rel) for rel in sig.relations if tr.is_new(rel) or rel in inflex]
    relations_z3 = [
        x for x in gsyms
        if not z3.is_const(x) or (z3.is_const(x) and x.sort() == z3.BoolSort())
    ]
コード例 #4
0
def interactive_updr():
    frames = ta._ivy_ag.states
    if len(frames) != 1:
        raise InteractionError(
            "Interactive UPDR can only be started when the ARG " +
            "contains nothing but the initial state.")

    bad_states = negate_clauses(ta.get_safety_property())
    action = ta.get_big_action()
    ta._ivy_ag.actions[repr(action)] = action

    init_frame = last_frame = frames[0]

    # TODO: test conjecture in initial

    while True:

        # the property is true in all frames and all "clauses" are pushed
        # the goal stack is empty

        # check if we found an infuctive invariant
        for i in range(len(frames) - 1):
            if t.check_cover(frames[i + 1], frames[i]):
                ta.step(msg="Inductive invariant found at frame {}".format(i),
                        i=i)
                # return True

        # add new frame

        last_frame = ta.arg_add_action_node(last_frame, action, None)
        ta.push_goal(ta.goal_at_arg_node(bad_states, last_frame))
        ta.step(msg="Added new frame")

        # push facts to last frame
        t.recalculate_facts(last_frame,
                            ta.arg_get_conjuncts(ta.arg_get_pred(last_frame)))

        while True:
            current_goal = ta.top_goal()
            if current_goal is None:
                # goal stack is empty
                break

            if t.remove_if_refuted(current_goal):
                continue

            if current_goal.node == init_frame:
                # no invariant
                print "No Invariant!"
                # return False

            dg = ta.get_diagram(current_goal, False)
            options = OrderedDict()
            for c in simplify_clauses(dg.formula).conjuncts():
                options[str(c)] = c
            user_selection = (yield UserSelectMultiple(
                options=options,
                title="Generalize Diagram",
                prompt="Choose which literals to take as the refutation goal",
                default=options.values()))
            assert user_selection is not None
            ug = ta.goal_at_arg_node(Clauses(list(user_selection)),
                                     current_goal.node)
            ta.push_goal(ug)
            ta.step(msg='Pushed user selected goal', ug=ug)

            goal = ta.top_goal()
            preds, action = ta.arg_get_preds_action(goal.node)
            assert action != 'join'
            assert len(preds) == 1
            pred = preds[0]
            axioms = ta._ivy_interp.background_theory()
            theory = and_clauses(
                ivy_transrel.forward_image(pred.clauses, axioms,
                                           action.update(ta._ivy_interp,
                                                         None)), axioms)
            goal_clauses = simplify_clauses(goal.formula)
            assert len(goal_clauses.defs) == 0

            s = z3.Solver()
            s.add(clauses_to_z3(theory))
            s.add(clauses_to_z3(goal_clauses))
            is_sat = s.check()
            if is_sat == z3.sat:
                bi = ta.backward_image(goal.formula, action)
                x, y = False, ta.goal_at_arg_node(bi, pred)
            elif is_sat == z3.unsat:
                user_selection, user_is_sat = yield UserSelectCore(
                    theory=theory,
                    constrains=goal_clauses.fmlas,
                    title="Refinement",
                    prompt="Choose the literals to use",
                )
                assert user_is_sat is False
                core = Clauses(user_selection)
                x, y = True, ivy_transrel.interp_from_unsat_core(
                    goal_clauses, theory, core, None)
            else:
                assert False, is_sat

            t.custom_refine_or_reverse(goal, x, y, False)

        # propagate phase
        for i in range(1, len(frames)):
            facts_to_check = (set(ta.arg_get_conjuncts(frames[i - 1])) -
                              set(ta.arg_get_conjuncts(frames[i])))
            t.recalculate_facts(frames[i], list(facts_to_check))
コード例 #5
0
ファイル: ivy_updr.py プロジェクト: jamella/ivy
    # globals are the inflexible symbols
    gsyms = [ns(sym) for sym in inflex]
    
    print "lsyms = {}".format(lsyms)
    print "gsyms = {}".format(gsyms)

    init = state.clauses
    init = forward_clauses(init,inflex)
    print "init = {}".format(init)

    error = forward_clauses(error,inflex)
    print "error = {}".format(error)

    axioms += forward_clauses(axioms,inflex)

    init_z3 = sv.clauses_to_z3(init)
    print "init_z3 = {}".format(init_z3)
    for a in updates:
        print lu.simplify_clauses(a[1])
    rho_z3 = z3.Or(*[sv.clauses_to_z3(lu.simplify_clauses(a[1])) for a in updates])
    print "rho_z3 = {}".format(rho_z3)
    bad_z3 = sv.clauses_to_z3(error)
    print "bad_z3 = {}".format(bad_z3)
    background_z3 = sv.clauses_to_z3(axioms)
    print "background_z3 = {}".format(background_z3)
    #relations_z3 = [ns(rel) for rel in sig.relations if tr.is_new(rel) or rel in inflex]
    relations_z3 =  [ x for x in gsyms if not z3.is_const(x) or (z3.is_const(x) and x.sort() == z3.BoolSort()) ]
    relations_z3 += [ x for _,x in lsyms if not z3.is_const(x) or (z3.is_const(x) and x.sort() == z3.BoolSort()) ]
    print "relations_z3 = {}".format(relations_z3)

    ### HACK: remove skolem predicates from the list of predicate symbols
コード例 #6
0
ファイル: iupdr.py プロジェクト: simudream/ivy
def interactive_updr():
    frames = ta._ivy_ag.states
    if len(frames) != 1:
        raise InteractionError(
            "Interactive UPDR can only be started when the ARG " + "contains nothing but the initial state."
        )

    bad_states = negate_clauses(ta.get_safety_property())
    action = ta.get_big_action()
    ta._ivy_ag.actions[repr(action)] = action

    init_frame = last_frame = frames[0]

    # TODO: test conjecture in initial

    while True:

        # the property is true in all frames and all "clauses" are pushed
        # the goal stack is empty

        # check if we found an infuctive invariant
        for i in range(len(frames) - 1):
            if t.check_cover(frames[i + 1], frames[i]):
                ta.step(msg="Inductive invariant found at frame {}".format(i), i=i)
                # return True

        # add new frame

        last_frame = ta.arg_add_action_node(last_frame, action, None)
        ta.push_goal(ta.goal_at_arg_node(bad_states, last_frame))
        ta.step(msg="Added new frame")

        # push facts to last frame
        t.recalculate_facts(last_frame, ta.arg_get_conjuncts(ta.arg_get_pred(last_frame)))

        while True:
            current_goal = ta.top_goal()
            if current_goal is None:
                # goal stack is empty
                break

            if t.remove_if_refuted(current_goal):
                continue

            if current_goal.node == init_frame:
                # no invariant
                print "No Invariant!"
                # return False

            dg = ta.get_diagram(current_goal, False)
            options = OrderedDict()
            for c in simplify_clauses(dg.formula).conjuncts():
                options[str(c)] = c
            user_selection = (
                yield UserSelectMultiple(
                    options=options,
                    title="Generalize Diagram",
                    prompt="Choose which literals to take as the refutation goal",
                    default=options.values(),
                )
            )
            assert user_selection is not None
            ug = ta.goal_at_arg_node(Clauses(list(user_selection)), current_goal.node)
            ta.push_goal(ug)
            ta.step(msg="Pushed user selected goal", ug=ug)

            goal = ta.top_goal()
            preds, action = ta.arg_get_preds_action(goal.node)
            assert action != "join"
            assert len(preds) == 1
            pred = preds[0]
            axioms = ta._ivy_interp.background_theory()
            theory = and_clauses(
                ivy_transrel.forward_image(pred.clauses, axioms, action.update(ta._ivy_interp, None)), axioms
            )
            goal_clauses = simplify_clauses(goal.formula)
            assert len(goal_clauses.defs) == 0

            s = z3.Solver()
            s.add(clauses_to_z3(theory))
            s.add(clauses_to_z3(goal_clauses))
            is_sat = s.check()
            if is_sat == z3.sat:
                bi = ta.backward_image(goal.formula, action)
                x, y = False, ta.goal_at_arg_node(bi, pred)
            elif is_sat == z3.unsat:
                user_selection, user_is_sat = yield UserSelectCore(
                    theory=theory,
                    constrains=goal_clauses.fmlas,
                    title="Refinement",
                    prompt="Choose the literals to use",
                )
                assert user_is_sat is False
                core = Clauses(user_selection)
                x, y = True, ivy_transrel.interp_from_unsat_core(goal_clauses, theory, core, None)
            else:
                assert False, is_sat

            t.custom_refine_or_reverse(goal, x, y, False)

        # propagate phase
        for i in range(1, len(frames)):
            facts_to_check = set(ta.arg_get_conjuncts(frames[i - 1])) - set(ta.arg_get_conjuncts(frames[i]))
            t.recalculate_facts(frames[i], list(facts_to_check))