diff options
-rw-r--r-- | polymatrix/polymatrix/typing.py | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/polymatrix/polymatrix/typing.py b/polymatrix/polymatrix/typing.py index ce33e67..cebf636 100644 --- a/polymatrix/polymatrix/typing.py +++ b/polymatrix/polymatrix/typing.py @@ -35,10 +35,18 @@ class VariableIndex(NamedTuple): class MonomialIndex(tuple[VariableIndex]): - """ + r""" Index for a monomial, i.e. a product of `VariableIndex`. - `MonomialIndex` has a partial order with respect to the degree. + `MonomialIndex` has a total order, they can be sorted with respect to the + degree. If they have the same degree then they are sorted with respect to + the index of the first variable. + + For example :math:`x^2 z \succeq xy` because the former has degree 3 while + the latter is quadratic. Then :math:`yz \succeq xy` (assuming :math:`x` has + index 0, :math:`y` has index 1 and :math:`z` 2) because :math:`y \succeq x`. + + Constant monomial indices are considered equal. """ @property @@ -50,7 +58,15 @@ class MonomialIndex(tuple[VariableIndex]): return sum(v.power for v in self) def __lt__(self, other): - """ Monomial indices can be sorted with respect to the exponent value. """ + # Constants are equal + if MonomialIndex.is_constant(self): + return False + + # they have the same degree the index counts + if self.degree == other.degree: + # Assumes that monomialindex is sorted! + return self[0] < other[0] + return self.degree < other.degree @staticmethod |