polynomials_on_simplices.polynomial.polynomials_unit_simplex_bases module

Functionality for working with different bases for polynomials on the unit simplex, and for converting between these bases.

convert_polynomial_to_basis(p, target_basis)[source]

Convert a polynomial in \(\mathcal{P}_r (\Delta_c^m)\) to the given basis.

Parameters:
  • p – Polynomial expanded in some basis.
  • target_basis (str) – Unique identifier for the basis we want to expand the polynomial in.
Returns:

Polynomial expanded in the given basis.

dual_polynomial_basis(r, n, basis)[source]

Generate all dual base functions for the space \(\mathcal{P}_r(\Delta_c^n)\) in the given basis (i.e. a basis for \(\mathcal{P}_r(\Delta_c^n)^*\)).

Parameters:
  • r (int) – Degree of the polynomial space.
  • n (int) – Dimension of the domain.
  • basis (str) – Unique identifier for the basis we should generate dual base functions for.
Returns:

List of dual base functions.

Return type:

List[callable q(p)].

dual_polynomial_basis_fn(mu, r, basis)[source]

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

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

where \(p_{\nu, r}\) is the degree r basis polynomial indexed by the multi-index \(\nu\) in the given basis 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 basis function should be generated.
  • r (int) – Degree of polynomial space.
  • basis (str) – Unique identifier for the basis we should generate a dual base function for.
Returns:

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

Return type:

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

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

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

See dual_vector_valued_polynomial_basis_fn().

Parameters:
  • r (int) – Degree of the polynomial space.
  • m (int) – Dimension of the domain.
  • n (int) – Dimension of the target.
  • basis (str) – Unique identifier for the basis we should generate dual base functions for.
  • 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_polynomial_basis_fn(mu, r, i, n, basis)[source]

Generate a dual basis function to a vector valued 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 basis polynomial indexed by the multi-index \(\nu\) with a non-zero i:th component in the given basis (see vector_valued_polynomial_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 basis function should be generated.
  • r (int) – Degree of polynomial space.
  • i (int) – Integer indicating which dual basis function should be generated.
  • n (int) – Dimension of the target.
  • basis (str) – Unique identifier for the basis we should generate a dual base function for.
Returns:

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

Return type:

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

polynomial_basis(r, n, basis)[source]

Generate all base polynomials for the space \(\mathcal{P}_r(\Delta_c^n)\) in the given basis.

Parameters:
  • r (int) – Degree of the polynomial space.
  • n (int) – Dimension of the unit simplex.
  • basis (str) – Unique identifier for the basis we should generate base polynomials for.
Returns:

List of base polynomials in the specified basis.

polynomial_basis_fn(nu, r, basis)[source]

Generate a basis polynomial in the space \(\mathcal{P}_r(\Delta_c^n)\) (where n is equal to the length of nu) in the given basis.

Parameters:
  • nu (int or MultiIndex or Tuple[int, …]) – Multi-index indicating which basis polynomial should be generated.
  • r (int) – Degree of polynomial.
  • basis (str) – Unique identifier for the basis we should generate a base polynomial for.
Returns:

The base polynomial as specified by nu, r and basis.

Return type:

Implementation of PolynomialBase.

polynomial_basis_fn_latex(nu, r, basis)[source]

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

Parameters:
  • nu (int or MultiIndex or Tuple[int, …]) – Multi-index indicating which basis polynomial should be generated.
  • r (int) – Degree of polynomial.
  • basis (str) – Unique identifier for the basis we should generate a basis polynomial Latex string for.
Returns:

Latex string for the base polynomial as specified by nu, r and basis.

Return type:

str

Examples

>>> polynomial_basis_fn_latex(3, 3, unique_identifier_monomial_basis())
'x^3'
>>> polynomial_basis_fn_latex((1, 1, 1), 3, unique_identifier_bernstein_basis())
'6 x_1 x_2 x_3'
polynomial_basis_fn_latex_compact(nu, r, basis)[source]

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

Parameters:
  • nu (int or MultiIndex or Tuple[int, …]) – Multi-index indicating which basis polynomial should be generated.
  • r (int) – Degree of polynomial.
  • basis (str) – Unique identifier for the basis we should generate a basis polynomial Latex string for.
Returns:

Latex string for the base polynomial as specified by nu, r and basis.

Return type:

str

Examples

>>> polynomial_basis_fn_latex_compact(3, 3, unique_identifier_monomial_basis())
'x^3'
>>> polynomial_basis_fn_latex_compact((1, 1), 3, unique_identifier_monomial_basis())
'x^{(1, 1)}'
>>> polynomial_basis_fn_latex_compact((1, 1, 1), 3, unique_identifier_bernstein_basis())
'b_{(1, 1, 1), 3}(x)'
polynomial_basis_latex(r, n, basis)[source]

Generate Latex strings for all base polynomials for the space \(\mathcal{P}_r(\Delta_c^n)\) in the given basis.

Parameters:
  • r (int) – Degree of the polynomial space.
  • n (int) – Dimension of the unit simplex.
  • basis (str) – Unique identifier for the basis we should generate base polynomial Latex strings for.
Returns:

List of Latex strings for each base polynomials in the specified basis.

Return type:

List[str]

Examples

>>> polynomial_basis_latex(2,1,unique_identifier_monomial_basis())
['1', 'x', 'x^2']
>>> polynomial_basis_latex(2,2,unique_identifier_bernstein_basis())
['(1 - x_1 - x_2)^2', '2 x_1 (1 - x_1 - x_2)', 'x_1^2', '2 x_2 (1 - x_1 - x_2)', '2 x_1 x_2', 'x_2^2']
polynomial_basis_latex_compact(r, n, basis)[source]

Generate compact Latex strings for all base polynomials for the space \(\mathcal{P}_r(\Delta_c^n)\) in the given basis.

Parameters:
  • r (int) – Degree of the polynomial space.
  • n (int) – Dimension of the unit simplex.
  • basis (str) – Unique identifier for the basis we should generate base polynomial Latex strings for.
Returns:

List of Latex strings for each base polynomials in the specified basis.

Return type:

List[str]

Examples

>>> polynomial_basis_latex_compact(2,1,unique_identifier_monomial_basis())
['1', 'x', 'x^2']
>>> polynomial_basis_latex_compact(1,2,unique_identifier_bernstein_basis())
['b_{(0, 0), 1}(x)', 'b_{(1, 0), 1}(x)', 'b_{(0, 1), 1}(x)']
vector_valued_polynomial_basis(r, m, n, basis, ordering='interleaved')[source]

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

Parameters:
  • r (int) – Degree of the polynomial space.
  • m (int) – Dimension of the domain.
  • n (int) – Dimension of the target.
  • basis (str) – Unique identifier for the basis we should generate base polynomials for.
  • 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 in the specified basis.

vector_valued_polynomial_basis_fn(nu, r, i, n, basis)[source]

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

Parameters:
  • nu (int or MultiIndex or Tuple[int, …]) – Multi-index indicating which basis polynomial should be generated.
  • r (int) – Degree of polynomial.
  • i (int) – Index of the vector component that is non-zero.
  • n (int) – Dimension of the target.
  • basis (str) – Unique identifier for the basis we should generate a base polynomial for.
Returns:

The base polynomial as specified by nu, r and basis.

Return type:

Implementation of PolynomialBase.