summaryrefslogtreecommitdiffstats
path: root/sumofsquares/sosexprbase/mixins/sosexprbasemixin.py
blob: e9eabacad247cca8e65935d98ca3b76d61c994e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import functools
import polymatrix

from sumofsquares.sosexprbase.mixins.exprbasemixin import ExprBaseMixin


class SOSExprBaseMixin(ExprBaseMixin):
    @functools.cached_property
    def sos_monom(self) -> polymatrix.Expression:
        return self.expr.quadratic_monomials(self.variables).cache()

    @functools.cached_property
    def sos_matrix(self) -> polymatrix.Expression:
        sos_matrix = self.expr.quadratic_in(
            variables=self.variables, 
            monomials=self.sos_monom,
        ).symmetric().cache()

        return sos_matrix

    @property
    def sos_matrix_vec(self) -> polymatrix.Expression:
        return self.sos_matrix.reshape(-1, 1)