composition_with_inner_matrix

Function composition_with_inner_matrix 

Source
pub fn composition_with_inner_matrix<Coeff, InnerCoeffs>(
    inner_coeffs: InnerCoeffs,
    inner_nvars: usize,
    inner_degree: Power,
    outer_nvars: usize,
    outer_degree: Power,
) -> Result<Array2<Coeff>, Error>
where Coeff: One + Zero + Clone + AddAssign, for<'a> &'a Coeff: Mul<Output = Coeff>, InnerCoeffs: Iterator<Item = Coeff>,
Expand description

Returns a matrix that flattens coefficients for a composition of polynomials.

Let $f$ be a polynomial in $m$ variables of degree $p$ and $g$ a vector of $m$ polynomials in $n$ variables of degree $q$. The composition $f ∘ g$ is a polynomial in $n$ variables of degree $p q$.

This function returns a matrix $M$ that, when multiplied with a vector of coefficients belonging to the outer polynomial $p$, produces the coefficients for the composition, for a fixed vector of inner polynomials $g$.

Argument inner_coeffs is a flattened sequence of the coefficients for the vector of inner polynomials $g$, with inner_nvars the number of inner variables $n$ and inner_degree the degree $q$.

§Errors

If the length of inner_coeffs sequence differs from the expected length, this function returns an error.

§Examples

Let $f(x) = x_1^2 + 2 x_0 x_1$ (coefficients: [1, 2, 0, 0, 0, 0]) and $g(y) = [y_1 - y_2, 3 y_0 + 2]$ (flattened coefficients: [-1, 1, 0, 0, 0, 0, 3, 2]]). The composition is

$$\begin{align} f(g(y)) &= (3 y_0 + 2)^2 + 2 (y_1 - y_2) (3 y_0 + 2) \\ &= -6 y_2 y_0 - 4 y_2 + 6 y_1 y_0 + 4 y_1 + 9 y_0^2 + 12 y_0 + 4, \end{align}$$

(coefficients: [0, 0, -6, -4, 0, 6, 4, 9, 12, 4]).

use ndarray::array;
use nutils_poly;
use sqnc::traits::*;

let f = array![1, 2, 0, 0, 0, 0];
let g = array![-1, 1, 0, 0, 0, 0, 3, 2];
let m = nutils_poly::composition_with_inner_matrix(g.iter().copied(), 3, 1, 2, 2)?;
assert_eq!(m.dot(&f), array![0, 0, -6, -4, 0, 6, 4, 9, 12, 4]);