Beispiel #1
0
 def interpret(self, thing):
     sig = self.domain.sig
     interp = sig.interp
     if isinstance(thing.formula.args[1], ivy_ast.NativeType):
         lhs = thing.formula.args[0].rep
         if lhs in interp or lhs in self.domain.native_types:
             raise IvyError(thing, "{} is already interpreted".format(lhs))
         self.domain.native_types[lhs] = thing.formula.args[1]
         return
     lhs, rhs = (a.rep for a in thing.formula.args)
     self.domain.interps[lhs].append(thing)
     if lhs in self.domain.native_types:
         raise IvyError(thing, "{} is already interpreted".format(lhs))
     if lhs in interp:
         if interp[lhs] != rhs:
             raise IvyError(thing, "{} is already interpreted".format(lhs))
         return
     if isinstance(rhs, ivy_ast.Range):
         interp[lhs] = ivy_logic.EnumeratedSort(lhs, [
             "{}:{}".format(i, lhs) for i in range(int(rhs.lo),
                                                   int(rhs.hi) + 1)
         ])
         return
     for x, y, z in zip([sig.sorts, sig.symbols],
                        [slv.is_solver_sort, slv.is_solver_op],
                        ['sort', 'symbol']):
         if lhs in x:
             if not y(rhs):
                 raise IvyError(thing, "{} not a native {}".format(rhs, z))
             interp[lhs] = rhs
             return
     raise IvyUndefined(thing, lhs)
Beispiel #2
0
        expr_context.code.append(CallAction(ivy_ast.Atom(self.rep, args), res))
        return res()
    return (ivy_logic.Equals if self.rep == '=' else
            ivy_logic.find_polymorphic_symbol(self.rep))(*args)


ivy_ast.App.cmpl = ivy_ast.Atom.cmpl = compile_app

ivy_ast.Variable.cmpl = lambda self: ivy_logic.Variable(
    self.rep,
    ivy_logic.find_sort(self.sort)
    if isinstance(self.sort, str) else self.sort)

ivy_ast.ConstantSort.cmpl = lambda self: ivy_logic.ConstantSort(self.rep)

ivy_ast.EnumeratedSort.cmpl = lambda self: ivy_logic.EnumeratedSort(
    self.name, self.extension)

SymbolList.cmpl = lambda self: self.clone(
    [find_symbol(s) for s in self.symbols])


def cquant(q):
    return ivy_logic.ForAll if isinstance(q,
                                          ivy_ast.Forall) else ivy_logic.Exists


ivy_ast.Quantifier.cmpl = lambda self: cquant(
    self)([v.compile() for v in self.bounds], self.args[0].compile())

ivy_ast.LabeledFormula.cmpl = lambda self: self.clone(
    [self.label, sortify_with_inference(self.formula)])
Beispiel #3
0
    #    # print clauses
    # print
    # z3_formula = clauses_to_z3(clauses)
    # print z3_formula
    # print
    # print

    # f = clauses_to_z3(ivy_logic.to_clauses("[[p()],[~p()]]"))
    # s = z3.Solver()
    # s.add(f)
    # print s.check() # should be unsat

    # f1 = clauses_to_z3(ivy_logic.to_clauses("[[p()]]"))
    # f2 = clauses_to_z3(ivy_logic.to_clauses("[[~p()]]"))
    # s = z3.Solver()
    # s.add(f1)
    # s.add(f2)
    # print s.check() # this is also unsat

    # ivy_logic.add_symbol('p',ivy_logic.RelationSort([ivy_logic.universe]))
    # cls = to_clauses("p(x) & ~p(y)")
    # print clauses_model_to_clauses(cls)

    s = ivy_logic.EnumeratedSort(["a", "b", "c"])
    for c in s.defines():
        t = add_symbol(c, s)
        ivy_logic.sig.constructors.add(t)
    add_symbol('f', ivy_logic.FunctionSort([ivy_logic.universe], s))
    cls = to_clauses("f(x) = a & f(y) = b")
    print clauses_model_to_clauses(cls)