- @_polymorphic
- def __mul__(self, other):
- coefficients = dict(other._coefficients)
- for symbol in coefficients:
- coefficients[symbol] *= self._constant
- constant = other._constant * self._constant
- return Expression(coefficients, constant)
-
- __rmul__ = __mul__
-
- @_polymorphic
- def __rtruediv__(self, other):
- coefficients = dict(other._coefficients)
- for symbol in coefficients:
- coefficients[symbol] /= self._constant
- constant = other._constant / self._constant
- return Expression(coefficients, constant)
-
- @classmethod
- def fromstring(cls, string):
- if not isinstance(string, str):
- raise TypeError('string must be a string instance')
- return Rational(string)
-