projects
/
linpy.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
a87eb29
)
Add _symbolunion method
author
Vivien Maisonneuve
<v.maisonneuve@gmail.com>
Wed, 18 Jun 2014 09:39:36 +0000
(11:39 +0200)
committer
Vivien Maisonneuve
<v.maisonneuve@gmail.com>
Wed, 18 Jun 2014 09:39:36 +0000
(11:39 +0200)
polyp.py
patch
|
blob
|
history
diff --git
a/polyp.py
b/polyp.py
index
9058c08
..
ca32493
100644
(file)
--- 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()
# 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):
def __eq__(self, other):
- symbols = se
t(self.symbols()) | set(other.symbols()
)
+ symbols = se
lf._symbolunion(other
)
string = '{} = {}'.format(self._toiscc(symbols), other._toiscc(symbols))
string = _iscc.eval(string)
return string == 'True'
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):
return (self & other).isempty()
def issubset(self, other):
- symbols = se
t(self.symbols()) | set(other.symbols()
)
+ symbols = se
lf._symbolunion(other
)
string = '{} <= {}'.format(self._toiscc(symbols), other._toiscc(symbols))
string = _iscc.eval(string)
return string == 'True'
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):
return self.issubset(other)
def __lt__(self, other):
- symbols = se
t(self.symbols()) | set(other.symbols()
)
+ symbols = se
lf._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
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 = se
t(self.symbols()) | set(other.symbols()
)
+ symbols = se
lf._symbolunion(other
)
string = '{} >= {}'.format(self._toiscc(symbols), other._toiscc(symbols))
string = _iscc.eval(string)
return string == 'True'
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):
return self.issuperset(other)
def __gt__(self, other):
- symbols = se
t(self.symbols() + other.symbols()
)
+ symbols = se
lf._symbolunion(other
)
string = '{} > {}'.format(self._toiscc(symbols), other._toiscc(symbols))
string = _iscc.eval(string)
return string == 'True'
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)
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))
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):
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:
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
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:
symbols = sorted(symbols)
strings = [self._toiscc(symbols)]
for other in others: