summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2024-04-24 22:44:33 +0200
committerNao Pross <np@0hm.ch>2024-04-24 22:44:33 +0200
commitc9dcddb40d61a80239a2ee7d0619e7ade29aacda (patch)
tree7f8222b4b3be4736d679db4fb59429719dfb3efb
parentDelete ancient class BroadCastedPolyMatrix (diff)
downloadpolymatrix-c9dcddb40d61a80239a2ee7d0619e7ade29aacda.tar.gz
polymatrix-c9dcddb40d61a80239a2ee7d0619e7ade29aacda.zip
Create partial order of MonomialIndex wrt degree of monomial
-rw-r--r--polymatrix/polymatrix/typing.py18
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. """