X-Git-Url: https://scm.cri.mines-paristech.fr/git/linpy.git/blobdiff_plain/36939fa400ed913afd44b37b8bb9c1a7a932e442..56ab422e3bbc5a6a072f5b2a5be9d88d1017f03f:/pypol/linear.py diff --git a/pypol/linear.py b/pypol/linear.py index 3cd7633..621a157 100644 --- a/pypol/linear.py +++ b/pypol/linear.py @@ -69,7 +69,7 @@ class Expression: self._coefficients = {} for symbol, coefficient in coefficients: if isinstance(symbol, Symbol): - symbol = str(symbol) + symbol = symbol.name elif not isinstance(symbol, str): raise TypeError('symbols must be strings or Symbol instances') if isinstance(coefficient, Constant): @@ -126,10 +126,6 @@ class Expression: yield self.coefficient(symbol) yield self.constant - @property - def symbol(self): - raise ValueError('not a symbol: {}'.format(self)) - def issymbol(self): return False @@ -330,26 +326,26 @@ class Symbol(Expression): def __new__(cls, name): if isinstance(name, Symbol): - name = name.symbol + name = name.name elif not isinstance(name, str): raise TypeError('name must be a string or a Symbol instance') self = object().__new__(cls) self._coefficients = {name: 1} self._constant = 0 self._symbols = tuple(name) - self._symbol = name + self._name = name self._dimension = 1 return self @property - def symbol(self): - return self._symbol + def name(self): + return self._name def issymbol(self): return True def __repr__(self): - return '{}({!r})'.format(self.__class__.__name__, self._symbol) + return '{}({!r})'.format(self.__class__.__name__, self._name) def symbols(names): if isinstance(names, str):