summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--polymatrix/polymatrix/index.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/polymatrix/polymatrix/index.py b/polymatrix/polymatrix/index.py
index 83eccf5..ba9d508 100644
--- a/polymatrix/polymatrix/index.py
+++ b/polymatrix/polymatrix/index.py
@@ -53,6 +53,9 @@ class MonomialIndex(tuple[VariableIndex]):
return "MonomialIndex(" + ",".join(repr(v) for v in self) + ")"
def __str__(self):
+ if len(self) == 0:
+ return ""
+
return " * ".join(str(v) for v in sorted(self))
@property
@@ -164,7 +167,9 @@ class PolyDict(UserDict[MonomialIndex, int | float]):
return f"{self.__class__.__qualname__}({super().__repr__()})"
def __str__(self) -> str:
- return " + ".join(f"{str(c)} * {str(m)}" for m, c in self.items())
+ return " + ".join(f"{str(c)} * {str(m)}"
+ if len(m) > 0 else f"{str(c)}"
+ for m, c in self.items())
def __setitem__(self, key: Iterable[VariableIndex] | MonomialIndex, value: int | float):
if not isinstance(key, MonomialIndex):