MulPlan

Struct MulPlan 

Source
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

Source

pub fn new<'vars, Vars>( vars: &'vars Vars, degree_left: Power, degree_right: Power, ) -> Self
where 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 or
  • MulVar::Both if the variable exists in both polynomials.

It is not possible to reorder the output variables with respect to the input variables.

Source

pub fn for_output_degree<'vars, Vars>( vars: &'vars Vars, degree_left: Power, degree_right: Power, degree_output: Power, ) -> Self
where 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.

Source

pub fn same_vars(nvars: usize, degree_left: Power, degree_right: Power) -> Self

Plan the product of two polynomials in the same variables.

Source

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.

Source

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.

Source

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.

Source

pub fn apply<LCoeffs, RCoeffs>( &self, coeffs_left: LCoeffs, coeffs_right: RCoeffs, ) -> Result<Mul<'_, LCoeffs, RCoeffs>, Error>
where LCoeffs: Sequence, RCoeffs: Sequence,

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.

Source

pub fn ncoeffs_left(&self) -> usize

Returns the number of coefficients for the left operand.

Source

pub fn ncoeffs_right(&self) -> usize

Returns the number of coefficients for the left operand.

Source

pub fn ncoeffs_output(&self) -> usize

Returns the number of coefficients for the product.

Source

pub fn nvars_output(&self) -> usize

Returns the number of variables for the product.

Source

pub fn degree_output(&self) -> Power

Returns the degree of the product.

Trait Implementations§

Source§

impl Clone for MulPlan

Source§

fn clone(&self) -> MulPlan

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MulPlan

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.