예제 #1
0
파일: ivy_solver.py 프로젝트: simudream/ivy
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
예제 #2
0
파일: ivy_solver.py 프로젝트: odedp/ivy
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