Skip to content

Polynomials

Torbjørn Cunis edited this page Mar 10, 2025 · 4 revisions

Notation

A polynomial $p$ is a finite linear combination of monomials, that is

$$p = \sum_{\alpha}c_{\alpha}x^{\alpha} = \sum_{\alpha} c_{\alpha}x_1^{\alpha_1} \dots x_n^{\alpha_n} ~~~ c_{\alpha}\in \mathbb{R}$$

where $\alpha = (\alpha_1, \dots, \alpha_n)$ is an $n$-tuple and $c_{\alpha}$ is the monomial coefficient. Therefore, to define one examplary monomial

$$m_{\alpha}(x) = c_{\alpha} x^{\alpha} = 3x_1^2x_2^4$$

we need the tuple $\alpha = (2, 4)$ and the coefficient $c_{\alpha}=3$.

Note

We call this multi-index notation

Indeterminate variables

CaΣoS distinguishes between indeterminate variables (symbols in a polynomial sense) and symbolic variables (variables in an optimization sense).

If for example, we want to solve the optimization problem

$$\begin{equation} \begin{aligned} \min_{t} \quad & -t \\\ \textrm{s.t.} \quad & \forall x, \, x^4 + 10x \geq t\\\ \end{aligned} \end{equation}$$

then $x$ is an indeterminate variable (of the polynomial $x^4 + 10x$) while $t$ is an decision variable.

Note

Polynomials of type casos.PS can have symbolic coefficients that can be used as decision variables in polynomial optimization.

Syntax for indeterminate variables

casos.Indeterminates('x',n)
casos.Indeterminates('x','y',...)

creates a tupel of n indeterminate variables; in the second case, n corresponds to the number of arguments.

Tupels of indeterminate variables can be converted into polynomials that correspond to vectors of indeterminate variables, and vice-versa.

Indeterminate variables in (polynomial) expressions

Moreover, indeterminate variables can be used in algebraic expressions to define polynomials with constant or symbolic coefficients, e.g.,

f = [-x(2); x(1) + (x(1)^2 - 1)*x(2)]
u = K*x

if x is a tuple of indeterminate variables and K is a double, casadi.DM, or casadi.SX matrix of suitable dimensions.

Polynomials in CaΣoS

The classes casos.PD and casos.PS implement polynomials of which the coefficients are constant doubles or can be symbolic expressions, respectively.

In the following we will introduce the syntax to define different polynomials.

Polynomials of degree 0

Polynomials of degree zero correspond to constant or symbolic expressions without indeterminate variables. They can be constant matrices where the coefficients are double such as

$$p_1(x) = \begin{bmatrix} 4 & 3 \\ 1 & 0 \end{bmatrix}$$
p1 = casos.PD([4 3; 1 0])

or constant symbolic matrices such as

$$p_2(x) = \begin{bmatrix} a_1 && a_4 \\ a_5 && a_4 \\ a_3 && a_6 \end{bmatrix}$$
p2 = casos.PS.sym('a',[2,3])

These expressions corresponds to the double or casadi.DMor casadi.SX matrix M.

The following syntaxes for constant matrices are also supported by casos.PS:

casos.PD(m,n)
casos.PD.zeros(m,n)
casos.PD.zeros(n)

creates a zero-degree polynomial which corresponds to a m × n matrix (resp., a column vector with length n) of zeros.

Similarly,

casos.PD.ones(m,n)
casos.PD.ones(n)

creates a zero-degree polynomial which corresponds to a m × n matrix (resp., a column vector with length n) of ones.

casos.PD.eye(n)

creates a zero-degree polynomial which corresponds to the n × n identity matrix.

Example

We define

$$ A = \begin{bmatrix} a_1 && a_3 \ a_2 && a_4 \end{bmatrix} \quad x = \begin{bmatrix} x_1 \ x_2 \end{bmatrix} $$

with

A = casos.PS.sym('a', [2,2]);
x = casos.Indeterminates('x',2);

which allows us to define a new polynomial of type casos.PS using matrix multiplication

$$p_3(x) = Ax$$

p3 = A*x;

> p3 = 
> 
> [(a_0)*x_1 + (a_2)*x_2]
> [(a_1)*x_1 + (a_3)*x_2]

Quick links

Cite us

If you use CaΣoS, please cite us.

CaΣoS logo

Clone this wiki locally