@@ -105,12 +105,11 @@ def __xor__(self, other):
105
105
def equals (self , other ):
106
106
"""
107
107
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.
110
108
111
109
Note: if there is a possibility that self is only a symbol, then
112
110
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.
114
113
115
114
Examples
116
115
========
@@ -126,16 +125,16 @@ def equals(self, other):
126
125
127
126
"""
128
127
from sympy .logic .inference import satisfiable
129
- from sympy .core .relational import Relational
130
128
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 )))
139
138
140
139
def to_nnf (self , simplify = True ):
141
140
# override where necessary
0 commit comments