def update_frame_constraint(update, relations): """ Return a clause list constraining all updated symbols to keep their previous values """ clauses = [] for sym in update[0]: if sym in relations: arity = relations[sym] vs = [Variable("V{}".format(i)) for i in range(0, arity)] lit1 = Literal(1, Atom(sym, vs)) lit2 = Literal(1, Atom(new(sym), vs)) clauses += [[~lit1, lit2], [lit1, ~lit2]] else: clauses.append([eq_lit(Constant(sym), Constant(new(sym)))]) return Clauses(clauses)
def interp_from_unsat_core(clauses1, clauses2, core, interpreted): used_syms = used_symbols_clauses(core) vars = used_variables_clauses(core) if vars: # print "interpolant would require skolem constants" return None core_consts = used_constants_clauses(core) clauses2_consts = used_constants_clauses(clauses2) # print "interp_from_unsat_core core_consts = {}".format(map(str,core_consts)) # print "interp_from_unsat_core clauses2_consts = {}".format(map(str,clauses2_consts)) renaming = dict() i = 0 for v in core_consts: if v not in clauses2_consts or v.is_skolem( ): # and v not in interpreted: renaming[v] = Variable('V' + str(i), Constant(v).get_sort()) i += 1 # print "interp_from_unsat_core core = {}".format(core) # print "interp_from_unsat_core renaming = {}".format(renaming) renamed_core = substitute_constants_clauses(core, renaming) # print "interp_from_unsat_core renamed_core = {}".format(renamed_core) res = simplify_clauses( Clauses([Or(*[negate(c) for c in renamed_core.fmlas])])) # print "interp_from_unsat_core res = {}".format(res) return res
def splatter(self, node, constants=None): if constants == None: constants = used_constants_clauses(self.constraints) eqs = [ eq_lit(node.variable('X'), Constant(c)) for c in constants if c.sort == node.sort ] # print "splatter eqs = {}".format(eqs) self.split_n_way(node, eqs)
def get_predicates(self, clauses): # print "get_predicates: {}".format(clauses) d = self.parent_state.domain sig = d.sig urs = [ x for x in used_unary_relations_clauses(clauses) if not is_skolem(x) ] cs = [ x for x in used_constants_clauses(clauses) if not is_skolem(x) and not has_enumerated_sort(sig, x) and not x.is_numeral() ] ufs = [ x for x in used_unary_functions_clauses(clauses) if not is_skolem(x) and has_enumerated_sort(sig, x) ] nrs = [x for x, arity in d.relations.iteritems() if arity == 0] union_to_list( urs, [x for x, arity in d.relations.iteritems() if arity == 1]) union_to_list(cs, [ x for x, arity in d.functions.iteritems() if arity == 0 and not has_enumerated_sort(sig, x) ]) union_to_list(ufs, [ x for x, arity in d.functions.iteritems() if arity == 1 and has_enumerated_sort(sig, x) ]) # print "ufs: {}".format(ufs) ccs = [Constant(c) for c in cs] # print "sorts: {}".format([(c,c.get_sort()) for c in ccs]) return ([Literal(1, Atom(c, [])) for c in nrs] + [ Literal(1, Atom(equals, [Variable("X", c.get_sort()), c])) for c in ccs ] + [Literal(1, Atom(r, [Variable("X", r.sort.dom[0])])) for r in urs] + [(App(f, Variable('X', f.sort.dom[0])), [ Constant(Symbol(x, f.sort.rng)) for x in f.sort.rng.defines() ]) for f in ufs])
def check_edge(self, f1, solver): x = var_to_skolem('__', Variable('X', self.sorts[0])).suffix(str(self.sorts[0])) solver.push() s_add(solver, cube_to_z3(substitute_clause(f1, {'X': x}))) # print "xsort: {}, ysort: {}".format(x.get_sort(),y.get_sort()) # print "rel_lit: {}, subs: {}".format(self.rel_lit,substitute_lit(self.rel_lit,{'X':x,'Y':y})) f = self.fmla vals = [Constant(Symbol(y, f.sort.rng)) for y in f.sort.rng.defines()] status = 'undef' for v in vals: if s_check_fmla(solver, self.test_lit(x, v).atom) == z3.unsat: status = v break solver.pop() return status