summaryrefslogtreecommitdiffstats
path: root/polymatrix/expression/mixins/namedexprmixin.py
blob: e6d72846893066f2d1954f5774bffb3f2a26b3b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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)