Difference between revisions of "PolynomialAsMatrix"

From QETLAB
Jump to navigation Jump to search
(Started page)
 
(now CVX-friendly)
 
(7 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
|name=PolynomialAsMatrix
 
|name=PolynomialAsMatrix
 
|desc=Creates a compact fully symmetric matrix representation of a polynomial
 
|desc=Creates a compact fully symmetric matrix representation of a polynomial
|rel=[[PolynomialOptimize]]<br />[[PolynomialSOS]]
+
|rel=[[CopositivePolynomial]]<br />[[PolynomialOptimize]]<br />[[PolynomialSOS]]
 
|cat=[[List of functions#Polynomial_optimization|Polynomial optimization]]
 
|cat=[[List of functions#Polynomial_optimization|Polynomial optimization]]
|upd=July 31, 2023
+
|upd=August 5, 2023
|cvx=no}}
+
|cvx=yes}}
<tt>'''PolynomialAsMatrix'''</tt> is a [[List of functions|function]] that computes a compact form of a fully symmetric matrix representation of an even-degree homogeneous polynomial. More specifically, if p is a homogeneous polynomial of degree 2d then there is a unique fully symmetric matrix <math>M</math> with the property that <math>p(x_1,x_2,\ldots,x_n) = (\mathbf{x}^{\otimes d})^T M(\mathbf{x}^{\otimes d})</math>, where <math>\mathbf{x} = (x_1,x_2,\ldots,x_n)</math> as a column vector. Here, "fully symmetric" means that <math>M^T = M</math>, <math>M</math> is supported on the [[symmetric subspace]] (i.e., <math>PMP = M</math>, where <math>P</math> is the [[symmetric projection|SymmetricProjection]]), and <math>M</math> equals its own [[partial transpose|PartialTranspose]] (across any bipartition).
+
<tt>'''PolynomialAsMatrix'''</tt> is a [[List of functions|function]] that computes a compact form of a fully symmetric matrix representation of an even-degree homogeneous polynomial. More specifically, if p is a homogeneous polynomial of degree 2d then there is a unique fully symmetric matrix <math>M</math> with the property that <math>p(x_1,x_2,\ldots,x_n) = (\mathbf{x}^{\otimes d})^T M(\mathbf{x}^{\otimes d})</math>, where <math>\mathbf{x} = (x_1,x_2,\ldots,x_n)</math> as a column vector. Here, "fully symmetric" means that <math>M^T = M</math>, <math>M</math> is supported on the [[symmetric subspace]] (i.e., <math>PMP = M</math>, where <math>P</math> is the [[SymmetricProjection|symmetric projection]]), and <math>M</math> equals its own [[PartialTranspose|partial transpose]] (across any bipartition).
  
This function returns this fully symmetric matrix <math>M</math>, in symmetric coordinates. That is, there is an isometry <math>V</math> from the symmetric subspace of <math>(\mathbb{C}^n)^{\otimes d}</math> to <math>(\mathbb{C}^n)^{\otimes d}</math> itself with the property that the output of this function equals <math>V^*MV</math>.
+
This function returns this fully symmetric matrix <math>M</math>, in symmetric coordinates. That is, there is an isometry <math>V</math> from the symmetric subspace of <math>(\mathbb{C}^n)^{\otimes d}</math> to <math>(\mathbb{C}^n)^{\otimes d}</math> itself with the property that the output of this function equals <math>V^*MV</math>. This isometry <math>V</math> is computed by <tt>[[SymmetricProjection]](N,D,1,0)</tt>.
  
 
==Syntax==
 
==Syntax==
* Coming soon.
+
* <tt>M = PolynomialAsMatrix(P,N,D)</tt>
 +
* <tt>M = PolynomialAsMatrix(P,N,D,K)</tt>
  
 
==Argument descriptions==
 
==Argument descriptions==
* Coming soon.
+
* <tt>P</tt>: The polynomial, represented as a vector of coefficients of its monomials in lexicographic order.
 +
* <tt>N</tt>: The number of variables in the polynomial.
 +
* <tt>D</tt>: Half the degree of the polynomial.
 +
* <tt>K</tt> (optional, default 0): A non-negative integer that indicates the level of the SOS or SOS-type hierarchy. More specifically, this input argument causes the output matrix to represent the polynomial (S(x))^K * P(x) instead of P(x) itself, where S(x) = x1^2 + x2^2 + ... + xN^2.
  
 
==Examples==
 
==Examples==
Coming soon.
+
===A simple low-degree polynomial===
 +
Let's turn the homogeneous polynomial <math>p(x,y,z) = x^2 + 2xy + 3xz + 4y^2 + 5yz + 6z^2</math> into its fully symmetric matrix representation.
 +
<syntaxhighlight>
 +
>> n = 3;% number of variables
 +
>> d = 1;% half the degree of the polynomial
 +
>> p = [1;2;3;4;5;6];% coefficients of the polynomial, in lexicographical order of the monomials
 +
>> M = full(PolynomialAsMatrix(p,n,d))
 +
 
 +
M =
 +
 
 +
    1.0000    1.0000    1.5000
 +
    1.0000    4.0000    2.5000
 +
    1.5000    2.5000    6.0000
 +
</syntaxhighlight>
 +
The output of this function is always sparse, so we used the <tt>full</tt> function around the output above just to make the output easier to see. Since <math>d = 1</math>, the above matrix is the usual symmetric matrix representation of the quadratric form <math>p</math>. The following verification of this fact requires MATLAB's symbolic toolbox:
 +
<syntaxhighlight>
 +
>> syms x y z
 +
>> expand([x y z]*M*[x;y;z])
 +
 +
ans =
 +
 +
x^2 + 2*x*y + 3*x*z + 4*y^2 + 5*y*z + 6*z^2
 +
</syntaxhighlight>
 +
 
 +
===The Motzkin polynomial===
 +
The Motzkin polynomial is the following degree-6 homogeneous polynomial: <math>p(x,y,z) = x^4y^2 + x^2y^4 - 3x^2y^2z^2 + z^6</math>. To use this <tt>PolynomialAsMatrix</tt> function, we have to first arrange the monomials of p (even the ones with coefficient 0) in lexicographical order and list them in a vector. To make this task (much!) easier, we use the <tt>[[exp2ind]]</tt> helper function:
 +
<syntaxhighlight>
 +
>> n = 3;% number of variables
 +
>> d = 3;% half the degree of the polynomial
 +
>> p = zeros(nchoosek(n+2*d-1,2*d),1);% initialize p to have the correct size
 +
>> p(exp2ind([4 2 0])) = 1;% the "4 2 0" here are the exponents in the term x^4y^2z^0, while the "1" is the coefficient of this term
 +
>> p(exp2ind([2 4 0])) = 1;
 +
>> p(exp2ind([2 2 2])) = -3;
 +
>> p(exp2ind([0 0 6])) = 1;% now p represents the Motzkin polynomial
 +
>> M = full(PolynomialAsMatrix(p,n,d))
 +
 
 +
M =
 +
 
 +
        0        0        0    0.1155        0        0        0        0        0        0
 +
        0    0.2000        0        0        0        0    0.1155        0  -0.1000        0
 +
        0        0        0        0        0        0        0  -0.1000        0        0
 +
    0.1155        0        0    0.2000        0  -0.1000        0        0        0        0
 +
        0        0        0        0  -0.2000        0        0        0        0        0
 +
        0        0        0  -0.1000        0        0        0        0        0        0
 +
        0    0.1155        0        0        0        0        0        0        0        0
 +
        0        0  -0.1000        0        0        0        0        0        0        0
 +
        0  -0.1000        0        0        0        0        0        0        0        0
 +
        0        0        0        0        0        0        0        0        0    1.0000
 +
</syntaxhighlight>
 +
 
 +
The output of this function is always sparse, so we used the <tt>full</tt> function around the output above just to make the output easier to see. When <math>d > 1</math> (like in this example), we can verify that the above matrix represents the given polynomial via the isometry created by the [[SymmetricProjection]] function. The following verification of this fact requires MATLAB's symbolic toolbox:
 +
<syntaxhighlight>
 +
>> P = SymmetricProjection(n,d,1,0);
 +
>> MF = P*M*P';
 +
>> syms x y z
 +
>> v = [x;y;z];
 +
>> expand(Tensor(v,3).'*MF*Tensor(v,3))
 +
 +
ans =
 +
 +
x^4*y^2 + x^2*y^4 - 3*x^2*y^2*z^2 + z^6
 +
</syntaxhighlight>
  
 
{{SourceCode|name=PolynomialAsMatrix}}
 
{{SourceCode|name=PolynomialAsMatrix}}

Latest revision as of 17:52, 5 August 2023

PolynomialAsMatrix
Creates a compact fully symmetric matrix representation of a polynomial

Other toolboxes required none
Related functions CopositivePolynomial
PolynomialOptimize
PolynomialSOS
Function category Polynomial optimization
Usable within CVX? yes

PolynomialAsMatrix is a function that computes a compact form of a fully symmetric matrix representation of an even-degree homogeneous polynomial. More specifically, if p is a homogeneous polynomial of degree 2d then there is a unique fully symmetric matrix \(M\) with the property that \(p(x_1,x_2,\ldots,x_n) = (\mathbf{x}^{\otimes d})^T M(\mathbf{x}^{\otimes d})\), where \(\mathbf{x} = (x_1,x_2,\ldots,x_n)\) as a column vector. Here, "fully symmetric" means that \(M^T = M\), \(M\) is supported on the symmetric subspace (i.e., \(PMP = M\), where \(P\) is the symmetric projection), and \(M\) equals its own partial transpose (across any bipartition).

This function returns this fully symmetric matrix \(M\), in symmetric coordinates. That is, there is an isometry \(V\) from the symmetric subspace of \((\mathbb{C}^n)^{\otimes d}\) to \((\mathbb{C}^n)^{\otimes d}\) itself with the property that the output of this function equals \(V^*MV\). This isometry \(V\) is computed by SymmetricProjection(N,D,1,0).

Syntax

  • M = PolynomialAsMatrix(P,N,D)
  • M = PolynomialAsMatrix(P,N,D,K)

Argument descriptions

  • P: The polynomial, represented as a vector of coefficients of its monomials in lexicographic order.
  • N: The number of variables in the polynomial.
  • D: Half the degree of the polynomial.
  • K (optional, default 0): A non-negative integer that indicates the level of the SOS or SOS-type hierarchy. More specifically, this input argument causes the output matrix to represent the polynomial (S(x))^K * P(x) instead of P(x) itself, where S(x) = x1^2 + x2^2 + ... + xN^2.

Examples

A simple low-degree polynomial

Let's turn the homogeneous polynomial \(p(x,y,z) = x^2 + 2xy + 3xz + 4y^2 + 5yz + 6z^2\) into its fully symmetric matrix representation.

>> n = 3;% number of variables
>> d = 1;% half the degree of the polynomial
>> p = [1;2;3;4;5;6];% coefficients of the polynomial, in lexicographical order of the monomials
>> M = full(PolynomialAsMatrix(p,n,d))

M =

    1.0000    1.0000    1.5000
    1.0000    4.0000    2.5000
    1.5000    2.5000    6.0000

The output of this function is always sparse, so we used the full function around the output above just to make the output easier to see. Since \(d = 1\), the above matrix is the usual symmetric matrix representation of the quadratric form \(p\). The following verification of this fact requires MATLAB's symbolic toolbox:

>> syms x y z
>> expand([x y z]*M*[x;y;z])
 
ans =
 
x^2 + 2*x*y + 3*x*z + 4*y^2 + 5*y*z + 6*z^2

The Motzkin polynomial

The Motzkin polynomial is the following degree-6 homogeneous polynomial\[p(x,y,z) = x^4y^2 + x^2y^4 - 3x^2y^2z^2 + z^6\]. To use this PolynomialAsMatrix function, we have to first arrange the monomials of p (even the ones with coefficient 0) in lexicographical order and list them in a vector. To make this task (much!) easier, we use the exp2ind helper function:

>> n = 3;% number of variables
>> d = 3;% half the degree of the polynomial
>> p = zeros(nchoosek(n+2*d-1,2*d),1);% initialize p to have the correct size
>> p(exp2ind([4 2 0])) = 1;% the "4 2 0" here are the exponents in the term x^4y^2z^0, while the "1" is the coefficient of this term
>> p(exp2ind([2 4 0])) = 1;
>> p(exp2ind([2 2 2])) = -3;
>> p(exp2ind([0 0 6])) = 1;% now p represents the Motzkin polynomial
>> M = full(PolynomialAsMatrix(p,n,d))

M =

         0         0         0    0.1155         0         0         0         0         0         0
         0    0.2000         0         0         0         0    0.1155         0   -0.1000         0
         0         0         0         0         0         0         0   -0.1000         0         0
    0.1155         0         0    0.2000         0   -0.1000         0         0         0         0
         0         0         0         0   -0.2000         0         0         0         0         0
         0         0         0   -0.1000         0         0         0         0         0         0
         0    0.1155         0         0         0         0         0         0         0         0
         0         0   -0.1000         0         0         0         0         0         0         0
         0   -0.1000         0         0         0         0         0         0         0         0
         0         0         0         0         0         0         0         0         0    1.0000

The output of this function is always sparse, so we used the full function around the output above just to make the output easier to see. When \(d > 1\) (like in this example), we can verify that the above matrix represents the given polynomial via the isometry created by the SymmetricProjection function. The following verification of this fact requires MATLAB's symbolic toolbox:

>> P = SymmetricProjection(n,d,1,0);
>> MF = P*M*P';
>> syms x y z
>> v = [x;y;z];
>> expand(Tensor(v,3).'*MF*Tensor(v,3))
 
ans =
 
x^4*y^2 + x^2*y^4 - 3*x^2*y^2*z^2 + z^6

Source code

Click here to view this function's source code on github.

References

Coming soon.