summaryrefslogtreecommitdiffstats
path: root/polymatrix/expression/mixins/namedexprmixin.py
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2024-05-27 12:24:10 +0200
committerNao Pross <np@0hm.ch>2024-05-27 12:24:10 +0200
commitd30823453e22d6bb53521997708c5903990492f9 (patch)
treec01ede0aef823f6e5be6084cca50db8d53a892ba /polymatrix/expression/mixins/namedexprmixin.py
parentFix pretty printing of PolyMatrix objects (diff)
downloadpolymatrix-d30823453e22d6bb53521997708c5903990492f9.tar.gz
polymatrix-d30823453e22d6bb53521997708c5903990492f9.zip
Create NamedExpr and polymatrix.give_name to give shorter names to expressions
Diffstat (limited to 'polymatrix/expression/mixins/namedexprmixin.py')
-rw-r--r--polymatrix/expression/mixins/namedexprmixin.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/polymatrix/expression/mixins/namedexprmixin.py b/polymatrix/expression/mixins/namedexprmixin.py
new file mode 100644
index 0000000..e6d7284
--- /dev/null
+++ b/polymatrix/expression/mixins/namedexprmixin.py
@@ -0,0 +1,32 @@
+from __future__ import annotations
+
+from abc import abstractmethod
+from typing_extensions import override
+
+from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
+from polymatrix.expressionstate import ExpressionState
+from polymatrix.polymatrix.index import PolyDict, MonomialIndex
+from polymatrix.polymatrix.init import init_broadcast_poly_matrix
+from polymatrix.polymatrix.mixins import PolyMatrixMixin
+
+class NamedExprMixin(ExpressionBaseMixin):
+ """
+ Give a name to an expression.
+
+ This is mostly to make the printing more understandable.
+ See also NamedExprImpl.__str__.
+ """
+
+ @property
+ @abstractmethod
+ def underlying(self) -> ExpressionBaseMixin:
+ """ The expresssion """
+
+ @property
+ @abstractmethod
+ def name(self) -> str:
+ """ The name for the expression """
+
+ @override
+ def apply(self, state: ExpressionState) -> tuple[ExpressionState, PolyMatrixMixin]:
+ return self.underlying.apply(state)