polynomials_on_simplices.polynomial.code_generation.generate_monomial_polynomial_functions module¶
Functionality for generating Python code used to evaluate monomial polynomials.
-
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 an m-dimensional domain, expressed in the monomial basis.
\[ \begin{align}\begin{aligned}p : \mathbb{R}^m \to \mathbb{R},\\p_{\nu, r}(x)=\sum_{i = 0}^{\dim(\mathcal{P}_r(\mathbb{R}^m)) - 1} a_{\nu_i} x^{\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 domain.
- r (int) – Degree of the polynomial space.
- a (Iterable[float]) – Coefficients for the polynomial in the monomial basis for \(\mathcal{P}_r (\mathbb{R}^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 monomial 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 an m-dimensional domain, expressed in the monomial basis.
\[ \begin{align}\begin{aligned}p : \mathbb{R}^m \to \mathbb{R}^n, n > 1,\\p_{\nu, r}(x)=\sum_{i = 0}^{\dim(\mathcal{P}_r(\mathbb{R}^m)) - 1} a_{\nu_i} x^{\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 domain.
- r (int) – Degree of the polynomial space.
- a (Iterable[n-dimensional vector]) – Coefficients for the polynomial in the monomial basis for \(\mathcal{P}_r (\mathbb{R}^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 monomial 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 monomial polynomial on an m-dimensional domain.
\[p(x) = \sum_{i = 0}^{\dim(\mathcal{P}_r(\mathbb{R}^m)) - 1} a_{\nu_i} x^{\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 monomial polynomial on an m-dimensional domain with given basis coefficients a.
\[p(x) = \sum_{i = 0}^{\dim(\mathcal{P}_r(\mathbb{R}^m)) - 1} a_{\nu_i} x^{\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 monomial basis for \(\mathcal{P}_r (\mathbb{R}^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:
-
generate_monomial_basis
(m, r)[source]¶ Generate code for evaluating all monomial base polynomials for the space \(\mathcal{P}_r(\mathbb{R}^m)\).
Parameters: Returns: List of codes for evaluating each of the base polynomials.
Return type: List[str]
-
generate_monomial_basis_fn
(nu)[source]¶ Generate code for evaluating a monomial basis polynomial on an m-dimensional domain, \(p_{\nu} (x) = x^{\nu}\), where m is equal to the length of nu.
Parameters: nu (int or MultiIndex
or Tuple[int, …]) – Multi-index indicating which monomial basis polynomial code should be generated for.Returns: Python code for evaluating the monomial base polynomial as specified by nu. Return type: str Examples
>>> generate_monomial_basis_fn(0) '1' >>> generate_monomial_basis_fn(1) 'x' >>> generate_monomial_basis_fn((1, 1)) 'x[0] * x[1]'