aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--mdpoly/abc.py23
-rw-r--r--mdpoly/algebra.py2
2 files changed, 15 insertions, 10 deletions
diff --git a/mdpoly/abc.py b/mdpoly/abc.py
index c503029..811910b 100644
--- a/mdpoly/abc.py
+++ b/mdpoly/abc.py
@@ -4,21 +4,26 @@ from .types import Number, Shape, MatrixIndex, PolyIndex
from .constants import NUMERICS_EPS
from .util import iszero
-from typing import Self, Iterable, Sequence, Protocol, runtime_checkable
-from abc import abstractmethod
+from typing import Self, Iterable, Sequence, Protocol
+from abc import ABC, abstractmethod
-@runtime_checkable
-class Leaf(Protocol):
+class Leaf(ABC):
""" Leaf of the binary tree. """
name: str
shape: Shape
-class Expr(Protocol):
+class Expr(ABC):
""" Binary tree to represent a mathematical expression. """
- left: Self | Leaf
- right: Self | Leaf
+
+ @property
+ @abstractmethod
+ def left(self) -> Self | Leaf: ...
+
+ @property
+ @abstractmethod
+ def right(self) -> Self | Leaf: ...
@property
@abstractmethod
@@ -97,13 +102,13 @@ class Expr(Protocol):
yield from self.children()
-class Rel(Protocol):
+class Rel(ABC):
""" Relation between two expressions. """
lhs: Expr
rhs: Expr
-class Repr(Protocol):
+class Repr(ABC):
r""" Representation of a multivariate matrix polynomial expression.
Concretely, a representation must be able to store a mathematical object
diff --git a/mdpoly/algebra.py b/mdpoly/algebra.py
index 670b537..abd15d5 100644
--- a/mdpoly/algebra.py
+++ b/mdpoly/algebra.py
@@ -73,7 +73,7 @@ class AlgebraicStructure(Protocol):
# f"objects with different shapes {cls.shape} and {other.shape}")
-class ReducibleExpr(Expr, Protocol):
+class ReducibleExpr(HasRepr, Protocol):
""" Reducible Expression
Algebraic expression that can be written in terms of other (existing)