polynomials_on_simplices.polynomial.polynomials_unit_simplex_bernstein_basis module

Polynomials on the m-dimensional unit simplex 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),\end{split}\]

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

\[b_{\nu, r}(x) = \binom{r}{\nu} x^{\nu} (1 - |x|)^{r - |\nu|}.\]

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 unit simplex, \(\mathcal{P}_r (\Delta_c^m)\).

The operations on Bernstein polynomials on a simplex used here is a generalization of the corresponding operations on Bernstein polynomials on the unit interval, as given in [Farouki_and_Rajan_1988].

References

[Farouki_and_Rajan_1988]R.T. Farouki and V.T. Rajan. Algorithms for polynomials in bernstein form, Computer Aided Geometric Design, 5 (1):1 – 26, 1988. ISSN 0167-8396. doi:10.1016/0167-8396(88)90016-7. URL http://www.sciencedirect.com/science/article/pii/0167839688900167.
class PolynomialBernstein(coeff, r=None, m=1)[source]

Bases: polynomials_on_simplices.polynomial.polynomials_base.PolynomialBase

Implementation of the abstract polynomial base class for a polynomial on the m-dimensional unit simplex, 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 (\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\)).
  • m (int) – Dimension of the domain of the polynomial.
  • 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 (\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=1)[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} b_{\nu, r}(x)\) be this polynomial, where \(\{ b_{\nu, r} \}_{\substack{\nu \in \mathbb{N}_0^m \\ |\nu| \leq r}}\) is the Bernstein basis for \(\mathcal{P}_r (\mathbb{R}^m)\). Let \(\{ b_{\nu, s} \}_{\substack{\nu \in \mathbb{N}_0^m \\ |\nu| \leq s}}, s \geq r\) be the Bernstein basis for \(\mathcal{P}_s (\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} b_{\nu, s}(x),\end{split}\]

such that \(p(x) = q(x) \, \forall x \in \Delta_c^n\).

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

Compute the monomial representation of this polynomial.

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

Evaluate a degree r barycentric polynomial on the m-dimensional unit simplex.

\[\begin{split}b(x) = \sum_{\substack{\nu \in \mathbb{N}_0^m \\ |\nu| \leq r}} a_{\nu} x^{\nu} (1 - |x|)^{r - |\nu|}.\end{split}\]
Parameters:
  • r (int) – Degree of the polynomial.
  • a – Coefficient in front of each barycentric base polynomial.
  • x – Point where the polynomial should be evaluated.
Returns:

Value of the polynomial.

bernstein_basis(r, n)[source]

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

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

List of base polynomials.

Return type:

List[PolynomialBernstein].

bernstein_basis_fn(nu, r)[source]

Generate a Bernstein basis polynomial on the n-dimensional unit simplex (\(\Delta_c^n\))

\[b_{\nu, r} (x) = \binom{r}{\nu} x^{\nu} (1 - |x|)^{r - |\nu|},\]

where n is equal to the length of nu.

Parameters:
  • nu (int or MultiIndex or Tuple[int, …]) – Multi-index indicating which Bernstein basis polynomial should be generated.
  • r (int) – Degree of polynomial.
Returns:

The Bernstein base polynomial as specified by nu and r.

Return type:

PolynomialBernstein.

Examples

>>> import sympy as sp
>>> x1, x2 = sp.symbols('x1 x2')
>>> bernstein_basis_fn(0, 1)(x1) - (-x1 + 1)
0
>>> bernstein_basis_fn(1, 1)(x1) - x1
0
>>> sp.simplify(bernstein_basis_fn((1, 0), 2)((x1, x2)) - 2*x1*(-x1 - x2 + 1))
0
>>> sp.simplify(bernstein_basis_fn((1, 1), 3)((x1, x2)) - 6*x1*x2*(-x1 - x2 + 1))
0
bernstein_basis_fn_latex(nu, r)[source]

Generate Latex string for a Bernstein basis polynomial on the n-dimensional unit simplex (\(\Delta_c^n\))

\[b_{\nu, r} (x) = \binom{r}{\nu} x^{\nu} (1 - |x|)^{r - |\nu|},\]

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.
Returns:

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

Return type:

str

Examples

>>> bernstein_basis_fn_latex(2, 3)
'3 x^2 (1 - x)'
>>> bernstein_basis_fn_latex((1, 1), 3)
'6 x_1 x_2 (1 - x_1 - x_2)'
bernstein_basis_fn_latex_compact(nu, r)[source]

Generate compact Latex string for a Bernstein basis polynomial on the n-dimensional unit simplex (\(\Delta_c^n\))

\[b_{\nu, r} (x) = \binom{r}{\nu} x^{\nu} (1 - |x|)^{r - |\nu|},\]

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.
Returns:

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

Return type:

str

Examples

>>> bernstein_basis_fn_latex_compact(2, 3)
'b_{2, 3}(x)'
>>> bernstein_basis_fn_latex_compact((1, 1), 3)
'b_{(1, 1), 3}(x)'
bernstein_basis_fn_monomial(nu, r)[source]

Generate a Bernstein basis polynomial on the n-dimensional unit simplex (\(\Delta_c^n\))

\[b_{\nu, r} (x) = \binom{r}{\nu} x^{\nu} (1 - |x|)^{r - |\nu|},\]

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() 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.
  • r (int) – Degree of polynomial.
Returns:

The Bernstein base polynomial as specified by nu and r.

Return type:

Polynomial.

Examples

>>> import sympy as sp
>>> x1, x2 = sp.symbols('x1 x2')
>>> bernstein_basis_fn_monomial(0, 1)(x1)
-x1 + 1
>>> bernstein_basis_fn_monomial(1, 1)(x1)
x1
>>> bernstein_basis_fn_monomial((1, 0), 2)((x1, x2))
-2*x1**2 - 2*x1*x2 + 2*x1
>>> bernstein_basis_fn_monomial((1, 1), 3)((x1, x2))
-6*x1**2*x2 - 6*x1*x2**2 + 6*x1*x2
bernstein_basis_latex(r, n)[source]

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

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

List of Latex strings for each Bernstein base polynomial.

Return type:

List[str]

Examples

>>> bernstein_basis_latex(2, 1)
['(1 - x)^2', '2 x (1 - x)', 'x^2']
>>> bernstein_basis_latex(2, 2)
['(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']
bernstein_basis_latex_compact(r, n)[source]

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

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

List of Latex strings for each Bernstein base polynomial.

Return type:

List[str]

Examples

>>> bernstein_basis_latex_compact(2, 1)
['b_{0, 2}(x)', 'b_{1, 2}(x)', 'b_{2, 2}(x)']
>>> bernstein_basis_latex_compact(1, 2)
['b_{(0, 0), 1}(x)', 'b_{(1, 0), 1}(x)', 'b_{(0, 1), 1}(x)']
bernstein_basis_monomial(r, n)[source]

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

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

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

List of base polynomials.

Return type:

List[Polynomial].

degree_elevated_bernstein_basis_fn(nu, r, s)[source]

Generate a Bernstein basis polynomial on the n-dimensional unit simplex (\(\Delta_c^n\)) \(b_{\nu, r} (x) = \binom{r}{\nu} x^{\nu} (1 - |x|)^{r - |\nu|}\), where n is equal to the length of nu, and degree elevate it to a degree s Bernstein polynomial.

Parameters:
  • nu (int or MultiIndex or Tuple[int, …]) – Multi-index indicating which Bernstein basis polynomial should be generated.
  • r (int) – Degree of polynomial.
  • s (int) – Degree for the polynomial basis the polynomial should be expressed in.
Returns:

The Bernstein base polynomial as specified by nu and r, expressed as a degree s Bernstein polynomial.

Return type:

PolynomialBernstein.

dual_bernstein_basis(r, n)[source]

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

See dual_bernstein_basis_fn().

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

List of dual base functions.

Return type:

List[callable q(b)].

dual_bernstein_basis_fn(mu, r)[source]

Generate a dual basis function to the Bernstein polynomial basis, i.e. the linear map \(q_{\mu, r} : \mathcal{P}_r(\Delta_c^n) \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 indexed by the multi-index \(\nu\) (see bernstein_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 Bernstein basis function should be generated.
  • r (int) – Degree of polynomial space.
Returns:

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

Return type:

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

dual_bernstein_basis_polynomial(mu, r)[source]

Generate a dual Bernstein basis polynomial on the n-dimensional unit simplex (\(\Delta_c^n\)) \(d_{\mu, r} (x)\), where n is equal to the length of mu.

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

\[\int_{\Delta_c^n} 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.
Returns:

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

Return type:

PolynomialBernstein.

Examples

>>> import sympy as sp
>>> x1, x2 = sp.symbols('x1 x2')
>>> d = dual_bernstein_basis_polynomial((0, 0), 2)((x1, x2))
>>> b = bernstein_basis_fn((0, 0), 2)((x1, x2))
>>> abs(sp.integrate(d * b, (x2, 0, -x1 + 1), (x1, 0, 1)) - 1.0) < 1e-10
True
>>> import sympy as sp
>>> x1, x2 = sp.symbols('x1 x2')
>>> d = dual_bernstein_basis_polynomial((0, 0), 2)((x1, x2))
>>> b = bernstein_basis_fn((1, 0), 2)((x1, x2))
>>> abs(sp.integrate(d * b, (x2, 0, -x1 + 1), (x1, 0, 1))) < 1e-10
True
dual_bernstein_polynomial_basis(r, n)[source]

Generate all dual Bernstein base polynomials for the space \(\mathcal{P}_r(\Delta_c^n)\).

See dual_bernstein_basis_polynomial().

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

List of dual base polynomials.

Return type:

List[PolynomialBernstein].

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

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

See dual_vector_valued_bernstein_basis_fn().

Parameters:
  • r (int) – Degree of the polynomial space.
  • m (int) – Dimension of the unit 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)].

dual_vector_valued_bernstein_basis_fn(mu, r, i, 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(\Delta_c^m, \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()) 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.
  • 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)\).

get_associated_sub_simplex(nu, r, simplex=None)[source]

Get the sub simplex associated with a Bernstein basis polynomial.

For a Bernstein basis polynomial p on a simplex T there exist a unique sub simplex f of T such that p vanishes to degree r on on f*, where f* is the sub simplex opposite to the simplex f (see polynomials_on_simplices.geometry.mesh.simplicial_complex.opposite_sub_simplex()). A polynomial vanishes to degree r on a simplex f* if

\[(\partial_{\alpha} p) = 0, \, \forall x \in f^*, \, \forall \alpha \in \mathbb{N}_0^n, |\alpha| \leq r - 1.\]
Parameters:
  • nu (int or MultiIndex or Tuple[int, …]) – Multi-index indicating for which Bernstein basis polynomial we should get the associated sub simplex.
  • r (int) – Degree of polynomial.
  • simplex (Optional[List[int]]) – Vertex indices for the vertices of the simplex. [0, 1, …, n] assumed if not specified.
Returns:

Tuple containing the associated sub simplex, and the sub multi-index associated with the sub simplex (where all non-zero entries has been removed).

Examples

>>> get_associated_sub_simplex((0,), 1)
([0], (1,))
>>> get_associated_sub_simplex((1,), 1)
([1], (1,))
>>> get_associated_sub_simplex((1, 0, 1), 2, [1, 2, 3, 4])
([2, 4], (1, 1))
unique_identifier_bernstein_basis()[source]

Get unique identifier for the Bernstein polynomial basis on the unit simplex.

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

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

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

The unit polynomial.

Return type:

PolynomialBernstein.

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

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

Parameters:
  • r (int) – Degree of the polynomial space.
  • m (int) – Dimension of the unit 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[PolynomialBernstein].

vector_valued_bernstein_basis_fn(nu, r, i, n)[source]

Generate a vector valued Bernstein basis polynomial on the m-dimensional unit simplex, \(b_{\nu, r, i} : \Delta_c^m \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.
  • n (int) – Dimension of the target.
Returns:

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

Return type:

PolynomialBernstein.

Examples

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

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

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

The zero polynomial.

Return type:

PolynomialBernstein.