summaryrefslogtreecommitdiffstats
path: root/polymatrix/expression/mixins/additionexprmixin.py
diff options
context:
space:
mode:
Diffstat (limited to 'polymatrix/expression/mixins/additionexprmixin.py')
-rw-r--r--polymatrix/expression/mixins/additionexprmixin.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/polymatrix/expression/mixins/additionexprmixin.py b/polymatrix/expression/mixins/additionexprmixin.py
index c4f3113..20ff5d0 100644
--- a/polymatrix/expression/mixins/additionexprmixin.py
+++ b/polymatrix/expression/mixins/additionexprmixin.py
@@ -1,6 +1,7 @@
import abc
import collections
+import math
import typing
import dataclass_abc
@@ -83,7 +84,11 @@ class AdditionExprMixin(ExpressionBaseMixin):
else:
terms_row_col[monomial] += value
- terms[row, col] = terms_row_col
+ if math.isclose(terms_row_col[monomial], 0):
+ del terms_row_col[monomial]
+
+ if 0 < len(terms_row_col):
+ terms[row, col] = terms_row_col
poly_matrix = init_poly_matrix(
terms=terms,