diff options
Diffstat (limited to '')
-rw-r--r-- | mdpoly/algebra.py | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/mdpoly/algebra.py b/mdpoly/algebra.py index a2d2325..3328d19 100644 --- a/mdpoly/algebra.py +++ b/mdpoly/algebra.py @@ -73,11 +73,7 @@ class AlgebraicStructure(Protocol): # f"objects with different shapes {cls.shape} and {other.shape}") -class ExprWithRepr(Expr, HasRepr, Protocol): - """ Expression that has a representation """ - - -class ReducibleExpr(ExprWithRepr, Protocol): +class ReducibleExpr(Expr, Protocol): """ Reducible Expression Algebraic expression that can be written in terms of other (existing) @@ -91,10 +87,11 @@ class ReducibleExpr(ExprWithRepr, Protocol): return self.reduce().to_repr(repr_type, state) @abstractmethod - def reduce(self) -> ExprWithRepr: + def reduce(self) -> HasRepr: """ Reduce the expression to its basic elements """ +# FIXME: The type checker really hates this trick, what is a better solution? def binary_operator(left_type: AlgebraicStructure, right_type: AlgebraicStructure): """ Class decorator that adds constructor for binary operations of Expr. @@ -129,6 +126,7 @@ def binary_operator(left_type: AlgebraicStructure, right_type: AlgebraicStructur return decorator +# FIXME: same as binary_operator def unary_operator(inner_type: AlgebraicStructure): """ Class decorator that adss constructor for unary operations of Expr @@ -197,7 +195,7 @@ class Sub(ReducibleExpr): raise InvalidShape(f"Cannot add shapes {self.left.shape} and {self.right.shape}.") return self.left.shape - def reduce(self) -> ExprWithRepr: + def reduce(self) -> HasRepr: """ See :py:meth:`mdpoly.algebra.ReducibleExpr.reduce`. """ # return self.left + (-1 * self.right) return Add(self.left, Mul(Const(value=-1), self.right)) @@ -252,7 +250,7 @@ class Exp(ReducibleExpr): raise InvalidShape(f"Cannot add shapes {self.left.shape} and {self.right.shape}.") return self.left.shape - def reduce(self) -> ExprWithRepr: + def reduce(self) -> HasRepr: """ See :py:meth:`mdpoly.algebra.ReducibleExpr.reduce`. """ var = self.left ntimes = self.right.value - 1 @@ -337,7 +335,7 @@ class PolyMul(Mul, PolyRingAlgebra): class PolyDiv(ReducibleExpr, PolyRingAlgebra): """ Division of scalar polynomial by scalar. """ - def reduce(self) -> ExprWithRepr: + def reduce(self) -> HasRepr: """ See :py:meth:`mdpoly.algebra.ReducibleExpr.reduce`. """ inverse = self._constant(value=1/self.right.value) return PolyMul(inverse, self.left) |