# module: polynomials¶

This module provides a calculus for uni- and multivariate polynomials using the vector exponent notation [Wildhaber2019], Chapter 6. This calculus simplifies to use polynomials in (squared error) cost functions, e.g., as localized signal models.

## Polynomial Classes¶

 Poly Univariate polyonimial in vector exponent notation: $$\alpha^\mathsf{T} x^q$$ MPoly Multivariate polynomials $${\tilde{\alpha}}^\mathsf{T} (x^q \otimes y^r)$$, or with factorized coefficient vector $$(\alpha \otimes \beta )^\mathsf{T} (x^q \otimes y^r)$$.

## Polynomial Operators¶

### Operators for Univariate Polynomials¶

Operators handling univariate polynomials. Return parameters are highlighted in $$\color{blue}{blue}$$.

#### Sum of Polynomials $$\alpha^\mathsf{T} x^q + \beta^\mathsf{T} x^r$$¶

 poly_sum(polys) $$\alpha^\mathsf{T} x^q + \dots + \beta^\mathsf{T} x^r = \color{blue}{\tilde{\alpha}^\mathsf{T} x^\tilde{q}}$$ poly_sum_coef(polys) $$\alpha^\mathsf{T} x^q + \dots + \beta^\mathsf{T} x^r = \color{blue}{\tilde{\alpha}}^\mathsf{T} x^\tilde{q}$$ poly_sum_coef_Ls(expos) $$\alpha^\mathsf{T} x^q + \dots + \beta^\mathsf{T} x^r = (\color{blue}{\Lambda_1} \alpha + \dots + \color{blue}{\Lambda_N}\beta)^\mathsf{T} x^{\tilde{q}}$$ poly_sum_expo(expos) $$\alpha^\mathsf{T} x^q + \dots + \beta^\mathsf{T} x^r = \tilde{\alpha}^\mathsf{T} x^{\color{blue}{\tilde{q}}}$$ poly_sum_expo_Ms(expos) $$\alpha^\mathsf{T} x^q + \dots + \beta^\mathsf{T} x^r = \tilde{\alpha}^\mathsf{T} x^{\color{blue}{M_1} q + \dots +\color{blue}{M_N} r}$$
>>> import lmlib as lm
>>>
>>> p1 = lm.Poly([1, 3, 5], [0, 1, 2])
>>> p2 = lm.Poly([2, -1], [0, 1])
>>>
>>> p_sum = lm.poly_sum((p1, p2))
>>> print(p_sum)
[ 1.  3.  5.  2. -1.], [0. 1. 2. 0. 1.]


#### Product of Polynomials $$\alpha^\mathsf{T} x^q \cdot \beta^\mathsf{T} x^r$$¶

 poly_prod(polys) $$\alpha^\mathsf{T} x^q \cdot \beta^\mathsf{T} x^q = \color{blue}{\tilde{\alpha}^\mathsf{T} x^\tilde{q}}$$ poly_prod_coef(polys) $$\alpha^\mathsf{T} x^q \cdot \beta^\mathsf{T} x^r = \color{blue}{\tilde{\alpha}}^\mathsf{T} x^\tilde{q}$$ poly_prod_expo(expos) $$\alpha^\mathsf{T} x^q \cdot \beta^\mathsf{T} x^r = \tilde{\alpha}^\mathsf{T} x^{\color{blue}{\tilde{q}}}$$ poly_prod_expo_Ms(expos) $$\alpha^\mathsf{T} x^q \cdot \beta^\mathsf{T} x^r = \tilde{\alpha}^\mathsf{T} x^{\color{blue}{M_1} q + \color{blue}{M_2} r}$$
>>> import lmlib as lm
>>>
>>> p1 = lm.Poly([1, 3, 5], [0, 1, 2])
>>> p2 = lm.Poly([2, -1], [0, 1])
>>>
>>> p_prod = lm.poly_prod((p1, p2))
>>> print(p_prod)
[ 2 -1  6 -3 10 -5], [0. 1. 1. 2. 2. 3.]


#### Square of a Polynomial $$(\alpha^\mathsf{T} x^q)^2$$¶

 poly_square(poly) $$(\alpha^\mathsf{T} x^q)^2 = \color{blue}{\tilde{\alpha}^\mathsf{T} x^\tilde{q}}$$ $$\color{blue}{\tilde{\alpha}}^\mathsf{T} x^\tilde{q}$$ $$\tilde{\alpha}^\mathsf{T} x^{\color{blue}{\tilde{q}}}$$ $$\tilde{\alpha}^\mathsf{T} x^{\color{blue}{M} q}$$
>>> import lmlib as lm
>>>
>>> p1 = lm.Poly([1, 3, 5], [0, 1, 2])
>>>
>>> p_square = lm.poly_square(p1)
>>> print(p_square)
[ 1  3  5  3  9 15  5 15 25], [0. 1. 2. 1. 2. 3. 2. 3. 4.]


#### Shift of a Polynomial $$\alpha^\mathsf{T} (x+ \gamma)^q$$¶

 poly_shift(poly, gamma) $$\alpha^\mathsf{T} (x+ \gamma)^q = \color{blue}{\tilde{\alpha}^\mathsf{T} x^\tilde{q}}$$ poly_shift_coef(poly, gamma) $$\color{blue}{\tilde{\alpha}}^\mathsf{T} x^\tilde{q}$$ poly_shift_coef_L(expo, gamma) $$\color{blue}{\Lambda} \alpha^\mathsf{T} x^{\tilde{q}}$$ $$\tilde{\alpha}^\mathsf{T} x^{\color{blue}{\tilde{q}}}$$
>>> import lmlib as lm
>>>
>>> p1 = lm.Poly([1, 3, 5], [0, 1, 2])
>>> gamma = 2
>>> p_shift = lm.poly_shift(p1, gamma)
>>> print(p_shift)
[27. 23.  5.], [0 1 2]


#### Dilation of a Polynomial $$\alpha^\mathsf{T} (\eta x)^q$$¶

 poly_dilation(poly, eta) $$\alpha^\mathsf{T} (\eta x)^q = \color{blue}{\tilde{\alpha}^\mathsf{T} x^q}$$ poly_dilation_coef(poly, eta) $$\alpha^\mathsf{T} (\eta x)^q =\color{blue}{\tilde{\alpha}}^\mathsf{T} x^q$$ poly_dilation_coef_L(expo, eta) $$\alpha^\mathsf{T} (\eta x)^q =\color{blue}{\Lambda} \alpha^\mathsf{T} x^{q}$$
>>> import lmlib as lm
>>>
>>> p1 = lm.Poly([1, 3, 5], [0, 1, 2])
>>> eta = -5
>>> p_dilation = lm.poly_dilation (p1, eta)
>>> print(p_dilation)
[  1 -15 125], [0 1 2]


#### Integral of a Polynomial $$\int (\alpha^\mathsf{T} x^q) dx$$¶

 poly_int(poly) $$\int \big(\alpha^{\mathsf{T}}x^q\big) dx = \color{blue}{\tilde{\alpha}^\mathsf{T} x^\tilde{q}}$$ poly_int_coef(poly) $$\int \big(\alpha^{\mathsf{T}}x^q\big) dx = \color{blue}{\tilde{\alpha}}^\mathsf{T} x^\tilde{q}$$ $$\int \big(\alpha^{\mathsf{T}}x^q\big) dx = \color{blue}{\Lambda} \alpha^\mathsf{T} x^{\tilde{q}}$$ poly_int_expo(expo) $$\int \big(\alpha^{\mathsf{T}}x^q\big) dx = \tilde{\alpha}^\mathsf{T} x^{\color{blue}{\tilde{q}}}$$
>>> import lmlib as lm
>>>
>>> p1 = lm.Poly([1, 3, 5], [0, 1, 2])
>>>
>>> p_int = lm.poly_int(p1)
>>> print(p_int)
[1.         1.5        1.66666667], [1 2 3]


#### Derivative of a Polynomial $$\frac{d}{dx} (\alpha^\mathsf{T} x^q)$$¶

 poly_diff(poly) $$\frac{d}{dx} \big(\alpha^{\mathsf{T}}x^q\big) = \color{blue}{\tilde{\alpha}^\mathsf{T} x^\tilde{q}}$$ poly_diff_coef(poly) $$\frac{d}{dx} \big(\alpha^{\mathsf{T}}x^q\big) =\color{blue}{\tilde{\alpha}}^\mathsf{T} x^\tilde{q}$$ $$\frac{d}{dx} \big(\alpha^{\mathsf{T}}x^q\big) =\color{blue}{\Lambda} \alpha^\mathsf{T} x^{\tilde{q}}$$ poly_diff_expo(expo) $$\frac{d}{dx} \big(\alpha^{\mathsf{T}}x^q\big) =\tilde{\alpha}^\mathsf{T} x^{\color{blue}{\tilde{q}}}$$
>>> import lmlib as lm
>>>
>>> p1 = lm.Poly([1, 3, 5], [0, 1, 2])
>>>
>>> p_diff = lm.poly_diff(p1)
>>> print(p_diff)
[ 0  3 10], [0 0 1]


### Operators for Multivariate Polynomials¶

Operators handling multi variate polynomials. Return parameters are highlighted in $$\color{blue}{blue}$$.

## API (module: polynomial)¶

### Classes¶

class Poly(coef, expo)

Bases: lmlib.polynomial.poly._PolyBase

Univariate polyonimial in vector exponent notation: $$\alpha^\mathsf{T} x^q$$

Polynomial class for uni-variate polynomials in vector exponent notation, [Wildhaber2019], see Chapter 6.

Such a polynomial p(x) in x is defined as

$\begin{split}p(x) &= \alpha^\mathsf{T}x^q = \begin{bmatrix}a_0& a_1& \cdots& a_{Q-1}\end{bmatrix} \begin{bmatrix}x^{q_0}\\ x^{q_1}\\ \vdots\\ x^{q_{Q-1}}\end{bmatrix}\\ &= a_0 x^{q_0} + a_1 x^{q_1}+ \dots + a_{Q-1} x^{q_{Q-1}} \ ,\end{split}$

with coefficient vector $$\alpha \in \mathbb{R}^Q$$, exponent vector $$q \in \mathbb{Z}_{\geq 0}^Q$$, and function variable $$x \in \mathbb{R}$$.

Parameters
• coef (array_like, shape=(Q)) – Coefficient vector

• expo (array_like, shape=(Q)) – Exponent vector

Q : number of elements in exponent vector

Examples

>>> import lmlib as lm
>>> p = Poly([0, 0.2, 3], [0, 1, 2])
>>> print(p)


Attributes

 Poly.coef Coefficient vector $$\alpha$$ Poly.expo Exponent vector $$q$$ Poly.Q Number of elements in exponent vector $$Q$$ Poly.coefs Coefficient vector (i.e., not factorized) Poly.expos Exponent vectors Poly.variable_count Number of dependent variables

Methods

 eval(variable) Evaluates the polynomial
eval(variable)

Evaluates the polynomial

Parameters

variable (array_like, scalar) – Dependent variables of a polynomial.

Returns

out (ndarray) – Output of evaluated polynomial. Shape is identical as a dependent variable

class MPoly(coefs, expos)

Bases: lmlib.polynomial.poly._PolyBase

Multivariate polynomials $${\tilde{\alpha}}^\mathsf{T} (x^q \otimes y^r)$$, or with factorized coefficient vector $$(\alpha \otimes \beta )^\mathsf{T} (x^q \otimes y^r)$$.

This polynomial class is for multivariate polynomials in vector exponent notation, see [Wildhaber2019], Chapter 6.

Such a multivariate polynomial is in general given by

$p(x) = \tilde{\alpha}^\mathsf{T}(x^q \otimes y^r) \ ,$

where $$\tilde{\alpha} \in \mathbb{R}^{Q \times R}$$ is the coefficient vectors, $$q \in \mathbb{Z}_{\geq 0}^Q$$ and $$r \in \mathbb{Z}_{\geq 0}^R$$ the exponent vectors, and $$x \in \mathbb{R}$$ and $$y \in \mathbb{R}$$ the independent variables.

As a special case, if the coefficient vector is in the form of a Kronecker product, i.e.,

$p(x) = (\alpha \otimes \beta)^\mathsf{T}(x^q \otimes y^r) \ ,$

where $$\alpha \in \mathbb{R}^Q$$ and $$\beta \in \mathbb{R}^R$$ are coefficient vectors, we denote a polynomial as factorized. This form often leads to algebraic simplifications (if it exists).

Examples

>>> # Bivariate (x,y) polynomial with factorized coefficients ([.2,.7],[-1.0,2.0,.1]) and terms x^1, x^2, y^1, y^2, y^3, and cross terms
>>> l= MPoly(([.2,.7],[-1.0,2.0,.1]),([1,2],[1,2,3]))
>>> l.coefs # gets coefficients
(array([0.2, 0.7]), array([-1. ,  2. ,  0.1]))
>>> l.coef_fac # gets factorized coefficients (if available)
array([-0.2 ,  0.4 ,  0.02, -0.7 ,  1.4 ,  0.07])
>>> l.eval([.3,.7])  # evaluating polynomial for x=.3 and y=.7
array(0.0386589)

>>> # Bivariate (x,y) polynomial with non-factorized coefficients ([.2,.7,1.3,1.4,.2,-1.6]) and terms x^1, x^2, y^1, y^2, y^3, and cross terms
>>> l= MPoly(([.2,.7,1.3,1.4,.2,-1.6],),([1,2],[1,2,3]))
>>> l.eval([.3,.7])  # evaluating polynomial for x=.3 and y=.7
array(0.326298)

Parameters
• coefs (tuple of array_like) – Set of coefficient vector(s)

• expos (tuple of array_like) – Set of exponent vector(s)

Attributes

 MPoly.coefs Coefficient vector (i.e., not factorized) MPoly.expos Exponent vectors MPoly.variable_count Number of dependent variables MPoly.coefs_fac Factorized coefficient vectors

Methods

 eval(variables) Evaluates the polynomial for given values (variables)
eval(variables)

Evaluates the polynomial for given values (variables)

Parameters

variables (tuple) – Dependent variables of a polynomial. Each element in variables has the same shape which is also the output shape.

Returns

out (ndarray) – Output of evaluated polynomial. Shape is identical as a dependent variable

Example

>>> # evaluate bivariate polynomial at multiple positions (x=.1 ... .4, y=.5)
>>> l = MPoly(([.2, .7], [1.3, 1.4, -.9],), ([0, 1], [0, 1, 2]))
>>> l.eval(([.1, .2, .3, .4], [.5, .5, .5, .5]))
array([0.47925, 0.6035, 0.72775, 0.852])


### Methods¶

poly_sum(polys)

$$\alpha^\mathsf{T} x^q + \dots + \beta^\mathsf{T} x^r = \color{blue}{\tilde{\alpha}^\mathsf{T} x^\tilde{q}}$$

Sum of univariate polynomials Poly(alpha,q),... , Poly(beta,r), all of common variable x

Parameters

polys (tuple of Poly) – (Poly(alpha,q),... , Poly(beta,r)), list of polynomials to be summed

Returns

out (Poly) – Poly(alpha_tilde, q_tilde)

References

[Wildhaber2019] (Eq. 6.4)

poly_sum_coef(polys)

$$\alpha^\mathsf{T} x^q + \dots + \beta^\mathsf{T} x^r = \color{blue}{\tilde{\alpha}}^\mathsf{T} x^\tilde{q}$$

Coefficient vector $$\tilde{q}$$ to sum of univariate polynomials polys, all of common variable x

Parameters

polys (tuple of Poly) – (Poly(alpha,q),... , Poly(beta,r)), list of polynomials to be summed

Returns

coef (ndarray) – alpha_tilde - Coefficient vector $$\tilde{\alpha}$$

Note

To get $$\tilde{q}$$, see poly_sum_expo().

References

[Wildhaber2019] (Eq. 6.4)

poly_sum_coef_Ls(expos)

$$\alpha^\mathsf{T} x^q + \dots + \beta^\mathsf{T} x^r = (\color{blue}{\Lambda_1} \alpha + \dots + \color{blue}{\Lambda_N}\beta)^\mathsf{T} x^{\tilde{q}}$$

Exponent manipulation matrices $$\Lambda_1, ...., Lambda_N$$ to sum univariate polynomials polys, all of common variable x

Parameters

expos (tuple of array_like) – (q, ..., r), list of exponent vectors of polynomials to be summed

Returns

Ls (list of ndarray) – (Lambda_1, ..., Lambda_N), Coefficient manipulation matrices, see also poly_sum()

Note

To get $$\tilde{q}$$, see poly_sum_expo().

References

[Wildhaber2019] (Eq. 6.4)

poly_sum_expo(expos)

$$\alpha^\mathsf{T} x^q + \dots + \beta^\mathsf{T} x^r = \tilde{\alpha}^\mathsf{T} x^{\color{blue}{\tilde{q}}}$$

Exponent vector $$\tilde{1}$$ of sum of univariate polynomials with exponent vectors expos, all of common variable x

Parameters

expos (tuple of array_like) – (q, ..., r), list of exponent vectors of polynomials to be summed

Returns

expo ndarrayq_tilde, exponent vector $$\tilde{q}$$

Note

To get $$\tilde{\alpha}$$, see poly_sum_coef().

References

[Wildhaber2019] (Eq. 6.4)

poly_sum_expo_Ms(expos)

$$\alpha^\mathsf{T} x^q + \dots + \beta^\mathsf{T} x^r = \tilde{\alpha}^\mathsf{T} x^{\color{blue}{M_1} q + \dots +\color{blue}{M_N} r}$$

Exponent manipulation matrices $$M_1, ... , M_N$$ to sum univariate polynomials with exponent vectors expos, all of common variable x

Parameters

expos (tuple of array_like) – (q, ..., r), list of exponent vectors of polynomials to be summed

Returns

Ms (list of ndarray) – (M_1, ..., M_N), list of exponent manipulation matrices, see also poly_sum().

References

[Wildhaber2019] (Eq. 6.4)

poly_prod(polys)

$$\alpha^\mathsf{T} x^q \cdot \beta^\mathsf{T} x^q = \color{blue}{\tilde{\alpha}^\mathsf{T} x^\tilde{q}}$$

Product of two univariate polynomials of common variable x

Parameters

polys (tuple of Poly) – (poly_1, poly_2), two polynomials to be multiplied

Returns

out (Poly) – poly_tilde, product as polynomial $$\tilde{\alpha}^\mathsf{T} x^\tilde{q}$$

References

[Wildhaber2019] (Eq. 6.14)

poly_prod_coef(polys)

$$\alpha^\mathsf{T} x^q \cdot \beta^\mathsf{T} x^r = \color{blue}{\tilde{\alpha}}^\mathsf{T} x^\tilde{q}$$

Coefficient vector $$\tilde{\alpha}$$ of product of two univariate polynomials of common variable x

Parameters

polys (tuple of Poly) – (poly_1, poly_2), two polynomials to be multiplied

Returns

coef ndarrayalpha_tilde, coefficient vector $$\tilde{\alpha}$$ of product polynomial $$\tilde{\alpha}^\mathsf{T} x^\tilde{q}$$, see poly_prod()

References

[Wildhaber2019] (Eq. 6.12)

poly_prod_expo(expos)

$$\alpha^\mathsf{T} x^q \cdot \beta^\mathsf{T} x^r = \tilde{\alpha}^\mathsf{T} x^{\color{blue}{\tilde{q}}}$$

Exponent vector $$\tilde{q}$$ of product of two univariate polynomials of common variable x

Parameters

expos (tuple of arraylike) – (q, r), exponent vectors of the two polynomials

Returns

coef ndarrayq_tilde, exponent vector $$\tilde{q}$$ of product polynomial $$\tilde{\alpha}^\mathsf{T} x^\tilde{q}$$, see poly_prod()

References

[Wildhaber2019] (Eq. 6.16)

poly_prod_expo_Ms(expos)

$$\alpha^\mathsf{T} x^q \cdot \beta^\mathsf{T} x^r = \tilde{\alpha}^\mathsf{T} x^{\color{blue}{M_1} q + \color{blue}{M_2} r}$$

Exponent manipulation matrices $$M_1, M_2$$ of product of two univariate polynomials of common variable x

Parameters

expos (tuple of array_like) – (q, r), exponent vectors

Returns

Ms (list of ndarray) – (M_1, ..., M_N), list of exponent manipulation matrices for the two polynomial exponent vectors, i.e., the new exponent vector results from $$\tilde{q} = M_1 q + M_2 r$$. See poly_prod().

References

[Wildhaber2019] (Eq. 6.16)

poly_square(poly)

$$(\alpha^\mathsf{T} x^q)^2 = \color{blue}{\tilde{\alpha}^\mathsf{T} x^\tilde{q}}$$

Square of a univariate polynomial

Parameters

poly (Poly) – poly, polynomial to be squared

Returns

out (Poly) – squared polynomial

References

[Wildhaber2019] (Eq. 6.11)

poly_square_coef(poly)

$$\color{blue}{\tilde{\alpha}}^\mathsf{T} x^\tilde{q}$$

Coefficient vector $$\tilde{\alpha}$$ of squared polynomial, see poly_square()

Parameters

poly (Poly) – poly, polynomial to be squared

Returns

coef ndarray, – alpha_tilde Coefficient vector $$\tilde{\alpha}$$

References

[Wildhaber2019] (Eq. 6.12)

poly_square_expo(expo)

$$\tilde{\alpha}^\mathsf{T} x^{\color{blue}{\tilde{q}}}$$

Exponent vector $$\tilde{q}$$ of squared polynomial, see poly_square().

Parameters

expo (array_like,) – q, exponent vector $$q$$

Returns

out ndarray, – q_tilde, exponent vector $$\tilde{q}$$

References

[Wildhaber2019] (Eq. 6.12)

poly_square_expo_M(expo)

$$\tilde{\alpha}^\mathsf{T} x^{\color{blue}{M} q}$$

Exponent manipulation matrix $$M$$ of squared polynomial, see poly_square()

Parameters

expo (array_like,) – q, exponent vector $$q$$

Returns

M (ndarray,) – M, exponent manipulation matrix $$M$$

References

[Wildhaber2019] (Eq. 6.10, Eq. 6.13)

poly_shift(poly, gamma)

$$\alpha^\mathsf{T} (x+ \gamma)^q = \color{blue}{\tilde{\alpha}^\mathsf{T} x^\tilde{q}}$$

Shifting an univariate polynomial by constant value $$\gamma \in \mathbb{R}$$

Parameters
• poly (Poly) – polynomial to be shifted

• gamma (float) – gamma, shift parameter $$\gamma$$

Returns

out (Poly) – shifted polynomial, $$\tilde{\alpha}^\mathsf{T} x^\tilde{q}$$

References

[Wildhaber2019] (Eq. 6.28)

poly_shift_coef(poly, gamma)

$$\color{blue}{\tilde{\alpha}}^\mathsf{T} x^\tilde{q}$$

Coefficient vector of shifted polynomial, see poly_shift()

Parameters
• poly (Poly) – polynomial to be shifted

• gamma (float) – gamma, shift parameter $$\gamma$$

Returns

coef (ndarray) – alpha_tilde Coefficient vector $$\tilde{\alpha}$$

References

[Wildhaber2019] (Eq. 6.29)

poly_shift_coef_L(expo, gamma)

$$\color{blue}{\Lambda} \alpha^\mathsf{T} x^{\tilde{q}}$$

Coefficient manipulation $$\Lambda}$$ for shifted polynomial, see poly_shift()

Parameters
• expo (array_like) – q, Exponent vector $$q$$

• gamma (float) – gamma, shift parameter $$\gamma$$

Returns

L (ndarray) – L, coefficient manipulation matrices $$\Lambda$$.

References

[Wildhaber2019] (Eq. 6.32)

poly_shift_expo(expo)

$$\tilde{\alpha}^\mathsf{T} x^{\color{blue}{\tilde{q}}}$$

Exponent vector $$\tilde{q}$$ for shifted polynomial, see poly_shift()

Parameters

expo (array_like) – q, Exponent vector $$q$$

Returns

expo (ndarray) – q_tilde, exponent vector $$\tilde{q}$$.

References

[Wildhaber2019] (Eq. 6.30)

poly_dilation(poly, eta)

$$\alpha^\mathsf{T} (\eta x)^q = \color{blue}{\tilde{\alpha}^\mathsf{T} x^q}$$

Dilation of a polynomial by scaling x by constant value $$\eta \in \mathbb{R}$$

Parameters
• poly (Poly) – polynomial to be scaled

• eta (float) – eta, dilation factor $$\eta$$

Returns

out (Poly) – dilated polynomial, $$\tilde{\alpha}^\mathsf{T} x^\tilde{q}$$

References

[Wildhaber2019] (Eq. 6.33)

poly_dilation_coef(poly, eta)

$$\alpha^\mathsf{T} (\eta x)^q =\color{blue}{\tilde{\alpha}}^\mathsf{T} x^q$$

Coefficient vector $$\tilde{\alpha}$$ of dilated polynomial by scaling x by constant value $$\eta \in \mathbb{R}$$, see poly_dilation().

Parameters
• poly (Poly) – polynomial to be scaled

• eta (float) – eta, dilation factor $$\eta$$

Returns

coef ndarray – Coefficient vector $$\tilde{\alpha}$$

References

[Wildhaber2019] (Eq. 6.34)

poly_dilation_coef_L(expo, eta)

$$\alpha^\mathsf{T} (\eta x)^q =\color{blue}{\Lambda} \alpha^\mathsf{T} x^{q}$$

Coefficient manipulation matrix $$\tilde{\Lambda}$$ to dilated polynomial by scaling x by constant value $$\eta \in \mathbb{R}$$, see poly_dilation().

Parameters
• expo (array_like) – q, Exponent vector $$q$$

• eta (float) – eta, dilation factor $$\eta$$

Returns

L (ndarray) – L, Coefficient Manipulation Matrices $$\Lambda$$

References

[Wildhaber2019] (Eq. 6.35)

poly_int(poly)

$$\int \big(\alpha^{\mathsf{T}}x^q\big) dx = \color{blue}{\tilde{\alpha}^\mathsf{T} x^\tilde{q}}$$

Indefinite integral of a polynomial

Parameters

poly (Poly) – polynomial to be integrated

Returns

out (Poly) – polynomial, $$\tilde{\alpha}^\mathsf{T} x^\tilde{q}$$

References

[Wildhaber2019] (Eq. 6.17)

poly_int_coef(poly)

$$\int \big(\alpha^{\mathsf{T}}x^q\big) dx = \color{blue}{\tilde{\alpha}}^\mathsf{T} x^\tilde{q}$$

Coefficient vector $$\tilde{\alpha}$$ of indefinite integral of a polynomial, see poly_int()

Parameters

poly (Poly) – polynomial to be integrated

Returns

coef (ndarray,) – alpha_tilde, Coefficient vector $$\tilde{\alpha}$$

References

[Wildhaber2019] (Eq. 6.18)

poly_int_coef_L(expo)

$$\int \big(\alpha^{\mathsf{T}}x^q\big) dx = \color{blue}{\Lambda} \alpha^\mathsf{T} x^{\tilde{q}}$$

Coefficient manipulation matrix $$\Lambda$$ of indefinite integral of a polynomial, see poly_int().

Parameters

expo (array_like) – q, Exponent vector $$q$$

Returns

L (ndarray) – L, coefficient Manipulation Matrices $$\Lambda$$

References

[Wildhaber2019] (Eq. 6.20-21)

poly_int_expo(expo)

$$\int \big(\alpha^{\mathsf{T}}x^q\big) dx = \tilde{\alpha}^\mathsf{T} x^{\color{blue}{\tilde{q}}}$$

Exponent vector $$\tilde{q}$$ of indefinite integral of a polynomial, see poly_int().

Parameters

expo (array_like) – q, exponent vector $$q$$

Returns

expo (ndarray) – q_tilde, exponent vector $$\tilde{q}$$

References

[Wildhaber2019] (Eq. 6.19)

poly_diff(poly)

$$\frac{d}{dx} \big(\alpha^{\mathsf{T}}x^q\big) = \color{blue}{\tilde{\alpha}^\mathsf{T} x^\tilde{q}}$$

Derivation of a polynomial

Parameters

poly (Poly) – polynomial for derivation

Returns

out (Poly) – derivative $$\tilde{\alpha}^\mathsf{T} x^\tilde{q}$$

References

[Wildhaber2019] (Eq. 6.24)

poly_diff_coef(poly)

$$\frac{d}{dx} \big(\alpha^{\mathsf{T}}x^q\big) =\color{blue}{\tilde{\alpha}}^\mathsf{T} x^\tilde{q}$$

Coefficient vector $$\tilde{\alpha}$$ of polynomial derivation, see poly_diff()

Parameters

poly (Poly) – polynomial for derivation

Returns

coef (ndarray) – alpha_tilde, coefficient vector $$\tilde{\alpha}$$

References

[Wildhaber2019] (Eq. 6.25)

poly_diff_coef_L(expo)

$$\frac{d}{dx} \big(\alpha^{\mathsf{T}}x^q\big) =\color{blue}{\Lambda} \alpha^\mathsf{T} x^{\tilde{q}}$$

Coefficient manipulation matrix $$\Lambda$$ of polynomial derivation, see poly_diff()

Parameters

expo (array_like) – Exponent vector $$q$$

Returns

L (ndarray) – L, coefficient manipulation matrices $$\Lambda$$

References

[Wildhaber2019] (Eq. 6.27)

poly_diff_expo(expo)

$$\frac{d}{dx} \big(\alpha^{\mathsf{T}}x^q\big) =\tilde{\alpha}^\mathsf{T} x^{\color{blue}{\tilde{q}}}$$

Exponent vector $$\tilde{q}$$ of polynomial derivation, see poly_diff()

Parameters

expo (array_like) – Exponent vector $$q$$

Returns

expo (ndarray) – q_tilde, exponent vector $$\tilde{q}$$

References

[Wildhaber2019] (Eq. 6.26)

mpoly_add(poly1, poly2)

Sum of two univariate polynomials different variables

Parameters
Returns

out (MPoly)

References

[Wildhaber2019] (Eq. 6.37)

mpoly_add_coefs(poly1, poly2)

Coefficients for mpoly_add()

Parameters
Returns

out (tuple of ndarray) – Tuple of coefficient vectors

References

[Wildhaber2019] (Eq. 6.38-39)

mpoly_add_expos(poly1, poly2)

Exponents for mpoly_add()

Parameters
Returns

out (tuple of ndarray) – Tuple of exponent vectors

References

[Wildhaber2019] (Eq. 6.38-39)

mpoly_multiply(poly1, poly2)

Product of two univariate polynomials different variables

Parameters
Returns

out (MPoly)

References

[Wildhaber2019] (Eq. 6.40)

mpoly_prod(polys)

Product of univariate polynomials different variables

Parameters

polys (list of Poly or MPoly) –

Returns

out (MPoly)

References

[Wildhaber2019] (Eq. 6.40)

mpoly_square(mpoly, sparse=False)

Square of multivariate polynomial

Parameters

mpoly (MPoly) –

Returns

out (MPoly)

References

[Wildhaber2019] (Eq. 6.42 - 6.43)

mpoly_square_coef(mpoly, sparse=False)

Non-factorized coefficient vector for mpoly_square()

Parameters

mpoly (MPoly) –

Returns

out (ndarray)

References

[Wildhaber2019] (Eq. 6.44)

mpoly_square_expos(expos)

Exponent vectors for mpoly_square()

Parameters

expos (tuple of array_like) –

Returns

expos (tuple of ndarray)

References

[Wildhaber2019] (Eq. 6.45)

mpoly_shift(poly)

Polynomial with variable shift

Parameters

poly (Poly) –

Returns

out (MPoly)

References

[Wildhaber2019] (Eq. 6.49)

mpoly_shift_coef(poly)

Coefficient vector for mpoly_shift()

Parameters

poly (Poly) –

Returns

out (ndarray)

References

[Wildhaber2019] (Eq. 6.50)

mpoly_shift_coef_L(expo)

Coefficient manipulation matrix for mpoly_shift()

Parameters

expo (array_like) –

Returns

out (ndarray)

References

[Wildhaber2019] (Eq. 6.52-6.53)

mpoly_shift_expos(expo)

Exponent vector for mpoly_shift()

Parameters

expo (array_like) –

Returns

out (tuple of ndarray)

References

[Wildhaber2019] (Eq. 6.51)

mpoly_int(mpoly, position)

Integral of a multivariate polynomial with respect to the scalar at a position

Parameters
Returns

out (MPoly)

References

[Wildhaber2019] (Eq. 6.60 - 6.61)

mpoly_int_coef(mpoly, position)

Coefficient vector for mpoly_int()

Parameters
Returns

out (ndarray)

References

[Wildhaber2019] (Eq. 6.61)

mpoly_int_coef_L(expos, position, sparse=False)

Coefficient manipulation matrix for mpoly_int()

Parameters
• expos (tuple of array_like) –

• position (int) –

Returns

References

[Wildhaber2019] (Eq. 6.61)

mpoly_int_expos(expos, position)

Exponent vectors for mpoly_int()

Parameters
• expos (tuple of array_like) –

• position (int) –

Returns

expos (tuple of ndarray)

References

[Wildhaber2019] (Eq. 6.61, Eq.6.19)

mpoly_def_int(mpoly, position, a, b)

Definite integral of a multivariate polynomial with respect to the scalar at a position

Parameters
• mpoly (MPoly) –

• position (int) –

• a (scalar) – lower integration boundary

• b (scalar) – upper integration boundary

Returns

out (MPoly)

References

[Wildhaber2019] (Eq. 6.62 - 6.63)

mpoly_def_int_coef(mpoly, position, a, b)

Coefficient vector for mpoly_def_int()

Parameters
• mpoly (MPoly) –

• position (int) –

• a (scalar) – lower integration boundary

• b (scalar) – upper integration boundary

Returns

out (ndarray)

References

[Wildhaber2019] (Eq. 6.61), (Eq. 6.58)

mpoly_def_int_coef_L(expos, position, a, b, sparse=False)

Coefficient manipulation matrix for mpoly_def_int()

Parameters
• expos (tuple of array_like) –

• position (int) –

• a (scalar) – lower integration boundary

• b (scalar) – upper integration boundary

Returns

References

[Wildhaber2019] (Eq. 6.61), (Eq. 6.58)

mpoly_def_int_expos(expos, position)

Exponent vectors for mpoly_def_int()

Parameters
• expos (tuple of array_like) –

• position (int) –

Returns

expos (tuple of ndarray)

References

[Wildhaber2019] (Eq. 6.61, Eq.6.19)

mpoly_diff(mpoly, position, sparse=False)

Derivative of a multivariate polynomial with respect to the variable at a position

Parameters
Returns

out (MPoly)

References

Todo: REF

mpoly_diff_coef(mpoly, position, sparse=False)

Coefficient vector for mpoly_diff()

Parameters
Returns

out (ndarray)

References

TODO: Ref

mpoly_diff_coef_L(expos, position, sparse=False)

Coefficient manipulation matrix for mpoly_diff()

Parameters
• expos (tuple of array_like) –

• position (int) –

Returns

References

TODO: Ref

mpoly_diff_expos(expos, position)

Exponent vectors for mpoly_diff()

Parameters
• expos (tuple of array_like) –

• position (int) –

Returns

expos (tuple of ndarray)

References

TODO: Ref

mpoly_substitute(mpoly, position, substitute)

Substituting a variable of a multivariate polynomial by a constant

Parameters
Returns

out (MPoly)

References

[Wildhaber2019] (Eq. 6.62 - 6.63)

mpoly_substitute_coef(mpoly, position, substitute)

Coefficient vector for mpoly_def_int()

Parameters
Returns

out (ndarray)

References

[Wildhaber2019] (Eq. 6.58)

mpoly_substitute_coef_L(expos, position, substitute)

Coefficient manipulation matrix for mpoly_def_int()

Parameters
• expos (tuple of array_like) –

• position (int) –

• substitute (scalar) –

Returns

References

[Wildhaber2019] (Eq. 6.58)

mpoly_substitute_expos(expos, position)

Exponent vectors for mpoly_substitute()

Parameters
• expos (tuple of array_like) –

• position (int) –

Returns

expos (tuple of ndarray)

References

[Wildhaber2019] (Eq. 6.58)

mpoly_dilate(mpoly, position, eta)

Dilate a multivariate polynomial by a constant eta

Parameters
Returns

mpoly (MPoly)

References

[Wildhaber2019] (Eq. 6.55)

mpoly_dilate_coefs(mpoly, position, eta)

Coefficient vectros for mpoly_dilate()

Parameters
Returns

out (tuple of ndarray)

References

[Wildhaber2019] (Eq. 6.55)

mpoly_dilate_coef_L(expos, position, eta)

Coefficient manipulation matrix for mpoly_dilate()

Parameters
• expos (tuple of array_like) –

• position (int) –

• eta (scalar) –

Returns

out (ndarray)

References

[Wildhaber2019] (Eq. 6.55)

mpoly_dilate_expos(expos)

Exponent vectors for mpoly_dilate()

Parameters

expos (tuple of array_like) –

Returns

expos (tuple of ndarray)

References

[Wildhaber2019] (Eq. 6.55)

mpoly_dilate_ind(poly)

$$\alpha^{mathsf{T}}(xy)^q = (\Delta_Q\alpha)^{mathsf{T}}(x^q \otimes y^q)$$

Dilates a univariate polynomial poly by an indeterminate y

Parameters

poly (Poly) – Univariate polynomial Poly(alpha, q)

Returns

mpoly (MPoly) – Multivariate polynomial Poly((alpha_tilde,), (q, q)) with dilation variable $$y$$

References

[Wildhaber2019] (Eq. 6.55)

mpoly_dilate_ind_coefs(poly)

Coefficient vectros for mpoly_dilate()

Parameters

poly (Poly) –

Returns

out (tuple of ndarray)

References

[Wildhaber2019] (Eq. 6.55)

mpoly_dilate_ind_coef_L(expo)

Coefficient manipulation matrix for mpoly_dilate()

Parameters

expo (tuple of array_like) –

Returns

out (ndarray)

References

[Wildhaber2019] (Eq. 6.55)

mpoly_dilate_ind_expos(expo)

Exponent vectors for mpoly_dilate()

Parameters

expo (array_like,) – q, exponent vector $$q$$

Returns

expos (tuple of ndarray)

References

[Wildhaber2019] (Eq. 6.55)

extend_basis(mpoly, new_expos)

(DEV) Extending the basis of a uni- or multi-variate polynomial by new variables

The new basis / variable are appended.

\begin{align}\begin{aligned}\alpha^T x^q = (A\alpha)^T(x^q \otimes y^r \otimes z^s) =\\A = (I^q \otimes 0^r \otimes 0^s)\end{aligned}\end{align}
Parameters
• mpoly (MPoly, Poly) – Polynomial to extent the basis (variables) * Each of the new exponent vectors has to contain 1 zero element. **

• new_expos (tuple of array_like) – Each array in the tuple corresponds to a new variable ** Each of the new exponent vectors has to contain 1 zero element. **

Returns

mpoly (MPoly) – Multivariate polynomial with extended basis (new variales)

References

TODO: Ref

permutation_matrix_square(m, i, sparse=False)

Returns permutation matrix for square matrices A and B

The permutation is given by

$vec(A\otimes B) = R_{m,n;i,j} \big(vec(A) \otimes vec(B)\big)$

with permutation matrix

$R_{m;i} = R_{m,m;i,i}$

and $$A_{\{m,m\}} \in \mathbb{R}$$ and $$B_{\{i,i\}} \in \mathbb{R}$$

Parameters
• m (int) – Size of first dimension of A

• i (int) – Size of first dimension of B

Returns

R (ndarray) – Commutation matrix

References

[Wildhaber2019] (Eq. 6.101-6.103)

permutation_matrix(m, n, i, j, sparse=False)

Returns permutation matrix

The permutation is given by

$vec(A\otimes B) = R_{m,n;i,j} \big(vec(A) \otimes vec(B)\big)$

with permutation matrix

$R_{m,n;i,j} = I_n \otimes K_{m,j} \otimes I_i \in \mathbb{R}^{mnij \times mnij}$

and $$A_{\{m,n\}} \in \mathbb{R}$$ and $$B_{\{i,j\}} \in \mathbb{R}$$

Parameters
• m (int) – Size of first dimension of A

• n (int) – Size of second dimension of A

• i (int) – Size of first dimension of B

• j (int) – Size of second dimension of B

Returns

R (ndarray) – Commutation matrix

References

[Wildhaber2019] (Eq. 6.100-6.102)

commutation_matrix(m, n, sparse=False)

Returns commutation matrix

$K_{m,n}vec(A) = vec(A^\mathsf{T}) \in \mathbb{R}^{mn \times mn}$

where $$A_{\{m,n\}} \in \mathbb{R}$$

Parameters
• m (int) – Size of first dimension of A

• n (int) – Size of second dimension of A

Returns

K (ndarray) – Commutation matrix squared

References

[Wildhaber2019] (Eq. 6.114-6.115)

## API (module: poly_cost)¶

### Classes¶

 TransformMPolyCost