polynomials_on_simplices.polynomial.polynomials_simplex_bernstein_basis module

Polynomials on an m-dimensional simplex T with values in \(\mathbb{R}^n\), expressed using the Bernstein basis.

\[\begin{split}b(x) = \sum_{\substack{\nu \in \mathbb{N}_0^m \\ |\nu| \leq r}} a_{\nu} b_{\nu, r}(x) = \sum_{\nu} a_{\nu} (\bar{b}_{\nu, r} \circ \Phi^{-1})(x),\end{split}\]

where \(a_{\nu} \in \mathbb{R}^n, \bar{l}_{\nu, r}\) is the Bernstein basis on the unit simplex and \(\Phi\) is the unique affine map which maps the unit simplex onto the simplex T (the i:th vertex of the unit simplex is mapped to the i:th vertex of the simplex T).

The set \(\{ b_{\nu, r} \}_{\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 the simplex T, \(\mathcal{P}_r (T)\).

class PolynomialBernsteinSimplex(coeff, vertices, r=None)[source]

Bases: polynomials_on_simplices.polynomial.polynomials_simplex_base.PolynomialSimplexBase

Implementation of the abstract polynomial base class for a polynomial on an m-dimensional simplex T, expressed in the Bernstein basis.

\[b(x) = \sum_{i = 0}^{\dim(\mathcal{P}_r(\mathbb{R}^m)) - 1} a_{\nu_i} b_{\nu_i, r}(x).\]
Parameters:
  • coeff – Coefficients for the polynomial in the Bernstein basis for \(\mathcal{P}_r (T, \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\)).
  • vertices – Vertices of the simplex T ((m + 1) x m matrix where row i contains the i:th vertex of the simplex).
  • r (int) – Degree of the polynomial space. Optional, will be inferred from the number of polynomial coefficients if not specified.
basis()[source]

Get basis for the space \(\mathcal{P}_r (T)\) 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^k \\ |\nu| \leq r}} a_{\nu} b_{\nu, r}(x)\) be this polynomial, where \(\{ b_{\nu, r} \}_{\substack{\nu \in \mathbb{N}_0^k \\ |\nu| \leq r}}\) is the Bernstein basis for \(\mathcal{P}_r (T)\). Let \(\{ b_{\nu, s} \}_{\substack{\nu \in \mathbb{N}_0^k \\ |\nu| \leq s}}, s \geq r\) be the Bernstein basis for \(\mathcal{P}_s (T)\). Then this function returns a polynomial \(q(x)\)

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

such that \(p(x) = q(x) \, \forall x \in T\).

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:PolynomialBernsteinSimplex.
latex_str()[source]

Generate a Latex string for this polynomial.

Returns:Latex string for this polynomial.
Return type:str
latex_str_expanded()[source]

Generate a Latex string for this polynomial, where each basis function has been expanded in the monomial basis.

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:PolynomialBernsteinSimplex.
to_monomial_basis()[source]

Compute the monomial representation of this polynomial.

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

Generate a Bernstein basis polynomial on an n-dimensional simplex T, where n is equal to the length of nu.

\[b_{\nu, r}(x) = (\bar{b}_{\nu, r} \circ \Phi^{-1})(x),\]

where \(\bar{b}_{\nu, r}\) is the corresponding Bernstein basis polynomial on the (n-dimensional) unit simplex, and \(\Phi\) is the unique affine map which maps the unit simplex to the simplex T.

Parameters:
  • nu (int or MultiIndex or Tuple[int, …]) – Multi-index indicating which Bernstein basis polynomial should be generated. The polynomial will have the value 1 at the point associated with the multi-index, and value 0 at all other points.
  • r (int) – Degree of polynomial.
  • vertices – Vertices of the simplex T ((n + 1) x n matrix where row i contains the i:th vertex of the simplex).
Returns:

The Bernstein base polynomial on the simplex T, as specified by nu and r.

Return type:

PolynomialBernsteinSimplex.

bernstein_basis_fn_simplex_latex(nu, r, vertices)[source]

Generate Latex string for a Bernstein basis polynomial on an n-dimensional simplex T, where n is equal to the length of nu.

Parameters:
  • nu (int or MultiIndex or Tuple[int, …]) – Multi-index indicating which Bernstein basis polynomial we should generate Latex string for.
  • r (int) – Degree of polynomial.
  • vertices – Vertices of the simplex T ((n + 1) x n matrix where row i contains the i:th vertex of the simplex).
Returns:

Latex string for the Bernstein base polynomial on T, as specified by nu and r.

Return type:

str

bernstein_basis_fn_simplex_monomial(nu, r, vertices)[source]

Generate a Bernstein basis polynomial on an n-dimensional simplex T, where n is equal to the length of nu, expanded in the monomial basis.

This is the same polynomial as given by the bernstein_basis_fn_simplex() function, but expressed in the monomial basis.

Parameters:
  • nu (int or MultiIndex or Tuple[int, …]) – Multi-index indicating which Bernstein basis polynomial should be generated The polynomial will have the value 1 at the point associated with the multi-index, and value 0 at all other points.
  • r (int) – Degree of polynomial.
  • vertices – Vertices of the simplex T ((n + 1) x n matrix where row i contains the i:th vertex of the simplex).
Returns:

The Bernstein base polynomial on the simplex T, as specified by nu and r.

Return type:

Polynomial.

bernstein_basis_simplex(r, vertices)[source]

Generate all Bernstein base polynomials for the space \(\mathcal{P}_r(T)\) where T is an n-dimensional simplex.

Parameters:
  • r (int) – Degree of the polynomial space.
  • vertices – Vertices of the simplex T ((n + 1) x n matrix where row i contains the i:th vertex of the simplex).
Returns:

List of base polynomials.

Return type:

List[PolynomialBernsteinSimplex].

bernstein_basis_simplex_latex(r, vertices)[source]

Generate Latex strings for all Bernstein base polynomials for the space \(\mathcal{P}_r(T)\), where T is an m-dimensional simplex.

Parameters:
  • r (int) – Degree of the polynomial space.
  • vertices – Vertices of the simplex T ((m + 1) x m matrix where row i contains the i:th vertex of the simplex).
Returns:

List of Latex strings for each Bernstein base polynomial.

Return type:

List[str]

bernstein_basis_simplex_monomial(r, vertices)[source]

Generate all Bernstein base polynomials for the space \(\mathcal{P}_r(T)\) where T is an n-dimensional simplex, expanded in the monomial basis.

This is the same set of polynomials as given by the bernstein_basis_simplex() function, but expressed in the monomial basis.

Parameters:
  • r (int) – Degree of the polynomial space.
  • vertices – Vertices of the simplex T ((n + 1) x n matrix where row i contains the i:th vertex of the simplex).
Returns:

List of base polynomials.

Return type:

List[Polynomial].

dual_bernstein_basis_fn_simplex(mu, r, vertices)[source]

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

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

where \(b_{\nu, r}\) is the degree r Bernstein basis polynomial on T indexed by the multi-index \(\nu\) (see bernstein_basis_fn_simplex()) 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 Bernstein basis function should be generated.
  • r (int) – Degree of polynomial space.
  • vertices – Vertices of the simplex T ((n + 1) x n matrix where row i contains the i:th vertex of the simplex).
Returns:

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

Return type:

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

dual_bernstein_basis_polynomial_simplex(mu, r, vertices)[source]

Generate a dual Bernstein basis polynomial on an n-dimensional simplex T, where n is equal to the length of nu.

The dual Bernstein basis \(d_{\mu, r} (x)\) is the unique polynomial that satisfies

\[\int_{T} d_{\mu, r}(x) b_{\nu, r} (x) \, dx = \delta_{\mu, \nu}.\]
Parameters:
  • mu (int or MultiIndex or Tuple[int, …]) – Multi-index indicating which dual Bernstein basis polynomial should be generated.
  • r (int) – Degree of polynomial.
  • vertices – Vertices of the simplex T ((n + 1) x n matrix where row i contains the i:th vertex of the simplex).
Returns:

The dual Bernstein base polynomial as specified by mu and r.

Return type:

PolynomialBernsteinSimplex.

dual_bernstein_basis_simplex(r, vertices)[source]

Generate all dual Bernstein base functions for the space \(\mathcal{P}_r(T)\), where T is an n-dimensional simplex (i.e. a basis for \(\mathcal{P}_r(T)^*\)).

See dual_bernstein_basis_fn_simplex().

Parameters:
  • r (int) – Degree of the polynomial space.
  • vertices – Vertices of the simplex T ((n + 1) x n matrix where row i contains the i:th vertex of the simplex).
Returns:

List of dual base functions.

Return type:

List[callable q(b)].

dual_bernstein_polynomial_basis_simplex(r, vertices)[source]

Generate all dual Bernstein base polynomials for the space \(\mathcal{P}_r(T)\) where T is an n-dimensional simplex.

See dual_bernstein_basis_polynomial_simplex().

Parameters:
  • r (int) – Degree of the polynomial space.
  • vertices – Vertices of the simplex T ((n + 1) x n matrix where row i contains the i:th vertex of the simplex).
Returns:

List of dual base polynomials.

Return type:

List[PolynomialBernsteinSimplex].

dual_vector_valued_bernstein_basis_fn_simplex(mu, r, i, vertices, n)[source]

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

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

where \(b_{\nu, r, j}\) is the degree r vector valued Bernstein basis polynomial indexed by the multi-index \(\nu\) with a non-zero i:th component (see vector_valued_bernstein_basis_fn_simplex()) 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 Bernstein basis function should be generated.
  • r (int) – Degree of polynomial space.
  • i (int) – Integer indicating which dual Bernstein basis function should be generated.
  • vertices – Vertices of the simplex T ((m + 1) x m matrix where row i contains the i:th vertex of the simplex).
  • n (int) – Dimension of the target.
Returns:

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

Return type:

Callable \(q_{\mu, r, i}(b)\).

dual_vector_valued_bernstein_basis_simplex(r, vertices, n, ordering='interleaved')[source]

Generate all dual Bernstein base functions for the space \(\mathcal{P}_r(T, \mathbb{R}^n)\), where T is an m-dimensional simplex (i.e. a basis for \(\mathcal{P}_r(T, \mathbb{R}^n)^*\)).

See dual_vector_valued_bernstein_basis_fn_simplex().

Parameters:
  • r (int) – Degree of the polynomial space.
  • vertices – Vertices of the simplex T ((m + 1) x m matrix where row i contains the i:th vertex of the simplex).
  • 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(b)].

unique_identifier_bernstein_basis_simplex(vertices)[source]

Get unique identifier for the Bernstein polynomial basis on a simplex T.

Parameters:vertices – Vertices of the simplex T ((m + 1) x m matrix where row i contains the i:th vertex of the simplex).
Returns:Unique identifier.
Return type:str
unit_polynomial_simplex(vertices, r=0, n=1)[source]

Get the Bernstein polynomial \(b \in \mathcal{P}(T, \mathbb{R}^n)\) which is identically one, where T is an m-dimensional simplex.

Parameters:
  • vertices – Vertices of the simplex T ((m + 1) x m matrix where row i contains the i:th vertex of the simplex).
  • r (int) – The unit polynomial will be expressed in the Bernstein basis for \(\mathcal{P}_r(T, \mathbb{R}^n)\).
  • n (int) – Dimension of the polynomial target.
Returns:

The unit polynomial.

Return type:

PolynomialBernsteinSimplex.

vector_valued_bernstein_basis_fn_simplex(nu, r, i, vertices, n)[source]

Generate a vector valued Bernstein basis polynomial on an m-dimensional simplex T, \(b_{\nu, r, i} : T \to \mathbb{R}^n\).

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}b_{\nu, r, i}^j (x) = \begin{cases} b_{\nu, r} (x), & i = j \\ 0, & \text{else} \end{cases},\end{split}\]

where m is equal to the length of nu.

Parameters:
  • nu (int or MultiIndex or Tuple[int, …]) – Multi-index indicating which scalar valued Bernstein basis polynomial should be generated for the non-zero component.
  • r (int) – Degree of polynomial.
  • i (int) – Index of the vector component that is non-zero.
  • vertices – Vertices of the simplex T ((m + 1) x m matrix where row i contains the i:th vertex of the simplex).
  • n (int) – Dimension of the target.
Returns:

The Bernstein base polynomial on the simplex T as specified by nu, r, i and n.

Return type:

PolynomialBernsteinSimplex.

vector_valued_bernstein_basis_simplex(r, vertices, n, ordering='interleaved')[source]

Generate all Bernstein base polynomials for the space \(\mathcal{P}_r(T, \mathbb{R}^n)\), where T is an m-dimensional simplex.

Parameters:
  • r (int) – Degree of the polynomial space.
  • vertices – Vertices of the simplex T ((m + 1) x m matrix where row i contains the i:th vertex of the simplex).
  • 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[PolynomialBernsteinSimplex].

zero_polynomial_simplex(vertices, r=0, n=1)[source]

Get the Bernstein polynomial \(b \in \mathcal{P}(T, \mathbb{R}^n)\) which is identically zero, where T is an m-dimensional simplex.

Parameters:
  • vertices – Vertices of the simplex T ((m + 1) x m matrix where row i contains the i:th vertex of the simplex).
  • r (int) – The zero polynomial will be expressed in the Bernstein basis for \(\mathcal{P}_r(T, \mathbb{R}^n)\).
  • n (int) – Dimension of the polynomial target.
Returns:

The zero polynomial.

Return type:

PolynomialBernsteinSimplex.