예제 #1
0
파일: ivy_transrel.py 프로젝트: ZZHGit/ivy
def compose_state_action(state,action,check=True):
    """ Compose a state and an action, returning a state """
    assert isinstance(state,SemStateValue) and isinstance(action,SemActionValue)
#    print "state: {}".format(state)
#    print "action: {}".format(action)
    su,sc,sp = state.comps
    au,ac,ap = action.comps
    sc,sp = clausify(sc),clausify(sp)
    axioms = im.background_theory()
    if check:
        pre_test = and_clauses(and_clauses(sc,ap),axioms)
        model = small_model_clauses(pre_test)
        if model != None:
            trans = extract_pre_post_model(pre_test,model,au)
            post_updated = [new(s) for s in au]
            pre_test = exist_quant(post_updated,pre_test)
            raise ActionFailed(pre_test,trans)
    if su != None:      # none means all moded
        ssu = set(su) # symbols already modified in state
        rn = dict((x,old(x)) for x in au if x not in ssu)
        sc = rename_clauses(sc,rn)
        ac = rename_clauses(ac,rn)
        su = list(su)
        union_to_list(su,au)
    img = forward_image(sc,action)
##    print "compose: {}".format((su,img,sp))
    return SemStateValue(su,img,sp)
예제 #2
0
파일: ivy_transrel.py 프로젝트: ZZHGit/ivy
def compose_updates(update1,update2):
    assert isinstance(update1,SemActionValue) and type(update1) is type(update2)
    axioms = im.background_theory()
    updated1, clauses1, pre1 = update1.comps
    updated2, clauses2, pre2 = update2.comps
    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,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 SemActionValue(new_updated,new_clauses,new_pre)
예제 #3
0
파일: ivy_transrel.py 프로젝트: asyaf/ivy
def compose_state_action(state, action, check=True):
    """ Compose a state and an action, returning a state """
    assert isinstance(state, SemStateValue) and isinstance(
        action, SemActionValue)
    #    print "state: {}".format(state)
    #    print "action: {}".format(action)
    su, sc, sp = state.comps
    au, ac, ap = action.comps
    sc, sp = clausify(sc), clausify(sp)
    axioms = im.background_theory()
    if check:
        pre_test = and_clauses(and_clauses(sc, ap), axioms)
        model = small_model_clauses(pre_test)
        if model != None:
            trans = extract_pre_post_model(pre_test, model, au)
            post_updated = [new(s) for s in au]
            pre_test = exist_quant(post_updated, pre_test)
            raise ActionFailed(pre_test, trans)
    if su != None:  # none means all moded
        ssu = set(su)  # symbols already modified in state
        rn = dict((x, old(x)) for x in au if x not in ssu)
        sc = rename_clauses(sc, rn)
        ac = rename_clauses(ac, rn)
        su = list(su)
        union_to_list(su, au)
    img = forward_image(sc, action)
    ##    print "compose: {}".format((su,img,sp))
    return SemStateValue(su, img, sp)
예제 #4
0
파일: ivy_transrel.py 프로젝트: asyaf/ivy
def implies(s1, s2):
    assert isinstance(s1, SemValue) and type(s1) is type(s2)
    op = s1.op
    axioms = im.background_theory()
    u1, c1, p1 = s1.comps
    u2, c2, p2 = s2.comps
    if u1 == None and u2 != None:
        return False


#    print "c1: {}".format(c1)
#    print "axioms: {}".format(axioms)
#    print "df: {}".format(diff_frame(u1,u2,relations,op))
    c1 = and_clauses(c1, axioms, diff_frame(u1, u2, op))
    if isinstance(c2, Clauses):
        if not c2.is_universal_first_order(
        ) or not p2.is_universal_first_order():
            return False
        c2 = and_clauses(c2, diff_frame(u2, u1, op))
        return clauses_imply(p1, p2) and clauses_imply(c1, c2)
    else:
        if not is_prenex_universal(c2) or not is_prenex_universal(p2):
            return False
        c2 = And(c2, clauses_to_formula(diff_frame(u2, u1, op)))
        return clauses_imply_formula_cex(p1, p2) and clauses_imply_formula_cex(
            c1, c2)
예제 #5
0
def false_properties(reporter=None):
    axioms = im.background_theory()
    props = [x for x in im.module.labeled_props if not x.temporal]
    subgoalmap = dict((x.id, y) for x, y in im.module.subgoals)
    aas = ([islvr.Assume(axioms)] +
           [(islvr.Assume if prop.id in subgoalmap else islvr.Assert)(
               formula_to_clauses(prop.formula), prop) for prop in props])
    truths = islvr.check_sequence(aas, reporter)
    return [c for c, t in zip(props, truths[1:]) if not t]
예제 #6
0
파일: ivy_interp.py 프로젝트: yotamfe/ivy
def false_properties(reporter= None):
    axioms = im.background_theory()
    props = [x for x in im.module.labeled_props if not x.temporal]
    subgoalmap = dict((x.id,y) for x,y in im.module.subgoals)
    aas = ([islvr.Assume(axioms)]
           + [(islvr.Assume if prop.id in subgoalmap else islvr.Assert)
              (formula_to_clauses(prop.formula),prop) for prop in props])
    truths = islvr.check_sequence(aas,reporter)
    return [c for c,t in zip(props,truths[1:]) if not t]
예제 #7
0
파일: ivy_transrel.py 프로젝트: ZZHGit/ivy
def interpolant(clauses1,clauses2,interpreted):
#    print "interpolant clauses1={} clauses2={}".format(clauses1,clauses2)
#    print "axioms = {}".format(axioms)
    axioms = im.background_theory()
    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)
예제 #8
0
파일: ivy_transrel.py 프로젝트: ZZHGit/ivy
def reverse_image(post_state,update):
    assert isinstance(post_state,Clauses) and isinstance(update,SemActionValue)
    updated, clauses, _precond = update.comps
    axioms = im.background_theory()
    post_ax = clauses_using_symbols(updated,axioms)
    post_clauses = conjoin(post_state,post_ax)
    post_clauses = rename_clauses(post_clauses, dict((x,new(x)) for x in updated))
    post_updated = [new(s) for s in updated]
    res = exist_quant(post_updated,conjoin(clauses,post_clauses))
#    res = simplify_clauses(res)
    return res
예제 #9
0
파일: ivy_transrel.py 프로젝트: ZZHGit/ivy
def forward_image_map(pre_state,update):
    assert isinstance(pre_state,Clauses) and isinstance(update,SemActionValue)
    updated, clauses, _precond = update.comps
#    print "transition_relation: {}".format(clauses)
    axioms = im.background_theory()
    pre_ax = clauses_using_symbols(updated,axioms)
    pre = conjoin(pre_state,pre_ax)
    map1,res = exist_quant_map(updated,conjoin(pre,clauses))
    res = rename_clauses(res, dict((new(x),x) for x in updated))
##    print "before simp: %s" % res
    # res = simplify_clauses(res)
    return map1,res
예제 #10
0
파일: ivy_transrel.py 프로젝트: asyaf/ivy
def interpolant(clauses1, clauses2, interpreted):
    #    print "interpolant clauses1={} clauses2={}".format(clauses1,clauses2)
    #    print "axioms = {}".format(axioms)
    axioms = im.background_theory()
    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)
예제 #11
0
파일: ivy_transrel.py 프로젝트: asyaf/ivy
def reverse_image(post_state, update):
    assert isinstance(post_state, Clauses) and isinstance(
        update, SemActionValue)
    updated, clauses, _precond = update.comps
    axioms = im.background_theory()
    post_ax = clauses_using_symbols(updated, axioms)
    post_clauses = conjoin(post_state, post_ax)
    post_clauses = rename_clauses(post_clauses,
                                  dict((x, new(x)) for x in updated))
    post_updated = [new(s) for s in updated]
    res = exist_quant(post_updated, conjoin(clauses, post_clauses))
    #    res = simplify_clauses(res)
    return res
예제 #12
0
파일: ivy_transrel.py 프로젝트: asyaf/ivy
def forward_image_map(pre_state, update):
    assert isinstance(pre_state, Clauses) and isinstance(
        update, SemActionValue)
    updated, clauses, _precond = update.comps
    #    print "transition_relation: {}".format(clauses)
    axioms = im.background_theory()
    pre_ax = clauses_using_symbols(updated, axioms)
    pre = conjoin(pre_state, pre_ax)
    map1, res = exist_quant_map(updated, conjoin(pre, clauses))
    res = rename_clauses(res, dict((new(x), x) for x in updated))
    ##    print "before simp: %s" % res
    # res = simplify_clauses(res)
    return map1, res
예제 #13
0
파일: ivy_transrel.py 프로젝트: ZZHGit/ivy
def implies(s1,s2):
    assert isinstance(s1,SemValue) and type(s1) is type(s2)
    op = s1.op
    axioms = im.background_theory()
    u1,c1,p1 = s1.comps
    u2,c2,p2 = s2.comps
    if u1 == None and u2 != None:
        return False
#    print "c1: {}".format(c1)
#    print "axioms: {}".format(axioms)
#    print "df: {}".format(diff_frame(u1,u2,relations,op))
    c1 = and_clauses(c1,axioms,diff_frame(u1,u2,op))
    if isinstance(c2,Clauses):
        if not c2.is_universal_first_order() or not p2.is_universal_first_order():
            return False
        c2 = and_clauses(c2,diff_frame(u2,u1,op))
        return clauses_imply(p1,p2) and clauses_imply(c1,c2)
    else:
        if not is_prenex_universal(c2) or not is_prenex_universal(p2):
            return False
        c2 = And(c2,clauses_to_formula(diff_frame(u2,u1,op)))
        return clauses_imply_formula_cex(p1,p2) and clauses_imply_formula_cex(c1,c2)
예제 #14
0
파일: ivy_transrel.py 프로젝트: asyaf/ivy
def compose_updates(update1, update2):
    assert isinstance(update1,
                      SemActionValue) and type(update1) is type(update2)
    axioms = im.background_theory()
    updated1, clauses1, pre1 = update1.comps
    updated2, clauses2, pre2 = update2.comps
    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,
                         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 SemActionValue(new_updated, new_clauses, new_pre)
예제 #15
0
파일: ivy_interp.py 프로젝트: odedp/ivy
def false_properties():
    axioms = im.background_theory()
    props = im.module.labeled_props
    goals = [formula_to_clauses(prop.formula) for prop in props]
    truths = clauses_imply_list(axioms,goals)
    return [c for c,t in zip(props,truths) if not t]
예제 #16
0
def false_properties():
    axioms = im.background_theory()
    props = im.module.labeled_props
    goals = [formula_to_clauses(prop.formula) for prop in props]
    truths = clauses_imply_list(axioms, goals)
    return [c for c, t in zip(props, truths) if not t]