diff options
Diffstat (limited to '')
-rw-r--r-- | polymatrix/polymatrix/index.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/polymatrix/polymatrix/index.py b/polymatrix/polymatrix/index.py index c906b35..e50df43 100644 --- a/polymatrix/polymatrix/index.py +++ b/polymatrix/polymatrix/index.py @@ -161,6 +161,20 @@ class PolyDict(UserDict[MonomialIndex, int | float]): return self[MonomialIndex.constant()] return 0 + def is_constant(self) -> bool: + """ + Check whether the polynomial is a constant polynomial. + """ + # polynomial is zero + if len(self.keys()) == 0: + return True + + if len(self.keys()) > 1: + return False + + m, *_ = self.keys() + return MonomialIndex.is_constant(m) + def terms(self) -> Iterable[tuple[MonomialIndex, int | float]]: """ Iterate over terms with a non-zero coefficient. """ # This is an alias for readability |