pub struct MulPlan { /* private fields */ }
Expand description
Plan for computing products of polynomials.
This struct holds a plan for efficiently evaluating products of polynomials.
§Examples
Consider the following polynomials: $f(x) = x^2$ (coefficients: [1, 0, 0]
), $g(x) = 2 x + 1$ (coefficients: [2, 1]
) and $h(x, y) = x y$
(coefficients: [0, 1, 0, 0, 0, 0]
).
use nutils_poly::{MulPlan, MulVar};
use sqnc::traits::*;
let f = [1, 0, 0]; // degree: 2, nvars: 1
let g = [2, 1]; // degree: 1, nvars: 1
let h = [0, 1, 0, 0, 0, 0]; // degree: 2, nvars: 2
Computing the coefficients for $x ↦ f(x) g(x)$:
use sqnc::traits::*;
let plan = MulPlan::same_vars(
1, // number of variables
2, // degree of left operand
1, // degree of right operand
);
let fx_gx = plan.apply(f.as_sqnc(), g.as_sqnc()).unwrap();
assert!(fx_gx.iter().eq([2, 1, 0, 0]));
Similarly, but with different variables, $(x, y) ↦ f(x) g(y)$:
use sqnc::traits::*;
let plan = MulPlan::different_vars(
1, // number of variables of the left operand
1, // number of variables of the right operand
2, // degree of left operand
1, // degree of right operand
)?;
let fx_gy = plan.apply(f.as_sqnc(), g.as_sqnc()).unwrap();
assert!(fx_gy.iter().eq([0, 0, 0, 2, 0, 0, 0, 1, 0, 0]));
Computing the coefficients for $(x, y) ↦ f(y) h(x,y)$:
use sqnc::traits::*;
let plan = MulPlan::new(
&[
MulVar::Right, // variable x, exists only in the right operand
MulVar::Both, // variable y, exists in both operands
].copied(),
2, // degree of left operand
2, // degree of right operand
);
let fy_hxy = plan.apply(f.as_sqnc(), h.as_sqnc()).unwrap();
assert!(fy_hxy.iter().eq([0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
Implementations§
Source§impl MulPlan
impl MulPlan
Sourcepub fn new<'vars, Vars>(
vars: &'vars Vars,
degree_left: Power,
degree_right: Power,
) -> Selfwhere
Vars: SequenceOwned<OwnedItem = MulVar>,
<Vars as SequenceTypes<'vars>>::Iter: DoubleEndedIterator,
pub fn new<'vars, Vars>(
vars: &'vars Vars,
degree_left: Power,
degree_right: Power,
) -> Selfwhere
Vars: SequenceOwned<OwnedItem = MulVar>,
<Vars as SequenceTypes<'vars>>::Iter: DoubleEndedIterator,
Plan the product of two polynomials.
For each output variable, vars
lists the relation between output and input variables:
MulVar::Left
if the variable exists only in the left polynomial,MulVar::Right
if the variable exists only in the right polynomial orMulVar::Both
if the variable exists in both polynomials.
It is not possible to reorder the output variables with respect to the input variables.
Sourcepub fn for_output_degree<'vars, Vars>(
vars: &'vars Vars,
degree_left: Power,
degree_right: Power,
degree_output: Power,
) -> Selfwhere
Vars: SequenceOwned<OwnedItem = MulVar>,
<Vars as SequenceTypes<'vars>>::Iter: DoubleEndedIterator,
pub fn for_output_degree<'vars, Vars>(
vars: &'vars Vars,
degree_left: Power,
degree_right: Power,
degree_output: Power,
) -> Selfwhere
Vars: SequenceOwned<OwnedItem = MulVar>,
<Vars as SequenceTypes<'vars>>::Iter: DoubleEndedIterator,
Plan the product of two polynomials for the given output degree.
If the output degree is smaller than the sum of the degrees of the input operands, then the product is truncated.
Sourcepub fn same_vars(nvars: usize, degree_left: Power, degree_right: Power) -> Self
pub fn same_vars(nvars: usize, degree_left: Power, degree_right: Power) -> Self
Plan the product of two polynomials in the same variables.
Sourcepub fn same_vars_for_output_degree(
nvars: usize,
degree_left: Power,
degree_right: Power,
degree_output: Power,
) -> Self
pub fn same_vars_for_output_degree( nvars: usize, degree_left: Power, degree_right: Power, degree_output: Power, ) -> Self
Plan the product of two polynomials in the same variables for the given output degree.
If the output degree is smaller than the sum of the degrees of the input operands, then the product is truncated.
Sourcepub fn different_vars(
nvars_left: usize,
nvars_right: usize,
degree_left: Power,
degree_right: Power,
) -> Result<Self, Error>
pub fn different_vars( nvars_left: usize, nvars_right: usize, degree_left: Power, degree_right: Power, ) -> Result<Self, Error>
Plan the product of two polynomials in different variables.
The coefficients returned by MulPlan::apply()
are ordered such that
the first nvars_left
variables are the variables of the left operand and
the last nvars_right
are the variables of the right operand.
Sourcepub fn different_vars_for_output_degree(
nvars_left: usize,
nvars_right: usize,
degree_left: Power,
degree_right: Power,
degree_output: Power,
) -> Result<Self, Error>
pub fn different_vars_for_output_degree( nvars_left: usize, nvars_right: usize, degree_left: Power, degree_right: Power, degree_output: Power, ) -> Result<Self, Error>
Plan the product of two polynomials in different variables for the given output degree.
The coefficients returned by MulPlan::apply()
are ordered such that
the first nvars_left
variables are the variables of the left operand and
the last nvars_right
are the variables of the right operand.
If the output degree is smaller than the sum of the degrees of the input operands, then the product is truncated.
Sourcepub fn apply<LCoeffs, RCoeffs>(
&self,
coeffs_left: LCoeffs,
coeffs_right: RCoeffs,
) -> Result<Mul<'_, LCoeffs, RCoeffs>, Error>
pub fn apply<LCoeffs, RCoeffs>( &self, coeffs_left: LCoeffs, coeffs_right: RCoeffs, ) -> Result<Mul<'_, LCoeffs, RCoeffs>, Error>
Returns the coefficients for the product of two polynomials.
§Errors
This function returns an error if the number of coefficients of the
left or right polynomial doesn’t match MulPlan::ncoeffs_left()
or
MulPlan::ncoeffs_right()
, respectively.
Sourcepub fn ncoeffs_left(&self) -> usize
pub fn ncoeffs_left(&self) -> usize
Returns the number of coefficients for the left operand.
Sourcepub fn ncoeffs_right(&self) -> usize
pub fn ncoeffs_right(&self) -> usize
Returns the number of coefficients for the left operand.
Sourcepub fn ncoeffs_output(&self) -> usize
pub fn ncoeffs_output(&self) -> usize
Returns the number of coefficients for the product.
Sourcepub fn nvars_output(&self) -> usize
pub fn nvars_output(&self) -> usize
Returns the number of variables for the product.
Sourcepub fn degree_output(&self) -> Power
pub fn degree_output(&self) -> Power
Returns the degree of the product.