"""
if not isinstance(symbol, Symbol):
raise TypeError('symbol must be a Symbol instance')
- return self._coefficients.get(symbol, 0)
+ return self._coefficients.get(symbol, Fraction(0))
__getitem__ = coefficient
Iterate over the pairs (symbol, value) of linear terms in the
expression. The constant term is ignored.
"""
- for symbol, coefficient in self._coefficients.items():
- yield symbol, coefficient
+ yield from self._coefficients.items()
@property
def constant(self):
Iterate over the coefficient values in the expression, and the constant
term.
"""
- for coefficient in self._coefficients.values():
- yield coefficient
+ yield from self._coefficients.values()
yield self._constant
def __bool__(self):
"""
Test whether two linear expressions are equal.
"""
- return isinstance(other, LinExpr) and \
- self._coefficients == other._coefficients and \
- self._constant == other._constant
+ if isinstance(other, LinExpr):
+ return self._coefficients == other._coefficients and \
+ self._constant == other._constant
+ return NotImplemented
def __le__(self, other):
from .polyhedra import Le
Return the expression multiplied by its lowest common denominator to
make all values integer.
"""
- lcm = functools.reduce(lambda a, b: a*b // gcd(a, b),
+ lcd = functools.reduce(lambda a, b: a*b // gcd(a, b),
[value.denominator for value in self.values()])
- return self * lcm
+ return self * lcd
def subs(self, symbol, expression=None):
"""
return True
def __eq__(self, other):
- return self.sortkey() == other.sortkey()
+ if isinstance(other, Symbol):
+ return self.sortkey() == other.sortkey()
+ return NotImplemented
def asdummy(self):
"""