summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Schneeberger <michael.schneeberger@fhnw.ch>2023-10-16 13:26:42 +0200
committerMichael Schneeberger <michael.schneeberger@fhnw.ch>2023-10-16 13:26:42 +0200
commitb42eace0775459a08e6d383f70ee3789b726a0c6 (patch)
tree897d1543699eca26b7a1061adb98e2e27363256b
parentupdate links in README (diff)
downloadpolymatrix-b42eace0775459a08e6d383f70ee3789b726a0c6.tar.gz
polymatrix-b42eace0775459a08e6d383f70ee3789b726a0c6.zip
do not delete position when substracting monomials
-rw-r--r--polymatrix/expression/mixins/quadraticinexprmixin.py7
-rw-r--r--polymatrix/expression/mixins/subtractmonomialsexprmixin.py3
2 files changed, 8 insertions, 2 deletions
diff --git a/polymatrix/expression/mixins/quadraticinexprmixin.py b/polymatrix/expression/mixins/quadraticinexprmixin.py
index 4568286..2b23827 100644
--- a/polymatrix/expression/mixins/quadraticinexprmixin.py
+++ b/polymatrix/expression/mixins/quadraticinexprmixin.py
@@ -41,7 +41,12 @@ class QuadraticInExprMixin(ExpressionBaseMixin):
terms = collections.defaultdict(lambda: collections.defaultdict(float))
- for monomial, value in underlying.get_poly(0, 0).items():
+ underlying_poly = underlying.get_poly(0, 0)
+
+ if underlying_poly is None:
+ raise Exception(f'{self.underlying} is empty')
+
+ for monomial, value in underlying_poly.items():
x_monomial = tuple((var_idx, count) for var_idx, count in monomial if var_idx in variable_indices)
p_monomial = tuple((var_idx, count) for var_idx, count in monomial if var_idx not in variable_indices)
diff --git a/polymatrix/expression/mixins/subtractmonomialsexprmixin.py b/polymatrix/expression/mixins/subtractmonomialsexprmixin.py
index d5091c6..09f71b1 100644
--- a/polymatrix/expression/mixins/subtractmonomialsexprmixin.py
+++ b/polymatrix/expression/mixins/subtractmonomialsexprmixin.py
@@ -37,7 +37,8 @@ class SubtractMonomialsExprMixin(ExpressionBaseMixin):
try:
remainder = subtract_monomial_indices(m1, m2)
except SubtractError:
- continue
+ # continue
+ remainder = tuple()
yield remainder