for symbol, coefficient in coefficients if coefficient != 0]
if len(coefficients) == 0:
return Constant(constant)
- elif len(coefficients) == 1:
+ elif len(coefficients) == 1 and constant == 0:
symbol, coefficient = coefficients[0]
if coefficient == 1:
return Symbol(symbol)
return False
def __bool__(self):
- True
+ return True
def __pos__(self):
return self
self.constant == other.constant
def __hash__(self):
- return hash((self._coefficients, self._constant))
+ return hash((tuple(sorted(self._coefficients.items())), self._constant))
def _toint(self):
lcm = functools.reduce(lambda a, b: a*b // gcd(a, b),