polynomials_on_simplices.polynomial.code_generation.generate_lagrange_polynomial_functions_simplex module¶
Functionality for generating Python code used to evaluate Lagrange polynomials.
-
generate_function_eval_general_scalar_valued
(m, r)[source]¶ Generate code for evaluating a general scalar valued degree r polynomial on the m-dimensional unit simplex (\(\Delta_c^m\)), expressed in the Lagrange basis.
\[p_{\nu, r}(x)=\sum_{i = 0}^{\dim(\mathcal{P}_r(\mathbb{R}^m)) - 1} a_{\nu_i} x^{\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).Parameters: Returns: Python code for evaluating a general degree r Lagrange polynomial on an m-dimensional domain.
Return type:
-
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 Lagrange basis.
\[ \begin{align}\begin{aligned}p : \Delta_c^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 Lagrange 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 Lagrange 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 Lagrange basis.
\[ \begin{align}\begin{aligned}p : \Delta_c^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 Lagrange 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 Lagrange 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 Lagrange polynomial on the m-dimensional unit simplex.
\[l(x) = \sum_{i = 0}^{\dim(\mathcal{P}_r(\mathbb{R}^m)) - 1} a_{\nu_i} l_{\nu, r}(x),\]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 Lagrange 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} l_{\nu, r}(x),\]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 Lagrange 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:
-
generate_lagrange_basis
(m, r)[source]¶ Generate code for evaluating all Lagrange 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_lagrange_basis_fn
(nu, r)[source]¶ Generate code for evaluating a Lagrange basis polynomial on the m-dimensional unit simplex, where m is equal to the length of nu.
Parameters: - nu (int or
MultiIndex
or Tuple[int, …]) – Multi-index indicating which Lagrange basis polynomial code should be generated for. - r (int) – Degree of polynomial.
Returns: Python code for evaluating the Lagrange base polynomial as specified by nu.
Return type: Examples
>>> generate_lagrange_basis_fn(1, 1) 'x' >>> generate_lagrange_basis_fn((1, 1), 2) '4 * x[0] * x[1]'
- nu (int or