'Symbol', 'Dummy', 'symbols',
'Rational',
]
'Symbol', 'Dummy', 'symbols',
'Rational',
]
if isinstance(coefficients, str):
if constant != 0:
raise TypeError('too many arguments')
if isinstance(coefficients, str):
if constant != 0:
raise TypeError('too many arguments')
if coefficients is None:
return Rational(constant)
if isinstance(coefficients, Mapping):
if coefficients is None:
return Rational(constant)
if isinstance(coefficients, Mapping):
for symbol, coefficient in other._coefficients.items():
coefficients[symbol] += coefficient
constant = self._constant + other._constant
for symbol, coefficient in other._coefficients.items():
coefficients[symbol] += coefficient
constant = self._constant + other._constant
for symbol, coefficient in other._coefficients.items():
coefficients[symbol] -= coefficient
constant = self._constant - other._constant
for symbol, coefficient in other._coefficients.items():
coefficients[symbol] -= coefficient
constant = self._constant - other._constant
coefficients = ((symbol, coefficient * other)
for symbol, coefficient in self._coefficients.items())
constant = self._constant * other
coefficients = ((symbol, coefficient * other)
for symbol, coefficient in self._coefficients.items())
constant = self._constant * other
coefficients = ((symbol, coefficient / other)
for symbol, coefficient in self._coefficients.items())
constant = self._constant / other
coefficients = ((symbol, coefficient / other)
for symbol, coefficient in self._coefficients.items())
constant = self._constant / other
if othersymbol != symbol]
coefficient = result._coefficients.get(symbol, 0)
constant = result._constant
if othersymbol != symbol]
coefficient = result._coefficients.get(symbol, 0)
constant = result._constant
Create an expression from a string.
"""
# add implicit multiplication operators, e.g. '5x' -> '5*x'
Create an expression from a string.
"""
# add implicit multiplication operators, e.g. '5x' -> '5*x'
tree = ast.parse(string, 'eval')
return cls._fromast(tree)
tree = ast.parse(string, 'eval')
return cls._fromast(tree)
coefficients.append((symbol, coefficient))
else:
raise ValueError('non-linear expression: {!r}'.format(expr))
coefficients.append((symbol, coefficient))
else:
raise ValueError('non-linear expression: {!r}'.format(expr))