polynomials_on_simplices.polynomial.polynomials_monomial_basis module

Polynomials on \(\mathbb{R}^m\) with values in \(\mathbb{R}^n\), expressed using the monomial basis.

An monomial in n variables of degree r is a product

\[m = x_1^{d_1} x_2^{d_2} \ldots x_n^{d_n},\]

where \(d_i \mathbb{N}_0, i = 1, 2, \ldots, n\) and \(\sum_{i = 1}^n d_i = r\). I.e. \(d = (d_1, d_2, \ldots, d_n) \in \mathbb{N}_0^n\) and in multi-index notation we simply have

\[m = x^d, x = (x_1, x_2, \ldots, x_n).\]

The set \(\{ x^{\nu} \}_{\substack{\nu \in \mathbb{N}_0^m \\ |\nu| \leq r}}\) is a basis for the space of all polynomials of degree less than or equal to r on \(\mathbb{R}^m, \mathcal{P}_r (\mathbb{R}^m)\).

\[\begin{split}p(x) = \sum_{\substack{\nu \in \mathbb{N}_0^m \\ |\nu| \leq r}} a_{\nu} x^{\nu},\end{split}\]

where \(a_{\nu} \in \mathbb{R}^n\).

class Polynomial(coeff, r=None, m=1)[source]

Bases: polynomials_on_simplices.polynomial.polynomials_base.PolynomialBase

Implementation of the abstract polynomial base class for a polynomial using the monomial basis.

\[p(x) = \sum_{i = 0}^{\dim(\mathcal{P}_r(\mathbb{R}^m)) - 1} a_{\nu_i} x^{\nu_i}.\]
Parameters:
  • coeff – Coefficients for the polynomial in the monomial basis for \(\mathcal{P}_r (\mathbb{R}^m, \mathbb{R}^n). \text{coeff}[i] = a_{\nu_i}\), where \(\nu_i\) is the i:th multi-index in the sequence of all multi-indices of dimension m with norm \(\leq r\) (see polynomials_on_simplices.algebra.multiindex.generate() function). Array of scalars for a scalar valued polynomial (n = 1) and array of n-dimensional vectors for a vector valued polynomial (\(n \geq 2\)).
  • r (int) – Degree of the polynomial space. Optional, will be inferred from the number of polynomial coefficients if not specified.
  • m (int) – Dimension of the domain of the polynomial.
basis()[source]

Get basis for the space \(\mathcal{P}_r (\mathbb{R}^m)\) used to express this polynomial.

Returns:Unique identifier for the basis used.
Return type:str
code_str(fn_name)[source]

Generate a function code string for evaluating this polynomial.

Parameters:fn_name (str) – Name for the function in the generated code.
Returns:Code string for evaluating this polynomial.
Return type:str
degree_elevate(s)[source]

Express the polynomial using a higher degree basis.

Let \(p(x) = \sum_{\substack{\nu \in \mathbb{N}_0^m \\ |\nu| \leq r}} a_{\nu} x^{\nu}\) be this polynomial expressed in the monomial basis for \(\mathcal{P}_r (\mathbb{R}^m)\). Then this function returns a polynomial \(q(x)\)

\[\begin{split}q(x) = \sum_{\substack{\nu \in \mathbb{N}_0^m \\ |\nu| \leq s}} \tilde{a}_{\nu} x^{\nu},\end{split}\]

such that \(p(x) = q(x) \, \forall x \in \mathbb{R}^m\).

Parameters:s (int) – New degree for the polynomial basis the polynomial should be expressed in.
Returns:Elevation of this polynomial to the higher degree basis.
Return type:Polynomial.
latex_str()[source]

Generate a Latex string for this polynomial.

Returns:Latex string for this polynomial.
Return type:str
partial_derivative(i=0)[source]

Compute the i:th partial derivative of the polynomial.

Parameters:i (int) – Index of partial derivative.
Returns:i:th partial derivative of this polynomial.
Return type:Polynomial.
to_monomial_basis()[source]

Compute the monomial representation of this polynomial.

Returns:This polynomial expressed in the monomial basis.
Return type:Polynomial.
dual_monomial_basis(r, n)[source]

Generate all dual monomial base functions for the space \(\mathcal{P}_r(\mathbb{R}^n)\) (i.e. the monomial basis for \(\mathcal{P}_r(\mathbb{R}^n)^*\)).

See dual_monomial_basis_fn().

Parameters:
  • r (int) – Degree of the polynomial space.
  • n (int) – Dimension of the domain.
Returns:

List of dual base functions.

Return type:

List[callable q(p)].

dual_monomial_basis_fn(mu)[source]

Generate a dual basis function to the monomial polynomial basis, i.e. the linear map \(q_{\mu} : \mathcal{P}_r(\mathbb{R}^n) \to \mathbb{R}\) that satisfies

\[q_{\mu}(p_{\nu}) = \delta_{\mu, \nu},\]

where \(p_{\nu}\) is the monomial basis polynomial indexed by the multi-index \(\nu\), \(n = |\nu|\) (see monomial_basis_fn()) and

\[\begin{split}\delta_{\mu, \nu} = \begin{cases} 1 & \mu = \nu \\ 0 & \text{else} \end{cases}.\end{split}\]
Parameters:mu (int or MultiIndex or Tuple[int, …]) – Multi-index indicating which dual monomial basis function should be generated.
Returns:The dual monomial basis function as specified by mu.
Return type:Callable \(q_{\mu}(p)\).
dual_vector_valued_monomial_basis(r, m, n, ordering='interleaved')[source]

Generate all dual monomial base functions for the space \(\mathcal{P}_r(\mathbb{R}^m, \mathbb{R}^n)\) (i.e. the monomial basis for \(\mathcal{P}_r(\mathbb{R}^m, \mathbb{R}^n)^*\)).

See dual_vector_valued_monomial_basis_fn().

Parameters:
  • r (int) – Degree of the polynomial space.
  • m (int) – Dimension of the domain.
  • n (int) – Dimension of the target.
  • ordering (str) – How the vector valued basis functions are ordered. Can be “sequential” or “interleaved”. For sequential, sorting is first done on the index of the component that is non-zero, and then the non-zero component is sorted in the same way as the scalar valued basis functions. For “interleaved” basis functions are first sorted on their non-zero component in the same way as scalar valued basis functions, and then they are sorted on the index of the component that is non-zero.
Returns:

List of dual base functions.

Return type:

List[callable q(p)].

dual_vector_valued_monomial_basis_fn(mu, i, n)[source]

Generate a dual basis function to the vector valued monomial polynomial basis, i.e. the linear map \(q_{\mu, i} : \mathcal{P}_r(\mathbb{R}^m, \mathbb{R}^n) \to \mathbb{R}\) that satisfies

\[q_{\mu, i}(p_{\nu, j}) = \delta_{\mu, \nu} \delta_{i, j},\]

where \(p_{\nu, j}\) is the degree \(|\nu|\) vector valued monomial basis polynomial indexed by the multi-index \(\nu\) with a non-zero i:th component (see vector_valued_monomial_basis_fn()) and

\[\begin{split}\delta_{\mu, \nu} = \begin{cases} 1 & \mu = \nu \\ 0 & \text{else} \end{cases}.\end{split}\]
Parameters:
  • mu (int or MultiIndex or Tuple[int, …].) – Multi-index indicating which dual monomial basis function should be generated.
  • i (int) – Integer indicating which dual monomial basis function should be generated.
  • n (int) – Dimension of the target.
Returns:

The dual monomial basis function as specified by mu, r and i.

Return type:

Callable \(q_{\mu, i}(p)\).

monomial_basis(r, n)[source]

Generate all monomial base polynomials for the space \(\mathcal{P}_r(\mathbb{R}^n)\).

Parameters:
  • r (int) – Degree of the polynomial space.
  • n (int) – Dimension of the domain.
Returns:

List of base polynomials.

Return type:

List[Polynomial].

monomial_basis_fn(nu)[source]

Generate a monomial basis polynomial \(p_{\nu}\) in the space \(\mathcal{P}_r(\mathbb{R}^n)\), where \(r = |\nu|\) and n is equal to the length of nu.

\[p_{\nu}(x) = x^{\nu}.\]
Parameters:nu (int or MultiIndex or Tuple[int, …]) – Multi-index indicating which monomial basis polynomial should be generated. Gives the exponent for each x_i term.
Returns:The monomial base polynomial as specified by nu.
Return type:Polynomial.

Examples

>>> import sympy as sp
>>> x1, x2 = sp.symbols('x1 x2')
>>> monomial_basis_fn(1)(x1)
x1
>>> monomial_basis_fn(2)(x1)
x1**2
>>> monomial_basis_fn((1, 1))((x1, x2))
x1*x2
monomial_basis_fn_latex(nu)[source]

Generate Latex string for a monomial basis polynomial in the space \(\mathcal{P}_r(\mathbb{R}^n)\), where n is equal to the length of nu.

Parameters:nu (int or MultiIndex or Tuple[int, …]) – Multi-index indicating which monomial basis polynomial we should generate Latex string for. Gives the exponent for each x_i term.
Returns:Latex string for the monomial base polynomial as specified by nu.
Return type:str

Examples

>>> monomial_basis_fn_latex(3)
'x^3'
>>> monomial_basis_fn_latex((1, 1, 0))
'x_1 x_2'
monomial_basis_fn_latex_compact(nu)[source]

Generate compact Latex string for a monomial basis polynomial in the space \(\mathcal{P}_r(\mathbb{R}^n)\), where n is equal to the length of nu.

Parameters:nu (int or MultiIndex or Tuple[int, …]) – Multi-index indicating which monomial basis polynomial we should generate Latex string for. Gives the exponent for each x_i term.
Returns:Latex string for the monomial base polynomial as specified by nu.
Return type:str

Examples

>>> monomial_basis_fn_latex_compact(3)
'x^3'
>>> monomial_basis_fn_latex_compact((1, 1, 0))
'x^{(1, 1, 0)}'
monomial_basis_latex(r, n)[source]

Generate Latex strings for all monomial base polynomials for the space \(\mathcal{P}_r(\mathbb{R}^n)\).

Parameters:
  • r (int) – Degree of the polynomial space.
  • n (int) – Dimension of the domain.
Returns:

List of Latex strings for each monomial base polynomial.

Return type:

List[str]

Examples

>>> monomial_basis_latex(2, 1)
['1', 'x', 'x^2']
>>> monomial_basis_latex(2, 2)
['1', 'x_1', 'x_1^2', 'x_2', 'x_1 x_2', 'x_2^2']
monomial_basis_latex_compact(r, n)[source]

Generate compact Latex strings for all monomial base polynomials for the space \(\mathcal{P}_r(\mathbb{R}^n)\).

Parameters:
  • r (int) – Degree of the polynomial space.
  • n (int) – Dimension of the space.
Returns:

List of Latex strings for each monomial base polynomial.

Return type:

List[str]

Examples

>>> monomial_basis_latex_compact(2, 1)
['1', 'x', 'x^2']
>>> monomial_basis_latex_compact(2, 2)
['x^{(0, 0)}', 'x^{(1, 0)}', 'x^{(2, 0)}', 'x^{(0, 1)}', 'x^{(1, 1)}', 'x^{(0, 2)}']
unique_identifier_monomial_basis()[source]

Get unique identifier for the monomial polynomial basis.

Returns:Unique identifier.
Return type:str
unit_polynomial(r=0, m=1, n=1)[source]

Get the monomial polynomial \(p \in \mathcal{P}(\mathbb{R}^m, \mathbb{R}^n)\) which is identically one.

Parameters:
  • m (int) – Dimension of the polynomial domain.
  • n (int) – Dimension of the polynomial target.
  • r (int) – The unit polynomial will be expressed in the monomial basis for \(\mathcal{P}_r(\mathbb{R}^m, \mathbb{R}^n)\).
Returns:

The unit polynomial.

Return type:

Polynomial.

vector_valued_monomial_basis(r, m, n, ordering='interleaved')[source]

Generate all monomial base polynomials for the space \(\mathcal{P}_r(\mathbb{R}^m, \mathbb{R}^n)\).

Parameters:
  • r (int) – Degree of the polynomial space.
  • m (int) – Dimension of the domain.
  • n (int) – Dimension of the target.
  • ordering (str) – How the vector valued basis functions are ordered. Can be “sequential” or “interleaved”. For sequential, sorting is first done on the index of the component that is non-zero, and then the non-zero component is sorted in the same way as the scalar valued basis functions. For “interleaved” basis functions are first sorted on their non-zero component in the same way as scalar valued basis functions, and then they are sorted on the index of the component that is non-zero.
Returns:

List of base polynomials.

Return type:

List[Polynomial].

vector_valued_monomial_basis_fn(nu, i, n)[source]

Generate a vector valued monomial basis polynomial \(p_{\nu, i}\) in the space \(\mathcal{P}_r(\mathbb{R}^m, \mathbb{R}^n)\), where \(r = |\nu|\) and m is equal to the length of nu.

The vector valued basis polynomial is generated by specifying a scalar valued basis polynomial and the component of the vector valued basis polynomial that should be equal to the scalar valued basis polynomial. All other components of the vector valued basis polynomial will be zero, i.e.

\[\begin{split}p_{\nu, i}^j (x) = \begin{cases} p_{\nu} (x), & i = j \\ 0, & \text{else} \end{cases}.\end{split}\]
Parameters:
  • nu (int or MultiIndex or Tuple[int, …]) – Multi-index indicating which scalar valued monomial basis polynomial should be generated for the non-zero component.
  • i (int) – Index of the vector component that is non-zero.
  • n (int) – Dimension of the target.
Returns:

The monomial base polynomial as specified by nu, r, i and n.

Return type:

Polynomial.

Examples

>>> import sympy as sp
>>> x1, x2 = sp.symbols('x1 x2')
>>> vector_valued_monomial_basis_fn(0, 0, 2)(x1)
array([1, 0])
>>> vector_valued_monomial_basis_fn(1, 1, 2)(x1)
array([0, x1], dtype=object)
>>> vector_valued_monomial_basis_fn((1, 0), 0, 2)((x1, x2))
array([x1, 0], dtype=object)
>>> vector_valued_monomial_basis_fn((1, 1), 1, 3)((x1, x2))
array([0, x1*x2, 0], dtype=object)
zero_polynomial(r=0, m=1, n=1)[source]

Get the monomial polynomial \(p \in \mathcal{P}(\mathbb{R}^m, \mathbb{R}^n)\) which is identically zero.

Parameters:
  • m (int) – Dimension of the polynomial domain.
  • n (int) – Dimension of the polynomial target.
  • r (int) – The zero polynomial will be expressed in the monomial basis for \(\mathcal{P}_r(\mathbb{R}^m, \mathbb{R}^n)\).
Returns:

The zero polynomial.

Return type:

Polynomial.