diff options
-rw-r--r-- | polymatrix/expression/mixins/expressionmixin.py | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/polymatrix/expression/mixins/expressionmixin.py b/polymatrix/expression/mixins/expressionmixin.py index 622db34..22702ca 100644 --- a/polymatrix/expression/mixins/expressionmixin.py +++ b/polymatrix/expression/mixins/expressionmixin.py @@ -14,6 +14,8 @@ from polymatrix.expression.init.initdivisionexpr import init_division_expr from polymatrix.expression.init.initelemmultexpr import init_elem_mult_expr from polymatrix.expression.init.initevalexpr import init_eval_expr from polymatrix.expression.init.initfilterexpr import init_filter_expr +from polymatrix.expression.init.initfromsymmetricmatrixexpr import init_from_symmetric_matrix_expr +from polymatrix.expression.init.inithalfnewtonpolytopeexpr import init_half_newton_polytope_expr from polymatrix.expression.init.initlinearinexpr import init_linear_in_expr from polymatrix.expression.init.initfromsympyexpr import init_from_sympy_expr from polymatrix.expression.init.initgetitemexpr import init_get_item_expr @@ -23,6 +25,7 @@ from polymatrix.expression.init.initmatrixmultexpr import init_matrix_mult_expr from polymatrix.expression.init.initmaxdegreeexpr import init_max_degree_expr from polymatrix.expression.init.initmaxexpr import init_max_expr from polymatrix.expression.init.initparametrizeexpr import init_parametrize_expr +from polymatrix.expression.init.initparametrizematrixexpr import init_parametrize_matrix_expr from polymatrix.expression.init.initquadraticinexpr import init_quadratic_in_expr from polymatrix.expression.init.initrepmatexpr import init_rep_mat_expr from polymatrix.expression.init.initreshapeexpr import init_reshape_expr @@ -37,6 +40,7 @@ from polymatrix.expression.init.inittoconstantexpr import init_to_constant_expr from polymatrix.expression.init.inittoquadraticexpr import init_to_quadratic_expr from polymatrix.expression.init.initdiagexpr import init_diag_expr from polymatrix.expression.init.inittosortedvariables import init_to_sorted_variables +from polymatrix.expression.init.inittosymmetricmatrixexpr import init_to_symmetric_matrix_expr from polymatrix.expression.init.inittransposeexpr import init_transpose_expr from polymatrix.expression.init.inittruncateexpr import init_truncate_expr @@ -142,6 +146,9 @@ class ExpressionMixin( return self + other * (-1) def __truediv__(self, other: ExpressionBaseMixin): + if isinstance(other, (int, float)): + return self * (1/other) + right = self._convert_to_expression(other) return dataclasses.replace( @@ -199,7 +206,7 @@ class ExpressionMixin( def diff( self, - variables: tuple, + variables: 'ExpressionMixin', introduce_derivatives: bool = None, ) -> 'ExpressionMixin': return dataclasses.replace( @@ -251,6 +258,28 @@ class ExpressionMixin( ), ) + def from_symmetric_matrix(self) -> 'ExpressionMixin': + return dataclasses.replace( + self, + underlying=init_from_symmetric_matrix_expr( + underlying=self.underlying, + ), + ) + + def half_newton_polytope( + self, + variables: 'ExpressionMixin', + filter: 'ExpressionMixin | None' = None, + ) -> 'ExpressionMixin': + return dataclasses.replace( + self, + underlying=init_half_newton_polytope_expr( + monomials=self.underlying, + variables=variables, + filter=filter, + ), + ) + def linear_matrix_in(self, variable: 'ExpressionMixin') -> 'ExpressionMixin': return dataclasses.replace( self, @@ -312,6 +341,15 @@ class ExpressionMixin( name=name, ), ) + + # def parametrize_matrix(self, name: str = None) -> 'ExpressionMixin': + # return dataclasses.replace( + # self, + # underlying=init_parametrize_matrix_expr( + # underlying=self.underlying, + # name=name, + # ), + # ) def quadratic_in(self, variables: 'ExpressionMixin', monomials: 'ExpressionMixin' = None) -> 'ExpressionMixin': if monomials is None: @@ -328,7 +366,7 @@ class ExpressionMixin( def quadratic_monomials( self, - variables: tuple, + variables: 'ExpressionMixin', ) -> 'ExpressionMixin': return dataclasses.replace( self, @@ -463,6 +501,14 @@ class ExpressionMixin( # ), # ) + def to_symmetric_matrix(self) -> 'ExpressionMixin': + return dataclasses.replace( + self, + underlying=init_to_symmetric_matrix_expr( + underlying=self.underlying, + ), + ) + def to_sorted_variables(self) -> 'ExpressionMixin': return dataclasses.replace( self, |