def formula_to_z3_int(fmla): # print "formula_to_z3_int: {} : {}".format(fmla,type(fmla)) if ivy_logic.is_atom(fmla): return atom_to_z3(fmla) if isinstance(fmla, ivy_logic.Definition) and ivy_logic.is_enumerated( fmla.args[0]): return encode_equality(*fmla.args) args = [formula_to_z3_int(arg) for arg in fmla.args] if isinstance(fmla, ivy_logic.And): return z3.And(args) if isinstance(fmla, ivy_logic.Or): return z3.Or(args) if isinstance(fmla, ivy_logic.Not): return z3.Not(args[0]) if isinstance(fmla, ivy_logic.Definition): return my_eq(args[0], args[1]) if isinstance(fmla, ivy_logic.Iff): return my_eq(args[0], args[1]) if isinstance(fmla, ivy_logic.Implies): return z3.Implies(args[0], args[1]) if isinstance(fmla, ivy_logic.Ite): return z3.If(args[0], args[1], args[2]) if ivy_logic.is_quantifier(fmla): variables = ivy_logic.quantifier_vars(fmla) q = z3.forall if ivy_logic.is_forall(fmla) else z3.Exists res = q([term_to_z3(v) for v in variables], args[0]) # print "res = {}".format(res) return res if ivy_logic.is_individual(fmla): return term_to_z3(fmla) print "bad fmla: {!r}".format(fmla) assert False
def formula_to_z3_int(fmla): # print "formula_to_z3_int: {} : {}".format(fmla,type(fmla)) if ivy_logic.is_atom(fmla): return atom_to_z3(fmla) if isinstance(fmla, ivy_logic.Definition) and ivy_logic.is_enumerated(fmla.args[0]) and not use_z3_enums: return encode_equality(*fmla.args) args = [formula_to_z3_int(arg) for arg in fmla.args] if isinstance(fmla, ivy_logic.And): return z3.And(args) if isinstance(fmla, ivy_logic.Or): return z3.Or(args) if isinstance(fmla, ivy_logic.Not): return z3.Not(args[0]) if isinstance(fmla, ivy_logic.Definition): return my_eq(args[0], args[1]) if isinstance(fmla, ivy_logic.Iff): return my_eq(args[0], args[1]) if isinstance(fmla, ivy_logic.Implies): return z3.Implies(args[0], args[1]) if isinstance(fmla, ivy_logic.Ite): return z3.If(args[0], args[1], args[2]) if ivy_logic.is_quantifier(fmla): variables = ivy_logic.quantifier_vars(fmla) q = z3.ForAll if ivy_logic.is_forall(fmla) else z3.Exists res = q([term_to_z3(v) for v in variables], args[0]) # print "res = {}".format(res) return res if ivy_logic.is_individual(fmla): return term_to_z3(fmla) print "bad fmla: {!r}".format(fmla) assert False
def action_update(self,domain,pvars): lhs = self.args[0] n = lhs.rep new_n = new(n) args = lhs.args vs = [Variable("X%d" % i,s) for i,s in enumerate(n.sort.dom)] eqs = [eq_atom(v,a) for (v,a) in zip(vs,args) if not isinstance(a,Variable)] if is_atom(lhs): clauses = And(*([Or(Not(Atom(new_n,vs)),Atom(n,vs),eq) for eq in eqs] + [Or(Atom(new_n,vs),Not(Atom(n,vs)),eq) for eq in eqs])) elif is_individual_ast(lhs.rep): clauses = And(*[Or(eq_atom(type(lhs)(new_n,vs),type(lhs)(n,vs)),eq) for eq in eqs]) else: # TODO: ??? clauses = And() clauses = formula_to_clauses(clauses) return ([n], clauses, false_clauses())
def action_update(self,domain,pvars): lhs = type_ast(domain,self.args[0]) n = lhs.rep new_n = new(n) args = lhs.args vs = [Variable("X%d" % i,s) for i,s in enumerate(n.sort.dom)] eqs = [eq_atom(v,a) for (v,a) in zip(vs,args) if not isinstance(a,Variable)] if is_atom(lhs): clauses = And(*([Or(Not(Atom(new_n,vs)),Atom(n,vs),eq) for eq in eqs] + [Or(Atom(new_n,vs),Not(Atom(n,vs)),eq) for eq in eqs])) elif is_individual_ast(lhs.rep): clauses = And(*[Or(eq_atom(type(lhs)(new_n,vs),type(lhs)(n,vs)),eq) for eq in eqs]) else: # TODO: ??? clauses = And() clauses = formula_to_clauses(clauses) return ([n], clauses, false_clauses())
def type_ast(domain,ast): if is_atom(ast) and ast.rep not in domain.relations and ast.rep != '=': return App(ast.rep,ast.args) if isinstance(ast,App) and ast.rep in domain.relations: return Atom(ast.rep,ast.args) return ast
def type_ast(domain, ast): if is_atom(ast) and ast.rep not in domain.relations and ast.rep != "=": return App(ast.rep, ast.args) if isinstance(ast, App) and ast.rep in domain.relations: return Atom(ast.rep, ast.args) return ast