diff options
Diffstat (limited to '')
-rw-r--r-- | polymatrix/polymatrix/typing.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/polymatrix/polymatrix/typing.py b/polymatrix/polymatrix/typing.py index 91544d1..50f3f52 100644 --- a/polymatrix/polymatrix/typing.py +++ b/polymatrix/polymatrix/typing.py @@ -13,7 +13,9 @@ class VariableIndex(NamedTuple): """ Index for a variable raised to an integral power. - `VariableIndex` has a total order with respect to the variable index. + `VariableIndex` has a partial order with respect to the variable index. For + example if :math:`x` had index 0, :math:`y` has index 1, then :math:`y + \succeq x`, the exponent does not matter so :math:`y \succeq x^2`. """ variable: int # index in ExpressionState object power: int @@ -34,8 +36,22 @@ class VariableIndex(NamedTuple): class MonomialIndex(tuple[VariableIndex]): """ Index for a monomial, i.e. a product of `VariableIndex`. + + `MonomialIndex` has a partial order with respect to the degree. """ + @property + def degree(self) -> int: + """ Degree of the monomial """ + if MonomialIndex.is_constant(self): + return 0 + + return sum(v.power for v in self) + + def __lt__(self, other): + """ Monomial indices can be sorted with respect to the exponent value. """ + return self.degree < other.degree + @staticmethod def empty() -> MonomialIndex: """ Get an empty monomial index. """ |