Exemple #1
0
 def check_node(self, n):
     x = var_to_skolem('__', Variable('X', n.sort)).suffix(str(n.sort))
     y = var_to_skolem('__', Variable('Y', n.sort)).suffix(str(n.sort))
     #        print "x.sort: {}",format(x.sort)
     self.solver.push()
     s = self.solver
     # if we have a witness we can show node is definite (present in all models)
     wit = get_witness(n)
     #        print "checking: {}".format(n.fmla)
     cube = substitute_clause(n.fmla, {'X': x})
     #        print "cube: {!r}".format(cube)
     #        print wit
     #        if wit != None:
     ##            print "wit: {}, wit.sort: {}, x.sort: {}".format(wit,wit.sort,x.sort)
     res = s_check_cube(s, cube,
                        (Atom(equals, [x, wit]) if wit != None else None))
     ##        print"check cube: %s = %s" % (cube,res)
     #        res = s_check_cube(s,substitute_clause(n.fmla,{'X':x}))
     #        print "status: {}".format(res)
     n.status = res
     s_add(s, cube_to_z3(substitute_clause(n.fmla, {'X': x})))
     s_add(s, cube_to_z3(substitute_clause(n.fmla, {'X': y})))
     s_add(s, cube_to_z3([Literal(0, Atom(equals, [x, y]))]))
     n.summary = s.check() != z3.unsat
     self.solver.pop()
Exemple #2
0
 def get_definite_facts(self, names, tvals):
     edges = self.get_edges()
     return [[
         substitute_lit(
             Literal(1 if status == 'true' else 0, self.rel_lit.atom),
             {'X': get_witness(p1)})
     ] for (p1, ), status in edges
             if status != 'undef' and status in tvals and p1.name in names]
Exemple #3
0
def rela_fact(polarity, relname, n1, n2):
    return ([~lit for lit in fmla1] + [
        ~lit
        for lit in substitute_clause(n2.fmla, {'X': Variable('Y', n2.sort)})
    ] + [
        Literal(
            polarity,
            Atom(relname, [Variable('X', n1.sort),
                           Variable('Y', n2.sort)]))
    ])
Exemple #4
0
 def split(self, node, p):
     if isinstance(p, tuple):
         self.split_n_way(node, [eq_lit(p[0], x) for x in p[1]])
         return
     label = make_lit_label(p)
     posname = node.name + "+" + label
     negname = node.name + "-" + label
     self.all_nodes = [n for n in self.all_nodes if n is not node]
     self.all_nodes.append(GraphNode(posname, node.fmla + [p], node.sort))
     neg_p = Literal(1 - p.polarity, p.atom)
     self.all_nodes.append(
         GraphNode(negname, node.fmla + [neg_p], node.sort))
     self.needs_recompute = True
Exemple #5
0
 def relation_concepts(self, relations):
     rcons = [r.to_concept_space() for r in relations]
     rprods = [
         ProductSpace([
             NamedSpace(x) for x in [
                 node_concept(r.sorts[0], 'X'),
                 Literal(1, cs[0]),
                 node_concept(r.sorts[1], 'Y')
             ]
         ]) for (r, cs) in zip(relations, rcons)
     ]
     rsp = to_atom('__rsp(X,Y)'), SumSpace(rprods)
     return rcons + [rsp]
Exemple #6
0
    def set_state(self, clauses, recomp=True):
        self.state = clauses
        self.solver_clauses = true_clauses()
        self.predicates = self.get_predicates(clauses)
        sig = self.parent_state.domain.sig
        ufs = [
            x for x, arity in self.parent_state.domain.functions.iteritems()
            if arity == 1 and not has_enumerated_sort(sig, x)
        ]
        if not hasattr(self, 'brels'):
            self.brels = ([
                self.make_rel_lit(r, ['X', 'Y'])
                for r, arity in self.parent_state.domain.all_relations
                if arity == 2
            ] + [
                Literal(
                    1,
                    Atom(equals, [
                        App(f, Variable('X', f.sort.dom[0])),
                        Variable('Y', f.sort.rng)
                    ])) for f in ufs
            ])
#        brels =  list(used_binary_relations_clauses(clauses))
#        brels = [r for r in brels if ((r != equals) and not r.startswith('__'))]
##        print "brels: %s" % brels
        self.relations = [GraphRelation(self, rel) for rel in self.brels]
        self.relations += [
            GraphRelationUnary(self, rel) for rel in self.predicates
            if not isinstance(rel, tuple) and used_variables_ast(rel)
        ]
        self.relations += [
            GraphFunctionUnary(self, Literal(1, rel[0]))
            for rel in self.predicates if isinstance(rel, tuple)
        ]
        self.needs_recompute = True
        if recomp:
            self.recompute()
Exemple #7
0
 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])
Exemple #8
0
 def make_rel_lit(self, rel, varnames):
     args = [Variable(v, t) for v, t in zip(varnames, rel.sort.dom)]
     return Literal(1, Atom(rel, args))
Exemple #9
0
def xtra_concept(sort, vn1, vn2):
    return Literal(
        1, Atom('__xtra:' + sort,
                [Variable(vn1, sort), Variable(vn2, sort)]))
Exemple #10
0
def node_concept(sort, varname):
    return Literal(1, Atom('__node:' + sort, [Variable(varname, sort)]))
Exemple #11
0
 def status_lit(self, status):
     return Literal(1, Atom(equals, [self.fmla, status]))