X-Git-Url: https://scm.cri.mines-paristech.fr/git/linpy.git/blobdiff_plain/a87eb293f1d72496c2645e8b90d40d896982520e..bb2fe6868c69f2d478da3ecbf4efeeef21c6eae2:/polyp.py?ds=inline diff --git a/polyp.py b/polyp.py index 9058c08..ca32493 100644 --- a/polyp.py +++ b/polyp.py @@ -425,8 +425,14 @@ class Polyhedron: # return false if the polyhedron is empty, true otherwise raise not self.isempty() + def _symbolunion(self, *others): + symbols = set(self.symbols()) + for other in others: + symbols.update(other.symbols()) + return sorted(symbols) + def __eq__(self, other): - symbols = set(self.symbols()) | set(other.symbols()) + symbols = self._symbolunion(other) string = '{} = {}'.format(self._toiscc(symbols), other._toiscc(symbols)) string = _iscc.eval(string) return string == 'True' @@ -442,7 +448,7 @@ class Polyhedron: return (self & other).isempty() def issubset(self, other): - symbols = set(self.symbols()) | set(other.symbols()) + symbols = self._symbolunion(other) string = '{} <= {}'.format(self._toiscc(symbols), other._toiscc(symbols)) string = _iscc.eval(string) return string == 'True' @@ -451,14 +457,14 @@ class Polyhedron: return self.issubset(other) def __lt__(self, other): - symbols = set(self.symbols()) | set(other.symbols()) + symbols = self._symbolunion(other) string = '{} < {}'.format(self._toiscc(symbols), other._toiscc(symbols)) string = _iscc.eval(string) return string == 'True' def issuperset(self, other): # test whether every element in other is in the polyhedron - symbols = set(self.symbols()) | set(other.symbols()) + symbols = self._symbolunion(other) string = '{} >= {}'.format(self._toiscc(symbols), other._toiscc(symbols)) string = _iscc.eval(string) return string == 'True' @@ -467,7 +473,7 @@ class Polyhedron: return self.issuperset(other) def __gt__(self, other): - symbols = set(self.symbols() + other.symbols()) + symbols = self._symbolunion(other) string = '{} > {}'.format(self._toiscc(symbols), other._toiscc(symbols)) string = _iscc.eval(string) return string == 'True' @@ -475,10 +481,7 @@ class Polyhedron: def union(self, *others): # return a new polyhedron with elements from the polyhedron and all # others (convex union) - symbols = set(self.symbols()) - for other in others: - symbols.update(other.symbols()) - symbols = sorted(symbols) + symbols = self._symbolunion(*others) strings = [self._toiscc(symbols)] for other in others: strings.append(other._toiscc(symbols)) @@ -490,9 +493,7 @@ class Polyhedron: return self.union(other) def intersection(self, *others): - symbols = set(self.symbols()) - for other in others: - symbols.update(other.symbols()) + symbols = self._symbolunion(*others) symbols = sorted(symbols) strings = [self._toiscc(symbols)] for other in others: @@ -507,9 +508,7 @@ class Polyhedron: def difference(self, *others): # return a new polyhedron with elements in the polyhedron that are not # in the others - symbols = set(self.symbols()) - for other in others: - symbols.update(other.symbols()) + symbols = self._symbolunion(*others) symbols = sorted(symbols) strings = [self._toiscc(symbols)] for other in others: