summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-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 ba9d508..bab991f 100644
--- a/polymatrix/polymatrix/index.py
+++ b/polymatrix/polymatrix/index.py
@@ -201,6 +201,12 @@ class PolyDict(UserDict[MonomialIndex, int | float]):
# This is an alias for readability
yield from self.items()
+ def terms_of_degree(self, d: int) -> Iterable[tuple[MonomialIndex, int | float]]:
+ """ Iterate over terms of degree `d` with a non-zero coefficient. """
+ yield from ((m, coeff)
+ for m, coeff in self.terms()
+ if m.degree == d)
+
def monomials(self) -> Iterable[MonomialIndex]:
""" Get monomials that compose the polynomial. """
# This is an alias for readability