polynomials_on_simplices.polynomial.code_generation.generate_barycentric_polynomial_functions_simplex module¶
Functionality for generating Python code used to evaluate barycentric polynomials.
-
generate_barycentric_basis
(m, r, str_type='python')[source]¶ Generate string representation for all barycentric base polynomials for the space \(\mathcal{P}_r(\Delta_c^m)\).
Parameters: Returns: List of codes for evaluating each of the base polynomials.
Return type: List[str]
-
generate_barycentric_basis_fn
(nu, r, str_type='python')[source]¶ Generate string representation for a barycentric basis polynomial on the m-dimensional unit simplex (\(\Delta_c^m\)), \(p_{\nu, r} (x) = x^{\nu} (1 - |x|)^{r - |\nu|}\), where m is equal to the length of nu.
Parameters: - nu (int or
MultiIndex
or Tuple[int, …]) – Multi-index indicating which barycentric basis polynomial should be generated. - r (int) – Degree of polynomial.
- str_type – What kind of string should be generated. Can be either “python” or “latex”.
Returns: Python code for evaluating the barycentric base polynomial as specified by nu and r.
Return type: Examples
>>> generate_barycentric_basis_fn(1, 2) 'x * (1 - x)' >>> generate_barycentric_basis_fn((1, 1), 3) 'x[0] * x[1] * (1 - x[0] - x[1])' >>> generate_barycentric_basis_fn((1, 1), 3, str_type="latex") 'x_1 x_2 (1 - x_1 - x_2)'
- nu (int or
-
generate_function_eval_specific_scalar_valued
(m, r, a, prettify_coefficients=False)[source]¶ Generate code for evaluating a specific scalar valued degree r polynomial on the m-dimensional unit simplex (\(\Delta_c^m\)), expressed in the barycentric basis.
\[ \begin{align}\begin{aligned}p_{\nu, r} : \Delta_c^m \to \mathbb{R},\\p_{\nu, r}(x)=\sum_{i = 0}^{\dim(\mathcal{P}_r(\Delta_c^m)) - 1} a_{\nu_i} x^{\nu_i} (1 - |x|)^{r - |\nu_i|},\end{aligned}\end{align} \]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).Parameters: - m (int) – Dimension of the unit simplex.
- r (int) – Degree of the polynomial space.
- a (Iterable[float]) – Coefficients for the polynomial in the barycentric basis for \(\mathcal{P}_r (\Delta_c^m)\).
\(\text{a}[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). - prettify_coefficients (bool) – Whether or not coefficients in the a array should be prettified in the generated code (e.g. converting 0.25 -> 1 / 4).
Returns: Python code for evaluating the barycentric base polynomial as specified by m, r and a.
Return type:
-
generate_function_eval_specific_vector_valued
(m, r, a)[source]¶ Generate code for evaluating a specific vector valued degree r polynomial on the m-dimensional unit simplex (\(\Delta_c^m\)), expressed in the barycentric basis.
\[ \begin{align}\begin{aligned}p_{\nu, r} : \Delta_c^m \to \mathbb{R}^n, n > 1,\\p_{\nu, r}(x)=\sum_{i = 0}^{\dim(\mathcal{P}_r(\Delta_c^m)) - 1} a_{\nu_i} x^{\nu_i} (1 - |x|)^{r - |\nu_i|},\end{aligned}\end{align} \]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).Parameters: - m (int) – Dimension of the unit simplex.
- r (int) – Degree of the polynomial space.
- a (Iterable[n-dimensional vector]) – Coefficients for the polynomial in the barycentric basis for \(\mathcal{P}_r (\Delta_c^m)\).
\(\text{a}[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).
Returns: Python code for evaluating the barycentric base polynomial as specified by m, r and a.
Return type:
-
generate_function_general
(m, r)[source]¶ Generate code for evaluating a general degree r barycentric polynomial on the m-dimensional unit simplex.
\[p(x) = \sum_{i = 0}^{\dim(\mathcal{P}_r(\Delta_c^m)) - 1} a_{\nu_i} x^{\nu} (1 - |x|)^{r - |\nu|},\]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).Parameters: Returns: Python code for evaluating the polynomial
Return type:
-
generate_function_specific
(m, r, a)[source]¶ Generate code for evaluating the degree r barycentric polynomial on the m-dimensional unit simplex with given basis coefficients a.
\[p(x) = \sum_{i = 0}^{\dim(\mathcal{P}_r(\Delta_c^m)) - 1} a_{\nu_i} x^{\nu} (1 - |x|)^{r - |\nu|},\]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).Parameters: - m (int) – Dimension of the domain of the polynomial.
- r (int) – Degree of the polynomial space.
- a (Union[Iterable[float], Iterable[n-dimensional vector]]) – Coefficients for the polynomial in the barycentric basis for \(\mathcal{P}_r (\Delta_c^m)\).
\(\text{a}[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).
Returns: Python code for evaluating the polynomial
Return type: