- self._coefficients = {}
- for symbol, coefficient in coefficients:
- if isinstance(symbol, Symbol):
- symbol = symbol.name
- elif not isinstance(symbol, str):
- raise TypeError('symbols must be strings or Symbol instances')
- if isinstance(coefficient, Constant):
- coefficient = coefficient.constant
- if not isinstance(coefficient, numbers.Rational):
- raise TypeError('coefficients must be rational numbers '
- 'or Constant instances')
- self._coefficients[symbol] = coefficient
- if isinstance(constant, Constant):
- constant = constant.constant
- if not isinstance(constant, numbers.Rational):
- raise TypeError('constant must be a rational number '
- 'or a Constant instance')
- self._constant = constant
- self._symbols = tuple(sorted(self._coefficients))
+ self._coefficients = OrderedDict(coefficients)
+ self._constant = Fraction(constant)
+ self._symbols = tuple(self._coefficients)