diff options
-rw-r--r-- | polymatrix/polymatrix/index.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/polymatrix/polymatrix/index.py b/polymatrix/polymatrix/index.py index c68e23f..fd2a759 100644 --- a/polymatrix/polymatrix/index.py +++ b/polymatrix/polymatrix/index.py @@ -74,10 +74,16 @@ class MonomialIndex(tuple[VariableIndex]): # they have the same degree the index counts if self.degree == other.degree: # Assumes that monomialindex is sorted! - # if the first variable is also the same continue until one - # finishes or the values differ. - # FIXME: check that return value is not none - s, o = next(dropwhile(lambda t: t[0] == t[1], zip(self, other))) + def expand(m): + for v in m: + for _ in range(v.power): + yield v + + def same_index(t): + s, o = t + return s.index == o.index + + s, o = next(dropwhile(same_index, zip(expand(self), expand(other)))) return s < o return self.degree < other.degree @@ -231,7 +237,7 @@ class PolyDict(UserDict[MonomialIndex, int | float]): p = PolyDict.empty() for (lm, lv), (rm, rv) in product(left.items(), right.items()): - pv = lv + rv + pv = lv * rv if math.isclose(pv, 0): continue |