summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--polymatrix/polymatrix/index.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/polymatrix/polymatrix/index.py b/polymatrix/polymatrix/index.py
index d31e987..c906b35 100644
--- a/polymatrix/polymatrix/index.py
+++ b/polymatrix/polymatrix/index.py
@@ -155,6 +155,12 @@ class PolyDict(UserDict[MonomialIndex, int | float]):
key = MonomialIndex(key)
return super().__setitem__(key, value)
+ def constant(self) -> int | float:
+ """ Get the constant term of the polynomial. """
+ if MonomialIndex.constant() in self:
+ return self[MonomialIndex.constant()]
+ return 0
+
def terms(self) -> Iterable[tuple[MonomialIndex, int | float]]:
""" Iterate over terms with a non-zero coefficient. """
# This is an alias for readability