def frame_def(sym, op):
    """ Add the condition that sym remains unchanged to a
    transition relation (using op = {new,old})"""
    lhs = sym_inst(op(sym) if op is new else sym)
    rhs = sym_inst(sym if op is new else op(sym))
    dfn = Definition(lhs, rhs)
    return dfn
Ejemplo n.º 2
0
def mk_variant_assign_clauses(lhs, rhs):
    n = lhs.rep
    new_n = new(n)
    args = lhs.args
    dlhs = new_n(*sym_placeholders(n))
    vs = dlhs.args
    eqs = [
        eq_atom(v, a) for (v, a) in zip(vs, args)
        if not isinstance(a, Variable)
    ]
    rn = dict((a.rep, v) for v, a in zip(vs, args) if isinstance(a, Variable))
    drhs = substitute_ast(rhs, rn)
    nondet = n.suffix("_nd").skolem()
    if eqs:
        nondet = Ite(And(*eqs), nondet, n(*dlhs.args))
    lsort, rsort = lhs.sort, rhs.sort
    fmlas = [
        Iff(
            pto(lsort, rsort)(dlhs, Variable('X', rsort)),
            Equals(Variable('X', rsort), drhs))
    ]
    for s in ivy_module.module.variants[lsort.name]:
        if s != rsort:
            fmlas.append(Not(pto(lsort, s)(dlhs, Variable('X', s))))
    new_clauses = Clauses(fmlas, [Definition(dlhs, nondet)])
    return new_clauses
Ejemplo n.º 3
0
    def action_update(self, domain, pvars):
        lhs, rhs = self.args
        n = lhs.rep

        # Handle the hierarchical case
        if n in domain.hierarchy:
            asgns = [
                postfix_atoms_ast(self, Atom(x, []))
                for x in domain.hierarchy[n]
            ]
            res = unzip_append(
                [asgn.action_update(domain, pvars) for asgn in asgns])
            return res

        # If the lhs application is partial, make it total by adding parameters
        xtra = len(lhs.rep.sort.dom) - len(lhs.args)
        if xtra < 0:
            raise IvyError(self,
                           "too many parameters in assignment to " + lhs.rep)
        if xtra > 0:
            extend = sym_placeholders(lhs.rep)[-xtra:]
            extend = variables_distinct_list_ast(extend,
                                                 self)  # get unused variables
            lhs = add_parameters_ast(lhs, extend)
            # Assignment of individual to a boolean is a special case
            if is_individual_ast(rhs) and not is_individual_ast(lhs):
                rhs = eq_atom(extend[-1],
                              add_parameters_ast(rhs, extend[0:-1]))
            else:
                rhs = add_parameters_ast(rhs, extend)

        type_check(domain, rhs)
        if is_individual_ast(lhs) != is_individual_ast(rhs):
            #            print type(lhs.rep)
            #            print str(lhs.rep)
            #            print type(lhs.rep.sort)
            #            print "lhs: %s: %s" % (lhs,type(lhs))
            #            print "rhs: %s: %s" % (rhs,type(rhs))
            raise IvyError(self,
                           "sort mismatch in assignment to {}".format(lhs.rep))

        new_n = new(n)
        args = lhs.args
        dlhs = new_n(*sym_placeholders(n))
        vs = dlhs.args
        eqs = [
            eq_atom(v, a) for (v, a) in zip(vs, args)
            if not isinstance(a, Variable)
        ]
        rn = dict(
            (a.rep, v) for v, a in zip(vs, args) if isinstance(a, Variable))
        drhs = substitute_ast(rhs, rn)
        if eqs:
            drhs = Ite(And(*eqs), drhs, n(*dlhs.args))
        new_clauses = Clauses([], [Definition(dlhs, drhs)])
        #        print "assign new_clauses = {}".format(new_clauses)
        return ([n], new_clauses, false_clauses())
Ejemplo n.º 4
0
def mk_assign_clauses(lhs,rhs):
    n = lhs.rep
    new_n = new(n)
    args = lhs.args
    dlhs = new_n(*sym_placeholders(n))
    vs = dlhs.args
    eqs = [eq_atom(v,a) for (v,a) in zip(vs,args) if not isinstance(a,Variable)]
    rn = dict((a.rep,v) for v,a in zip(vs,args) if isinstance(a,Variable))
    drhs = substitute_ast(rhs,rn)
    if eqs:
        drhs = Ite(And(*eqs),drhs,n(*dlhs.args))
    new_clauses = Clauses([],[Definition(dlhs,drhs)])
    return new_clauses
Ejemplo n.º 5
0
def assert_action(fmla):
    fail_flag = Symbol("sys:fail", RelationSort([]))
    return SemActionValue(
        [fail_flag], true_clauses(),
        Clauses(defs=[Definition(new(fail_flag), Or(fail_flag, Not(fmla)))]))