From b42eace0775459a08e6d383f70ee3789b726a0c6 Mon Sep 17 00:00:00 2001 From: Michael Schneeberger Date: Mon, 16 Oct 2023 13:26:42 +0200 Subject: do not delete position when substracting monomials --- polymatrix/expression/mixins/quadraticinexprmixin.py | 7 ++++++- polymatrix/expression/mixins/subtractmonomialsexprmixin.py | 3 ++- 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 -- cgit v1.2.1