Crate nutils_poly

Source
Expand description

Low-level functions for evaluating and manipulating polynomials.

The polynomials considered in this crate are power series in zero or more variables centered at zero and truncated to order $p$,

$$ \sum_{\substack{k ∈ ℤ^n \\ \sum_i k_i ≤ p}} c_k \prod_i x_i^{k_i} $$

where $c$ is a vector of coefficients, $x$ a vector of $n$ variables and $p$ a nonnegative integer degree.

This crate requires the coefficients to be stored in a linear array in reverse lexicographic order: the coefficient for powers $j ∈ ℤ^n$ comes before the coefficient for powers $k ∈ ℤ^n \setminus \{j\}$ iff $j_i > k_i$, where $i = \max_l(j_l ≠ k_l)$, the index of the last non-matching power.

This crate provides functions for evaluating polynomials, computing coefficients for the partial derivativative and products of polynomials.

§Examples

The vector of coefficients for the polynomial $f(x, y) = 3 x y + x^2$ is [0, 3, 0, 1, 0, 0].

With eval() we can evaluate this polynomial:

use nutils_poly;

let coeffs = [0, 3, 0, 1, 0, 0];
assert_eq!(nutils_poly::eval(&coeffs, &[1, 0], 2), Ok( 1)); // f(1, 0) =  1
assert_eq!(nutils_poly::eval(&coeffs, &[1, 1], 2), Ok( 4)); // f(1, 1) =  4
assert_eq!(nutils_poly::eval(&coeffs, &[2, 3], 2), Ok(22)); // f(2, 3) = 22

PartialDerivPlan::apply() computes the coefficients for the partial derivative of a polynomial to one of the variables. The partial derivative of $f$ to $x$, the first variable, is $∂_x f(x, y) = 3 y + 2 x$ (coefficients: [3, 2, 0]):

use nutils_poly::PartialDerivPlan;

let coeffs = [0, 3, 0, 1, 0, 0];
let pd = PartialDerivPlan::new(
    2, // number of variables
    2, // degree
    0, // variable to compute the partial derivative to
).unwrap();
assert_eq!(Vec::from_iter(pd.apply(coeffs)?), vec![3, 2, 0]);

§Nutils project

This crate is part of the Nutils project.

Structs§

MapDegree
Index map relating coefficients from one degree to another.
Mul
The product of two polynomials.
MulPlan
Plan for computing products of polynomials.
PartialDeriv
The partial derivative of a polynomial.
PartialDerivIter
An iterator of the coefficients of a partial derivative.
PartialDerivPlan
Plan for computing coefficients for partial derivatives.

Enums§

Error
The error type for fallible operations in this crate.
MulVar
Existence of a variable in the operands of a product polynomial.
ValueMoreOrLess
Enum used by Error::IncorrectNumberOfCoefficients.

Traits§

EvalOps
Operations for evaluating polynomials.
Multiple
Interface for computing a multiple.

Functions§

composition_with_inner_matrix
Returns a matrix that flattens coefficients for a composition of polynomials.
degree
Returns the degree of a polynomial given the number of variables and coefficients.
degree_ncoeffs_iter
Returns an iterator of degrees and number of coefficients.
eval
Evaluates a polynomial for the given values.
ncoeffs
Returns the number of coefficients for a polynomial of given degree and number of variables.
ncoeffs_iter
Returns an iterator of the number of coefficients for a polynomial of degree zero and up.

Type Aliases§

Power