Struct au::polynomial::Poly[][src]

pub struct Poly<T> { /* fields omitted */ }

Polynomial object

Contains the vector of coefficients form the lowest to the highest degree

p(x) = c0 + c1*x + c2*x^2 + ...

Implementations

impl<T: Float + FloatConst> Poly<T>[src]

#[must_use]pub fn mul_fft(self, rhs: Self) -> Self[src]

Polynomial multiplication through fast Fourier transform.

Arguments

  • rhs - right hand side of multiplication

Example

use au::poly;
let a = poly![1., 0., 3.];
let b = poly![1., 0., 3.];
let expected = &a * &b;
let actual = a.mul_fft(b);
assert_eq!(expected, actual);

impl<T: Clone + Div<Output = T> + PartialEq + Zero> Poly<T>[src]

pub fn div_mut(&mut self, d: &T)[src]

In place division with a scalar

Arguments

  • d - Scalar divisor

Example

use au::poly;
let mut p = poly!(3, 4, 5);
p.div_mut(&2);
assert_eq!(poly!(1, 2, 2), p);

impl<T: Clone + Mul<Output = T> + One + PartialEq + Zero> Poly<T>[src]

#[must_use]pub fn powi(&self, exp: u32) -> Self[src]

Calculate the power of a polynomial. With the exponentiation by squaring.

#Arguments

  • exp - Positive integer exponent

Example

use au::poly;
let p = poly!(0, 0, 1);
let pow = p.powi(4);
assert_eq!(poly!(0, 0, 0, 0, 0, 0, 0, 0, 1), pow);

impl<T: Float + RealField> Poly<T>[src]

#[must_use]pub fn real_roots(&self) -> Option<Vec<T>>[src]

Calculate the real roots of the polynomial using companion matrix eigenvalues decomposition.

Example

use au::polynomial::Poly;
let roots = &[1., -1., 0.];
let p = Poly::new_from_roots(roots);
assert_eq!(roots, p.real_roots().unwrap().as_slice());

#[must_use]pub fn complex_roots(&self) -> Vec<Complex<T>>[src]

Calculate the complex roots of the polynomial using companion matrix eigenvalues decomposition.

Example

use au::polynomial::Poly;
let p = Poly::new_from_coeffs(&[1., 0., 1.]);
let i = num_complex::Complex::i();
assert_eq!(vec![-i, i], p.complex_roots());

impl<T: Float + FloatConst> Poly<T>[src]

#[must_use]pub fn iterative_roots(&self) -> Vec<Complex<T>>[src]

Calculate the complex roots of the polynomial using Aberth-Ehrlich method.

Example

use au::polynomial::Poly;
let p = Poly::new_from_coeffs(&[1., 0., 1.]);
let i = num_complex::Complex::i();
assert_eq!(vec![-i, i], p.iterative_roots());

#[must_use]pub fn iterative_roots_with_max(&self, max_iter: u32) -> Vec<Complex<T>>[src]

Calculate the complex roots of the polynomial using companion Aberth-Ehrlich method, with the given iteration limit.

Arguments

  • max_iter - maximum number of iterations for the algorithm

Example

use au::polynomial::Poly;
let p = Poly::new_from_coeffs(&[1., 0., 1.]);
let i = num_complex::Complex::i();
assert_eq!(vec![-i, i], p.iterative_roots_with_max(10));

impl<T> Poly<T>[src]

#[must_use]pub fn as_slice(&self) -> &[T][src]

Return the coefficients of the polynomial as a slice

Example

use au::polynomial::Poly;
let c = &[1., 2., 3.];
let p = Poly::new_from_coeffs(c);
assert_eq!(c, p.as_slice());

impl<T: Clone + PartialEq + Zero> Poly<T>[src]

pub fn new_from_coeffs(coeffs: &[T]) -> Self[src]

Create a new polynomial given a slice of real coefficients. It trims any leading zeros in the high order coefficients.

Arguments

  • coeffs - slice of coefficients

Example

use au::polynomial::Poly;
let p = Poly::new_from_coeffs(&[1., 2., 3.]);

pub fn new_from_coeffs_iter<II>(coeffs: II) -> Self where
    II: IntoIterator<Item = T>, 
[src]

Create a new polynomial given a iterator of real coefficients. It trims any leading zeros in the high order coefficients.

Arguments

  • coeffs - iterator of coefficients

Example

use au::polynomial::Poly;
let p = Poly::new_from_coeffs_iter(1..4);

#[must_use]pub fn degree(&self) -> Option<usize>[src]

Degree of the polynomial

Example

use au::polynomial::Poly;
let p = Poly::new_from_coeffs(&[1., 2., 3.]);
assert_eq!(Some(2), p.degree());

pub fn extend(&mut self, degree: usize)[src]

Extend the polynomial coefficients with 0 to the given degree in place. It does not truncate the polynomial.

Arguments

  • degree - Degree of the new highest coefficient.

Example

use au::polynomial::Poly;
let mut p = Poly::new_from_coeffs(&[1, 2, 3]);
p.extend(5);
assert_eq!(vec![1, 2, 3, 0, 0, 0], p.coeffs());

impl<T: Clone + Div<Output = T> + One + PartialEq + Zero> Poly<T>[src]

#[must_use]pub fn monic(&self) -> (Self, T)[src]

Return the monic polynomial and the leading coefficient.

Example

use au::polynomial::Poly;
let p = Poly::new_from_coeffs(&[1., 2., 10.]);
let (p2, c) = p.monic();
assert_eq!(Poly::new_from_coeffs(&[0.1, 0.2, 1.]), p2);
assert_eq!(10., c);

impl<T: Clone + Div<Output = T> + One + PartialEq + Zero> Poly<T>[src]

pub fn monic_mut(&mut self) -> T[src]

Return the monic polynomial and the leading coefficient, it mutates the polynomial in place.

Example

use au::polynomial::Poly;
let mut p = Poly::new_from_coeffs(&[1., 2., 10.]);
let c = p.monic_mut();
assert_eq!(Poly::new_from_coeffs(&[0.1, 0.2, 1.]), p);
assert_eq!(10., c);

impl<T: Clone + One> Poly<T>[src]

#[must_use]pub fn leading_coeff(&self) -> T[src]

Return the leading coefficient of the polynomial.

Example

use au::polynomial::Poly;
let p = Poly::new_from_coeffs(&[1., 2., 10.]);
let c = p.leading_coeff();
assert_eq!(10., c);

impl<T: Clone + Mul<Output = T> + Neg<Output = T> + One + PartialEq + Zero> Poly<T>[src]

pub fn new_from_roots(roots: &[T]) -> Self[src]

Create a new polynomial given a slice of real roots It trims any leading zeros in the high order coefficients.

Arguments

  • roots - slice of roots

Example

use au::polynomial::Poly;
let p = Poly::new_from_roots(&[1., 2., 3.]);

pub fn new_from_roots_iter<II>(roots: II) -> Self where
    II: IntoIterator<Item = T>, 
[src]

Create a new polynomial given an iterator of real roots It trims any leading zeros in the high order coefficients.

Arguments

  • roots - iterator of roots

Example

use au::polynomial::Poly;
let p = Poly::new_from_roots_iter((1..4));

impl<T: Clone + PartialEq + PartialOrd + Signed + Zero> Poly<T>[src]

pub fn roundoff(&self, atol: &T) -> Self[src]

Round off to zero coefficients smaller than atol.

Arguments

  • atol - Absolute tolerance (should be positive)

Example

 use au::Poly;
 let p = Poly::new_from_coeffs(&[1., 0.002, 1., -0.0001]);
 let actual = p.roundoff(&0.01);
 let expected = Poly::new_from_coeffs(&[1., 0., 1.]);
 assert_eq!(expected, actual);

pub fn roundoff_mut(&mut self, atol: &T)[src]

Round off to zero coefficients smaller than atol in place.

Arguments

  • atol - Absolute tolerance (should be positive)

Example

 use au::Poly;
 let mut p = Poly::new_from_coeffs(&[1., 0.002, 1., -0.0001]);
 p.roundoff_mut(&0.01);
 let expected = Poly::new_from_coeffs(&[1., 0., 1.]);
 assert_eq!(expected, p);

impl<T: Clone + Mul<Output = T> + NumCast + One + PartialEq + Zero> Poly<T>[src]

#[must_use]pub fn derive(&self) -> Self[src]

Calculate the derivative of the polynomial.

Example

use au::polynomial::Poly;
let p = Poly::new_from_coeffs(&[1., 0., 1.]);
let d = p.derive();
assert_eq!(Poly::new_from_coeffs(&[0., 2.]), d);

Panics

Panics when the exponent of the term (usize) cannot be converted to T.

impl<T: Clone + Div<Output = T> + NumCast + PartialEq + Zero> Poly<T>[src]

pub fn integrate(&self, constant: T) -> Self[src]

Calculate the integral of the polynomial. When used with integral types it does not convert the coefficients to floats, division is between integers.

Arguments

  • constant - Integration constant

Example

use au::polynomial::Poly;
let p = Poly::new_from_coeffs(&[1., 0., 3.]);
let d = p.integrate(5.3);
assert_eq!(Poly::new_from_coeffs(&[5.3, 1., 0., 1.]), d);

Panics

Panics when the exponent of the term (usize) cannot be converted to T.

impl<T: Clone> Poly<T>[src]

#[must_use]pub fn coeffs(&self) -> Vec<T>[src]

Vector copy of the polynomial’s coefficients

Example

use au::polynomial::Poly;
let p = Poly::new_from_coeffs(&[1., 2., 3.]);
assert_eq!(vec![1., 2., 3.], p.coeffs());

pub fn eval_by_val<U>(&self, x: U) -> U where
    U: Add<T, Output = U> + Clone + Mul<U, Output = U> + Zero
[src]

Evaluate the polynomial using Horner’s method.

Arguments

  • x - Value at which the polynomial is evaluated.

Example

use au::{num_complex::Complex, Poly};
let p = Poly::new_from_coeffs(&[0., 0., 2.]);
assert_eq!(18., p.eval_by_val(3.));
assert_eq!(Complex::new(-18., 0.), p.eval_by_val(Complex::new(0., 3.)));

impl<T> Poly<T>[src]

pub fn eval<'a, U>(&'a self, x: &'a U) -> U where
    T: 'a,
    U: 'a + Add<&'a T, Output = U> + Mul<&'a U, Output = U> + Zero
[src]

Evaluate the polynomial using Horner’s method.

Arguments

  • x - Value at which the polynomial is evaluated.

Example

use au::{num_complex::Complex, Poly};
let p = Poly::new_from_coeffs(&[0., 0., 2.]);
assert_eq!(18., p.eval(&3.));
assert_eq!(Complex::new(-18., 0.), p.eval(&Complex::new(0., 3.)));

Trait Implementations

impl<T: Clone + PartialEq + Zero> Add<&'_ Poly<T>> for &Poly<T>[src]

Implementation of polynomial addition

type Output = Poly<T>

The resulting type after applying the + operator.

impl<'a, T> Add<&'a Poly<T>> for Poly<T> where
    T: Add<&'a T, Output = T> + Clone + PartialEq + Zero
[src]

Implementation of polynomial addition

type Output = Self

The resulting type after applying the + operator.

impl<'a, T: Add<&'a T, Output = T> + Clone> Add<&'a T> for Poly<T>[src]

Implementation of polynomial and real number addition

type Output = Self

The resulting type after applying the + operator.

impl<T: Add<Output = T> + Clone + PartialEq + Zero> Add<Poly<T>> for Poly<T>[src]

Implementation of polynomial addition

type Output = Self

The resulting type after applying the + operator.

impl<T: Add<Output = T> + Clone> Add<T> for Poly<T>[src]

Implementation of polynomial and real number addition

type Output = Self

The resulting type after applying the + operator.

impl<T: Add<Output = T> + Clone> Add<T> for &Poly<T>[src]

Implementation of polynomial and real number addition

type Output = Poly<T>

The resulting type after applying the + operator.

impl<T> AsRef<[T]> for Poly<T>[src]

View the Poly coefficients as slice.

impl<T: Binary + PartialOrd + Zero> Binary for Poly<T>[src]

impl<T: Clone> Clone for Poly<T>[src]

impl<T: Debug> Debug for Poly<T>[src]

impl<T: Display + PartialOrd + Zero> Display for Poly<T>[src]

impl<T: Float> Div<&'_ Poly<T>> for &Poly<T>[src]

Implementation of division between polynomials

Panics

This method panics if the denominator is zero.

type Output = Poly<T>

The resulting type after applying the / operator.

impl<'a, T> Div<&'a T> for &'a Poly<T> where
    T: Clone + PartialEq + Zero,
    &'a T: Div<Output = T>, 
[src]

Implementation of polynomial and real number division

type Output = Poly<T>

The resulting type after applying the / operator.

impl<T: Float> Div<Poly<T>> for Poly<T>[src]

Implementation of division between polynomials

Panics

This method panics if the denominator is zero.

type Output = Self

The resulting type after applying the / operator.

impl<T: Clone + Div<Output = T> + PartialEq + Zero> Div<T> for Poly<T>[src]

Implementation of polynomial and real number division

type Output = Self

The resulting type after applying the / operator.

impl<T: Clone + Div<Output = T> + PartialEq + Zero> Div<T> for &Poly<T>[src]

Implementation of polynomial and real number division

type Output = Poly<T>

The resulting type after applying the / operator.

impl<T> Index<usize> for Poly<T>[src]

Implement read only indexing of polynomial returning its coefficients.

Panics

Panics for out of bounds access.

Example

use au::polynomial::Poly;
let p = Poly::new_from_coeffs(&[0, 1, 2, 3]);
assert_eq!(2, p[2]);

type Output = T

The returned type after indexing.

impl<T> IndexMut<usize> for Poly<T>[src]

Implement mutable indexing of polynomial returning its coefficients. Misuse of this method may invalidate some polynomial invariant. If some coefficient is zeroed a call to roundoff of roundoff_mut may be needed.

Panics

Panics for out of bounds access.

Example

use au::polynomial::Poly;
let mut p = Poly::new_from_coeffs(&[0, 1, 2, 3]);
p[2] = 4;
assert_eq!(4, p[2]);

impl<T: LowerExp + PartialOrd + Zero> LowerExp for Poly<T>[src]

impl<T: LowerHex + PartialOrd + Zero> LowerHex for Poly<T>[src]

impl<T: Clone + Mul<Output = T> + PartialEq + Zero> Mul<&'_ Poly<T>> for &Poly<T>[src]

Implementation of polynomial multiplication

type Output = Poly<T>

The resulting type after applying the * operator.

impl<T: Clone + Mul<Output = T> + PartialEq + Zero> Mul<&'_ Poly<T>> for Poly<T>[src]

Implementation of polynomial multiplication

type Output = Self

The resulting type after applying the * operator.

impl<T: Clone + Mul<Output = T> + PartialEq + Zero> Mul<&'_ T> for Poly<T>[src]

Implementation of polynomial and float multiplication

type Output = Self

The resulting type after applying the * operator.

impl<T: Clone + Mul<Output = T> + PartialEq + Zero> Mul<&'_ T> for &Poly<T>[src]

Implementation of polynomial and float multiplication

type Output = Poly<T>

The resulting type after applying the * operator.

impl<T: Clone + Mul<Output = T> + PartialEq + Zero> Mul<Poly<T>> for Poly<T>[src]

Implementation of polynomial multiplication

type Output = Self

The resulting type after applying the * operator.

impl<T: Clone + Mul<Output = T> + PartialEq + Zero> Mul<T> for Poly<T>[src]

Implementation of polynomial and float multiplication

type Output = Self

The resulting type after applying the * operator.

impl<T: Clone + Mul<Output = T> + PartialEq + Zero> Mul<T> for &Poly<T>[src]

Implementation of polynomial and float multiplication

type Output = Poly<T>

The resulting type after applying the * operator.

impl<T: Clone + Neg<Output = T>> Neg for &Poly<T>[src]

Implementation of polynomial negation

type Output = Poly<T>

The resulting type after applying the - operator.

impl<T: Clone + Neg<Output = T>> Neg for Poly<T>[src]

Implementation of polynomial negation

type Output = Self

The resulting type after applying the - operator.

impl<T: Octal + PartialOrd + Zero> Octal for Poly<T>[src]

impl<T: Clone + Mul<Output = T> + One + PartialEq + Zero> One for Poly<T>[src]

Implementation of the multiplicative identity for polynomials

Example

use au::{num_traits::One, polynomial::Poly};
let one = Poly::<u8>::one();
assert!(one.is_one());

impl<T: PartialEq> PartialEq<Poly<T>> for Poly<T>[src]

impl<T: Float> Rem<&'_ Poly<T>> for &Poly<T>[src]

Implementation of reminder between polynomials.

Panics

This method panics if the denominator is zero.

type Output = Poly<T>

The resulting type after applying the % operator.

impl<T: Float> Rem<Poly<T>> for Poly<T>[src]

Implementation of reminder between polynomials.

Panics

This method panics if the denominator is zero.

type Output = Self

The resulting type after applying the % operator.

impl<T> StructuralPartialEq for Poly<T>[src]

impl<T: Clone + PartialEq + Sub<Output = T> + Zero> Sub<&'_ Poly<T>> for &Poly<T>[src]

Implementation of polynomial subtraction

type Output = Poly<T>

The resulting type after applying the - operator.

impl<T: Clone + PartialEq + Sub<Output = T> + Zero> Sub<Poly<T>> for Poly<T>[src]

Implementation of polynomial subtraction

type Output = Self

The resulting type after applying the - operator.

impl<T: Clone + Sub<Output = T>> Sub<T> for Poly<T>[src]

Implementation of polynomial and real number subtraction

type Output = Self

The resulting type after applying the - operator.

impl<T: Clone + Sub<Output = T>> Sub<T> for &Poly<T>[src]

Implementation of polynomial and real number subtraction

type Output = Poly<T>

The resulting type after applying the - operator.

impl<T: UpperExp + PartialOrd + Zero> UpperExp for Poly<T>[src]

impl<T: UpperHex + PartialOrd + Zero> UpperHex for Poly<T>[src]

impl<T: Clone + PartialEq + Zero> Zero for Poly<T>[src]

Implementation of the additive identity for polynomials

Example

use au::{num_traits::Zero, polynomial::Poly};
let zero = Poly::<u8>::zero();
assert!(zero.is_zero());

Auto Trait Implementations

impl<T> RefUnwindSafe for Poly<T> where
    T: RefUnwindSafe

impl<T> Send for Poly<T> where
    T: Send

impl<T> Sync for Poly<T> where
    T: Sync

impl<T> Unpin for Poly<T> where
    T: Unpin

impl<T> UnwindSafe for Poly<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> ClosedNeg for T where
    T: Neg<Output = T>, 

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, Rhs, Output> NumOps<Rhs, Output> for T where
    T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<SS, SP> SupersetOf<SS> for SP where
    SS: SubsetOf<SP>, 

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,