aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mdpoly/types.py20
1 files changed, 14 insertions, 6 deletions
diff --git a/mdpoly/types.py b/mdpoly/types.py
index 0a4c68e..b580b99 100644
--- a/mdpoly/types.py
+++ b/mdpoly/types.py
@@ -76,9 +76,17 @@ class PolyVarIndex(NamedTuple):
@classmethod
@property
def constant(cls):
- """ Special index for constants, which have no variable """
+ """ Special index for constants.
+
+ Constants do not have an associated variable,
+ and the field power is ignored.
+ """
return cls(var_idx=-1, power=0)
+ @staticmethod
+ def is_constant(index: Self) -> bool:
+ return index.var_idx == -1
+
@classmethod
def of_var(cls, variable: Var, state: State, power: Number =1) -> Self:
return cls(var_idx=state.index(variable), power=power)
@@ -90,17 +98,17 @@ class PolyIndex(tuple[PolyVarIndex]):
Example:
- Suppose there are two variables x, y with indices 0, 1 respectively.
- Then the monomal xy^2 has PolyIndex
+ Suppose there are two variables x, y with indices 0, 1 respectively (in
+ the State object). Then the monomal xy^2 has PolyIndex
- (PolyVarIndex(varindex=0, power=1), PolyVarIndex(varindex=1, power=2)
+ (PolyVarIndex(var_idx=0, power=1), PolyVarIndex(var_idx=1, power=2)
Then given the polynomial
p(x, y) = 3x^2 + 5xy^2
The with the PolyIndex above we can retrieve the coefficient 5 in front
- of xy^2.
+ of xy^2 from the Repr object.
"""
def __repr__(self) -> str:
@@ -112,4 +120,4 @@ class PolyIndex(tuple[PolyVarIndex]):
@property
def constant(cls):
""" Index of the constant term """
- return cls(PolyVarIndex.constant)
+ return cls((PolyVarIndex.constant,))