Skip to content

Commit eda38cc

Browse files
authored
Update boolalg.py
1 parent e341221 commit eda38cc

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

sympy/logic/boolalg.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,11 @@ def __xor__(self, other):
105105
def equals(self, other):
106106
"""
107107
Returns ``True`` if the given formulas have the same truth table.
108-
For two formulas to be equal one must have the all the literals
109-
of the other.
110108
111109
Note: if there is a possibility that self is only a symbol, then
112110
it is better to test as ``BooleanFunction.equals(self, other)``
113-
otherwise the ``Expr.equals`` will return False.
111+
otherwise the ``Expr.equals`` will return False if other is not
112+
the same symbol.
114113
115114
Examples
116115
========
@@ -126,16 +125,16 @@ def equals(self, other):
126125
127126
"""
128127
from sympy.logic.inference import satisfiable
129-
from sympy.core.relational import Relational
130128

131-
if self.has(Relational) or other.has(Relational):
132-
raise NotImplementedError('handling of relationals')
133-
more = self.free_symbols
134-
less = other.free_symbols
135-
if len(more) < len(less):
136-
more, less = less, more
137-
return not less - more and \
138-
not satisfiable(Not(Equivalent(self, other)))
129+
def ok(f):
130+
return isinstance(f, (BooleanFunction, Symbol)) and (not f.args or
131+
all(ok(a) for a in f.args))
132+
if not ok(self) or not ok(other):
133+
raise NotImplementedError('non-literal BooleanFunction')
134+
135+
# simplification can remove redundant symbols
136+
args = simpler(self), simpler(other)
137+
return not satisfiable(Not(Equivalent(*args)))
139138

140139
def to_nnf(self, simplify=True):
141140
# override where necessary

0 commit comments

Comments
 (0)