Esempio n. 1
0
    def ask(self, query):
        """Checks if the query is true given the set of clauses.

        Examples
        ========

        >>> from sympy.logic.inference import PropKB
        >>> from sympy.abc import x, y
        >>> l = PropKB()
        >>> l.tell(x & ~y)
        >>> l.ask(x)
        True
        >>> l.ask(y)
        False
        """
        if len(self.clauses) == 0:
            return False
        from sympy.logic.algorithms.dpll import dpll

        query_conjuncts = self.clauses[:]
        query_conjuncts.extend(conjuncts(to_cnf(query)))
        s = set()
        for q in query_conjuncts:
            s = s.union(q.atoms(C.Symbol))
        return bool(dpll(query_conjuncts, list(s), {}))
Esempio n. 2
0
 def ask(self, query):
     """TODO: examples"""
     if len(self.clauses) == 0: return False
     query_conjuncts = self.clauses[:]
     query_conjuncts.extend(conjuncts(to_cnf(query)))
     s = set()
     for q in query_conjuncts:
         s = s.union(q.atoms(Symbol))
     return bool(dpll(query_conjuncts, list(s), {}))
Esempio n. 3
0
 def ask(self, query):
     """TODO: examples"""
     if len(self.clauses) == 0: return False
     from sympy.logic.algorithms.dpll import dpll
     query_conjuncts = self.clauses[:]
     query_conjuncts.extend(conjuncts(to_cnf(query)))
     s = set()
     for q in query_conjuncts:
         s = s.union(q.atoms(C.Symbol))
     return bool(dpll(query_conjuncts, list(s), {}))
Esempio n. 4
0
 def ask(self, query):
     """TODO: examples"""
     if len(self.clauses) == 0: return False
     from sympy.logic.algorithms.dpll import dpll
     query_conjuncts = self.clauses[:]
     query_conjuncts.extend(conjuncts(to_cnf(query)))
     s = set()
     for q in query_conjuncts:
         s = s.union(q.atoms(C.Symbol))
     return bool(dpll(query_conjuncts, list(s), {}))
Esempio n. 5
0
    def ask(self, query):
        """Checks if the query is true given the set of clauses.

        Examples
        ========
        >>> from sympy.logic.inference import PropKB
        >>> from sympy.abc import x, y
        >>> l = PropKB()
        >>> l.tell(x & ~y)
        >>> l.ask(x)
        True
        >>> l.ask(y)
        False
        """
        if len(self.clauses) == 0: return False
        from sympy.logic.algorithms.dpll import dpll
        query_conjuncts = self.clauses[:]
        query_conjuncts.extend(conjuncts(to_cnf(query)))
        s = set()
        for q in query_conjuncts:
            s = s.union(q.atoms(C.Symbol))
        return bool(dpll(query_conjuncts, list(s), {}))
Esempio n. 6
0
def test_dpll():
    """This is also tested in test_dimacs"""
    A, B, C = symbols('A,B,C')
    assert dpll([A | B], [A, B], {A: True, B: True}) == {A: True, B: True}
Esempio n. 7
0
def test_dpll():
    """This is also tested in test_dimacs"""
    A, B, C = symbols('A,B,C')
    assert dpll([A | B], [A, B], {A: True, B: True}) == {A: True, B: True}