Skip to content

Polynomials

Torbjørn Cunis edited this page Dec 11, 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 the exemplary 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$. The representation of monomials in $p$ above is called 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 problems.

Syntax for indeterminate variables

In CaΣoS,

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. Expressions of indeterminate variables and double, casadi.DM, and/or casadi.SX return a compatible polynomial data type.

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 introduce the syntax to define different polynomials. For a detailed description, see polynomial data types.

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}$$

and

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}$$

and

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:

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 $p_3(x) = Ax$ of type casos.PS using matrix multiplication

The syntax

p3 = A*x;

yields

p3 = 

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

Conversion to CasADi function

Polynomials in CaΣoS can be converted to functions in CasADi using the to_function operation. This replaces the indeterminate variables by CasADi's symbolic variables. Each function input corresponds to a scalar indeterminate variable. Thus, a polynomial with $n$ indeterminate variables becomes

f:(x1,...,xn)->(poly) SXFunction

Note that, if a polynomial has symbolic coefficients (as in the example p3 = A*x above, where A is a matrix of type casadi.SX), those will become free variables of the function. However, this must be explicitly enabled by passing the allow_free option to the created CasADi function, viz.

to_function(A*x,struct('allow_free',true))

Warning

Creating a CasADi function with free variables but without enabling the allow_free option will lead to an exception.

Quick links

Cite us

If you use CaΣoS, please cite us.

CaΣoS logo

Clone this wiki locally