diff options
-rw-r--r-- | mdpoly/abc.py | 8 | ||||
-rw-r--r-- | mdpoly/algebra.py | 34 |
2 files changed, 21 insertions, 21 deletions
diff --git a/mdpoly/abc.py b/mdpoly/abc.py index 989fa7f..c5fadbe 100644 --- a/mdpoly/abc.py +++ b/mdpoly/abc.py @@ -89,7 +89,7 @@ class Expr(ABC): # --- Magic Methods --- - def __repr__(self): + def __str__(self): name = self.__class__.__qualname__ return f"{name}(left={self.left}, right={self.right})" @@ -278,7 +278,7 @@ class Leaf(Expr): # --- Magic methods --- - def __repr__(self) -> str: + def __str__(self) -> str: return self.name # -- Overloads --- @@ -328,7 +328,7 @@ class Const(Leaf, Generic[T]): def value(self) -> T: """ Value of the constant. """ - def __repr__(self) -> str: + def __str__(self) -> str: if not self.name: return repr(self.value) @@ -355,7 +355,7 @@ class Nothing(Leaf): def to_repr(self, repr_type: Type[ReprT], state: State) -> tuple[ReprT, State]: raise ValueError("Nothing cannot be represented.") - def __repr__(self) -> str: + def __str__(self) -> str: return "Nothing" diff --git a/mdpoly/algebra.py b/mdpoly/algebra.py index b45f0e0..c51113e 100644 --- a/mdpoly/algebra.py +++ b/mdpoly/algebra.py @@ -202,7 +202,7 @@ class PolyRingExpr(Expr): if not isinstance(other, PolyConst | PolyParam): raise AlgebraicError(f"Cannot raise to powers of type {type(other)} in " "polynomial ring. Only constants and parameters are allowed.") - return PolyExp(self, other) + return PolyExp(left=self, right=other) # -- Other mathematical operations --- @@ -210,7 +210,7 @@ class PolyRingExpr(Expr): return PolyPartialDiff(self, wrt) -@dataclassabc(frozen=True, repr=False) +@dataclassabc(frozen=True) class PolyVar(Var, PolyRingExpr): """ Variable TODO: desc """ name: str # overloads Leaf.name @@ -223,7 +223,7 @@ class PolyVar(Var, PolyRingExpr): return r, state -@dataclassabc(frozen=True, repr=False) +@dataclassabc(frozen=True) class PolyConst(Const, PolyRingExpr): """ Constant TODO: desc """ value: Number # overloads Const.value @@ -236,7 +236,7 @@ class PolyConst(Const, PolyRingExpr): return r, state -@dataclassabc(frozen=True, repr=False) +@dataclassabc(frozen=True) class PolyParam(Param, PolyRingExpr): """ Polynomial parameter TODO: desc """ name: str # overloads Leaf.name @@ -270,7 +270,7 @@ class PolyAdd(BinaryOp, PolyRingExpr): return r, state - def __repr__(self) -> str: + def __str__(self) -> str: return f"({self.left} + {self.right})" @@ -281,7 +281,7 @@ class PolySub(BinaryOp, PolyRingExpr, Reducible): """ See :py:meth:`mdpoly.algebra.Reducible.reduce`. """ return self.left + (-1 * self.right) - def __repr__(self) -> str: + def __str__(self) -> str: return f"({self.left} - {self.right})" @@ -310,7 +310,7 @@ class PolyMul(BinaryOp, PolyRingExpr): return r, state - def __repr__(self) -> str: + def __str__(self) -> str: return f"({self.left} * {self.right})" @@ -340,7 +340,7 @@ class PolyExp(BinaryOp, PolyRingExpr, Reducible): ntimes = self.right.value - 1 return reduce(operator.mul, (var for _ in range(ntimes)), var) - def __repr__(self) -> str: + def __str__(self) -> str: return f"({self.left} ** {self.right})" @@ -374,7 +374,7 @@ class PolyPartialDiff(UnaryOp, PolyRingExpr): return r, state - def __repr__(self) -> str: + def __str__(self) -> str: return f"(∂_{self.wrt} {self.inner})" def replace(self, old: PolyRingExpr, new: PolyRingExpr) -> Self: @@ -500,7 +500,7 @@ class MatConst(Const, MatrixExpr): return r, state - def __repr__(self) -> str: + def __str__(self) -> str: if not self.name: return repr(self.value) @@ -535,7 +535,7 @@ class MatVar(Var, MatrixExpr): return r, state - def __repr__(self) -> str: + def __str__(self) -> str: return self.name @@ -554,7 +554,7 @@ class MatParam(Param, MatrixExpr): # Ignore typecheck because dataclassabc has not type stub return MatConst(state.parameters[self]).to_repr(repr_type, state) # type: ignore[call-arg] - def __repr__(self) -> str: + def __str__(self) -> str: return self.name @@ -587,7 +587,7 @@ class MatAdd(BinaryOp, MatrixExpr): return r, state - def __repr__(self) -> str: + def __str__(self) -> str: return f"({self.left} + {self.right})" @@ -606,7 +606,7 @@ class MatSub(BinaryOp, MatrixExpr, Reducible): """ See :py:meth:`mdpoly.algebra.Reducible.reduce`. """ return self.left + (-1 * self.right) - def __repr__(self) -> str: + def __str__(self) -> str: return f"({self.left} - {self.right})" @@ -644,7 +644,7 @@ class MatElemMul(BinaryOp, MatrixExpr): return r, state - def __repr__(self) -> str: + def __str__(self) -> str: return f"({self.left} .* {self.right})" @@ -680,7 +680,7 @@ class MatScalarMul(BinaryOp, MatrixExpr): return r, state - def __repr__(self) -> str: + def __str__(self) -> str: return f"({self.left} * {self.right})" @@ -714,7 +714,7 @@ class MatMul(BinaryOp, MatrixExpr): return Shape(self.left.shape.rows, self.right.shape.cols) - def __repr__(self) -> str: + def __str__(self) -> str: return f"({self.left} @ {self.right})" |