if not isinstance(symbol, Symbol):
raise TypeError('symbols must be Symbol instances')
if not isinstance(coefficient, numbers.Rational):
if not isinstance(symbol, Symbol):
raise TypeError('symbols must be Symbol instances')
if not isinstance(coefficient, numbers.Rational):
coefficients = [(symbol, Fraction(coefficient))
for symbol, coefficient in coefficients if coefficient != 0]
if not isinstance(constant, numbers.Rational):
coefficients = [(symbol, Fraction(coefficient))
for symbol, coefficient in coefficients if coefficient != 0]
if not isinstance(constant, numbers.Rational):
constant = Fraction(constant)
if len(coefficients) == 0:
return Rational(constant)
constant = Fraction(constant)
if len(coefficients) == 0:
return Rational(constant)