summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2024-06-15 18:24:57 +0200
committerNao Pross <np@0hm.ch>2024-06-15 18:24:57 +0200
commitf96229f1a2bd2e61cd9d7993f08e6d7c291331df (patch)
tree8471d6aa1d7dd73cb263cc240155f82726c34476
parentFix bug in NegationExpr, typo in AffineExpression (diff)
downloadpolymatrix-f96229f1a2bd2e61cd9d7993f08e6d7c291331df.tar.gz
polymatrix-f96229f1a2bd2e61cd9d7993f08e6d7c291331df.zip
Fix bug in MonomialIndex.__lt__
Diffstat (limited to '')
-rw-r--r--polymatrix/polymatrix/index.py16
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