context[symbol] = Symbol(symbol)
return eval(string, context)
+ @property
def symbols(self):
- yield from sorted(self._coefficients)
+ return tuple(sorted(self._coefficients))
@property
def dimension(self):
- return len(list(self.symbols()))
+ return len(list(self.symbols))
def coefficient(self, symbol):
symbol = _strsymbol(symbol)
__getitem__ = coefficient
def coefficients(self):
- for symbol in self.symbols():
+ for symbol in self.symbols:
yield symbol, self.coefficient(symbol)
@property
return len(self._coefficients) == 0
def values(self):
- for symbol in self.symbols():
+ for symbol in self.symbols:
yield self.coefficient(symbol)
yield self.constant
def symbol(self):
if not self.issymbol():
raise ValueError('not a symbol: {}'.format(self))
- for symbol in self.symbols():
+ for symbol in self.symbols:
return symbol
def issymbol(self):
def __repr__(self):
string = ''
- symbols = sorted(self.symbols())
+ symbols = self.symbols
i = 0
for symbol in symbols:
coefficient = self[symbol]
inequalities = []
symbols = set()
for equality in equalities:
- symbols.update(equality.symbols())
+ symbols.update(equality.symbols)
for inequality in inequalities:
- symbols.update(inequality.symbols())
- symbols = sorted(symbols)
+ symbols.update(inequality.symbols)
+ symbols = list(symbols)
string = _iscc.set(symbols, equalities, inequalities)
string = _iscc.eval(string)
return cls._fromiscc(symbols, string)
if re.match(r'^\s*\{\s*\}\s*$', string):
return empty
self = super().__new__(cls)
- self._symbols = _strsymbols(symbols)
+ self._symbols = sorted(_strsymbols(symbols))
self._equalities = []
self._inequalities = []
string = re.sub(r'^\s*\{\s*(.*?)\s*\}\s*$', lambda m: m.group(1), string)
yield from self.equalities
yield from self.inequalities
+ @property
def symbols(self):
- yield from self._symbols
+ return tuple(self._symbols)
@property
def dimension(self):
- return len(self.symbols())
+ return len(self.symbols)
def __bool__(self):
# return false if the polyhedron is empty, true otherwise
raise not self.isempty()
def _symbolunion(self, *others):
- symbols = set(self.symbols())
+ symbols = set(self.symbols)
for other in others:
- symbols.update(other.symbols())
+ symbols.update(other.symbols)
return sorted(symbols)
def __eq__(self, other):
def intersection(self, *others):
symbols = self._symbolunion(*others)
- symbols = sorted(symbols)
strings = [self._toiscc(symbols)]
for other in others:
strings.append(other._toiscc(symbols))
# return a new polyhedron with elements in the polyhedron that are not
# in the others
symbols = self._symbolunion(*others)
- symbols = sorted(symbols)
strings = [self._toiscc(symbols)]
for other in others:
strings.append(other._toiscc(symbols))
def projection(self, symbols):
symbols = _strsymbols(symbols)
- string = _iscc.map(symbols, self.symbols(),
+ string = _iscc.map(symbols, self.symbols,
self.equalities, self.inequalities)
string = _iscc.eval('poly (dom ({}))'.format(string))
return Polyhedron._fromiscc(symbols, string)