[][src]Struct polynomials::Polynomial

pub struct Polynomial<T>(_);

A Polynomial is just a vector of coefficients. Each coefficient corresponds to a power of x in increasing order. For example, the following polynomial is equal to 4x^2 + 3x - 9.

// Construct polynomial 4x^2 + 3x - 9
let mut a = poly![-9, 3, 4];
assert_eq!(a[0], -9);
assert_eq!(a[1], 3);
assert_eq!(a[2], 4);

Implementations

impl<T> Polynomial<T>[src]

pub fn new() -> Polynomial<T>[src]

Create a new, empty, instance of a polynomial.

pub fn push(&mut self, value: T)[src]

Adds a new coefficient to the Polynomial, in the next highest order position.

let mut a = poly![-8, 2, 4];
a.push(7);
assert_eq!(a, poly![-8, 2, 4, 7]);

pub fn pop(&mut self) -> Option<T>[src]

Removes the highest order coefficient from the Polynomial.

let mut a = poly![-8, 2, 4];
assert_eq!(a.pop().unwrap(), 4);
assert_eq!(a, poly![-8, 2]);

pub fn degree(&self) -> usize where
    T: Sub<T, Output = T> + Eq + Copy
[src]

Calculates the degree of a Polynomial.

The following polynomial is of degree 2: (4x^2 + 2x - 8)

let a = poly![-8, 2, 4];
assert_eq!(a.degree(), 2);

pub fn eval<X>(&self, x: X) -> Option<T> where
    T: AddAssign + Copy,
    X: MulAssign + Mul<T, Output = T> + Copy
[src]

Evaluate a Polynomial for some value x.

The following example evaluates the polynomial (4x^2 + 2x - 8) for x = 3.

let a = poly![-8, 2, 4];
assert_eq!(a.eval(3).unwrap(), 34);

pub fn iter(&self) -> impl Iterator<Item = &T>[src]

pub fn into_iter(self) -> impl IntoIterator<Item = T, IntoIter = IntoIter<T>>[src]

Trait Implementations

impl<T: Add<Output = T>> Add<Polynomial<T>> for Polynomial<T> where
    T: Add + Copy + Clone
[src]

Add two Polynomials.

The following example adds two polynomials: (4x^2 + 2x - 8) + (x + 1) = (4x^2 + 3x - 7)

let a = poly![-8, 2, 4];
let b = poly![1, 1];
assert_eq!(a + b, poly![-7, 3, 4]);

type Output = Self

The resulting type after applying the + operator.

impl<T> AddAssign<Polynomial<T>> for Polynomial<T> where
    T: Add<Output = T> + Copy
[src]

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

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

impl<'de, T> Deserialize<'de> for Polynomial<T> where
    T: Deserialize<'de>, 
[src]

impl<T> Div<T> for Polynomial<T> where
    T: DivAssign + Copy
[src]

Divide a Polynomial by some value.

The following example divides a polynomial (4x^2 + 2x - 8) by 2:

let p = poly![-8, 2, 4] / 2;
assert_eq!(p, poly![-4, 1, 2]);

type Output = Self

The resulting type after applying the / operator.

impl<T> DivAssign<T> for Polynomial<T> where
    T: DivAssign + Copy
[src]

impl<T> Eq for Polynomial<T> where
    T: Sub<T, Output = T> + Eq + Copy
[src]

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

impl<T, I: SliceIndex<[T]>> Index<I> for Polynomial<T>[src]

type Output = I::Output

The returned type after indexing.

impl<T, I: SliceIndex<[T]>> IndexMut<I> for Polynomial<T>[src]

impl<T> Into<Vec<T>> for Polynomial<T>[src]

impl<T> Mul<Polynomial<T>> for Polynomial<T> where
    T: Mul<Output = T> + AddAssign + Sub<Output = T>,
    T: Copy + Clone
[src]

Multiply a Polynomial by some value.

The following example multiplies a polynomial (4x^2 + 2x - 8) by 2:

let p = poly![-8, 2, 4] * 2;
assert_eq!(p, poly![-16, 4, 8]);

type Output = Self

The resulting type after applying the * operator.

impl<T> Mul<T> for Polynomial<T> where
    T: MulAssign + Copy
[src]

Multiply two Polynomials.

The following example multiplies two polynomials: (4x^2 + 2x - 8) * (x + 1) = (4x^3 + 6x^2 - 6x - 8)

let a = poly![-8, 2, 4];
let b = poly![1, 1];
assert_eq!(a * b, poly![-8, -6, 6, 4]);

type Output = Self

The resulting type after applying the * operator.

impl<T> MulAssign<Polynomial<T>> for Polynomial<T> where
    T: Mul<Output = T> + AddAssign + Sub<Output = T>,
    T: Copy + Clone
[src]

impl<T> MulAssign<T> for Polynomial<T> where
    T: MulAssign + Copy
[src]

impl<T> PartialEq<Polynomial<T>> for Polynomial<T> where
    T: Sub<T, Output = T> + Eq + Copy
[src]

impl<T> Serialize for Polynomial<T> where
    T: Serialize
[src]

impl<T: Sub<Output = T>> Sub<Polynomial<T>> for Polynomial<T> where
    T: Sub + Neg<Output = T> + Copy + Clone
[src]

Subtract two Polynomials.

The following example subtracts two polynomials: (4x^2 + 2x - 8) - (x + 1) = (4x^2 + x - 9)

let a = poly![-8, 2, 4];
let b = poly![1, 1];
assert_eq!(a - b, poly![-9, 1, 4]);

type Output = Self

The resulting type after applying the - operator.

impl<T> SubAssign<Polynomial<T>> for Polynomial<T> where
    T: Sub<Output = T> + Neg<Output = T> + Copy
[src]

Auto Trait Implementations

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

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

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

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

impl<T> UnwindSafe for Polynomial<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> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

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

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

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

type Owned = T

The resulting type after obtaining ownership.

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.